/**
* @author fcolusso
*/
var w3gMappaTerritoriale = Class.create();
Object.extend(w3gMappaTerritoriale.prototype,{
net:{
actionNav: '/atportal/mappaTerritorialeVisualizzaImmagine.do?img=imgG',
actionGeo: '/atportal/mappaTerritorialeInit.do?op=G&mode=init'
},
options: {},
keybindings:{},
container: false,
map: false,
slider:false,
moveBy:200,
tracker:false,
labels:{
reset:'torna al punto di partenza',
path:'calcola percorso da...',
print:'stampa pagina',
info:'mostra/nascondi indirizzo',
zoombounds:'disegna area di zoom',
moveup:'sposta verso l`alto',
movedown:'sposta verso il basso',
moveleft:'sposta verso sinistra',
moveright:'sposta verso destra',
zoomin:'zoom avanti',
zoomout:'zoom indietro',
tracker:'trascina per zoomare',
locazione:'indirizzo',
title:'Mappe Territoriali',
error:'Sessione scaduta.
Si prega di chiudere la finestra.',
printdialog:'Scrivi qui sotto le tue annotazioni.
Verrano stampate sotto la mappa.'
},
/**
Costructor
@param container: Id or div container element
@param options
*/
initialize: function(container, options){
container = $(container);
this.runtime={};
this.runtime.edgebounds={
max: 21875000,
min: 700,
width: 770,
height: 550
}
this.runtime.requests= $A(new Array());
this.preventAction=false;
this.printer =false;
this.observeHandlers = {}; // stack of event handler functions
this.session={};
this.session.eventsRegistry={};
this.keybindings={
/*sx*/ 37:this.moveMapWindow.bind(this,{x:this.moveBy,y:0}),
/*su*/ 38:this.moveMapWindow.bind(this,{x:0,y:this.moveBy}),
/*dx*/ 39:this.moveMapWindow.bind(this,{x:-this.moveBy,y:0}),
/*giu*/ 40:this.moveMapWindow.bind(this,{x:0,y:-this.moveBy}),
/*HOME*/ 36:this.reset.bind(this),
/*PAGUP*/ 33:this.scaleUp.bind(this),
/*PAGDOWN*/ 34:this.scaleDown.bind(this),
/*DEL*/ 46:this.abort.bind(this)
}
this.options={
mapSize:{
width:container.getDimensions().width || parseInt(container.getStyle('width')),
height:container.getDimensions().height || parseInt(container.getStyle('height'))
}, //image size in pixels
useSlider:true, //enable zoom slider
scale:7000, //starting map scale
sliderStart:5, //starting zoom value value
info:{},
poi:false,
noCPin: false
};
this.options.noCPin= typeof options.info == 'undefined' || options.info == false;
this.runtime.centerCoord = false;
this.runtime.centerOffset= {left:0,top:0}
this.html={};
this.xhttp = false;
this.container = $(container);
Object.extend(this.options, options||{});
this.load();
},
reload:function(options){
this.disabled();
//this.abort();
this.dialog.hide();
this.loader.show();
this.deletePOI();
this.options.info.coords=false;
this.load(options);
},
load:function(options){
var next_f = options ? Prototype.emptyFunction :this.setup.bind(this);
var complete_f = options ? this.reset.bind(this):this.setup.bind(this);
next_f = this.__ready.bind(this,next_f);
//complete_f = this.__ready.bind(this,complete_f);
this.runtime.centerCoord = false;
Object.extend(this.options, options||{});
if(this.options.poi && !this.options.info.coords){
if(this.options.noCPin && this.buttons){
this.buttons.info.hide();
this.buttons.path.hide();
this.buttons.print.hide();
}
var y= {max:0,min:0}
var x= {max:0,min:0}
var validPOI = $A(new Array());
for(var i =0; i< this.options.poi.length; i++){
var poi = this.options.poi[i].coords;
//is valid POI
if(poi.y >0 && poi.x>0){
validPOI.push(this.options.poi[i]);
y.max = Math.max(poi.y,y.max);
x.max = Math.max(poi.x,x.max);
y.min = y.min == 0 ? poi.y : Math.min(poi.y,y.min);
x.min = x.min == 0 ? poi.x : Math.min(poi.x,x.min);
}
}
if(validPOI.length != this.options.poi.length){
this.options.poi = validPOI.toArray();
if(this.options.poi.length == 0){
//NO POI TO DISPLAY --EXIT
return;
}
}
x.delta = (x.max - x.min);
x.delta = x.delta ==0 ? 0 : x.delta / 2;
y.delta = (y.max - y.min);
y.delta = y.delta ==0 ? 0 : y.delta / 2;
this.runtime.centerCoord={
x: parseInt(x.min) + parseInt(x.delta),
y: parseInt(y.min) + parseInt(y.delta)
}
this.options.scale = Math.max(x.max - x.min, y.max - y.min);
if(this.options.scale!=0){
this.options.scale = Math.max(
parseInt(this.options.scale / this.options.mapSize.width * this.runtime.edgebounds.width),
parseInt(this.options.scale / this.options.mapSize.height * this.runtime.edgebounds.height));
}
this.options.scale = this.options.scale || 7000;
}
// var callback = options ? this.setup : this.reset;
this.xhttp = false;
this.session.originalSrc = this.net.actionNav+'&mapW='+this.options.mapSize.width+'&mapH='+this.options.mapSize.height+'&scale='+this.options.scale; //map +="ctrl=xhttp";
this.runtime.centerCoord = this.options.info.coords || this.runtime.centerCoord;
if(!this.loader){
this.loader =$(document.createElement('DIV')).addClassName('mappaTerritoriale-Loader');
this.container.up().appendChild(this.loader);
this.loader.dim ={width :100,height : 100}
Position.clone(this.container,this.loader,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width/2 -(this.loader.dim.width/2),offsetTop:this.options.mapSize.height/2 -(this.loader.dim.height/2)});
}
this.loader.show();
if(this.options.info && this.runtime.centerCoord){
this.sendRequest({
ppX:this.runtime.centerCoord.x,
ppY:this.runtime.centerCoord.y,
mapW:this.options.mapSize.width,
mapH:this.options.mapSize.height,
scale:this.options.scale,
act:'go'
},complete_f,this.net.actionGeo);
}else
next_f();
},
__ready:function(next){
if(next){
var readyState = 'unknow';
try{
readyState = document.readyState;
}catch(e){}
if(!/complete/.test(readyState)){
Event.observe(window,'load',next);
//onloadAddFunction(next);
}else{
next();
}
}
},
setup:function(){
this.container.setStyle({overflow:'hidden',position:'relative','text-align':'center'})
this.map = $(document.createElement('IMG'));
this.maploader = $(document.createElement('IMG'));
this.upperlayer = $(document.createElement('DIV'));
this.upperlayer.addClassName('mtbtn-upperLayer');
this.mappin = $(document.createElement('DIV'));
this.mappin.addClassName('mtbtn-mapPin');
this.mappin.setStyle({position:'absolute'});
this.markerpin = $(document.createElement('DIV'));
this.markerpin.addClassName('mtbtn-markerPin');
this.markerpin.setStyle({position:'absolute'});
this.w3glogo = $(document.createElement('DIV'));
this.w3glogo.addClassName('mtbtn-w3gLogo');
this.w3glogo.setStyle({position:'absolute'});
this.cmdform = $(document.createElement('FORM'));
this.mappin.hide();
this.markerpin.hide();
this.cmdform.setStyle({display:'none'});
this.map.setAttribute('galleryimg','no'); //disable IE img contex menu
this.maploader.setAttribute('galleryimg','no');
this.session.currentScale = false;
this.session.delta={x:0,y:0}; //
this.session.traslation={x:0,y:0};
this.session.currentEdge = this.snapEdge(this.options.scale);
this.session.defaultCursor='url(/atportal/services/pw/mappaTerritoriale/images/drag.cur), move';
this.upperlayer.style.cursor=this.session.defaultCursor;
this.map.setStyle({display:'none',position:'relative'});
this.maploader.setStyle({display:'none',position:'relative',visibility:'hidden'});
this.upperlayer.setStyle({width:this.options.mapSize.width,height:this.options.mapSize.height,
border:'none',display:'none',position:'absolute',visibility:'hidden'});
this.observeHandlers.mapLoaded = this.mapLoaded.bind(this);
this.registerEvent(window,'resize',this.resizeHandler.bind(this));
//IE fix for IFRAME manipulation (execute on document rendering)
if(!this.printer){
this.printer = $(document.createElement('iframe'));
this.printer.setAttribute('id','mtPrinterFrame');
this.printer.setAttribute('name','mtPrinterFrame');
if(!/MSIE/.test(navigator.userAgent)){
this.container.up().appendChild(this.printer);
this.printer.setStyle({border:'none',width:'0px',height:'0px',visibility:'hidden',display:'block'});
}
}
this.timers={keepAlive: true};
this.draw();
},
/**
Send periodical xhttp request for keep alive user session
@param Number time: interval beetween request, '0' value stop temporization
*/
keepAlive:function(time){
if(!this.timers.keepAlive) return;
if(time==0){
clearTimeout(this.timers.keepAlive);
this.timers.keepAlive = false;
}else{
this.timers.keepAlive = setTimeout(this.sendRequest.bind(this,{ctrl:'keepAlive'},this.keepAlive.bind(this,time),null),time);
}
},
/**
Enable map Drag & drop
*/
enabled:function(){
this.slider.control.options.onSlide = this.observeHandlers.onslide;
this.slider.control.options.onChange= this.observeHandlers.onslidechange;
this.preventAction = false;
this.upperlayer.update(' ')
if(this.session.drag)return;
this.session.draggable = true;
this.dragStartAt=false;
this.upperlayer.setStyle({'background-color':'white'});
this.upperlayer.setOpacity(0);
try{
this.upperlayer.focus();
}catch(e){}
this.session.drag = new Draggable(this.map,{
onEnd:this.dragEnd.bind(this),
onStart:this.dragStart.bindAsEventListener(this),
onDrag:this.dragWatcher.bindAsEventListener(this),
snap:this.snapRegion.bind(this),
revert:false,
/*endeffect:false,*/
handle:this.upperlayer
});
},
/**
Map Drag end handler
; @param event
*/
dragEnd:function(event){
Position.clone(this.map,this.upperlayer);
if(!this.options.noCPin){
Position.clone(this.map,this.mappin,{setWidth:false,setHeight:false,offsetLeft: this.mappin.offset.left,offsetTop: this.mappin.offset.top});
this.mappin.show();
}
this.showPOI();
this.markerpin.hide();
this.popup.hide();
this.traslateMap();
},
/**
Map Drag handler
@param event
*/
dragWatcher:function(event){
//Position.clone(this.map,this.upperlayer,{offsetLeft:0,offsetTop:0});
},
/**
Map Drag start handler
@param event
*/
dragStart:function(event){
this.map.setStyle({visibility:'visible'});
this.upperlayer.style.cursor='move';
var delta = Position.cumulativeOffset(this.map);
delta = {x:delta[0]- this.session.mapStartOffset.left,y:delta[1]- this.session.mapStartOffset.top}
if(!this.dragStartAt || isNaN(this.dragStartAt.x) || isNaN(this.dragStartAt.y))
this.dragStartAt=delta;
var ret= {x: delta.x- this.dragStartAt.x,y: delta.y- this.dragStartAt.y }
this.dragStartAt=delta;
this.mappin.hide();
this.hidePOI();
return ret;
},
/**
Disable map Drag & drop
*/
disabled:function(){
try{
this.slider.control.options.onSlide = Prototype.emptyFunction;
this.slider.control.options.onChange=Prototype.emptyFunction;
this.preventAction = true;
this.session.drag.destroy();
this.session.drag=false;
}catch(er){}
},
/**
Block map drag in a box region
@param x
@param y
*/
snapRegion: function(x,y) {
var map={w:this.options.mapSize.width/2-10,h:this.options.mapSize.height/2-10}
var bound={x0: map.w,x1: -map.w,y0: map.h,y1: -map.h}
x= x < bound.x0 ? (x > bound.x1 ? x : bound.x1 ) : bound.x0;
y= y < bound.y0 ? (y > bound.y1 ? y : bound.y1 ) : bound.y0;
return [x,y];
},
/**
Apply ALT & TITLE text to an element
@param element
@param label: text to apply in ALT and TITLE element's attribute
*/
applyLabel:function(element,label){
element.setAttribute("alt",label);
element.setAttribute("title",label);
},
/**
Draw map and controls (attach Event observer also).
*/
draw: function(){
this.w3glogo.update(' ');
this.container.appendChild(this.maploader);
this.container.appendChild(this.map);
this.container.appendChild(this.mappin);
this.container.appendChild(this.markerpin);
this.container.appendChild(this.w3glogo);
this.container.appendChild(this.upperlayer);
this.container.up().appendChild(this.cmdform);
if(!/MSIE/.test(navigator.userAgent)){
this.printer= window.frames['mtPrinterFrame'];
}
Position.clone(this.map,this.upperlayer);
//animate loading gif
this.smallloader = $(document.createElement('DIV')).addClassName('mappaTerritoriale-LoaderSmall');
this.loader.hide();
this.buttons={};
/******* CONTROLS *****/
this.buttons.moveup = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-up']);
this.container.up().appendChild(this.buttons.moveup);
this.bwidth = parseInt(this.buttons.moveup.getStyle("width"));
this.bheight = parseInt(this.buttons.moveup.getStyle("height"));
Position.absolutize(this.buttons.moveup);
Position.clone(this.container,this.buttons.moveup,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width/2 -(this.bwidth/2),offsetTop:-(this.bheight/2)});
this.buttons.movedown = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-down']);
this.container.up().appendChild(this.buttons.movedown)
Position.absolutize(this.buttons.movedown);
Position.clone(this.container,this.buttons.movedown,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width/2 -(this.bwidth/2),offsetTop:this.options.mapSize.height-(this.bheight/2)});
this.buttons.moveleft = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-left']);
this.container.up().appendChild(this.buttons.moveleft)
Position.absolutize(this.buttons.moveleft);
Position.clone(this.container,this.buttons.moveleft,{setWidth:false,setHeight:false,offsetLeft: -(this.bwidth/2),offsetTop:this.options.mapSize.height/2-(this.bheight/2)});
this.buttons.moveright = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-right']);
this.container.up().appendChild(this.buttons.moveright)
Position.absolutize(this.buttons.moveright);
Position.clone(this.container,this.buttons.moveright,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width-(this.bwidth/2),offsetTop:this.options.mapSize.height/2-(this.bheight/2)});
this.commandBar = $(document.createElement('DIV')).addClassName('mappaTerritoriale-commandBar');
this.container.up().appendChild(this.commandBar);
Position.absolutize(this.commandBar);
Position.clone(this.container,this.commandBar,{setWidth:false,setHeight:false,offsetLeft:5,offsetTop:5});
this.commandBar.style.width='auto';
this.buttons.reset = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-reset']);
this.commandBar.appendChild(this.buttons.reset);
this.buttons.info = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-info']);
this.commandBar.appendChild(this.buttons.info);
this.buttons.path = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-path']);
this.commandBar.appendChild(this.buttons.path);
this.buttons.print = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-print']);
this.commandBar.appendChild(this.buttons.print);
this.buttons.zoombounds = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-bounds']);
this.commandBar.appendChild(this.buttons.zoombounds);
this.buttons.coordsInfo = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-bounds']);
if(this.options.noCPin){
this.buttons.info.hide();
this.buttons.path.hide();
this.buttons.print.hide();
}
this.controls = $(document.createElement('DIV')).addClassName("mappaTerritoriale-ScaleControl");
this.container.up().appendChild(this.controls);
Position.absolutize(this.controls);
this.controls.setStyle({width: '26px',height:'186px'});
this.controls.bg = $(document.createElement('DIV')).addClassName("mappaTerritoriale-Background");
this.controls.appendChild(this.controls.bg);
this.controls.setStyle({width: '26px'});
this.zoom = $(document.createElement('DIV'));
this.buttons.zoomin = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-zoomin']);
this.buttons.zoomout = $(document.createElement('DIV')).addClassName(['mappaTerritoriale-Button','mtbtn-zoomout']);
this.controls.bg.appendChild(this.buttons.zoomout);
Position.clone(this.container,this.controls,{setWidth:false,setHeight:false,offsetLeft:this.options.mapSize.width-this.bwidth-10,offsetTop:25});
this.slider = $(document.createElement('DIV'));
this.slider.setStyle({position:'relative',height:'140px'});
this.tracker = $(document.createElement('DIV'));
this.tracker.addClassName('mappaTerritoriale-Tracker');
this.tracker.setStyle({left:'0px'});
this.tracker.update(' ');
this.slider.appendChild(this.tracker);
this.controls.bg.appendChild(this.slider)
this.controls.bg.appendChild(this.buttons.zoomin);
this.observeHandlers.onslide=this.redimMap.bind(this);
this.observeHandlers.onslidechange=this.scaleMap.bind(this);
//Script.aculo.us slider
this.slider.control =new Control.Slider( this.tracker, this.slider,{
axis:'vertical',
range: $R(1, 10),
sliderValue: this.options.sliderStart,
increment:0.1,
onSlide:this.observeHandlers.onslide,
onChange:this.observeHandlers.onslidechange
});
this.slider.control.setDeltaValue=function(delta) {
this.setValueBy(-delta);
}
this.slider.addClassName('mappaTerritoriale-Slider');
//Controls label
this.applyLabel(this.buttons.moveup,this.labels.moveup);
this.applyLabel(this.buttons.movedown,this.labels.movedown);
this.applyLabel(this.buttons.moveleft,this.labels.moveleft);
this.applyLabel(this.buttons.moveright,this.labels.moveright);
this.applyLabel(this.buttons.reset,this.labels.reset);
this.applyLabel(this.buttons.info,this.labels.info);
this.applyLabel(this.buttons.path,this.labels.path);
this.applyLabel(this.buttons.print,this.labels.print);
this.applyLabel(this.buttons.zoombounds,this.labels.zoombounds);
this.applyLabel(this.tracker,this.labels.tracker);
this.applyLabel(this.buttons.zoomin,this.labels.zoomin);
this.applyLabel(this.buttons.zoomout,this.labels.zoomout);
this.applyLabel(this.buttons.coordsInfo,this.labels.zoomout);
//Event observer
this.registerEvent(this.buttons.reset,'click',this.__doAction.bind(this,this.reset.bind(this)));
this.registerEvent(this.buttons.zoomout,'click',this.__doAction.bind(this,this.scaleUp.bindAsEventListener(this)));
this.registerEvent(this.buttons.zoomin,'click',this.__doAction.bind(this,this.scaleDown.bindAsEventListener(this)));
this.registerEvent(this.buttons.moveup,'click',this.__doAction.bind(this,this.moveMapWindow.bind(this,{x:0,y:this.moveBy})));
this.registerEvent(this.buttons.movedown,'click',this.__doAction.bind(this,this.moveMapWindow.bind(this,{x:0,y:-this.moveBy})));
this.registerEvent(this.buttons.moveleft,'click',this.__doAction.bind(this,this.moveMapWindow.bind(this,{x:this.moveBy,y:0})));
this.registerEvent(this.buttons.moveright,'click',this.__doAction.bind(this,this.moveMapWindow.bind(this,{x:-this.moveBy,y:0})));
this.registerEvent(this.buttons.zoombounds,'click',this.__doAction.bind(this,this.observeBoundsRegion.bindAsEventListener(this)));
this.registerEvent(this.buttons.path,'click',this.__doAction.bind(this,this.togglePathRequest.bind(this)));
this.registerEvent(this.buttons.print,'click',this.__doAction.bind(this,this.print.bind(this)));
this.registerEvent(this.buttons.info,'click',this.__doAction.bind(this,this.toggleMapInfo.bind(this)));
this.registerEvent(this.buttons.coordsInfo, 'click', this.__doAction.bind(this,this.coordTrackerInit.bindAsEventListener(this)));
this.registerEvent(this.container, 'DOMMouseScroll', this.__doAction.bind(this,this.wheel.bind(this)));// mozilla
this.registerEvent(this.container, 'mousewheel', this.__doAction.bind(this,this.wheel.bind(this)));// IE/Opera
this.registerEvent(document, 'keypress', this.keypressHandler.bindAsEventListener(this));
//information box
this.dialog = $(document.createElement('DIV')).addClassName('mtDialogs');
this.map.onselectstart=function(){return false;};
this.container.up().appendChild(this.dialog);
this.dialog.setOpacity(0.90);
Position.absolutize(this.dialog);
this.dialog.setStyle({display:'none',height:'auto'});
Position.clone(this.container,this.dialog,{setHeight:false,setWidth:false,offsetLeft:10,offsetTop:35});
this.dialog.update('');
this.dialog.header = Element.getElementsByClassName(this.dialog,'mtDialogs-header')[0];
this.dialog.body =Element.getElementsByClassName(this.dialog,'mtDialogs-body')[0];
this.dialog.icon = Element.getElementsByClassName(this.dialog,'mtDialogs-icon')[0];
this.dialog.message = Element.getElementsByClassName(this.dialog,'mtDialogs-message')[0];
this.dialog.footer = Element.getElementsByClassName(this.dialog,'mtDialogs-footer')[0];
this.dialog.header.onselectstart=function(){return false;};
//popup tooltips
this.popup = $(document.createElement('DIV')).addClassName('mtTooltip');
this.map.onselectstart=function(){return false;};
this.container.up().appendChild(this.popup);
this.popup.setOpacity(0.70);
Position.absolutize(this.popup);
this.popup.setStyle({display:'none'});
Position.clone(this.container,this.popup,{setHeight:false,setWidth:false});
this.popup.update('');
this.popup.body =Element.getElementsByClassName(this.popup,'mtTooltip-body')[0];
this.popup.message =Element.getElementsByClassName(this.popup,'mtTooltip-message')[0];
if(!this.options.noCPin){
this.showMapInfo();
}
this.changeSource(this.maploader);
this.loader.show();
var errHandler = this.options.onError|| this.errorHandler;
this.registerEvent(this.maploader,'load',this.observeHandlers.mapLoaded );
this.registerEvent(this.map,'error',errHandler.bindAsEventListener(this) );
this.registerEvent(this.maploader,'error',errHandler.bindAsEventListener(this) );
//this.registerEvent(this.map,'abort',errHandler.bindAsEventListener(this) );
//this.registerEvent(this.maploader,'abort',errHandler.bindAsEventListener(this) );
this.zoomer={};
this.zoomer.container=$(document.createElement('DIV')).addClassName('mtbtn-zoomerContainer');
this.zoomer.top=$(document.createElement('DIV')).addClassName('mtbtn-zoomerContainer-top');
this.zoomer.top.appendChild($(document.createElement('DIV')).addClassName('mtbtn-zoomerCorner-topleft'));
this.zoomer.top.appendChild($(document.createElement('DIV')).addClassName('mtbtn-zoomerCorner-topright'));
this.zoomer.middle=$(document.createElement('DIV')).addClassName('mtbtn-zoomerContainer-middle');
this.zoomer.middle.update(' ');
this.zoomer.bottom=$(document.createElement('DIV')).addClassName('mtbtn-zoomerContainer-bottom');
this.zoomer.bottom.appendChild($(document.createElement('DIV')).addClassName('mtbtn-zoomerCorner-bottomleft'));
this.zoomer.bottom.appendChild($(document.createElement('DIV')).addClassName('mtbtn-zoomerCorner-bottomright'));
this.zoomer.container.appendChild(this.zoomer.top);
this.zoomer.container.appendChild(this.zoomer.middle);
this.zoomer.container.appendChild(this.zoomer.bottom);
this.container.up().appendChild(this.zoomer.container);
this.restoreZoomer();
this.keepAlive(600000);
this.notify('load');
},
__doAction:function(action /*,arg1, arg2, arg3, ..., argN*/){
if(!this.preventAction){
if(arguments.length>1){
action(this,$A(arguments).slice(1));
}else{
action();
}
this.notify('action');
}
},
/**
Show path request form in the info box
*/
showCoords:function(response){
if (200 == response.status){
eval('this.xhttp='+response.responseText);
this.popup.mode='info';
/*var closebutton= $(document.createElement('DIV'));
closebutton.addClassName('mtDialogs-CLOSE');
this.popup.header.appendChild(closebutton);
this.registerEvent(closebutton, "click", this.popup.hide.bind(this.popup));*/
this.buildMarkerInfo(this.xhttp);
this.showMapInfo();
this.popup.show();
Position.clone(this.markerpin,this.popup,{setHeight:false,setWidth:false,offsetLeft:-90,offsetTop:-75});
}else{
alert('NO RESPONSE');
}
},
coordTrackerInit:function(event){
this.upperlayer.setStyle({cursor:'crosshair'});
this.disabled();
this.unregisterEvent(this.container,'mousemove',this.observeHandlers.containerMouseMove);
this.observeHandlers.containerMouseMove=this.coordTrackerHandler.bindAsEventListener(this)
this.registerEvent(this.container, 'mousemove',this.observeHandlers.containerMouseMove );
this.unregisterEvent(this.container, 'mousedown', this.observeHandlers.containerMouseDown);
this.observeHandlers.containerMouseDown=this.coordTrackerLunch.bindAsEventListener(this)
this.registerEvent(this.container, 'mousedown',this.observeHandlers.containerMouseDown );
},
coordTrackerHandler:function(event){
this.markerpin.show();
var offset = Position.cumulativeOffset(this.map);
offset = {left:offset[0],top:offset[1]}
this.markerpin.offset={
left: Event.pointerX(event) - offset.left,
top: Event.pointerY(event) - offset.top
}
this.markerpin.show();
this.markerpin.setStyle({left:(this.markerpin.offset.left-10)+'px',top:(this.markerpin.offset.top-18)+'px'})
},
coordTrackerLunch:function(event){
this.unregisterEvent(this.container, 'mousemove', this.observeHandlers.containerMouseMove)
this.unregisterEvent(this.container, 'mousedown', this.observeHandlers.containerMouseDown);
this.upperlayer.setStyle({cursor:this.session.defaultCursor});
this.enabled();
this.sendRequest(
{ctrl:'xhttp',lookup:this.markerpin.offset.left+":"+this.markerpin.offset.top}
,this.showCoords.bind(this)
);
},
/**
Restore initial attributes of zoomer DIVs
@param width
@param height
@param revert: if 'true' revert div position and flow
*/
restoreZoomer:function(width,height,revert){
if(!revert){
this.zoomer.top.down().removeClassName('mtbtn-zoomerCorner-bottomright').addClassName('mtbtn-zoomerCorner-topleft').setStyle({float:'left'});
this.zoomer.top.down().next().removeClassName('mtbtn-zoomerCorner-bottomleft').addClassName('mtbtn-zoomerCorner-topright').setStyle({float:'right'});
this.zoomer.bottom.down().removeClassName('mtbtn-zoomerCorner-topright').addClassName('mtbtn-zoomerCorner-bottomleft').setStyle({float:'left'});
this.zoomer.bottom.down().next().removeClassName('mtbtn-zoomerCorner-topleft').addClassName('mtbtn-zoomerCorner-bottomright').setStyle({float:'right'});
}else{
this.zoomer.top.down().removeClassName('mtbtn-zoomerCorner-topleft').addClassName('mtbtn-zoomerCorner-bottomright').setStyle({float:'left'});
this.zoomer.top.down().next().removeClassName('mtbtn-zoomerCorner-topright').addClassName('mtbtn-zoomerCorner-bottomleft').setStyle({float:'right'});
this.zoomer.bottom.down().removeClassName('mtbtn-zoomerCorner-bottomleft').addClassName('mtbtn-zoomerCorner-topright').setStyle({float:'left'});
this.zoomer.bottom.down().next().removeClassName('mtbtn-zoomerCorner-bottomright').addClassName('mtbtn-zoomerCorner-topleft').setStyle({float:'right'});
}
if(!width || !height){
width=150;
height=150;
}
this.zoomer.container.hide();
this.zoomer.container.setOpacity(.70);
this.zoomer.container.setStyle({width:width+'px',height:height+'px'});
this.zoomer.middle.setStyle({width:width+'px',height:(height-40)+'px'});
this.zoomer.container.setStyle({margin:'0px',padding:'0px'});
//this.container.setStyle({padding:'0px'});
Position.clone(this.container,this.zoomer.container,{
setWidth:false,setHeight:false,
offsetLeft:this.options.mapSize.width/2 -(width/2),
offsetTop:this.options.mapSize.height/2 -(height/2)});
},
/**
Create and lunch visual zoom-in effect
*/
showZoomin:function(){
this.restoreZoomer(150,150,false);
this.zoomer.container.show();
new Effect.Parallel([
new Effect.Move(this.zoomer.container,{sync:true, x: -75, y: -75, mode: 'relative' }),
new Effect.Morph(this.zoomer.container,{ style: 'width:300px;height:300px',sync: true}),
new Effect.Morph(this.zoomer.middle,{ style: 'width:300px;height:260px',sync: true})
],{duration: 0.5,afterFinish:this.restoreZoomer.bind(this)});
},
/**
Create and lunch visual zoom-out effect
*/
showZoomout:function(){
this.restoreZoomer(300,300,true);
this.zoomer.container.show();
new Effect.Parallel([
new Effect.Move(this.zoomer.container,{sync:true, x: 75, y: 75, mode: 'relative' }),
new Effect.Morph(this.zoomer.container,{ style: 'width:150px;height:150px',sync: true}),
new Effect.Morph(this.zoomer.middle,{ style: 'width:150px;height:110px',sync: true})
],{duration: 0.5,afterFinish:this.restoreZoomer.bind(this)});
},
/**
Manage errors and display message.
@param event: the error event
*/
errorHandler:function(event){
this.keepAlive(0);
this.maploader.hide();
this.map.setStyle({width:'',height:'', left:'0',top:'0','z-index':0,visibility:'visible'});
this.map.show();
if(this.loader)this.loader.hide();
this.map.setOpacity(1);
if(!this.session.mapStartOffset){
var roff = Position.cumulativeOffset(this.container);
this.session.mapStartOffset={left:roff[0],top:roff[1]};
}
for(bname in this.buttons)
this.unregisterEvent(this.buttons[bname],'click');
this.unregisterEvent(document, 'keypress');
w3gAlertError(this.labels.error,Prototype.emptyFunction,this.labels.title);
},
/**
Window resize handler
@param event
*/
resizeHandler: function(event){
//Controls Re-position
Position.clone(this.container,this.controls,{setWidth:false,setHeight:false,offsetLeft:this.options.mapSize.width-this.bwidth-5,offsetTop:25});
Position.clone(this.container,this.buttons.moveup,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width/2 -(this.bwidth/2),offsetTop:-(this.bheight/2)});
Position.clone(this.container,this.buttons.movedown,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width/2 -(this.bwidth/2),offsetTop:this.options.mapSize.height-(this.bheight/2)});
Position.clone(this.container,this.buttons.moveleft,{setWidth:false,setHeight:false,offsetLeft: -(this.bwidth/2),offsetTop:this.options.mapSize.height/2-(this.bheight/2)});
Position.clone(this.container,this.buttons.moveright,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width-(this.bwidth/2),offsetTop:this.options.mapSize.height/2-(this.bheight/2)});
Position.clone(this.container,this.commandBar,{setWidth:false,setHeight:false,offsetLeft:5,offsetTop:5});
Position.clone(this.container,this.loader,{setWidth:false,setHeight:false,offsetLeft: this.options.mapSize.width/2 -(this.loader.dim.width/2),offsetTop:this.options.mapSize.height/2 -(this.loader.dim.height/2)});
//map reposition
var roff = Position.cumulativeOffset(this.container);
this.session.mapStartOffset={left:roff[0],top:roff[1]};
Position.clone(this.container,this.dialog,{setHeight:false,setWidth:false,offsetLeft:7,offsetTop:35});
Position.clone(this.markerpin,this.popup,{setHeight:false,setWidth:false,offsetLeft:-90,offsetTop:-75});
this.boundsRegion=false;
},
/**
Absolutize scale value
@param scale
@param offset
*/
findScale:function(scale, offset){
scale = scale scale
*/
redimMap:function(scale){
scale = this.findScale(scale,this.session.currentScale || this.options.sliderStart);
var width = (this.options.mapSize.width * (scale));
var height = (this.options.mapSize.height * scale);
var left= -(width - this.options.mapSize.width)/2;
var top= -(height - this.options.mapSize.height)/2;
if(scale < 1){left= 0;top= +(this.options.mapSize.height - height)/2;}
this.map.setStyle({width:width+'px',height:height+'px'});
this.map.setStyle({left:left+'px',top:top+'px'});
Position.clone(this.map,this.upperlayer);
if(!this.options.noCPin){
var pinoffset={
left:(this.mappin.offset.left+21)*scale -21,
top:(this.mappin.offset.top+21)*scale -21
}
Position.clone(this.map,this.mappin,{setWidth:false,setHeight:false,offsetLeft: pinoffset.left,offsetTop: pinoffset.top});
}
this.showPOI(scale);
return scale;
},
/**
Check if edge param in between edgebounds limit, otherwise return overflowed limit (min or max)
@param edge: the edge value to snap
@return snapped edge.
*/
snapEdge: function(edge){
if(edge > this.runtime.edgebounds.max){
return this.runtime.edgebounds.max;
}else if(edge < this.runtime.edgebounds.min){
return this.runtime.edgebounds.min;
}else{
return edge;
}
},
/**
Refresh scale and edge value with the new scale
@param scale, the new scale
*/
applyScale:function(scale){
this.upperlayer.style.cursor='wait';
var edge = this.session.currentEdge * (1/this.findScale(scale,this.options.sliderStart));
this.session.currentScale = scale;
this.session.currentEdge = this.snapEdge(edge);
},
/**
Refresh scale and edge value with the new scale
@param scale, the new scale
*/
applyEdgeFactor:function(factor){
this.upperlayer.style.cursor='wait';
this.session.currentEdge = this.snapEdge(this.session.currentEdge / factor);
},
/**
Redim, Scale and Reload map image for adjust scale.
@param scale
*/
scaleMap:function(scale){
if((this.session.currentScale && this.sesonSlidesion.currentScale5))
this.showZoomin();
else if ((this.session.currentScale &&this.session.currentScale>scale )|| (!this.session.currentScale && scale<5))
this.showZoomout();
this.applyScale(scale);
this.disabled();
this.reloadMap(this.session.currentEdge,null,null);
},
/**
Move and reload map image
@param offset, x and y movement offset in relative pixel
*/
moveMapWindow:function(offset){
this.upperlayer.style.cursor='wait';
var traslation = { x: offset.x, y: offset.y, mode: 'relative',sync: true};
var effects = [
new Effect.Move(this.map, traslation),
new Effect.Move(this.upperlayer, traslation),
new Effect.Move(this.mappin, traslation)
]
if(this.options.poi){
this.options.poi.each(function(poi){
if(poi.pin){
effects.push(new Effect.Move(poi.pin, traslation));
}});
}
new Effect.Parallel(effects,{duration: 0.5, queue :{ position: 'end', scope: 'mapmove', limit: 10 },
afterFinish:this.reloadMap.bind(this,this.session.currentEdge,offset,null)
});
this.disabled(); //block map
},
/**
Apply current position delta and calculate values for move map image funcition
@param delta
*/
applyDelta:function(delta){
var noffset= Position.cumulativeOffset(this.map);
this.upperlayer.style.cursor=this.session.defaultCursor;
this.session.delta.x = noffset[0] -this.session.mapStartOffset.left +this.session.delta.x;
this.session.delta.y = noffset[1] -this.session.mapStartOffset.top +this.session.delta.y;
this.session.traslation = { x:noffset[0] -this.session.mapStartOffset.left, y:noffset[1] -this.session.mapStartOffset.top};
},
/**
Move and reload map image by curent attribute
*/
traslateMap:function(){
this.applyDelta()
this.reloadMap(this.session.currentEdge,this.session.traslation,null);
this.session.traslation={x:0,y:0};
this.disabled();
},
/**
reset map image and controls to the initial state
*/
reset:function(){
this.slider.control.setValue(this.options.sliderStart);
this.session.delta={x:0,y:0};
this.dragStartAt=false;
this.session.currentEdge = this.snapEdge(this.options.scale);
this.session.currentScale = false;
this.session.delta={x:0,y:0};
this.session.traslation={x:0,y:0};
this.changeSource(this.maploader,{scale:this.session.currentEdge,reset:'true'});
this.disabled();
this.notify('reset');
},
/**
Invoke map generator with draw directive
@param edge: absolute scale for map image
@param delta: relative offset from the original coords (in pixels)
@param step: [UNUSED] path step
*/
reloadMap:function(edge,delta,step){
edge = edge==null?this.session.currentEdge:edge;
delta = delta==null?this.session.traslation:delta;
this.loader.show();
//attach map loaded event handler if necessary (first call)
if(!this.observeHandlers.mapLoaded ){
this.observeHandlers.mapLoaded = this.mapLoaded.bind(this);
this.registerEvent(this.maploader,'load',this.observeHandlers.mapLoaded );
}
this.slider.control.setDisabled();
//reload image with new params
var imgParam = {};
if(step!=null){imgParam.step = step};
if(delta){imgParam.delta = delta.x + ":" + delta.y };
if(edge){imgParam.scale = parseInt(edge)};this.slider.control
imgParam.act='rel'
this.changeSource(this.maploader,imgParam);
},
/**
Hasherize string in query string format
@param : query string
@return: hash contains parameters and values
*/
__queryStringToHash:function(string){
var pars = {};
if(string){
if(string.charAt(0)=='?')
string = string.substr(1);
string = string.split('&');
for(var i=0;i hash: the parameters to serialize
@return: : qs serialized hash
*/
__hashToQueryString:function(hash) {
var qs = '';
for(var name in hash){
if(name){
qs+=(qs==''?'':'&')+name;
qs+='='+(hash[name]==null?'':hash[name]);
}
}
return qs;
},
/**
Build ner src attribute for an image tag and change it.
@param image: image tag element
@param params: params to append in src
*/
changeSource:function(image,params){
var newSrc = this.session.originalSrc;
params = params || {};
var uri = newSrc.replace(/\?.*$/,'');
var qs = newSrc.replace(/^.*\?/,'');
qs = this.__queryStringToHash(qs);
for(var name in params){
qs[name]=params[name];
}
qs.t = new Date().getTime();
qs = this.__hashToQueryString(qs);
newSrc = uri + '?' + qs;
image.setAttribute('src',newSrc);
},
/**
Map changing completly done handler
*/
loadComplete:function(){
this.upperlayer.setStyle({visibility:'visible'});
Position.clone(this.map,this.upperlayer);
this.upperlayer.style.cursor=this.session.defaultCursor;
this.enabled();
if(this.slider.control){
//re enable zoom slider
this.slider.control.options.onSlide=Prototype.emptyFunction();
this.slider.control.options.onChange=Prototype.emptyFunction();
this.slider.control.setValue(this.options.sliderStart);
this.slider.control.options.onSlide=this.observeHandlers.onslide;
this.slider.control.options.onChange=this.observeHandlers.onslidechange;
this.slider.control.setEnabled();
}
this.registerEvent(document, 'keypress', this.keypressHandler.bindAsEventListener(this));
if(!this.options.noCPin){
this.mappin.show();
this.mappin.offset={left:this.xhttp.pin.left-21,top:this.xhttp.pin.top-21}
}
this.showPOI();
if(!this.options.noCPin){
Position.clone(this.map,this.mappin,{setWidth:false,setHeight:false,offsetLeft: this.mappin.offset.left,offsetTop: this.mappin.offset.top});
}
if(this.loader){
this.loader.hide();
}
//Position.clone(this.map,this.markerpin,{setWidth:false,setHeight:false,offsetLeft: this.markerpin.offset.left,offsetTop: this.markerpin.offset.top});
this.notify('complete');
},
/**
POI Click event handler, reload map with central point equals the POI passed
@param poi: POI descriptor
*/
clickPOI:function(poi){
this.disabled();
this.loader.show();
this.upperlayer.style.cursor='wait';
var id = typeof poi == 'string' ? poi : false;
for(var i = 0 ; i < this.options.poi.length; i++){
var apoi = this.options.poi[i];
apoi.active=false;
apoi.pin.setAttribute('_active','false');
apoi.marker.removeClassName('active');
if(id !=false && apoi.id == id){
poi = apoi;
id = false;
}
}
poi.active=true;
poi.pin.setAttribute('_active','true');
poi.marker.addClassName('active');
this.options.info = poi;
this.session.currentScale = false;
this.session.delta={x:0,y:0};
this.dragStartAt=false;
this.options.scale=7000
this.session.delta={x:0,y:0};
this.session.traslation={x:0,y:0};
this.sendRequest({
ppX:poi.coords.x,
ppY:poi.coords.y,
mapW:this.options.mapSize.width,
mapH:this.options.mapSize.height,
scale:this.options.scale,
act:'POI'
},this.centerToPOI.bind(this),this.net.actionGeo);
this.notify('clickPOI',poi);
},
/**
Reset map with central point equals the POI passed
@param poi: POI descriptor
*/
centerToPOI:function(poi){
this.upperlayer.style.cursor=this.session.defaultCursor;
this.loader.hide();
this.reset();
this.showMapInfo(true);
this.buttons.info.show();
this.buttons.path.show();
this.buttons.print.show();
},
/**
Draw POI pins on map
@param scale: current map image scale
*/
showPOI:function(scale){
scale = scale || 1
if(this.options.poi){
this.options.poi = this.options.poi.toArray();
var factor = {
x:(parseInt(this.xhttp.se.x) - parseInt(this.xhttp.nw.x)) / this.options.mapSize.width,
y:(parseInt(this.xhttp.nw.y) - parseInt(this.xhttp.se.y)) / this.options.mapSize.height
}
for(var i = 0 ; i < this.options.poi.length; i++){
var poi = this.options.poi[i];
if(!poi.pin){
poi.active=false;
poi.index = i;
poi.pin = $(document.createElement('DIV'));
poi.pin.setAttribute('_active','false');
poi.pin.addClassName('mtbtn-mapPOI');
poi.pin.setAttribute('id','mtbtn-mapPOI-'+(poi.id||poi.index))
poi.pin.setStyle({position:'absolute'});
poi.marker = $(document.createElement('DIV'));
this.map.up().appendChild(poi.pin);
poi.pin.appendChild(poi.marker);
if(poi.label){
poi.marker.update(poi.label);
}
if(poi.title){
poi.marker.setAttribute('title',poi.title);
}
poi.eventHandlers={};
if(this.options.onMouseOverPOI){
poi.eventHandlers.mouseover=this.options.onMouseOverPOI.bind(this,poi);
this.registerEvent(poi.pin,'mouseover',poi.eventHandlers.mouseover);
}
if(this.options.onMouseOutPOI){
poi.eventHandlers.mouseout=this.options.onMouseOutPOI.bind(this,poi);
this.registerEvent(poi.pin,'mouseout',poi.eventHandlers.mouseout);
}
poi.eventHandlers.click=this.clickPOI.bind(this,poi);
this.registerEvent(poi.pin,'click',poi.eventHandlers.click);
this.options.poi[i]=poi;
}
poi.pin.offset={
left:parseInt((poi.coords.x - this.xhttp.nw.x) / factor.x)* scale -(parseInt(poi.pin.getStyle('width')||'27px')/2),
top:parseInt(this.options.mapSize.height + (this.xhttp.se.y - poi.coords.y ) / factor.y)* scale -(parseInt(poi.pin.getStyle('height')||'27px'))
}
if(poi.active)
poi.marker.addClassName('active');
else
poi.marker.removeClassName('active');
Position.clone(this.map,poi.pin,{setWidth:false,setHeight:false,offsetLeft: poi.pin.offset.left,offsetTop: poi.pin.offset.top});
poi.pin.show();
}
}
},
/**
Hide POI pins
*/
hidePOI:function(){
if(this.options.poi){
this.options.poi.each(function(poi){
if(poi.pin){
poi.pin.hide();
}});
}
},
/**
Delete POI pins from map and remove reference
*/
deletePOI:function(){
if(this.options.poi){
for(var i = 0 ; i< this.options.poi.length; i++){
poi = this.options.poi[i];
if(poi.pin){
this.unregisterEvent(poi.pin,'click');
this.unregisterEvent(poi.pin,'click');
if(poi.eventHandlers.mouseover)
this.unregisterEvent(poi.pin,'mouseover');
if(poi.eventHandlers.mouseout)
this.unregisterEvent(poi.pin,'mouseout');
poi.marker.remove();
poi.marker=false;
poi.pin.remove();
poi.pin=false;
}}
}
this.options.poi = false;
},
/**
Exchange map loader with map, in other words rotate map elements roles.
*/
switchMap:function(){
this.maploader.originalSrc = this.session.originalSrc;
var switcher = $(this.map);
this.map = $(this.maploader);
this.maploader= switcher;
if(this.observeHandlers.mapLoaded ){
this.unregisterEvent(this.map,'load');
this.registerEvent(this.maploader,'load',this.observeHandlers.mapLoaded );
}
this.map.setStyle({width:'',height:'', top:this.runtime.centerOffset.top+'px',left:this.runtime.centerOffset.left+'px','z-index':0});
this.map.show();
this.maploader.hide();
},
/**
Map loaded Event handler wich reset map attribute
*/
mapLoaded:function(){
this.upperlayer.hide();
this.maploader.setStyle({width:'',height:'',top:this.runtime.centerOffset.top+'px',left:this.runtime.centerOffset.left+'px','z-index':0,visibility:'visible'});
this.maploader.show();
var roff = Position.cumulativeOffset(this.container);
this.switchMap();
this.upperlayer.setStyle({/*'z-index':1,*/visibility:'hidden'});
this.upperlayer.show();
Position.clone(this.map,this.upperlayer);
this.mappin.hide();
this.hidePOI();
this.sendRequest();
if(!this.session.mapStartOffset){
var roff = Position.cumulativeOffset(this.container);
this.session.mapStartOffset={left:roff[0],top:roff[1]};
}
this.session.currentScale = false;
},
/**
Abort xhttp requests and image loading
*/
abort:function(){
this.enabled();
this.loader.hide();
this.upperlayer.setStyle({cursor:this.session.defaultCursor});
this.runtime.requests.invoke('abort');
this.runtime.requests= $A(new Array());
try{
if(!this.maploader.complete){
this.unregisterEvent(this.maploader,'load');
//this.maploader.src='';
this.switchMap();
}
}catch(e){}
this.notify('abort');
},
/**
Send an XHTTP asyncronous request (AJAX)
@param params: query string to append
@param callback: request callback function, if not specify callback at evalResponse()
*/
sendRequest:function(params,callback,url){
if(this.runtime.requests.length>0){
var requests = $A(this.runtime.requests.toArray());
requests.each(function(ajax){
try{
if(ajax.success()){
requests.pop(ajax);
}
}catch(e){requests.pop(ajax);}
});
this.runtime.requests=requests.compact();
}
params = params || {ctrl:'xhttp'};
url = url || this.session.originalSrc;
var uri = url.replace(/\?.*$/,'');
var qs = url.replace(/^.*\?/,'');
qs = this.__queryStringToHash(qs);
for(var name in params){
qs[name]=params[name];
}
qs.t = new Date().getTime();
qs = this.__hashToQueryString(qs);
url = uri + '?' + qs;
this.runtime.requests.push(new Ajax.Request( url, {
method: 'get',
onComplete: callback || this.evalResponse.bind(this)
}));
this.notify('request');
},
/**
Parse and execute javascript on an Ajax request (callback use)
@param