From a905543d12ee0ea2bfef933d137d0677d0191269 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 6 Dec 2011 20:56:54 -0500 Subject: [PATCH] Renaming shortcut from mm to MM --- modestmaps.js | 69 +++++++++++++++++++++++------------------------ modestmaps.min.js | 2 +- src/start.js | 6 ++--- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/modestmaps.js b/modestmaps.js index c3c9092..dfcdc57 100644 --- a/modestmaps.js +++ b/modestmaps.js @@ -12,7 +12,7 @@ * */ -var previous_mm = mm; +var previousMM = MM; // namespacing for backwards-compatibility if (!com) { @@ -20,9 +20,9 @@ if (!com) { if (!com.modestmaps) com.modestmaps = {}; } -var mm = com.modestmaps = { +var MM = com.modestmaps = { noConflict: function() { - mm = previous_mm; + MM = previousMM; return this; } }; @@ -1899,7 +1899,7 @@ var mm = com.modestmaps = { if(!(layerOrLayers instanceof Array)) { layerOrLayers = [ layerOrLayers ]; } - + for (var i = 0; i < layerOrLayers.length; i++) { this.addLayer(layerOrLayers[i]); } @@ -1912,7 +1912,7 @@ var mm = com.modestmaps = { this.tileSize = new MM.Point(256, 256); // default 0-18 zoom level - // with infinite horizontal pan and clamped vertical pan + // with infinite horizontal pan and clamped vertical pan this.coordLimits = [ new MM.Coordinate(0,-Infinity,0), // top left outer new MM.Coordinate(1,Infinity,0).zoomTo(18) // bottom right inner @@ -2014,14 +2014,14 @@ var mm = com.modestmaps = { } return this._windowResize; }, - + // A convenience function to restrict interactive zoom ranges. // (you should also adjust map provider to restrict which tiles get loaded, // or modify map.coordLimits and provider.tileLimits for finer control) setZoomRange: function(minZoom, maxZoom) { this.coordLimits[0] = this.coordLimits[0].zoomTo(minZoom); this.coordLimits[1] = this.coordLimits[1].zoomTo(maxZoom); - }, + }, // zooming zoomBy: function(zoomOffset) { @@ -2258,7 +2258,6 @@ var mm = com.modestmaps = { }, // layers - // HACK for 0.x.y - stare at @RandomEtc // this method means we can also pass a URL template or a MapProvider to addLayer coerceLayer: function(layerish) { @@ -2273,7 +2272,7 @@ var mm = com.modestmaps = { return new MM.Layer(layerish); } }, - + // return a copy of the layers array getLayers: function() { return this.layers.slice(); @@ -2283,7 +2282,7 @@ var mm = com.modestmaps = { getLayerAt: function(index) { return this.layers[index]; }, - + // put the given layer on top of all the others addLayer: function(layer) { layer = this.coerceLayer(layer); @@ -2292,7 +2291,7 @@ var mm = com.modestmaps = { layer.map = this; // TODO: remove map property from MM.Layer? return this; }, - + // find the given layer and remove it removeLayer: function(layer) { for (var i = 0; i < this.layers.length; i++) { @@ -2306,8 +2305,8 @@ var mm = com.modestmaps = { // replace the current layer at the given index with the given layer setLayerAt: function(index, layer) { - - if(index < 0 || index >= this.layers.length) { + + if (index < 0 || index >= this.layers.length) { throw new Error('invalid index in setLayerAt(): ' + index); } @@ -2319,22 +2318,22 @@ var mm = com.modestmaps = { if (index < this.layers.length) { this.layers[index].destroy(); } - + // pass it on. this.layers[index] = layer; this.parent.appendChild(layer.parent); - layer.map = this; // TODO: remove map property from MM.Layer - + layer.map = this; // TODO: remove map property from MM.Layer + MM.getFrame(this.getRedraw()); } - + return this; }, // put the given layer at the given index, moving others if necessary insertLayerAt: function(index, layer) { - if(index < 0 || index > this.layers.length) { + if (index < 0 || index > this.layers.length) { throw new Error('invalid index in insertLayerAt(): ' + index); } @@ -2352,15 +2351,15 @@ var mm = com.modestmaps = { } layer.map = this; // TODO: remove map property from MM.Layer - + MM.getFrame(this.getRedraw()); - + return this; }, // remove the layer at the given index, call .destroy() on the layer removeLayerAt: function(index) { - if(index < 0 || index >= this.layers.length) { + if (index < 0 || index >= this.layers.length) { throw new Error('invalid index in removeLayer(): ' + index); } @@ -2368,14 +2367,14 @@ var mm = com.modestmaps = { var old = this.layers[index]; this.layers.splice(index, 1); old.destroy(); - + return this; }, // switch the stacking order of two layers, by index swapLayers: function(i, j) { - if(i < 0 || i >= this.layers.length || j < 0 || j >= this.layers.length) { + if (i < 0 || i >= this.layers.length || j < 0 || j >= this.layers.length) { throw new Error('invalid index in swapLayers(): ' + index); } @@ -2395,7 +2394,7 @@ var mm = com.modestmaps = { // now do it to the layers array this.layers[i] = layer2; this.layers[j] = layer1; - + return this; }, @@ -2403,7 +2402,7 @@ var mm = com.modestmaps = { enforceZoomLimits: function(coord) { var limits = this.coordLimits; - if (limits) { + if (limits) { // clamp zoom level: var minZoom = limits[0].zoom; var maxZoom = limits[1].zoom; @@ -2416,21 +2415,21 @@ var mm = com.modestmaps = { } return coord; }, - + enforcePanLimits: function(coord) { - + var limits = this.coordLimits; - - if (limits) { - + + if (limits) { + coord = coord.copy(); - + // clamp pan: var topLeftLimit = limits[0].zoomTo(coord.zoom); var bottomRightLimit = limits[1].zoomTo(coord.zoom); var currentTopLeft = this.pointCoordinate(new MM.Point(0,0)); var currentBottomRight = this.pointCoordinate(this.dimensions); - + // this handles infinite limits: // (Infinity - Infinity) is Nan // NaN is never less than anything @@ -2448,7 +2447,7 @@ var mm = com.modestmaps = { } if (bottomRightLimit.column - topLeftLimit.column < currentBottomRight.column - currentTopLeft.column) { // if the limit is smaller than the current view, center it - coord.column = (bottomRightLimit.column + topLeftLimit.column) / 2; + coord.column = (bottomRightLimit.column + topLeftLimit.column) / 2; } else { if (currentTopLeft.column < topLeftLimit.column) { @@ -2459,8 +2458,8 @@ var mm = com.modestmaps = { } } } - - return coord; + + return coord; }, // Prevent accidentally navigating outside the `coordLimits` of the map. diff --git a/modestmaps.min.js b/modestmaps.min.js index 6f22fd5..d361ba0 100644 --- a/modestmaps.min.js +++ b/modestmaps.min.js @@ -11,4 +11,4 @@ * See CHANGELOG and http://semver.org/ for more details. * */ -var previous_mm=mm;if(!com){var com={};if(!com.modestmaps){com.modestmaps={}}}var mm=com.modestmaps={noConflict:function(){mm=previous_mm;return this}};(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){var d=function(g){g=this.sourceCoordinate(g);if(!g){return null}var e=c;if(b&&b.length&&e.indexOf("{S}")>=0){var f=parseInt(g.zoom+g.row+g.column,10)%b.length;e=e.replace("{S}",b[f])}return e.replace("{Z}",g.zoom.toFixed(0)).replace("{X}",g.column.toFixed(0)).replace("{Y}",g.row.toFixed(0))};a.MapProvider.call(this,d)};a.extend(a.TemplatedMapProvider,a.MapProvider);a.TilePaintingProvider=function(b){this.template_provider=b};a.TilePaintingProvider.prototype={getTile:function(b){return this.template_provider.getTileUrl(b)},releaseTile:function(b){}};a.extend(a.TilePaintingProvider,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;this._mouseWheel=a.bind(this.mouseWheel,this);a.addEvent(b.parent,"mousewheel",this._mouseWheel)},remove:function(){a.removeEvent(this.map.parent,"mousewheel",this._mouseWheel)},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;this._doubleClick=a.bind(this.doubleClick,this);a.addEvent(b.parent,"dblclick",this._doubleClick)},remove:function(){a.removeEvent(this.map.parent,"dblclick",this._doubleClick)},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;this._mouseDown=a.bind(this.mouseDown,this);a.addEvent(b.parent,"mousedown",this._mouseDown)},remove:function(){a.removeEvent(this.map.parent,"mousedown",this._mouseDown)},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(b){a.removeEvent(document,"mouseup",this._mouseUp);a.removeEvent(document,"mousemove",this._mouseMove);this.prevMouse=null;this.map.parent.style.cursor="";return a.cancelEvent(b)}};a.MouseHandler=function(b){if(b!==undefined){this.init(b)}};a.MouseHandler.prototype={init:function(b){this.map=b;this.handlers=[new a.DragHandler(b),new a.DoubleClickHandler(b),new a.MouseWheelHandler(b)]},remove:function(){for(var b=0;bthis.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 f)){this.loadingBay.removeChild(c);this.openRequestCount--;c.src=c.coord=c.onload=c.onerror=null}}for(var k in this.requestsById){if(this.requestsById.hasOwnProperty(k)){if(!(k in f)){var h=this.requestsById[k];delete this.requestsById[k];if(h!==null){h=h.id=h.coord=h.url=null}}}}},hasRequest:function(b){return(b in this.requestsById)},requestTile:function(e,d,b){if(!(e in this.requestsById)){var c={id:e,coord:d.copy(),url:b};this.requestsById[e]=c;if(b){this.requestQueue.push(c)}}},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.id;b.style.position="absolute";b.coord=c.coord;this.loadingBay.appendChild(b);b.onload=b.onerror=this.getLoadComplete();b.src=c.url;c=c.id=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.Layer=function(b){this.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.levels={};this.requestManager=new a.RequestManager();this.requestManager.addCallback("requestcomplete",this.getTileComplete());this.setProvider(b)};a.Layer.prototype={map:null,parent:null,tiles:null,levels:null,requestManager:null,tileCacheSize:null,maxTileCacheSize:null,provider:null,recentTiles:null,recentTilesById:null,enablePyramidLoading:false,_tileComplete:null,getTileComplete:function(){if(!this._tileComplete){var b=this;this._tileComplete=function(d,e){b.tiles[e.id]=e;b.tileCacheSize++;var c={id:e.id,lastTouchedTime:new Date().getTime()};b.recentTilesById[e.id]=c;b.recentTiles.push(c);b.positionTile(e)}}return this._tileComplete},draw:function(){var n=Math.round(this.map.coordinate.zoom);var m=this.map.pointCoordinate(new a.Point(0,0)).zoomTo(n).container();var h=this.map.pointCoordinate(this.map.dimensions).zoomTo(n).container().right().down();var j={};var l=this.createOrGetLevel(m.zoom);var g=m.copy();for(g.column=m.column;g.column<=h.column;g.column++){for(g.row=m.row;g.row<=h.row;g.row++){var c=this.inventoryVisibleTile(l,g);while(c.length){j[c.pop()]=true}}}for(var e in this.levels){if(this.levels.hasOwnProperty(e)){var o=parseInt(e,10);if(o>=m.zoom-5&&o0){c.style.display="block";f=Math.pow(2,this.map.coordinate.zoom-l);k=k.zoomTo(l)}else{c.style.display="none"}var i=this.map.tileSize.x*f;var g=this.map.tileSize.y*f;var b=new a.Point(this.map.dimensions.x/2,this.map.dimensions.y/2);var j=this.tileElementsInLevel(c);while(j.length){var h=j.pop();if(!e[h.id]){this.provider.releaseTile(h.coord);this.requestManager.clearRequest(h.coord.toKey());c.removeChild(h)}else{a.moveElement(h,{x:Math.round(b.x+(h.coord.column-k.column)*i),y:Math.round(b.y+(h.coord.row-k.row)*g),scale:f,width:this.map.tileSize.x,height:this.map.tileSize.y});this.recentTilesById[h.id].lastTouchedTime=d}}},createOrGetLevel:function(b){if(b in this.levels){return this.levels[b]}var c=document.createElement("div");c.id=this.parent.id+"-zoom-"+b;c.style.cssText=this.parent.style.cssText;c.style.zIndex=b;this.parent.appendChild(c);this.levels[b]=c;return c},addTileImage:function(c,d,b){this.requestManager.requestTile(c,d,b)},addTileElement:function(d,e,c){c.id=d;c.coord=e.copy();this.tiles[d]=c;this.tileCacheSize++;var b={id:d,lastTouchedTime:new Date().getTime()};this.recentTilesById[d]=b;this.recentTiles.push(b);this.positionTile(c)},positionTile:function(f){var e=this.map.coordinate.zoomTo(f.coord.zoom);f.style.position="absolute";var g=Math.pow(2,this.map.coordinate.zoom-f.coord.zoom);var c=((this.map.dimensions.x/2)+(f.coord.column-e.column)*this.map.tileSize.x*g);var b=((this.map.dimensions.y/2)+(f.coord.row-e.row)*this.map.tileSize.y*g);a.moveElement(f,{x:Math.round(c),y:Math.round(b),scale:g,width:this.map.tileSize.x,height:this.map.tileSize.y});var d=this.levels[f.coord.zoom];d.appendChild(f);f.className="map-tile-loaded";if(Math.round(this.map.coordinate.zoom)==f.coord.zoom){d.style.display="block"}this.requestRedraw()},_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},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--}}},setProvider:function(c){if("getTileUrl" in c&&(typeof c.getTileUrl==="function")){c=new a.TilePaintingProvider(c)}var d=(this.provider===null);if(!d){this.requestManager.clear();for(var b in this.levels){if(this.levels.hasOwnProperty(b)){var e=this.levels[b];while(e.firstChild){this.provider.releaseTile(e.firstChild.coord);e.removeChild(e.firstChild)}}}}this.tiles={};this.tileCacheSize=0;this.maxTileCacheSize=64;this.recentTilesById={};this.recentTiles=[];this.provider=c;if(!d){this.draw()}},getCenterDistanceCompare:function(){var b=this.map.coordinate.zoomTo(Math.round(this.map.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}},destroy:function(){this.requestManager.clear();this.requestManager.removeCallback("requestcomplete",this.getTileComplete());this.provider=null;this.parent.parentNode.removeChild(this.parent);this.map=null}};a.Map=function(f,e,g,h){if(typeof f=="string"){f=document.getElementById(f);if(!f){throw"The ID provided to modest maps could not be found."}}this.parent=f;this.parent.style.padding="0";this.parent.style.overflow="hidden";var b=a.getStyle(this.parent,"position");if(b!="relative"&&b!="absolute"){this.parent.style.position="relative"}this.layers=[];if(!(e instanceof Array)){e=[e]}for(var d=0;d=this.layers.length){throw new Error("invalid index in setLayerAt(): "+b)}c=this.coerceLayer(c);if(this.layers[b]!=c){if(bthis.layers.length){throw new Error("invalid index in insertLayerAt(): "+c)}d=this.coerceLayer(d);if(c==this.layers.length){this.layers.push(d);this.parent.appendChild(d.parent)}else{var b=this.layers[c];this.parent.insertBefore(d.parent,b.parent);this.layers.splice(c,0,d)}d.map=this;a.getFrame(this.getRedraw());return this},removeLayerAt:function(c){if(c<0||c>=this.layers.length){throw new Error("invalid index in removeLayer(): "+c)}var b=this.layers[c];this.layers.splice(c,1);b.destroy();return this},swapLayers:function(c,b){if(c<0||c>=this.layers.length||b<0||b>=this.layers.length){throw new Error("invalid index in swapLayers(): "+index)}var f=this.layers[c],d=this.layers[b],e=document.createElement("div");this.parent.replaceChild(e,d.parent);this.parent.replaceChild(d.parent,f.parent);this.parent.replaceChild(f.parent,e);this.layers[c]=d;this.layers[b]=f;return this},enforceZoomLimits:function(e){var c=this.coordLimits;if(c){var d=c[0].zoom;var b=c[1].zoom;if(e.zoomb){e=e.zoomTo(b)}}}return e},enforcePanLimits:function(g){var c=this.coordLimits;if(c){g=g.copy();var e=c[0].zoomTo(g.zoom);var b=c[1].zoomTo(g.zoom);var d=this.pointCoordinate(new a.Point(0,0));var f=this.pointCoordinate(this.dimensions);if(b.row-e.rowb.row){g.row-=f.row-b.row}}}if(b.column-e.columnb.column){g.column-=f.column-b.column}}}}return g},enforceLimits:function(b){return this.enforcePanLimits(this.enforceZoomLimits(b))},draw:function(){this.coordinate=this.enforceLimits(this.coordinate);if(this.dimensions.x<=0||this.dimensions.y<=0){if(this.autoSize){var b=this.parent.offsetWidth,d=this.parent.offsetHeight;this.dimensions=new a.Point(b,d);if(b<=0||d<=0){return}}else{return}}for(var c=0;c=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){var d=function(g){g=this.sourceCoordinate(g);if(!g){return null}var e=c;if(b&&b.length&&e.indexOf("{S}")>=0){var f=parseInt(g.zoom+g.row+g.column,10)%b.length;e=e.replace("{S}",b[f])}return e.replace("{Z}",g.zoom.toFixed(0)).replace("{X}",g.column.toFixed(0)).replace("{Y}",g.row.toFixed(0))};a.MapProvider.call(this,d)};a.extend(a.TemplatedMapProvider,a.MapProvider);a.TilePaintingProvider=function(b){this.template_provider=b};a.TilePaintingProvider.prototype={getTile:function(b){return this.template_provider.getTileUrl(b)},releaseTile:function(b){}};a.extend(a.TilePaintingProvider,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;this._mouseWheel=a.bind(this.mouseWheel,this);a.addEvent(b.parent,"mousewheel",this._mouseWheel)},remove:function(){a.removeEvent(this.map.parent,"mousewheel",this._mouseWheel)},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;this._doubleClick=a.bind(this.doubleClick,this);a.addEvent(b.parent,"dblclick",this._doubleClick)},remove:function(){a.removeEvent(this.map.parent,"dblclick",this._doubleClick)},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;this._mouseDown=a.bind(this.mouseDown,this);a.addEvent(b.parent,"mousedown",this._mouseDown)},remove:function(){a.removeEvent(this.map.parent,"mousedown",this._mouseDown)},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(b){a.removeEvent(document,"mouseup",this._mouseUp);a.removeEvent(document,"mousemove",this._mouseMove);this.prevMouse=null;this.map.parent.style.cursor="";return a.cancelEvent(b)}};a.MouseHandler=function(b){if(b!==undefined){this.init(b)}};a.MouseHandler.prototype={init:function(b){this.map=b;this.handlers=[new a.DragHandler(b),new a.DoubleClickHandler(b),new a.MouseWheelHandler(b)]},remove:function(){for(var b=0;bthis.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 f)){this.loadingBay.removeChild(c);this.openRequestCount--;c.src=c.coord=c.onload=c.onerror=null}}for(var k in this.requestsById){if(this.requestsById.hasOwnProperty(k)){if(!(k in f)){var h=this.requestsById[k];delete this.requestsById[k];if(h!==null){h=h.id=h.coord=h.url=null}}}}},hasRequest:function(b){return(b in this.requestsById)},requestTile:function(e,d,b){if(!(e in this.requestsById)){var c={id:e,coord:d.copy(),url:b};this.requestsById[e]=c;if(b){this.requestQueue.push(c)}}},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.id;b.style.position="absolute";b.coord=c.coord;this.loadingBay.appendChild(b);b.onload=b.onerror=this.getLoadComplete();b.src=c.url;c=c.id=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.Layer=function(b){this.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.levels={};this.requestManager=new a.RequestManager();this.requestManager.addCallback("requestcomplete",this.getTileComplete());this.setProvider(b)};a.Layer.prototype={map:null,parent:null,tiles:null,levels:null,requestManager:null,tileCacheSize:null,maxTileCacheSize:null,provider:null,recentTiles:null,recentTilesById:null,enablePyramidLoading:false,_tileComplete:null,getTileComplete:function(){if(!this._tileComplete){var b=this;this._tileComplete=function(d,e){b.tiles[e.id]=e;b.tileCacheSize++;var c={id:e.id,lastTouchedTime:new Date().getTime()};b.recentTilesById[e.id]=c;b.recentTiles.push(c);b.positionTile(e)}}return this._tileComplete},draw:function(){var n=Math.round(this.map.coordinate.zoom);var m=this.map.pointCoordinate(new a.Point(0,0)).zoomTo(n).container();var h=this.map.pointCoordinate(this.map.dimensions).zoomTo(n).container().right().down();var j={};var l=this.createOrGetLevel(m.zoom);var g=m.copy();for(g.column=m.column;g.column<=h.column;g.column++){for(g.row=m.row;g.row<=h.row;g.row++){var c=this.inventoryVisibleTile(l,g);while(c.length){j[c.pop()]=true}}}for(var e in this.levels){if(this.levels.hasOwnProperty(e)){var o=parseInt(e,10);if(o>=m.zoom-5&&o0){c.style.display="block";f=Math.pow(2,this.map.coordinate.zoom-l);k=k.zoomTo(l)}else{c.style.display="none"}var i=this.map.tileSize.x*f;var g=this.map.tileSize.y*f;var b=new a.Point(this.map.dimensions.x/2,this.map.dimensions.y/2);var j=this.tileElementsInLevel(c);while(j.length){var h=j.pop();if(!e[h.id]){this.provider.releaseTile(h.coord);this.requestManager.clearRequest(h.coord.toKey());c.removeChild(h)}else{a.moveElement(h,{x:Math.round(b.x+(h.coord.column-k.column)*i),y:Math.round(b.y+(h.coord.row-k.row)*g),scale:f,width:this.map.tileSize.x,height:this.map.tileSize.y});this.recentTilesById[h.id].lastTouchedTime=d}}},createOrGetLevel:function(b){if(b in this.levels){return this.levels[b]}var c=document.createElement("div");c.id=this.parent.id+"-zoom-"+b;c.style.cssText=this.parent.style.cssText;c.style.zIndex=b;this.parent.appendChild(c);this.levels[b]=c;return c},addTileImage:function(c,d,b){this.requestManager.requestTile(c,d,b)},addTileElement:function(d,e,c){c.id=d;c.coord=e.copy();this.tiles[d]=c;this.tileCacheSize++;var b={id:d,lastTouchedTime:new Date().getTime()};this.recentTilesById[d]=b;this.recentTiles.push(b);this.positionTile(c)},positionTile:function(f){var e=this.map.coordinate.zoomTo(f.coord.zoom);f.style.position="absolute";var g=Math.pow(2,this.map.coordinate.zoom-f.coord.zoom);var c=((this.map.dimensions.x/2)+(f.coord.column-e.column)*this.map.tileSize.x*g);var b=((this.map.dimensions.y/2)+(f.coord.row-e.row)*this.map.tileSize.y*g);a.moveElement(f,{x:Math.round(c),y:Math.round(b),scale:g,width:this.map.tileSize.x,height:this.map.tileSize.y});var d=this.levels[f.coord.zoom];d.appendChild(f);f.className="map-tile-loaded";if(Math.round(this.map.coordinate.zoom)==f.coord.zoom){d.style.display="block"}this.requestRedraw()},_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},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--}}},setProvider:function(c){if("getTileUrl" in c&&(typeof c.getTileUrl==="function")){c=new a.TilePaintingProvider(c)}var d=(this.provider===null);if(!d){this.requestManager.clear();for(var b in this.levels){if(this.levels.hasOwnProperty(b)){var e=this.levels[b];while(e.firstChild){this.provider.releaseTile(e.firstChild.coord);e.removeChild(e.firstChild)}}}}this.tiles={};this.tileCacheSize=0;this.maxTileCacheSize=64;this.recentTilesById={};this.recentTiles=[];this.provider=c;if(!d){this.draw()}},getCenterDistanceCompare:function(){var b=this.map.coordinate.zoomTo(Math.round(this.map.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}},destroy:function(){this.requestManager.clear();this.requestManager.removeCallback("requestcomplete",this.getTileComplete());this.provider=null;this.parent.parentNode.removeChild(this.parent);this.map=null}};a.Map=function(f,e,g,h){if(typeof f=="string"){f=document.getElementById(f);if(!f){throw"The ID provided to modest maps could not be found."}}this.parent=f;this.parent.style.padding="0";this.parent.style.overflow="hidden";var b=a.getStyle(this.parent,"position");if(b!="relative"&&b!="absolute"){this.parent.style.position="relative"}this.layers=[];if(!(e instanceof Array)){e=[e]}for(var d=0;d=this.layers.length){throw new Error("invalid index in setLayerAt(): "+b)}c=this.coerceLayer(c);if(this.layers[b]!=c){if(bthis.layers.length){throw new Error("invalid index in insertLayerAt(): "+c)}d=this.coerceLayer(d);if(c==this.layers.length){this.layers.push(d);this.parent.appendChild(d.parent)}else{var b=this.layers[c];this.parent.insertBefore(d.parent,b.parent);this.layers.splice(c,0,d)}d.map=this;a.getFrame(this.getRedraw());return this},removeLayerAt:function(c){if(c<0||c>=this.layers.length){throw new Error("invalid index in removeLayer(): "+c)}var b=this.layers[c];this.layers.splice(c,1);b.destroy();return this},swapLayers:function(c,b){if(c<0||c>=this.layers.length||b<0||b>=this.layers.length){throw new Error("invalid index in swapLayers(): "+index)}var f=this.layers[c],d=this.layers[b],e=document.createElement("div");this.parent.replaceChild(e,d.parent);this.parent.replaceChild(d.parent,f.parent);this.parent.replaceChild(f.parent,e);this.layers[c]=d;this.layers[b]=f;return this},enforceZoomLimits:function(e){var c=this.coordLimits;if(c){var d=c[0].zoom;var b=c[1].zoom;if(e.zoomb){e=e.zoomTo(b)}}}return e},enforcePanLimits:function(g){var c=this.coordLimits;if(c){g=g.copy();var e=c[0].zoomTo(g.zoom);var b=c[1].zoomTo(g.zoom);var d=this.pointCoordinate(new a.Point(0,0));var f=this.pointCoordinate(this.dimensions);if(b.row-e.rowb.row){g.row-=f.row-b.row}}}if(b.column-e.columnb.column){g.column-=f.column-b.column}}}}return g},enforceLimits:function(b){return this.enforcePanLimits(this.enforceZoomLimits(b))},draw:function(){this.coordinate=this.enforceLimits(this.coordinate);if(this.dimensions.x<=0||this.dimensions.y<=0){if(this.autoSize){var b=this.parent.offsetWidth,d=this.parent.offsetHeight;this.dimensions=new a.Point(b,d);if(b<=0||d<=0){return}}else{return}}for(var c=0;c