/* * Modest Maps JS v0.18.3 * http://modestmaps.com/ * * Copyright (c) 2010 Stamen Design, All Rights Reserved. * * Open source under the BSD License. * http://creativecommons.org/licenses/BSD/ * * Versioned using Semantic Versioning (v.major.minor.patch) * See CHANGELOG and http://semver.org/ for more details. * */ if(!com){var com={};if(!com.modestmaps){com.modestmaps={}}}(function(a){a.extend=function(d,b){for(var c in b.prototype){if(typeof d.prototype[c]=="undefined"){d.prototype[c]=b.prototype[c]}}return d};a.getFrame=function(){return function(b){(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(c){window.setTimeout(function(){c(+new Date())},10)})(b)}}();a.transformProperty=(function(d){if(!this.document){return}var c=document.documentElement.style;for(var b=0;b=c){return null}var f=d.column-b.column;var e=g.column%f;while(e<0){e+=f}return new a.Coordinate(g.row,e,g.zoom)}};a.TemplatedMapProvider=function(c,b){a.MapProvider.call(this,function(f){f=this.sourceCoordinate(f);if(!f){return null}var d=c;if(b&&b.length&&d.indexOf("{S}")>=0){var e=parseInt(f.zoom+f.row+f.column,10)%b.length;d=d.replace("{S}",b[e])}return d.replace("{Z}",f.zoom.toFixed(0)).replace("{X}",f.column.toFixed(0)).replace("{Y}",f.row.toFixed(0))})};a.extend(a.TemplatedMapProvider,a.MapProvider);a.getMousePoint=function(f,d){var b=new a.Point(f.clientX,f.clientY);b.x+=document.body.scrollLeft+document.documentElement.scrollLeft;b.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var c=d.parent;c;c=c.offsetParent){b.x-=c.offsetLeft;b.y-=c.offsetTop}return b};a.MouseWheelHandler=function(b){if(b!==undefined){this.init(b)}};a.MouseWheelHandler.prototype={init:function(b){this.map=b;a.addEvent(b.parent,"mousewheel",a.bind(this.mouseWheel,this))},mouseWheel:function(d){var f=0;this.prevTime=this.prevTime||new Date().getTime();if(d.wheelDelta){f=d.wheelDelta}else{if(d.detail){f=-d.detail}}var c=new Date().getTime()-this.prevTime;if(Math.abs(f)>0&&(c>200)){var b=a.getMousePoint(d,this.map);this.map.zoomByAbout(f>0?1:-1,b);this.prevTime=new Date().getTime()}return a.cancelEvent(d)}};a.DoubleClickHandler=function(b){if(b!==undefined){this.init(b)}};a.DoubleClickHandler.prototype={init:function(b){this.map=b;a.addEvent(b.parent,"dblclick",this._doubleClick=a.bind(this.doubleClick,this))},doubleClick:function(c){var b=a.getMousePoint(c,this.map);this.map.zoomByAbout(c.shiftKey?-1:1,b);return a.cancelEvent(c)}};a.DragHandler=function(b){if(b!==undefined){this.init(b)}};a.DragHandler.prototype={init:function(b){this.map=b;a.addEvent(b.parent,"mousedown",a.bind(this.mouseDown,this))},mouseDown:function(b){a.addEvent(document,"mouseup",this._mouseUp=a.bind(this.mouseUp,this));a.addEvent(document,"mousemove",this._mouseMove=a.bind(this.mouseMove,this));this.prevMouse=new a.Point(b.clientX,b.clientY);this.map.parent.style.cursor="move";return a.cancelEvent(b)},mouseMove:function(b){if(this.prevMouse){this.map.panBy(b.clientX-this.prevMouse.x,b.clientY-this.prevMouse.y);this.prevMouse.x=b.clientX;this.prevMouse.y=b.clientY;this.prevMouse.t=+new Date()}return a.cancelEvent(b)},mouseUp:function(d){a.removeEvent(document,"mouseup",this._mouseUp);a.removeEvent(document,"mousemove",this._mouseMove);var b=50;var c={x:(d.clientX-this.prevMouse.x)*(b/Math.min(+new Date()-this.prevMouse.t,1)),y:(d.clientY-this.prevMouse.y)*(b/Math.min(+new Date()-this.prevMouse.t,1))};this.prevMouse=null;this.map.parent.style.cursor="";return a.cancelEvent(d)}};a.MouseHandler=function(b){if(b!==undefined){this.init(b)}};a.MouseHandler.prototype={init:function(b){this.map=b;new a.DragHandler(b);new a.DoubleClickHandler(b);new a.MouseWheelHandler(b)}};a.TouchHandler=function(){};a.TouchHandler.prototype={maxTapTime:250,maxTapDistance:30,maxDoubleTapDelay:350,locations:{},taps:[],wasPinching:false,lastPinchCenter:null,init:function(c,b){this.map=c;b=b||{};a.addEvent(c.parent,"touchstart",a.bind(this.touchStartMachine,this));a.addEvent(c.parent,"touchmove",a.bind(this.touchMoveMachine,this));a.addEvent(c.parent,"touchend",a.bind(this.touchEndMachine,this));this.options={};this.options.snapToZoom=b.snapToZoom||true},updateTouches:function(f){for(var d=0;dthis.maxTapDistance){}else{if(f>this.maxTapTime){n.end=c;n.duration=f;this.onHold(n)}else{n.time=c;this.onTap(n)}}}var m={};for(var g=0;g=0;d--){var c=b[d];if(!(c.id in g)){this.loadingBay.removeChild(c);this.openRequestCount--;c.src=c.coord=c.onload=c.onerror=null}}for(var h in this.requestsById){if(this.requestsById.hasOwnProperty(h)){if(!(h in g)){var f=this.requestsById[h];delete this.requestsById[h];if(f!==null){f=f.key=f.coord=f.url=null}}}}},hasRequest:function(b){return(b in this.requestsById)},requestTile:function(c,e,b){if(!(c in this.requestsById)){var d={key:c,coord:e.copy(),url:b};this.requestsById[c]=d;if(b){this.requestQueue.push(d)}}},getProcessQueue:function(){if(!this._processQueue){var b=this;this._processQueue=function(){b.processQueue()}}return this._processQueue},processQueue:function(d){if(d&&this.requestQueue.length>8){this.requestQueue.sort(d)}while(this.openRequestCount0){var c=this.requestQueue.pop();if(c){this.openRequestCount++;var b=document.createElement("img");b.id=c.key;b.style.position="absolute";b.coord=c.coord;this.loadingBay.appendChild(b);b.onload=b.onerror=this.getLoadComplete();b.src=c.url;c=c.key=c.coord=c.url=null}}},_loadComplete:null,getLoadComplete:function(){if(!this._loadComplete){var b=this;this._loadComplete=function(d){d=d||window.event;var c=d.srcElement||d.target;c.onload=c.onerror=null;b.loadingBay.removeChild(c);b.openRequestCount--;delete b.requestsById[c.id];if(d.type==="load"&&(c.complete||(c.readyState&&c.readyState=="complete"))){b.dispatchCallback("requestcomplete",c)}else{c.src=null}setTimeout(b.getProcessQueue(),0)}}return this._loadComplete}};a.Map=function(k,j,b,c){if(typeof k=="string"){k=document.getElementById(k);if(!k){throw"The ID provided to modest maps could not be found."}}this.parent=k;this.parent.style.padding="0";this.parent.style.overflow="hidden";var g=a.getStyle(this.parent,"position");if(g!="relative"&&g!="absolute"){this.parent.style.position="relative"}if(!b){var l=this.parent.offsetWidth;var f=this.parent.offsetHeight;if(!l){l=640;this.parent.style.width=l+"px"}if(!f){f=480;this.parent.style.height=f+"px"}b=new a.Point(l,f);var d=this;a.addEvent(window,"resize",function(h){d.dimensions=new a.Point(d.parent.offsetWidth,d.parent.offsetHeight);d.draw();d.dispatchCallback("resized",[d.dimensions])})}else{this.parent.style.width=Math.round(b.x)+"px";this.parent.style.height=Math.round(b.y)+"px"}this.dimensions=b;this.requestManager=new a.RequestManager(this.parent);this.requestManager.addCallback("requestcomplete",this.getTileComplete());this.layers={};this.layerParent=document.createElement("div");this.layerParent.id=this.parent.id+"-layers";this.layerParent.style.cssText="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; margin: 0; padding: 0; z-index: 0";this.parent.appendChild(this.layerParent);this.coordinate=new a.Coordinate(0.5,0.5,0);this.setProvider(j);this.enablePyramidLoading=false;this.callbackManager=new a.CallbackManager(this,["zoomed","panned","centered","extentset","resized","drawn"]);if(c===undefined){this.eventHandlers=[];this.eventHandlers.push(new a.MouseHandler(this))}else{this.eventHandlers=c;if(c instanceof Array){for(var e=0;eb){e=e.zoomTo(b)}}}return e},draw:function(){this.coordinate=this.enforceLimits(this.coordinate);var o=Math.round(this.coordinate.zoom);var u=this.pointCoordinate(new a.Point(0,0)).zoomTo(o).container();var s=this.pointCoordinate(this.dimensions).zoomTo(o).container().right().down();var k=0;if(k){u=u.left(k).up(k);s=s.right(k).down(k)}var E={};var l=this.createOrGetLayer(u.zoom);var e=u.copy();for(e.column=u.column;e.column<=s.column;e.column+=1){for(e.row=u.row;e.row<=s.row;e.row+=1){var m=e.toKey();E[m]=true;if(m in this.tiles){var H=this.tiles[m];if(H.parentNode!=l){l.appendChild(H)}}else{if(!this.requestManager.hasRequest(m)){var n=this.provider.getTileUrl(e);this.requestManager.requestTile(m,e,n)}var q=false;var D=e.zoom;for(var r=1;r<=D;r++){var t=e.zoomBy(-r).container();var y=t.toKey();if(this.enablePyramidLoading){E[y]=true;var z=this.createOrGetLayer(t.zoom);if(y in this.tiles){var v=this.tiles[y];if(v.parentNode!=z){z.appendChild(v)}}else{if(!this.requestManager.hasRequest(y)){this.requestManager.requestTile(y,t,this.provider.getTileUrl(t))}}}else{if(y in this.tiles){E[y]=true;q=true;break}}}if(!q&&!this.enablePyramidLoading){var h=e.zoomBy(1);E[h.toKey()]=true;h.column+=1;E[h.toKey()]=true;h.row+=1;E[h.toKey()]=true;h.column-=1;E[h.toKey()]=true}}}}for(var I in this.layers){if(this.layers.hasOwnProperty(I)){var d=parseInt(I,10);if(d>=u.zoom-5&&d=0;w--){G.removeChild(C[w])}}}var f=new Date().getTime();var A=u.zoom-5;var g=u.zoom+2;for(var x=A;x0){G.style.display="block";F=Math.pow(2,this.coordinate.zoom-x);c=c.zoomTo(x)}else{G.style.display="none"}var b=this.provider.tileWidth*F,p=this.provider.tileHeight*F,B=new a.Point(this.dimensions.x/2,this.dimensions.y/2);for(var w=C.length-1;w>=0;w--){var H=C[w];if(!E[H.id]){G.removeChild(H)}else{a.moveElement(H,{x:Math.round(B.x+(H.coord.column-c.column)*b),y:Math.round(B.y+(H.coord.row-c.row)*p),scale:F,width:this.provider.tileWidth,height:this.provider.tileHeight});this.recentTilesById[H.id].lastTouchedTime=f}}}this.requestManager.clearExcept(E);this.requestManager.processQueue(this.getCenterDistanceCompare());this.checkCache();this.dispatchCallback("drawn")},_tileComplete:null,getTileComplete:function(){if(!this._tileComplete){var b=this;this._tileComplete=function(g,h){b.tiles[h.id]=h;b.tileCacheSize++;var e={id:h.id,lastTouchedTime:new Date().getTime()};b.recentTilesById[h.id]=e;b.recentTiles.push(e);var f=b.coordinate.zoomTo(h.coord.zoom);var j=Math.pow(2,b.coordinate.zoom-h.coord.zoom);var d=((b.dimensions.x/2)+(h.coord.column-f.column)*b.provider.tileWidth*j);var c=((b.dimensions.y/2)+(h.coord.row-f.row)*b.provider.tileHeight*j);a.moveElement(h,{x:Math.round(d),y:Math.round(c),scale:j,width:b.provider.tileWidth,height:b.provider.tileHeight});var i=b.layers[h.coord.zoom];i.appendChild(h);h.className="map-tile-loaded";if(Math.round(b.coordinate.zoom)===h.coord.zoom){i.style.display="block"}b.requestRedraw()}}return this._tileComplete},_redrawTimer:undefined,requestRedraw:function(){if(!this._redrawTimer){this._redrawTimer=setTimeout(this.getRedraw(),1000)}},_redraw:null,getRedraw:function(){if(!this._redraw){var b=this;this._redraw=function(){b.draw();b._redrawTimer=0}}return this._redraw},createOrGetLayer:function(c){if(c in this.layers){return this.layers[c]}var b=document.createElement("div");b.id=this.parent.id+"-zoom-"+c;b.style.cssText=this.layerParent.style.cssText;b.style.zIndex=c;this.layerParent.appendChild(b);this.layers[c]=b;return b},checkCache:function(){var f=this.parent.getElementsByTagName("img").length;var d=Math.max(f,this.maxTileCacheSize);if(this.tileCacheSize>d){this.recentTiles.sort(function(h,g){return g.lastTouchedTimeh.lastTouchedTime?1:0})}while(this.tileCacheSize>d){var c=this.recentTiles.pop();var b=new Date().getTime();delete this.recentTilesById[c.id];var e=this.tiles[c.id];if(e.parentNode){alert("Gah: trying to removing cached tile even though it's still in the DOM")}else{delete this.tiles[c.id];this.tileCacheSize--}}},getCenterDistanceCompare:function(){var b=this.coordinate.zoomTo(Math.round(this.coordinate.zoom));return function(e,d){if(e&&d){var g=e.coord;var f=d.coord;if(g.zoom==f.zoom){var c=Math.abs(b.row-g.row-0.5)+Math.abs(b.column-g.column-0.5);var h=Math.abs(b.row-f.row-0.5)+Math.abs(b.column-f.column-0.5);return ch?-1:0}else{return g.zoomf.zoom?-1:0}}return e?1:d?-1:0}}};if(typeof module!=="undefined"&&module.exports){module.exports={Point:a.Point,Projection:a.Projection,MercatorProjection:a.MercatorProjection,LinearProjection:a.LinearProjection,Transformation:a.Transformation,Location:a.Location,MapProvider:a.MapProvider,TemplatedMapProvider:a.TemplatedMapProvider,Coordinate:a.Coordinate}}})(com.modestmaps);