var previousMM=MM;if(!com){var com={};if(!com.modestmaps)com.modestmaps={}}var MM=com.modestmaps={noConflict:function(){MM=previousMM;return this}};(function(MM){MM.extend=function(child,parent){for(var property in parent.prototype){if(typeof child.prototype[property]=="undefined"){child.prototype[property]=parent.prototype[property]}}return child};MM.getFrame=function(){return function(callback){(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(callback){window.setTimeout(function(){callback(+new Date)},10)})(callback)}}();MM.transformProperty=function(props){if(!this.document)return;var style=document.documentElement.style;for(var i=0;ithis.north)this.north=loc.lat;if(loc.latthis.east)this.east=loc.lon;if(loc.lonthis.north)this.north=extent.north;if(extent.souththis.east)this.east=extent.east;if(extent.west=this.south&&loc.lat<=this.north&&loc.lon>=this.west&&loc.lon<=this.east},toArray:function(){return[this.northWest(),this.southEast()]}};MM.Extent.fromString=function(str){var parts=str.split(/\s*,\s*/);if(parts.length!=4){throw"Invalid extent string (expecting 4 comma-separated numbers)"}return new MM.Extent(parseFloat(parts[0]),parseFloat(parts[1]),parseFloat(parts[2]),parseFloat(parts[3]))};MM.Extent.fromArray=function(locations){var extent=new MM.Extent;extent.setFromLocations(locations);return extent};MM.Transformation=function(ax,bx,cx,ay,by,cy){this.ax=ax;this.bx=bx;this.cx=cx;this.ay=ay;this.by=by;this.cy=cy};MM.Transformation.prototype={ax:0,bx:0,cx:0,ay:0,by:0,cy:0,transform:function(point){return new MM.Point(this.ax*point.x+this.bx*point.y+this.cx,this.ay*point.x+this.by*point.y+this.cy)},untransform:function(point){return new MM.Point((point.x*this.by-point.y*this.bx-this.cx*this.by+this.cy*this.bx)/(this.ax*this.by-this.ay*this.bx),(point.x*this.ay-point.y*this.ax-this.cx*this.ay+this.cy*this.ax)/(this.bx*this.ay-this.by*this.ax))}};MM.deriveTransformation=function(a1x,a1y,a2x,a2y,b1x,b1y,b2x,b2y,c1x,c1y,c2x,c2y){var x=MM.linearSolution(a1x,a1y,a2x,b1x,b1y,b2x,c1x,c1y,c2x);var y=MM.linearSolution(a1x,a1y,a2y,b1x,b1y,b2y,c1x,c1y,c2y);return new MM.Transformation(x[0],x[1],x[2],y[0],y[1],y[2])};MM.linearSolution=function(r1,s1,t1,r2,s2,t2,r3,s3,t3){r1=parseFloat(r1);s1=parseFloat(s1);t1=parseFloat(t1);r2=parseFloat(r2);s2=parseFloat(s2);t2=parseFloat(t2);r3=parseFloat(r3);s3=parseFloat(s3);t3=parseFloat(t3);var a=((t2-t3)*(s1-s2)-(t1-t2)*(s2-s3))/((r2-r3)*(s1-s2)-(r1-r2)*(s2-s3));var b=((t2-t3)*(r1-r2)-(t1-t2)*(r2-r3))/((s2-s3)*(r1-r2)-(s1-s2)*(r2-r3));var c=t1-r1*a-s1*b;return[a,b,c]};MM.Projection=function(zoom,transformation){if(!transformation){transformation=new MM.Transformation(1,0,0,0,1,0)}this.zoom=zoom;this.transformation=transformation};MM.Projection.prototype={zoom:0,transformation:null,rawProject:function(point){throw"Abstract method not implemented by subclass."},rawUnproject:function(point){throw"Abstract method not implemented by subclass."},project:function(point){point=this.rawProject(point);if(this.transformation){point=this.transformation.transform(point)}return point},unproject:function(point){if(this.transformation){point=this.transformation.untransform(point)}point=this.rawUnproject(point);return point},locationCoordinate:function(location){var point=new MM.Point(Math.PI*location.lon/180,Math.PI*location.lat/180);point=this.project(point);return new MM.Coordinate(point.y,point.x,this.zoom)},coordinateLocation:function(coordinate){coordinate=coordinate.zoomTo(this.zoom);var point=new MM.Point(coordinate.column,coordinate.row);point=this.unproject(point);return new MM.Location(180*point.y/Math.PI,180*point.x/Math.PI)}};MM.LinearProjection=function(zoom,transformation){MM.Projection.call(this,zoom,transformation)};MM.LinearProjection.prototype={rawProject:function(point){return new MM.Point(point.x,point.y)},rawUnproject:function(point){return new MM.Point(point.x,point.y)}};MM.extend(MM.LinearProjection,MM.Projection);MM.MercatorProjection=function(zoom,transformation){MM.Projection.call(this,zoom,transformation)};MM.MercatorProjection.prototype={rawProject:function(point){return new MM.Point(point.x,Math.log(Math.tan(.25*Math.PI+.5*point.y)))},rawUnproject:function(point){return new MM.Point(point.x,2*Math.atan(Math.pow(Math.E,point.y))-.5*Math.PI)}};MM.extend(MM.MercatorProjection,MM.Projection);MM.MapProvider=function(getTile){if(getTile){this.getTile=getTile}};MM.MapProvider.prototype={tileLimits:[new MM.Coordinate(0,0,0),new MM.Coordinate(1,1,0).zoomTo(18)],getTileUrl:function(coordinate){throw"Abstract method not implemented by subclass."},getTile:function(coordinate){throw"Abstract method not implemented by subclass."},releaseTile:function(element){},setZoomRange:function(minZoom,maxZoom){this.tileLimits[0]=this.tileLimits[0].zoomTo(minZoom);this.tileLimits[1]=this.tileLimits[1].zoomTo(maxZoom)},sourceCoordinate:function(coord){var TL=this.tileLimits[0].zoomTo(coord.zoom).container(),BR=this.tileLimits[1].zoomTo(coord.zoom),columnSize=Math.pow(2,coord.zoom),wrappedColumn;BR=new MM.Coordinate(Math.ceil(BR.row),Math.ceil(BR.column),Math.floor(BR.zoom));if(coord.column<0){wrappedColumn=(coord.column%columnSize+columnSize)%columnSize}else{wrappedColumn=coord.column%columnSize}if(coord.row=BR.row){return null}else if(wrappedColumn=BR.column){return null}else{return new MM.Coordinate(coord.row,wrappedColumn,coord.zoom)}}};MM.Template=function(template,subdomains){var isQuadKey=template.match(/{(Q|quadkey)}/);if(isQuadKey)template=template.replace("{subdomain}","{S}").replace("{zoom}","{Z}").replace("{quadkey}","{Q}");var hasSubdomains=subdomains&&subdomains.length&&template.indexOf("{S}")>=0;function quadKey(row,column,zoom){var key="";for(var i=1;i<=zoom;i++){key+=(row>>zoom-i&1)<<1|column>>zoom-i&1}return key||"0"}var getTileUrl=function(coordinate){var coord=this.sourceCoordinate(coordinate);if(!coord){return null}var base=template;if(hasSubdomains){var index=parseInt(coord.zoom+coord.row+coord.column,10)%subdomains.length;base=base.replace("{S}",subdomains[index])}if(isQuadKey){return base.replace("{Z}",coord.zoom.toFixed(0)).replace("{Q}",quadKey(coord.row,coord.column,coord.zoom))}else{return base.replace("{Z}",coord.zoom.toFixed(0)).replace("{X}",coord.column.toFixed(0)).replace("{Y}",coord.row.toFixed(0))}};MM.MapProvider.call(this,getTileUrl)};MM.Template.prototype={getTile:function(coord){return this.getTileUrl(coord)}};MM.extend(MM.Template,MM.MapProvider);MM.TemplatedLayer=function(template,subdomains,name){return new MM.Layer(new MM.Template(template,subdomains),null,name)};MM.getMousePoint=function(e,map){var point=new MM.Point(e.clientX,e.clientY);point.x+=document.body.scrollLeft+document.documentElement.scrollLeft;point.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var node=map.parent;node;node=node.offsetParent){point.x-=node.offsetLeft;point.y-=node.offsetTop}return point};MM.MouseWheelHandler=function(){var handler={id:"MouseWheelHandler"},map,_zoomDiv,prevTime,precise=false;function mouseWheel(e){var delta=0;prevTime=prevTime||(new Date).getTime();try{_zoomDiv.scrollTop=1e3;_zoomDiv.dispatchEvent(e);delta=1e3-_zoomDiv.scrollTop}catch(error){delta=e.wheelDelta||-e.detail*5}var timeSince=(new Date).getTime()-prevTime;var point=MM.getMousePoint(e,map);if(Math.abs(delta)>0&&timeSince>200&&!precise){map.zoomByAbout(delta>0?1:-1,point);prevTime=(new Date).getTime()}else if(precise){map.zoomByAbout(delta*.001,point)}return MM.cancelEvent(e)}handler.init=function(x){map=x;_zoomDiv=document.body.appendChild(document.createElement("div"));_zoomDiv.style.cssText="visibility:hidden;top:0;height:0;width:0;overflow-y:scroll";var innerDiv=_zoomDiv.appendChild(document.createElement("div"));innerDiv.style.height="2000px";MM.addEvent(map.parent,"mousewheel",mouseWheel);return handler};handler.precise=function(x){if(!arguments.length)return precise;precise=x;return handler};handler.remove=function(){MM.removeEvent(map.parent,"mousewheel",mouseWheel);_zoomDiv.parentNode.removeChild(_zoomDiv)};return handler};MM.DoubleClickHandler=function(){var handler={id:"DoubleClickHandler"},map;function doubleClick(e){var point=MM.getMousePoint(e,map);map.zoomByAbout(e.shiftKey?-1:1,point);return MM.cancelEvent(e)}handler.init=function(x){map=x;MM.addEvent(map.parent,"dblclick",doubleClick);return handler};handler.remove=function(){MM.removeEvent(map.parent,"dblclick",doubleClick)};return handler};MM.DragHandler=function(){var handler={id:"DragHandler"},prevMouse,map;function mouseDown(e){if(e.shiftKey||e.button==2)return;MM.addEvent(document,"mouseup",mouseUp);MM.addEvent(document,"mousemove",mouseMove);prevMouse=new MM.Point(e.clientX,e.clientY);map.parent.style.cursor="move";return MM.cancelEvent(e)}function mouseUp(e){MM.removeEvent(document,"mouseup",mouseUp);MM.removeEvent(document,"mousemove",mouseMove);prevMouse=null;map.parent.style.cursor="";return MM.cancelEvent(e)}function mouseMove(e){if(prevMouse){map.panBy(e.clientX-prevMouse.x,e.clientY-prevMouse.y);prevMouse.x=e.clientX;prevMouse.y=e.clientY;prevMouse.t=+new Date}return MM.cancelEvent(e)}handler.init=function(x){map=x;MM.addEvent(map.parent,"mousedown",mouseDown);return handler};handler.remove=function(){MM.removeEvent(map.parent,"mousedown",mouseDown)};return handler};MM.MouseHandler=function(){var handler={id:"MouseHandler",handlers:[]},map;handler.init=function(x){map=x;handler.handlers=[MM.DragHandler().init(map),MM.DoubleClickHandler().init(map),MM.MouseWheelHandler().init(map)];return handler};handler.remove=function(){for(var i=0;imaxTapDistance){}else if(time>maxTapTime){pos.end=now;pos.duration=time;onHold(pos)}else{pos.time=now;onTap(pos)}}var validTouchIds={};for(var j=0;j=0;j--){var img=openRequests[j];if(!(img.id in validIds)){this.loadingBay.removeChild(img);this.openRequestCount--;img.src=img.coord=img.onload=img.onerror=null}}for(var id in this.requestsById){if(!(id in validIds)){if(this.requestsById.hasOwnProperty(id)){var requestToRemove=this.requestsById[id];delete this.requestsById[id];if(requestToRemove!==null){requestToRemove=requestToRemove.id=requestToRemove.coord=requestToRemove.url=null}}}}},hasRequest:function(id){return id in this.requestsById},requestTile:function(id,coord,url){if(!(id in this.requestsById)){var request={id:id,coord:coord.copy(),url:url};this.requestsById[id]=request;if(url){this.requestQueue.push(request)}}},getProcessQueue:function(){if(!this._processQueue){var theManager=this;this._processQueue=function(){theManager.processQueue()}}return this._processQueue},processQueue:function(sortFunc){if(sortFunc&&this.requestQueue.length>8){this.requestQueue.sort(sortFunc)}while(this.openRequestCount0){var request=this.requestQueue.pop();if(request){this.openRequestCount++;var img=document.createElement("img");img.id=request.id;img.style.position="absolute";img.coord=request.coord;this.loadingBay.appendChild(img);img.onload=img.onerror=this.getLoadComplete();img.src=request.url;request=request.id=request.coord=request.url=null}}},_loadComplete:null,getLoadComplete:function(){if(!this._loadComplete){var theManager=this;this._loadComplete=function(e){e=e||window.event;var img=e.srcElement||e.target;img.onload=img.onerror=null;theManager.loadingBay.removeChild(img);theManager.openRequestCount--;delete theManager.requestsById[img.id];if(e.type==="load"&&(img.complete||img.readyState&&img.readyState=="complete")){theManager.dispatchCallback("requestcomplete",img)}else{theManager.dispatchCallback("requesterror",{element:img,url:""+img.src});img.src=null}setTimeout(theManager.getProcessQueue(),0)}}return this._loadComplete}};MM.Layer=function(provider,parent,name){this.parent=parent||document.createElement("div");this.parent.style.cssText="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; margin: 0; padding: 0; z-index: 0";this.name=name;this.levels={};this.requestManager=new MM.RequestManager;this.requestManager.addCallback("requestcomplete",this.getTileComplete());this.requestManager.addCallback("requesterror",this.getTileError());if(provider)this.setProvider(provider)};MM.Layer.prototype={map:null,parent:null,name:null,enabled:true,tiles:null,levels:null,requestManager:null,provider:null,_tileComplete:null,getTileComplete:function(){if(!this._tileComplete){var theLayer=this;this._tileComplete=function(manager,tile){theLayer.tiles[tile.id]=tile;theLayer.positionTile(tile);tile.style.visibility="inherit";tile.className="map-tile-loaded"}}return this._tileComplete},getTileError:function(){if(!this._tileError){var theLayer=this;this._tileError=function(manager,tile){tile.onload=tile.onerror=null;theLayer.tiles[tile.element.id]=tile.element;theLayer.positionTile(tile.element);tile.element.style.visibility="hidden"}}return this._tileError},draw:function(){if(!this.enabled||!this.map)return;var theCoord=this.map.coordinate.zoomTo(Math.round(this.map.coordinate.zoom));function centerDistanceCompare(r1,r2){if(r1&&r2){var c1=r1.coord;var c2=r2.coord;if(c1.zoom==c2.zoom){var ds1=Math.abs(theCoord.row-c1.row-.5)+Math.abs(theCoord.column-c1.column-.5);var ds2=Math.abs(theCoord.row-c2.row-.5)+Math.abs(theCoord.column-c2.column-.5);return ds1ds2?-1:0}else{return c1.zoomc2.zoom?-1:0}}return r1?1:r2?-1:0}var baseZoom=Math.round(this.map.coordinate.zoom);var startCoord=this.map.pointCoordinate(new MM.Point(0,0)).zoomTo(baseZoom).container();var endCoord=this.map.pointCoordinate(this.map.dimensions).zoomTo(baseZoom).container().right().down();var validTileKeys={};var levelElement=this.createOrGetLevel(startCoord.zoom);var tileCoord=startCoord.copy();for(tileCoord.column=startCoord.column;tileCoord.column=startCoord.zoom-5&&zoom0){level.style.display="block";scale=Math.pow(2,this.map.coordinate.zoom-zoom);theCoord=theCoord.zoomTo(zoom)}else{level.style.display="none";return false}var tileWidth=this.map.tileSize.x*scale;var tileHeight=this.map.tileSize.y*scale;var center=new MM.Point(this.map.dimensions.x*.5,this.map.dimensions.y*.5);var tiles=this.tileElementsInLevel(level);while(tiles.length){var tile=tiles.pop();if(!valid_tile_keys[tile.id]){this.provider.releaseTile(tile.coord);this.requestManager.clearRequest(tile.coord.toKey());level.removeChild(tile)}else{MM.moveElement(tile,{x:Math.round(center.x+(tile.coord.column-theCoord.column)*tileWidth),y:Math.round(center.y+(tile.coord.row-theCoord.row)*tileHeight),scale:scale,width:this.map.tileSize.x,height:this.map.tileSize.y})}}},createOrGetLevel:function(zoom){if(zoom in this.levels){return this.levels[zoom]}var level=document.createElement("div");level.id=this.parent.id+"-zoom-"+zoom;level.style.cssText="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; margin: 0; padding: 0;";level.style.zIndex=zoom;this.parent.appendChild(level);this.levels[zoom]=level;return level},addTileImage:function(key,coord,url){this.requestManager.requestTile(key,coord,url)},addTileElement:function(key,coordinate,element){element.id=key;element.coord=coordinate.copy();this.positionTile(element)},positionTile:function(tile){var theCoord=this.map.coordinate.zoomTo(tile.coord.zoom);tile.style.cssText="position:absolute;-webkit-user-select:none;"+"-webkit-user-drag:none;-moz-user-drag:none;-webkit-transform-origin:0 0;"+"-moz-transform-origin:0 0;-o-transform-origin:0 0;-ms-transform-origin:0 0;"+"width:"+this.map.tileSize.x+"px; height: "+this.map.tileSize.y+"px;";tile.ondragstart=function(){return false};var scale=Math.pow(2,this.map.coordinate.zoom-tile.coord.zoom);MM.moveElement(tile,{x:Math.round(this.map.dimensions.x*.5+(tile.coord.column-theCoord.column)*this.map.tileSize.x*scale),y:Math.round(this.map.dimensions.y*.5+(tile.coord.row-theCoord.row)*this.map.tileSize.y*scale),scale:scale,width:this.map.tileSize.x,height:this.map.tileSize.y});var theLevel=this.levels[tile.coord.zoom];theLevel.appendChild(tile);if(Math.round(this.map.coordinate.zoom)==tile.coord.zoom){theLevel.style.display="block"}this.requestRedraw()},_redrawTimer:undefined,requestRedraw:function(){if(!this._redrawTimer){this._redrawTimer=setTimeout(this.getRedraw(),1e3)}},_redraw:null,getRedraw:function(){if(!this._redraw){var theLayer=this;this._redraw=function(){theLayer.draw();theLayer._redrawTimer=0}}return this._redraw},setProvider:function(newProvider){var firstProvider=this.provider===null;if(!firstProvider){this.requestManager.clear();for(var name in this.levels){if(this.levels.hasOwnProperty(name)){var level=this.levels[name];while(level.firstChild){this.provider.releaseTile(level.firstChild.coord);level.removeChild(level.firstChild)}}}}this.tiles={};this.provider=newProvider;if(!firstProvider){this.draw()}},enable:function(){this.enabled=true;this.parent.style.display="";this.draw();return this},disable:function(){this.enabled=false;this.requestManager.clear();this.parent.style.display="none";return this},destroy:function(){this.requestManager.clear();this.requestManager.removeCallback("requestcomplete",this.getTileComplete());this.requestManager.removeCallback("requesterror",this.getTileError());this.provider=null;if(this.parent.parentNode){this.parent.parentNode.removeChild(this.parent) }this.map=null}};MM.Map=function(parent,layerOrLayers,dimensions,eventHandlers){if(typeof parent=="string"){parent=document.getElementById(parent);if(!parent){throw"The ID provided to modest maps could not be found."}}this.parent=parent;this.parent.style.padding="0";this.parent.style.overflow="hidden";var position=MM.getStyle(this.parent,"position");if(position!="relative"&&position!="absolute"){this.parent.style.position="relative"}this.layers=[];if(!layerOrLayers){layerOrLayers=[]}if(!(layerOrLayers instanceof Array)){layerOrLayers=[layerOrLayers]}for(var i=0;i=this.layers.length){throw new Error("invalid index in setLayerAt(): "+index)}if(this.layers[index]!=layer){if(indexthis.layers.length){throw new Error("invalid index in insertLayerAt(): "+index)}if(index==this.layers.length){this.layers.push(layer);this.parent.appendChild(layer.parent)}else{var other=this.layers[index];this.parent.insertBefore(layer.parent,other.parent);this.layers.splice(index,0,layer)}layer.map=this;MM.getFrame(this.getRedraw());return this},removeLayerAt:function(index){if(index<0||index>=this.layers.length){throw new Error("invalid index in removeLayer(): "+index)}var old=this.layers[index];this.layers.splice(index,1);old.destroy();return this},swapLayersAt:function(i,j){if(i<0||i>=this.layers.length||j<0||j>=this.layers.length){throw new Error("invalid index in swapLayersAt(): "+index)}var layer1=this.layers[i],layer2=this.layers[j],dummy=document.createElement("div");this.parent.replaceChild(dummy,layer2.parent);this.parent.replaceChild(layer2.parent,layer1.parent);this.parent.replaceChild(layer1.parent,dummy);this.layers[i]=layer2;this.layers[j]=layer1;return this},enableLayer:function(name){var l=this.getLayer(name);if(l)l.enable();return this},enableLayerAt:function(index){var l=this.getLayerAt(index);if(l)l.enable();return this},disableLayer:function(name){var l=this.getLayer(name);if(l)l.disable();return this},disableLayerAt:function(index){var l=this.getLayerAt(index);if(l)l.disable();return this},enforceZoomLimits:function(coord){var limits=this.coordLimits;if(limits){var minZoom=limits[0].zoom;var maxZoom=limits[1].zoom;if(coord.zoommaxZoom){coord=coord.zoomTo(maxZoom)}}return coord},enforcePanLimits:function(coord){if(this.coordLimits){coord=coord.copy();var topLeftLimit=this.coordLimits[0].zoomTo(coord.zoom);var bottomRightLimit=this.coordLimits[1].zoomTo(coord.zoom);var currentTopLeft=this.pointCoordinate(new MM.Point(0,0)).zoomTo(coord.zoom);var currentBottomRight=this.pointCoordinate(this.dimensions).zoomTo(coord.zoom);if(bottomRightLimit.row-topLeftLimit.rowbottomRightLimit.row){coord.row-=currentBottomRight.row-bottomRightLimit.row}}if(bottomRightLimit.column-topLeftLimit.columnbottomRightLimit.column){coord.column-=currentBottomRight.column-bottomRightLimit.column}}}return coord},enforceLimits:function(coord){return this.enforcePanLimits(this.enforceZoomLimits(coord))},draw:function(){this.coordinate=this.enforceLimits(this.coordinate);if(this.dimensions.x<=0||this.dimensions.y<=0){if(this.autoSize){var w=this.parent.offsetWidth,h=this.parent.offsetHeight;this.dimensions=new MM.Point(w,h);if(w<=0||h<=0){return}}else{return}}for(var i=0;i