/** * @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 response: prototype Ajax response object. */ evalResponse:function(response){ this.xhttp=false; try{ if (200 == response.status) eval('this.xhttp='+response.responseText); }catch(e){/*NOP*/} this.loadComplete(); }, /** Hot Key event handler. increment zoom by 1 @param event: */ scaleUp:function(event){ if(this.slider.control.disabled)return; this.slider.control.setDeltaValue(1); }, /** Hot Key event handler. decrement zoom by 1 @param event: */ scaleDown:function(event){ if(this.slider.control.disabled)return; this.slider.control.setDeltaValue(-1); }, /** Mouse wheel event handler. modifify zoom scale @param event: */ wheel:function(event){ if(this.slider.control.disabled)return; var delta = 0; if (!event)event = window.event; if (event.wheelDelta) { delta = event.wheelDelta/120; if (window.opera) delta = -delta; } else if (event.detail) { delta = -event.detail/3; } if (delta){ this.slider.control.setDeltaValue(delta) } if (event.preventDefault)event.preventDefault(); Event.stop(event); }, /** [UNIMPLEMENTED] for path */ loadStep:function(index){ this.reloadMap(null,null,index); }, /** Mouse up Event handler for drawed zoom region @param event: Mouse up Event */ applyBoundsRegion:function(event){ Event.stop(event); this.unregisterEvent(document.body, 'mouseup',this.observeHandlers.mapMouseUp); this.unregisterEvent(this.container, 'mousemove',this.observeHandlers.boundsRegionMouseMove); this.unregisterEvent(this.container, 'mousedown',this.observeHandlers.containerMouseDown); var size =this.boundsRegion.getDimensions(); this.upperlayer.setStyle({cursor:this.session.defaultCursor}); var props ={ width:this.options.mapSize.width/size.width, height:this.options.mapSize.height/size.height }; var scale = (props.width <= props.height) ? props.width : props.height; var c = Position.cumulativeOffset(this.boundsRegion); c = { left:c[0] + (size.width/2 ) -(this.session.mapStartOffset.left) - (this.options.mapSize.width/2), top: c[1] + (size.height/2) -(this.session.mapStartOffset.top ) - (this.options.mapSize.height/2) } c.left = parseInt(c.left); c.top = parseInt(c.top); this.map.setStyle({left:-c.left+'px',top:-c.top+'px'}); this.slider.control.options.onSlide=Prototype.emptyFunction(); this.slider.control.options.onChange=Prototype.emptyFunction(); this.applyDelta(/*{x:c.left,y:c.top}*/); this.applyEdgeFactor(scale); 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.showPOI() this.markerpin.hide(); this.popup.hide(); this.boundsRegion.remove(); this.boundsRegion=false; this.reloadMap(null,null,null); this.slider.control.options.onSlide=this.observeHandlers.onslide; this.slider.control.options.onChange=this.observeHandlers.onslidechange; }, /** init Event handler for drawing zoom region @param event: Mouse click on button Event */ observeBoundsRegion:function(event){ Event.stop(event); this.upperlayer.setStyle({cursor:'crosshair'}); this.disabled(); this.boundsRegion=false; this.observeHandlers.containerMouseDown=this.drawBoundsRegion.bindAsEventListener(this) this.registerEvent(this.container, 'mousedown',this.observeHandlers.containerMouseDown ); }, /** Mouse move Event handler for drawing zoom region @param event: Mouse move Event */ drawBoundsRegion:function(event){ Event.stop(event); var offset = Position.cumulativeOffset(this.map); offset = {left:offset[0],top:offset[1]} var pointer={ x: Event.pointerX(event) - offset.left, y: Event.pointerY(event) - offset.top } //var ponterZ = {x:Event.pointerX(event),y: Event.pointerY(event)}; if(!this.boundsRegion){ this.unregisterEvent(this.container, 'mousedown',this.observeHandlers.containerMouseDown); this.boundsRegion= $(document.createElement("DIV")); //this.boundsRegion.background = $(document.createElement("DIV")); this.boundsRegion.addClassName('mappaTerritoriale-BoundsRectangle'); this.boundsRegion.setStyle({width:'0px',height:'0px','line-height':'1px'}); this.observeHandlers.boundsRegionMouseMove =this.drawBoundsRegion.bindAsEventListener(this); this.observeHandlers.mapMouseUp = this.applyBoundsRegion.bindAsEventListener(this); this.registerEvent(this.container, 'mousemove',this.observeHandlers.boundsRegionMouseMove); this.registerEvent(document.body, 'mouseup', this.observeHandlers.mapMouseUp ); this.boundsRegion.start = pointer; this.container.appendChild(this.boundsRegion); this.boundsRegion.update(' '); this.boundsRegion.setStyle({'z-index':'99',cursor:'crosshair'}); } var start = this.boundsRegion.start; var size = { width: pointer.x - start.x, height: pointer.y - start.y } this.boundsRegion.setStyle({width:(Math.abs(size.width))+'px',height:(Math.abs(size.height))+'px'}); Position.absolutize(this.boundsRegion); Position.clone(this.map,this.boundsRegion,{setWidth:false,setHeight:false, offsetLeft: size.width<0 ? pointer.x : start.x, offsetTop: size.height<0 ? pointer.y : start.y }); }, /** Hide map controls */ hideControls:function(){ if(this.dialog.visible()){ this.dialog.hide(); this.dialog.restoreVisibility=true; } if(this.popup.visible()){ this.popup.hide(); this.popup.restoreVisibility=true; } $H(this.buttons).values().each(function(b){b.hide()}); this.controls.hide(); }, /** Show map controls */ showControls:function(){ if(this.dialog.restoreVisibility){ this.dialog.show(); this.dialog.restoreVisibility=false; } if(this.popup.restoreVisibility){ this.popup.show(); this.popup.restoreVisibility=false; } $H(this.buttons).values().each(function(b){b.show()}); this.controls.show(); }, /** Buid address info popup */ buildMarkerInfo:function(json){ var html = $(document.createElement('DIV')); var ul = $(document.createElement('UL')).addClassName('mappaTerritoriale-Info'); var li = $(document.createElement('LI')).addClassName('mappaTerritoriale-Info'); li.update('X:'+json.center.x); ul.appendChild(li); li = $(document.createElement('LI')).addClassName('mappaTerritoriale-Info'); li.update('Y:'+json.center.x); ul.appendChild(li); li = $(document.createElement('LI')).addClassName('mappaTerritoriale-Info'); li.update('strada ~'+json.address.street+''); ul.appendChild(li); html.appendChild(ul); ul.setStyle({'margin-top':'0px'}); this.html.markerInfo = html.innerHTML; this.popup.message.update(this.html.markerInfo); }, /** Buid address info dialog */ buildMapInfo:function(refresh){ if(!this.options.info) return '  -NO INFO-'; if(!this.html.mapInfo || refresh){ var html = $(document.createElement('DIV')); var ul = $(document.createElement('UL')).addClassName('mappaTerritoriale-Info'); var li = $(document.createElement('LI')).addClassName('mappaTerritoriale-Info'); li.update(''+this.options.info.localita+' ('+this.options.info.provincia+')'); ul.appendChild(li); li = $(document.createElement('LI')).addClassName('mappaTerritoriale-Info'); li.update(this.options.info.indirizzo+' '+this.options.info.numero); ul.appendChild(li); html.appendChild(ul); this.html.mapInfo = html.innerHTML; } this.changeDialog(180,70,this.html.mapInfo); }, /** Show address info dialog */ showMapInfo:function(refresh){ this.dialog.mode='info'; this.dialog.header.update(this.labels.locazione) var closebutton= $(document.createElement('DIV')); closebutton.addClassName('mtDialogs-CLOSE'); this.dialog.header.appendChild(closebutton); this.registerEvent(closebutton, "click", this.dialog.hide.bind(this.dialog)); this.buildMapInfo(refresh); }, /** Buid address info dialog */ buildPathRequest:function(response){ if(!this.html.pathRequest){ if(response){ this.html.pathRequest =response.responseText;//html.innerHTML; //this.dialog.message.update(this.html.pathRequest); this.changeDialog(350,110,this.html.pathRequest); }else{ this.runtime.requests.push(new Ajax.Request('/atportal/mappaTerritorialeRichiestaDomicilio.do?ajax=true',{method:'POST',onComplete:this.buildPathRequest.bind(this)})); this.dialog.message.update('
'); this.dialog.message.appendChild(this.smallloader); } }else this.changeDialog(350,110,this.html.pathRequest); }, /** Change espect and content of dialog box @param w: the new width @param h: the new height @param content */ changeDialog:function(w,h,content,dialog){ dialog = dialog || this.dialog; dialog.show(); dialog.message.setStyle({'overflow':'hidden'}); if(!dialog.loading){ dialog.message.update('
'); dialog.message.appendChild(this.smallloader); }else dialog.loading = false; if(!dialog.preDim)dialog.preDim={width:0,height:0}; if(dialog.preDim.width!=w ||dialog.preDim.height!=h){ var callback= function(content){ dialog.message.update(content) dialog.message.setStyle({'overflow':'visible'}); dialog.dragControl= new Draggable(dialog,{handle:dialog.header}); dialog.header.setStyle({cursor:'move'}); if($('mtSubmit')){ this.registerEvent($('mtSubmit'),'click',this.submitPathRequest.bind(this)); $('mtSubmit').setAttribute('href','#'); } } var init= function(){ if(dialog.dragControl){ dialog.dragControl.destroy(); dialog.dragControl=false; dialog.header.setStyle({cursor:'default'}); } } new Effect.Parallel([ new Effect.Morph(dialog, { sync: true, style:{width:w+'px'}}), new Effect.Morph(dialog.message, { sync: true, style:{width:(w-14)+'px',height:(h-14)+'px'}}) ], { duration:1.0, afterFinish:callback.bind(this,content), beforeStart:init.bind(this) }); }else{ dialog.message.update(content); dialog.message.setStyle({'overflow':'visible'}); } dialog.preDim={width:w,height:h}; }, /** Toggle address info dialog visibility */ togglePathRequest:function(){ if(this.dialog.visible() && this.dialog.mode=='path') this.dialog.hide() else{ this.showPathRequest(); } }, /** Show path request form in the info box */ showPathRequest:function(){ this.dialog.mode='path'; this.dialog.header.update(this.labels.path); var closebutton= $(document.createElement('DIV')); closebutton.addClassName('mtDialogs-CLOSE'); this.dialog.header.appendChild(closebutton); this.registerEvent(closebutton, "click", this.dialog.hide.bind(this.dialog)); this.buildPathRequest(); this.dialog.show(); }, /** Validate and subit path request form */ submitPathRequest:function(){ var form=document.getElementById('geoForm'); var error= form['partenza.provincia'].value=='-1' || form['partenza.comune'].value=='' || form['partenza.indirizzo'].value=='' || form['partenza.numero'].value=='' if(!error){ this.loader.show(); this.disabled(); form.submit(); }else $('validationError').show(); }, /** Toggle address info dialog visibility */ toggleMapInfo:function(){ if(this.dialog.visible() && this.dialog.mode=='info') this.dialog.hide(); else{ this.showMapInfo(); } }, /** Key press handler for hotkey @param evt: key pressed */ keypressHandler:function(evt){ evt = (evt) ? evt : ((window.event) ? event : null); var keynum; keynum = evt.keyCode; if(keynum && $H(this.keybindings).keys().indexOf(keynum)>=0){ this.unregisterEvent(document, 'keypress'); this.keybindings[keynum](); Event.stop(evt); this.notify('keypress',evt); } }, /** Ask for note and send print command */ print:function(){ //this.unregisterEvent(document, 'keypress'); this.disabled(); new w3gDialogs.input({ title:this.labels.title, message:this.labels.printdialog, cols:40,rows:10, onAction:this.sendPrint.bind(this) }); }, /** Analyze w3gDialogs return and proccess print command @param action: w3gDialogs return object */ sendPrint:function(action){ this.enabled(); //this.registerEvent(document, 'keypress', this.keypressHandler.bindAsEventListener(this)); if(!action || action.button==w3gDialogs.CANCEL) return; this.cmdform.setAttribute('target',this.printer.name); this.cmdform.setAttribute('method','POST'); this.cmdform.setAttribute('action','/atportal/mappaTerritorialeStampaImmagine.do?t='+new Date().getTime()); var fields ={ note:action.input, localita: this.options.info.localita, numero: this.options.info.numero, indirizzo:this.options.info.indirizzo, numero:this.options.info.numero, provincia:this.options.info.provincia } for(var prop in fields){ if(!this.cmdform[prop]){ var field = $(document.createElement('INPUT')); field.setAttribute('type','text'); field.setAttribute('name',prop); this.cmdform.appendChild(field); this.cmdform[prop]=field; } this.cmdform[prop].value=fields[prop]||''; } this.cmdform.submit(); this.notify('print'); }, /** Register an event observer @param sorce: DOM Element or its id to observe @param event: event name to observe @param handler: function to call on event fired */ registerEvent: function(source,event,handler){ if(!source.evtRegKey){ source.evtRegKey=(source.tagName||'OBJ')+(source.id ? '#'+source.id :(source.className?' @'+source.className : ''))+":"+new Date().getTime(); } this.session.eventsRegistry[source.evtRegKey]=this.session.eventsRegistry[source.evtRegKey]||{}; if(this.session.eventsRegistry[source.evtRegKey][event]){ var old_handler = this.session.eventsRegistry[source.evtRegKey][event]; Event.stopObserving(source,event,old_handler); } Event.observe(source,event,handler); this.session.eventsRegistry[source.evtRegKey][event]=handler; }, /** Unregister an event observer @param sorce: DOM Element or its id observed @param event: event name observed @param handler: function call on event fired */ unregisterEvent: function(source,event,handler){ if(!source.evtRegKey)return false; this.session.eventsRegistry[source.evtRegKey]=this.session.eventsRegistry[source.evtRegKey]||{}; if(!event){ for(innerevent in this.session.eventsRegistry[source.evtRegKey]) this.unregisterEvent(source,innerevent,handler); }else if(this.session.eventsRegistry[source.evtRegKey][event]){ handler = handler || this.session.eventsRegistry[source.evtRegKey][event]; Event.stopObserving(source,event,handler); } this.session.eventsRegistry[source.evtRegKey][event]=false; }, notify: function(eventFired){ eventFired = /^on.*/.test(eventFired)? eventFired: 'on'+eventFired.capitalize(); if(this.options[eventFired]){ var args = $A(arguments).slice(1); args.push(this); return [this.options[eventFired].apply(this.options[eventFired],args)]; } }, /** [DEBUG] */ __inspectEventsRegistry: function(){ var message = ""; for(src in this.session.eventsRegistry){ message += src.id||src.name||src + ":
"; for(evt in this.session.eventsRegistry[src]){ message += " - "+evt + "
"; } } return message; } }); w3gMappaTerritoriale.Version= function(){ this.release ='2'; this.major='0'; this.minor='2'; function fullVersion(){ return this.release+'.'+this.major+'.'+this.minor; } return fullVersion(); } if(typeof Ajax.Request.prototype.abort == 'undefined'){ Ajax.Request.prototype.abort = function() { // prevent and state change callbacks from being issued this.transport.onreadystatechange = Prototype.emptyFunction; // abort the XHR this.transport.abort(); // update the request counter Ajax.activeRequestCount--; }; }