diff --git a/modestmaps.js b/modestmaps.js index 416021f..03f3cb7 100644 --- a/modestmaps.js +++ b/modestmaps.js @@ -92,10 +92,92 @@ var MM = com.modestmaps = { }; MM._browser = (function(window) { + /* + * Copy code from Leaflet's L.Browser, handles different browser and feature detections for internal Leaflet use. + */ + + var ie = !!window.ActiveXObject, + ie6 = ie && !window.XMLHttpRequest, + ie7 = ie && !document.querySelector, + + // terrible browser detection to work around Safari / iOS / Android browser bugs + ua = navigator.userAgent.toLowerCase(), + webkit = ('WebKitCSSMatrix' in window), //ua.indexOf('webkit') !== -1, + chrome = ua.indexOf('chrome') !== -1, + android = ua.indexOf('android') !== -1, + android23 = ua.search('android [23]') !== -1, + + mobile = typeof orientation !== undefined + '', + msTouch = window.navigator && window.navigator.msPointerEnabled && + window.navigator.msMaxTouchPoints, + retina = ('devicePixelRatio' in window && window.devicePixelRatio > 1) || + ('matchMedia' in window && window.matchMedia('(min-resolution:144dpi)') && + window.matchMedia('(min-resolution:144dpi)').matches), + + doc = document.documentElement, + ie3d = ie && ('transition' in doc.style), + webkit3d = ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()), + gecko3d = 'MozPerspective' in doc.style, + opera3d = 'OTransition' in doc.style, + any3d = (ie3d || webkit3d || gecko3d || opera3d); + + var touch = (function () { + + var startName = 'ontouchstart'; + + // IE10+ (We simulate these into touch* events in L.DomEvent and L.DomEvent.MsTouch) or WebKit, etc. + if (msTouch || (startName in doc)) { + return true; + } + + // Firefox/Gecko + var div = document.createElement('div'), + supported = false; + + if (!div.setAttribute) { + return false; + } + div.setAttribute(startName, 'return;'); + + if (typeof div[startName] === 'function') { + supported = true; + } + + div.removeAttribute(startName); + div = null; + + return supported; + }()); + + return { - webkit: ('WebKitCSSMatrix' in window), - webkit3d: ('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()) + ie: ie, + ie6: ie6, + ie7: ie7, + webkit: webkit, + + android: android, + android23: android23, + + chrome: chrome, + + ie3d: ie3d, + webkit3d: webkit3d, + gecko3d: gecko3d, + opera3d: opera3d, + any3d: any3d, + + mobile: mobile, + mobileWebkit: mobile && webkit, + mobileWebkit3d: mobile && webkit3d, + mobileOpera: mobile && window.opera, + + touch: touch, + msTouch: msTouch, + + retina: retina }; + })(this); // use this for node.js global MM.moveElement = function(el, point) { @@ -1043,14 +1125,28 @@ var MM = com.modestmaps = { maxDoubleTapDelay = 350, locations = {}, taps = [], - snapToZoom = true, + snapToZoom = false, wasPinching = false, lastPinchCenter = null; + function setCss () { + var s = document.createElement('style'); + s.setAttribute("type", "text/css"); + document.getElementsByTagName('head').item(0).appendChild(s); + var ss = s.sheet; + var mapid = map.parent.id; + + ss.insertRule("#" + mapid + " div {-webkit-touch-callout:none;-webkit-tap-highlight-color:rgba(0,0,0,0);}", 0); + ss.insertRule("#" + mapid + " {-webkit-touch-callout:none;-webkit-tap-highlight-color:rgba(0,0,0,0);}", 0); + } + function isTouchable () { - var el = document.createElement('div'); - el.setAttribute('ongesturestart', 'return;'); - return (typeof el.ongesturestart === 'function'); + if (MM._browser.touch) { + setCss(); + return true; + } else { + return false; + } } function updateTouches(e) { @@ -1060,11 +1156,9 @@ var MM = com.modestmaps = { var l = locations[t.identifier]; l.x = t.clientX; l.y = t.clientY; - l.scale = e.scale; } else { locations[t.identifier] = { - scale: e.scale, startPos: { x: t.clientX, y: t.clientY }, x: t.clientX, y: t.clientY, @@ -1082,7 +1176,10 @@ var MM = com.modestmaps = { } function touchStart(e) { + locations = {}; updateTouches(e); + //MM.addEvent(window, 'touchmove', touchMove); + //MM.addEvent(window, 'touchend', touchEnd); } function touchMove(e) { @@ -1100,6 +1197,7 @@ var MM = com.modestmaps = { function touchEnd(e) { var now = new Date().getTime(); + // round zoom if we're done pinching if (e.touches.length === 0 && wasPinching) { onPinched(lastPinchCenter); @@ -1197,16 +1295,19 @@ var MM = com.modestmaps = { l0 = locations[t0.identifier], l1 = locations[t1.identifier]; + if (!l0 || !l1) return; // mark these touches so they aren't used as taps/holds l0.wasPinch = true; l1.wasPinch = true; // scale about the center of these touches - var center = MM.Point.interpolate(p0, p1, 0.5); + var center = MM.Point.interpolate(p0, p1, 0.5); + var scale = MM.Point.distance(p0, p1); + var prevScale = MM.Point.distance(l0, l1); map.zoomByAbout( - Math.log(e.scale) / Math.LN2 - - Math.log(l0.scale) / Math.LN2, + Math.log(scale) / Math.LN2 - + Math.log(prevScale) / Math.LN2, center ); // pan from the previous center of these touches @@ -1227,6 +1328,7 @@ var MM = com.modestmaps = { map.zoomByAbout(tz - z, p); } wasPinching = false; + locations = {}; } handler.init = function(x) { diff --git a/modestmaps.min.js b/modestmaps.min.js index de2d335..86d21ac 100644 --- a/modestmaps.min.js +++ b/modestmaps.min.js @@ -1,14 +1,2 @@ -/*! - * Modest Maps JS v3.3.6 - * http://modestmaps.com/ - * - * Copyright (c) 2011 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. - * - */var previousMM=MM;if(!com){var com={};com.modestmaps||(com.modestmaps={})}var MM=com.modestmaps={noConflict:function(){return MM=previousMM,this}};(function(a){a.extend=function(a,b){for(var c in b.prototype)typeof a.prototype[c]=="undefined"&&(a.prototype[c]=b.prototype[c]);return a},a.getFrame=function(){return function(a){(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(function(){a(+(new Date))},10)})(a)}}(),a.transformProperty=function(a){if(!this.document)return;var b=document.documentElement.style;for(var c=0;cthis.north&&(this.north=a.lat),a.latthis.east&&(this.east=a.lon),a.lonthis.north&&(this.north=a.north),a.souththis.east&&(this.east=a.east),a.west=this.south&&a.lat<=this.north&&a.lon>=this.west&&a.lon<=this.east},toArray:function(){return[this.northWest(),this.southEast()]}},a.Extent.fromString=function(b){var c=b.split(/\s*,\s*/);if(c.length!=4)throw"Invalid extent string (expecting 4 comma-separated numbers)";return new a.Extent(parseFloat(c[0]),parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3]))},a.Extent.fromArray=function(b){var c=new a.Extent;return c.setFromLocations(b),c},a.Transformation=function(a,b,c,d,e,f){this.ax=a,this.bx=b,this.cx=c,this.ay=d,this.by=e,this.cy=f},a.Transformation.prototype={ax:0,bx:0,cx:0,ay:0,by:0,cy:0,transform:function(b){return new a.Point(this.ax*b.x+this.bx*b.y+this.cx,this.ay*b.x+this.by*b.y+this.cy)},untransform:function(b){return new a.Point((b.x*this.by-b.y*this.bx-this.cx*this.by+this.cy*this.bx)/(this.ax*this.by-this.ay*this.bx),(b.x*this.ay-b.y*this.ax-this.cx*this.ay+this.cy*this.ax)/(this.bx*this.ay-this.by*this.ax))}},a.deriveTransformation=function(b,c,d,e,f,g,h,i,j,k,l,m){var n=a.linearSolution(b,c,d,f,g,h,j,k,l),o=a.linearSolution(b,c,e,f,g,i,j,k,m);return new a.Transformation(n[0],n[1],n[2],o[0],o[1],o[2])},a.linearSolution=function(a,b,c,d,e,f,g,h,i){a=parseFloat(a),b=parseFloat(b),c=parseFloat(c),d=parseFloat(d),e=parseFloat(e),f=parseFloat(f),g=parseFloat(g),h=parseFloat(h),i=parseFloat(i);var j=((f-i)*(b-e)-(c-f)*(e-h))/((d-g)*(b-e)-(a-d)*(e-h)),k=((f-i)*(a-d)-(c-f)*(d-g))/((e-h)*(a-d)-(b-e)*(d-g)),l=c-a*j-b*k;return[j,k,l]},a.Projection=function(b,c){c||(c=new a.Transformation(1,0,0,0,1,0)),this.zoom=b,this.transformation=c},a.Projection.prototype={zoom:0,transformation:null,rawProject:function(a){throw"Abstract method not implemented by subclass."},rawUnproject:function(a){throw"Abstract method not implemented by subclass."},project:function(a){return a=this.rawProject(a),this.transformation&&(a=this.transformation.transform(a)),a},unproject:function(a){return this.transformation&&(a=this.transformation.untransform(a)),a=this.rawUnproject(a),a},locationCoordinate:function(b){var c=new a.Point(Math.PI*b.lon/180,Math.PI*b.lat/180);return c=this.project(c),new a.Coordinate(c.y,c.x,this.zoom)},coordinateLocation:function(b){b=b.zoomTo(this.zoom);var c=new a.Point(b.column,b.row);return c=this.unproject(c),new a.Location(180*c.y/Math.PI,180*c.x/Math.PI)}},a.LinearProjection=function(b,c){a.Projection.call(this,b,c)},a.LinearProjection.prototype={rawProject:function(b){return new a.Point(b.x,b.y)},rawUnproject:function(b){return new a.Point(b.x,b.y)}},a.extend(a.LinearProjection,a.Projection),a.MercatorProjection=function(b,c){a.Projection.call(this,b,c)},a.MercatorProjection.prototype={rawProject:function(b){return new a.Point(b.x,Math.log(Math.tan(.25*Math.PI+.5*b.y)))},rawUnproject:function(b){return new a.Point(b.x,2*Math.atan(Math.pow(Math.E,b.y))-.5*Math.PI)}},a.extend(a.MercatorProjection,a.Projection),a.MapProvider=function(a){a&&(this.getTile=a)},a.MapProvider.prototype={tileLimits:[new a.Coordinate(0,0,0),(new a.Coordinate(1,1,0)).zoomTo(18)],getTileUrl:function(a){throw"Abstract method not implemented by subclass."},getTile:function(a){throw"Abstract method not implemented by subclass."},releaseTile:function(a){},setZoomRange:function(a,b){this.tileLimits[0]=this.tileLimits[0].zoomTo(a),this.tileLimits[1]=this.tileLimits[1].zoomTo(b)},sourceCoordinate:function(b){var c=this.tileLimits[0].zoomTo(b.zoom).container(),d=this.tileLimits[1].zoomTo(b.zoom),e=Math.pow(2,b.zoom),f;return d=new a.Coordinate(Math.ceil(d.row),Math.ceil(d.column),Math.floor(d.zoom)),b.column<0?f=(b.column%e+e)%e:f=b.column%e,b.row=d.row?null:f=d.column?null:new a.Coordinate(b.row,f,b.zoom)}},a.Template=function(b,c){function f(a,b,c){var d="";for(var e=1;e<=c;e++)d+=(a>>c-e&1)<<1|b>>c-e&1;return d||"0"}var d=b.match(/{(Q|quadkey)}/);d&&(b=b.replace("{subdomains}","{S}").replace("{zoom}","{Z}").replace("{quadkey}","{Q}"));var e=c&&c.length&&b.indexOf("{S}")>=0,g=function(a){var g=this.sourceCoordinate(a);if(!g)return null;var h=b;if(e){var i=parseInt(g.zoom+g.row+g.column,10)%c.length;h=h.replace("{S}",c[i])}return d?h.replace("{Z}",g.zoom.toFixed(0)).replace("{Q}",f(g.row,g.column,g.zoom)):h.replace("{Z}",g.zoom.toFixed(0)).replace("{X}",g.column.toFixed(0)).replace("{Y}",g.row.toFixed(0))};a.MapProvider.call(this,g)},a.Template.prototype={getTile:function(a){return this.getTileUrl(a)}},a.extend(a.Template,a.MapProvider),a.TemplatedLayer=function(b,c,d){return new a.Layer(new a.Template(b,c),null,d)},a.getMousePoint=function(b,c){var d=new a.Point(b.clientX,b.clientY);d.x+=document.body.scrollLeft+document.documentElement.scrollLeft,d.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var e=c.parent;e;e=e.offsetParent)d.x-=e.offsetLeft,d.y-=e.offsetTop;return d},a.MouseWheelHandler=function(){function g(b){var g=0;e=e||(new Date).getTime();try{d.scrollTop=1e3,d.dispatchEvent(b),g=1e3-d.scrollTop}catch(h){g=b.wheelDelta||-b.detail*5}var i=(new Date).getTime()-e,j=a.getMousePoint(b,c);return Math.abs(g)>0&&i>200&&!f?(c.zoomByAbout(g>0?1:-1,j),e=(new Date).getTime()):f&&c.zoomByAbout(g*.001,j),a.cancelEvent(b)}var b={},c,d,e,f=!1;return b.init=function(e){c=e,d=document.body.appendChild(document.createElement("div")),d.style.cssText="visibility:hidden;top:0;height:0;width:0;overflow-y:scroll";var f=d.appendChild(document.createElement("div"));return f.style.height="2000px",a.addEvent(c.parent,"mousewheel",g),b},b.precise=function(a){return arguments.length?(f=a,b):f},b.remove=function(){a.removeEvent(c.parent,"mousewheel",g),d.parentNode.removeChild(d)},b},a.DoubleClickHandler=function(){function d(b){var d=a.getMousePoint(b,c);return c.zoomByAbout(b.shiftKey?-1:1,d),a.cancelEvent(b)}var b={},c;return b.init=function(e){return c=e,a.addEvent(c.parent,"dblclick",d),b},b.remove=function(){a.removeEvent(c.parent,"dblclick",d)},b},a.DragHandler=function(){function e(b){if(b.shiftKey||b.button==2)return;return a.addEvent(document,"mouseup",f),a.addEvent(document,"mousemove",g),c=new a.Point(b.clientX,b.clientY),d.parent.style.cursor="move",a.cancelEvent(b)}function f(b){return a.removeEvent(document,"mouseup",f),a.removeEvent(document,"mousemove",g),c=null,d.parent.style.cursor="",a.cancelEvent(b)}function g(b){return c&&(d.panBy(b.clientX-c.x,b.clientY-c.y),c.x=b.clientX,c.y=b.clientY,c.t=+(new Date)),a.cancelEvent(b)}var b={},c,d;return b.init=function(c){return d=c,a.addEvent(d.parent,"mousedown",e),b},b.remove=function(){a.removeEvent(d.parent,"mousedown",e)},b},a.MouseHandler=function(){var b={},c,d;return b.init=function(e){return c=e,d=[a.DragHandler().init(c),a.DoubleClickHandler().init(c),a.MouseWheelHandler().init(c)],b},b.remove=function(){for(var a=0;ae||(m>d?(l.end=c,l.duration=m,r(l)):(l.time=c,s(l)))}var o={};for(var p=0;p=0;e--){var f=d[e];f.id in a||(this.loadingBay.removeChild(f),this.openRequestCount--,f.src=f.coord=f.onload=f.onerror=null)}for(var g in this.requestsById)if(!(g in a)&&this.requestsById.hasOwnProperty(g)){var h=this.requestsById[g];delete this.requestsById[g],h!==null&&(h=h.id=h.coord=h.url=null)}},hasRequest:function(a){return a in this.requestsById},requestTile:function(a,b,c){if(!(a in this.requestsById)){var d={id:a,coord:b.copy(),url:c};this.requestsById[a]=d,c&&this.requestQueue.push(d)}},getProcessQueue:function(){if(!this._processQueue){var a=this;this._processQueue=function(){a.processQueue()}}return this._processQueue},processQueue:function(a){a&&this.requestQueue.length>8&&this.requestQueue.sort(a);while(this.openRequestCount0){var b=this.requestQueue.pop();if(b){this.openRequestCount++;var c=document.createElement("img");c.id=b.id,c.style.position="absolute",c.coord=b.coord,this.loadingBay.appendChild(c),c.onload=c.onerror=this.getLoadComplete(),c.src=b.url,b=b.id=b.coord=b.url=null}}},_loadComplete:null,getLoadComplete:function(){if(!this._loadComplete){var a=this;this._loadComplete=function(b){b=b||window.event;var c=b.srcElement||b.target;c.onload=c.onerror=null,a.loadingBay.removeChild(c),a.openRequestCount--,delete a.requestsById[c.id],b.type==="load"&&(c.complete||c.readyState&&c.readyState=="complete")?a.dispatchCallback("requestcomplete",c):(a.dispatchCallback("requesterror",{element:c,url:""+c.src}),c.src=null),setTimeout(a.getProcessQueue(),0)}}return this._loadComplete}},a.Layer=function(b,c,d){this.parent=c||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=d,this.levels={},this.requestManager=new a.RequestManager,this.requestManager.addCallback("requestcomplete",this.getTileComplete()),this.requestManager.addCallback("requesterror",this.getTileError()),b&&this.setProvider(b)},a.Layer.prototype={map:null,parent:null,name:null,enabled:!0,tiles:null,levels:null,requestManager:null,provider:null,_tileComplete:null,getTileComplete:function(){if(!this._tileComplete){var a=this;this._tileComplete=function(b,c){a.tiles[c.id]=c,a.positionTile(c),c.style.visibility="inherit",c.className="map-tile-loaded"}}return this._tileComplete},getTileError:function(){if(!this._tileError){var a=this;this._tileError=function(b,c){c.onload=c.onerror=null,a.tiles[c.element.id]=c.element,a.positionTile(c.element),c.element.style.visibility="hidden"}}return this._tileError},draw:function(){function c(a,c){if(a&&c){var d=a.coord,e=c.coord;if(d.zoom==e.zoom){var f=Math.abs(b.row-d.row-.5)+Math.abs(b.column-d.column-.5),g=Math.abs(b.row-e.row-.5)+Math.abs(b.column-e.column-.5);return fg?-1:0}return d.zoome.zoom?-1:0}return a?1:c?-1:0}if(!this.enabled||!this.map)return;var b=this.map.coordinate.zoomTo(Math.round(this.map.coordinate.zoom)),d=Math.round(this.map.coordinate.zoom),e=this.map.pointCoordinate(new a.Point(0,0)).zoomTo(d).container(),f=this.map.pointCoordinate(this.map.dimensions).zoomTo(d).container().right().down(),g={},h=this.createOrGetLevel(e.zoom),i=e.copy();for(i.column=e.column;i.column<=f.column;i.column++)for(i.row=e.row;i.row<=f.row;i.row++){var j=this.inventoryVisibleTile(h,i);while(j.length)g[j.pop()]=!0}for(var k in this.levels)if(this.levels.hasOwnProperty(k)){var l=parseInt(k,10);if(l>=e.zoom-5&&l0)b.style.display="block",e=Math.pow(2,this.map.coordinate.zoom-c),f=f.zoomTo(c);else return b.style.display="none",!1;var g=this.map.tileSize.x*e,h=this.map.tileSize.y*e,i=new a.Point(this.map.dimensions.x/2,this.map.dimensions.y/2),j=this.tileElementsInLevel(b);while(j.length){var k=j.pop();d[k.id]?a.moveElement(k,{x:Math.round(i.x+(k.coord.column-f.column)*g),y:Math.round(i.y+(k.coord.row-f.row)*h),scale:e,width:this.map.tileSize.x,height:this.map.tileSize.y}):(this.provider.releaseTile(k.coord),this.requestManager.clearRequest(k.coord.toKey()),b.removeChild(k))}},createOrGetLevel:function(a){if(a in this.levels)return this.levels[a];var b=document.createElement("div");return b.id=this.parent.id+"-zoom-"+a,b.style.cssText="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; margin: 0; padding: 0;",b.style.zIndex=a,this.parent.appendChild(b),this.levels[a]=b,b},addTileImage:function(a,b,c){this.requestManager.requestTile(a,b,c)},addTileElement:function(a,b,c){c.id=a,c.coord=b.copy(),this.positionTile(c)},positionTile:function(b){var c=this.map.coordinate.zoomTo(b.coord.zoom);b.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;",b.ondragstart=function(){return!1};var d=Math.pow(2,this.map.coordinate.zoom-b.coord.zoom);a.moveElement(b,{x:Math.round(this.map.dimensions.x/2+(b.coord.column-c.column)*this.map.tileSize.x),y:Math.round(this.map.dimensions.y/2+(b.coord.row-c.row)*this.map.tileSize.y),scale:d,width:this.map.tileSize.x,height:this.map.tileSize.y});var e=this.levels[b.coord.zoom];e.appendChild(b),Math.round(this.map.coordinate.zoom)==b.coord.zoom&&(e.style.display="block"),this.requestRedraw()},_redrawTimer:undefined,requestRedraw:function(){this._redrawTimer||(this._redrawTimer=setTimeout(this.getRedraw(),1e3))},_redraw:null,getRedraw:function(){if(!this._redraw){var a=this;this._redraw=function(){a.draw(),a._redrawTimer=0}}return this._redraw},setProvider:function(a){var b=this.provider===null;if(!b){this.requestManager.clear();for(var c in this.levels)if(this.levels.hasOwnProperty(c)){var d=this.levels[c];while(d.firstChild)this.provider.releaseTile(d.firstChild.coord),d.removeChild(d.firstChild)}}this.tiles={},this.provider=a,b||this.draw()},enable:function(){return this.enabled=!0,this.parent.style.display="",this.draw(),this},disable:function(){return this.enabled=!1,this.requestManager.clear(),this.parent.style.display="none",this},destroy:function(){this.requestManager.clear(),this.requestManager.removeCallback("requestcomplete",this.getTileComplete()),this.requestManager.removeCallback("requesterror",this.getTileError()),this.provider=null,this.parent.parentNode&&this.parent.parentNode.removeChild(this.parent),this.map=null}},a.Map=function(b,c,d,e){if(typeof b=="string"){b=document.getElementById(b);if(!b)throw"The ID provided to modest maps could not be found."}this.parent=b,this.parent.style.padding="0",this.parent.style.overflow="hidden";var f=a.getStyle(this.parent,"position");f!="relative"&&f!="absolute"&&(this.parent.style.position="relative"),this.layers=[],c||(c=[]),c instanceof Array||(c=[c]);for(var g=0;g=this.layers.length)throw new Error("invalid index in setLayerAt(): "+b);if(this.layers[b]!=c){if(bthis.layers.length)throw new Error("invalid index in insertLayerAt(): "+b);if(b==this.layers.length)this.layers.push(c),this.parent.appendChild(c.parent);else{var d=this.layers[b];this.parent.insertBefore(c.parent,d.parent),this.layers.splice(b,0,c)}return c.map=this,a.getFrame(this.getRedraw()),this},removeLayerAt:function(a){if(a<0||a>=this.layers.length)throw new Error("invalid index in removeLayer(): "+a);var b=this.layers[a];return this.layers.splice(a,1),b.destroy(),this},swapLayersAt:function(a,b){if(a<0||a>=this.layers.length||b<0||b>=this.layers.length)throw new Error("invalid index in swapLayersAt(): "+index);var c=this -.layers[a],d=this.layers[b],e=document.createElement("div");return this.parent.replaceChild(e,d.parent),this.parent.replaceChild(d.parent,c.parent),this.parent.replaceChild(c.parent,e),this.layers[a]=d,this.layers[b]=c,this},enableLayer:function(a){var b=this.getLayer(a);return b&&b.enable(),this},enableLayerAt:function(a){var b=this.getLayerAt(a);return b&&b.enable(),this},disableLayer:function(a){var b=this.getLayer(a);return b&&b.disable(),this},disableLayerAt:function(a){var b=this.getLayerAt(a);return b&&b.disable(),this},enforceZoomLimits:function(a){var b=this.coordLimits;if(b){var c=b[0].zoom,d=b[1].zoom;a.zoomd&&(a=a.zoomTo(d))}return a},enforcePanLimits:function(b){if(this.coordLimits){b=b.copy();var c=this.coordLimits[0].zoomTo(b.zoom),d=this.coordLimits[1].zoomTo(b.zoom),e=this.pointCoordinate(new a.Point(0,0)).zoomTo(b.zoom),f=this.pointCoordinate(this.dimensions).zoomTo(b.zoom);d.row-c.rowd.row&&(b.row-=f.row-d.row),d.column-c.columnd.column&&(b.column-=f.column-d.column)}return b},enforceLimits:function(a){return this.enforcePanLimits(this.enforceZoomLimits(a))},draw:function(){this.coordinate=this.enforceLimits(this.coordinate);if(this.dimensions.x<=0||this.dimensions.y<=0){if(!this.autoSize)return;var b=this.parent.offsetWidth,c=this.parent.offsetHeight;this.dimensions=new a.Point(b,c);if(b<=0||c<=0)return}for(var d=0;d1||"matchMedia"in window&&window.matchMedia("(min-resolution:144dpi)")&&window.matchMedia("(min-resolution:144dpi)").matches,doc=document.documentElement,ie3d=ie&&"transition"in doc.style,webkit3d="WebKitCSSMatrix"in window&&"m11"in new window.WebKitCSSMatrix,gecko3d="MozPerspective"in doc.style,opera3d="OTransition"in doc.style,any3d=ie3d||webkit3d||gecko3d||opera3d;var touch=function(){var startName="ontouchstart";if(msTouch||startName in doc){return true}var div=document.createElement("div"),supported=false;if(!div.setAttribute){return false}div.setAttribute(startName,"return;");if(typeof div[startName]==="function"){supported=true}div.removeAttribute(startName);div=null;return supported}();return{ie:ie,ie6:ie6,ie7:ie7,webkit:webkit,android:android,android23:android23,chrome:chrome,ie3d:ie3d,webkit3d:webkit3d,gecko3d:gecko3d,opera3d:opera3d,any3d:any3d,mobile:mobile,mobileWebkit:mobile&&webkit,mobileWebkit3d:mobile&&webkit3d,mobileOpera:mobile&&window.opera,touch:touch,msTouch:msTouch,retina:retina}}(this);MM.moveElement=function(el,point){if(MM.transformProperty){if(!point.scale)point.scale=1;if(!point.width)point.width=0;if(!point.height)point.height=0;var ms=MM.matrixString(point);if(el[MM.transformProperty]!==ms){el.style[MM.transformProperty]=el[MM.transformProperty]=ms}}else{el.style.left=point.x+"px";el.style.top=point.y+"px";if(point.width&&point.height&&point.scale){el.style.width=Math.ceil(point.width*point.scale)+"px";el.style.height=Math.ceil(point.height*point.scale)+"px"}}};MM.cancelEvent=function(e){e.cancelBubble=true;e.cancel=true;e.returnValue=false;if(e.stopPropagation){e.stopPropagation()}if(e.preventDefault){e.preventDefault()}return false};MM.coerceLayer=function(layerish){if(typeof layerish=="string"){return new MM.Layer(new MM.TemplatedLayer(layerish))}else if("draw"in layerish&&typeof layerish.draw=="function"){return layerish}else{return new MM.Layer(layerish)}};MM.addEvent=function(obj,type,fn){if(obj.addEventListener){obj.addEventListener(type,fn,false);if(type=="mousewheel"){obj.addEventListener("DOMMouseScroll",fn,false)}}else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event)};obj.attachEvent("on"+type,obj[type+fn])}};MM.removeEvent=function(obj,type,fn){if(obj.removeEventListener){obj.removeEventListener(type,fn,false);if(type=="mousewheel"){obj.removeEventListener("DOMMouseScroll",fn,false)}}else if(obj.detachEvent){obj.detachEvent("on"+type,obj[type+fn]);obj[type+fn]=null}};MM.getStyle=function(el,styleProp){if(el.currentStyle)return el.currentStyle[styleProp];else if(window.getComputedStyle)return document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp)};MM.Point=function(x,y){this.x=parseFloat(x);this.y=parseFloat(y)};MM.Point.prototype={x:0,y:0,toString:function(){return"("+this.x.toFixed(3)+", "+this.y.toFixed(3)+")"},copy:function(){return new MM.Point(this.x,this.y)}};MM.Point.distance=function(p1,p2){return Math.sqrt(Math.pow(p2.x-p1.x,2)+Math.pow(p2.y-p1.y,2))};MM.Point.interpolate=function(p1,p2,t){return new MM.Point(p1.x+(p2.x-p1.x)*t,p1.y+(p2.y-p1.y)*t)};MM.Coordinate=function(row,column,zoom){this.row=row;this.column=column;this.zoom=zoom};MM.Coordinate.prototype={row:0,column:0,zoom:0,toString:function(){return"("+this.row.toFixed(3)+", "+this.column.toFixed(3)+" @"+this.zoom.toFixed(3)+")"},toKey:function(){return this.zoom+","+this.row+","+this.column},copy:function(){return new MM.Coordinate(this.row,this.column,this.zoom)},container:function(){return new MM.Coordinate(Math.floor(this.row),Math.floor(this.column),Math.floor(this.zoom))},zoomTo:function(destination){var power=Math.pow(2,destination-this.zoom);return new MM.Coordinate(this.row*power,this.column*power,destination)},zoomBy:function(distance){var power=Math.pow(2,distance);return new MM.Coordinate(this.row*power,this.column*power,this.zoom+distance)},up:function(dist){if(dist===undefined)dist=1;return new MM.Coordinate(this.row-dist,this.column,this.zoom)},right:function(dist){if(dist===undefined)dist=1;return new MM.Coordinate(this.row,this.column+dist,this.zoom)},down:function(dist){if(dist===undefined)dist=1;return new MM.Coordinate(this.row+dist,this.column,this.zoom)},left:function(dist){if(dist===undefined)dist=1;return new MM.Coordinate(this.row,this.column-dist,this.zoom)}};MM.Location=function(lat,lon){this.lat=parseFloat(lat);this.lon=parseFloat(lon)};MM.Location.prototype={lat:0,lon:0,toString:function(){return"("+this.lat.toFixed(3)+", "+this.lon.toFixed(3)+")"},copy:function(){return new MM.Location(this.lat,this.lon)}};MM.Location.distance=function(l1,l2,r){if(!r){r=6378e3}var deg2rad=Math.PI/180,a1=l1.lat*deg2rad,b1=l1.lon*deg2rad,a2=l2.lat*deg2rad,b2=l2.lon*deg2rad,c=Math.cos(a1)*Math.cos(b1)*Math.cos(a2)*Math.cos(b2),d=Math.cos(a1)*Math.sin(b1)*Math.cos(a2)*Math.sin(b2),e=Math.sin(a1)*Math.sin(a2);return Math.acos(c+d+e)*r};MM.Location.interpolate=function(l1,l2,f){if(l1.lat===l2.lat&&l1.lon===l2.lon){return new MM.Location(l1.lat,l1.lon)}var deg2rad=Math.PI/180,lat1=l1.lat*deg2rad,lon1=l1.lon*deg2rad,lat2=l2.lat*deg2rad,lon2=l2.lon*deg2rad;var d=2*Math.asin(Math.sqrt(Math.pow(Math.sin((lat1-lat2)/2),2)+Math.cos(lat1)*Math.cos(lat2)*Math.pow(Math.sin((lon1-lon2)/2),2)));var A=Math.sin((1-f)*d)/Math.sin(d);var B=Math.sin(f*d)/Math.sin(d);var x=A*Math.cos(lat1)*Math.cos(lon1)+B*Math.cos(lat2)*Math.cos(lon2);var y=A*Math.cos(lat1)*Math.sin(lon1)+B*Math.cos(lat2)*Math.sin(lon2);var z=A*Math.sin(lat1)+B*Math.sin(lat2);var latN=Math.atan2(z,Math.sqrt(Math.pow(x,2)+Math.pow(y,2)));var lonN=Math.atan2(y,x);return new MM.Location(latN/deg2rad,lonN/deg2rad)};MM.Location.bearing=function(l1,l2){var deg2rad=Math.PI/180,lat1=l1.lat*deg2rad,lon1=l1.lon*deg2rad,lat2=l2.lat*deg2rad,lon2=l2.lon*deg2rad;var result=Math.atan2(Math.sin(lon1-lon2)*Math.cos(lat2),Math.cos(lat1)*Math.sin(lat2)-Math.sin(lat1)*Math.cos(lat2)*Math.cos(lon1-lon2))/-(Math.PI/180);return result<0?result+360:result};MM.Extent=function(north,west,south,east){if(north instanceof MM.Location&&west instanceof MM.Location){var northwest=north,southeast=west;north=northwest.lat;west=northwest.lon;south=southeast.lat;east=southeast.lon}if(isNaN(south))south=north;if(isNaN(east))east=west;this.north=Math.max(north,south);this.south=Math.min(north,south);this.east=Math.max(east,west);this.west=Math.min(east,west)};MM.Extent.prototype={north:0,south:0,east:0,west:0,copy:function(){return new MM.Extent(this.north,this.west,this.south,this.east)},toString:function(precision){if(isNaN(precision))precision=3;return[this.north.toFixed(precision),this.west.toFixed(precision),this.south.toFixed(precision),this.east.toFixed(precision)].join(", ")},northWest:function(){return new MM.Location(this.north,this.west)},southEast:function(){return new MM.Location(this.south,this.east)},northEast:function(){return new MM.Location(this.north,this.east)},southWest:function(){return new MM.Location(this.south,this.west)},center:function(){return new MM.Location(this.south+(this.north-this.south)/2,this.east+(this.west-this.east)/2)},encloseLocation:function(loc){if(loc.lat>this.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("{subdomains}","{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={},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={},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={},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={},map,handlers;handler.init=function(x){map=x;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<=endCoord.column;tileCoord.column++){for(tileCoord.row=startCoord.row;tileCoord.row<=endCoord.row;tileCoord.row++){var validKeys=this.inventoryVisibleTile(levelElement,tileCoord);while(validKeys.length){validTileKeys[validKeys.pop()]=true}}}for(var name in this.levels){if(this.levels.hasOwnProperty(name)){var zoom=parseInt(name,10);if(zoom>=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/2,this.map.dimensions.y/2);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/2+(tile.coord.column-theCoord.column)*this.map.tileSize.x),y:Math.round(this.map.dimensions.y/2+(tile.coord.row-theCoord.row)*this.map.tileSize.y),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 1) || + ('matchMedia' in window && window.matchMedia('(min-resolution:144dpi)') && + window.matchMedia('(min-resolution:144dpi)').matches), + + doc = document.documentElement, + ie3d = ie && ('transition' in doc.style), + webkit3d = ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()), + gecko3d = 'MozPerspective' in doc.style, + opera3d = 'OTransition' in doc.style, + any3d = (ie3d || webkit3d || gecko3d || opera3d); + + var touch = (function () { + + var startName = 'ontouchstart'; + + // IE10+ (We simulate these into touch* events in L.DomEvent and L.DomEvent.MsTouch) or WebKit, etc. + if (msTouch || (startName in doc)) { + return true; + } + + // Firefox/Gecko + var div = document.createElement('div'), + supported = false; + + if (!div.setAttribute) { + return false; + } + div.setAttribute(startName, 'return;'); + + if (typeof div[startName] === 'function') { + supported = true; + } + + div.removeAttribute(startName); + div = null; + + return supported; + }()); + + return { - webkit: ('WebKitCSSMatrix' in window), - webkit3d: ('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()) + ie: ie, + ie6: ie6, + ie7: ie7, + webkit: webkit, + + android: android, + android23: android23, + + chrome: chrome, + + ie3d: ie3d, + webkit3d: webkit3d, + gecko3d: gecko3d, + opera3d: opera3d, + any3d: any3d, + + mobile: mobile, + mobileWebkit: mobile && webkit, + mobileWebkit3d: mobile && webkit3d, + mobileOpera: mobile && window.opera, + + touch: touch, + msTouch: msTouch, + + retina: retina }; + })(this); // use this for node.js global MM.moveElement = function(el, point) {