/usr/share/javascript/modestmaps/modestmaps.min.js is in libjs-modestmaps 3.3.6+ds1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /*!
* 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(e){e.extend=function(e,t){for(var n in t.prototype)typeof e.prototype[n]=="undefined"&&(e.prototype[n]=t.prototype[n]);return e},e.getFrame=function(){return function(e){(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(function(){e(+(new Date))},10)})(e)}}(),e.transformProperty=function(e){if(!this.document)return;var t=document.documentElement.style;for(var n=0;n<e.length;n++)if(e[n]in t)return e[n];return!1}(["transform","WebkitTransform","OTransform","MozTransform","msTransform"]),e.matrixString=function(t){t.scale*t.width%1&&(t.scale+=(1-t.scale*t.width%1)/t.width);var n=t.scale||1;return e._browser.webkit3d?"translate3d("+t.x.toFixed(0)+"px,"+t.y.toFixed(0)+"px, 0px)"+"scale3d("+n+","+n+", 1)":"translate("+t.x.toFixed(6)+"px,"+t.y.toFixed(6)+"px)"+"scale("+n+","+n+")"},e._browser=function(e){return{webkit:"WebKitCSSMatrix"in e,webkit3d:"WebKitCSSMatrix"in e&&"m11"in new WebKitCSSMatrix}}(this),e.moveElement=function(t,n){if(e.transformProperty){n.scale||(n.scale=1),n.width||(n.width=0),n.height||(n.height=0);var r=e.matrixString(n);t[e.transformProperty]!==r&&(t.style[e.transformProperty]=t[e.transformProperty]=r)}else t.style.left=n.x+"px",t.style.top=n.y+"px",n.width&&n.height&&n.scale&&(t.style.width=Math.ceil(n.width*n.scale)+"px",t.style.height=Math.ceil(n.height*n.scale)+"px")},e.cancelEvent=function(e){return e.cancelBubble=!0,e.cancel=!0,e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),!1},e.coerceLayer=function(t){return typeof t=="string"?new e.Layer(new e.TemplatedLayer(t)):"draw"in t&&typeof t.draw=="function"?t:new e.Layer(t)},e.addEvent=function(e,t,n){e.addEventListener?(e.addEventListener(t,n,!1),t=="mousewheel"&&e.addEventListener("DOMMouseScroll",n,!1)):e.attachEvent&&(e["e"+t+n]=n,e[t+n]=function(){e["e"+t+n](window.event)},e.attachEvent("on"+t,e[t+n]))},e.removeEvent=function(e,t,n){e.removeEventListener?(e.removeEventListener(t,n,!1),t=="mousewheel"&&e.removeEventListener("DOMMouseScroll",n,!1)):e.detachEvent&&(e.detachEvent("on"+t,e[t+n]),e[t+n]=null)},e.getStyle=function(e,t){if(e.currentStyle)return e.currentStyle[t];if(window.getComputedStyle)return document.defaultView.getComputedStyle(e,null).getPropertyValue(t)},e.Point=function(e,t){this.x=parseFloat(e),this.y=parseFloat(t)},e.Point.prototype={x:0,y:0,toString:function(){return"("+this.x.toFixed(3)+", "+this.y.toFixed(3)+")"},copy:function(){return new e.Point(this.x,this.y)}},e.Point.distance=function(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))},e.Point.interpolate=function(t,n,r){return new e.Point(t.x+(n.x-t.x)*r,t.y+(n.y-t.y)*r)},e.Coordinate=function(e,t,n){this.row=e,this.column=t,this.zoom=n},e.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 e.Coordinate(this.row,this.column,this.zoom)},container:function(){return new e.Coordinate(Math.floor(this.row),Math.floor(this.column),Math.floor(this.zoom))},zoomTo:function(t){var n=Math.pow(2,t-this.zoom);return new e.Coordinate(this.row*n,this.column*n,t)},zoomBy:function(t){var n=Math.pow(2,t);return new e.Coordinate(this.row*n,this.column*n,this.zoom+t)},up:function(t){return t===undefined&&(t=1),new e.Coordinate(this.row-t,this.column,this.zoom)},right:function(t){return t===undefined&&(t=1),new e.Coordinate(this.row,this.column+t,this.zoom)},down:function(t){return t===undefined&&(t=1),new e.Coordinate(this.row+t,this.column,this.zoom)},left:function(t){return t===undefined&&(t=1),new e.Coordinate(this.row,this.column-t,this.zoom)}},e.Location=function(e,t){this.lat=parseFloat(e),this.lon=parseFloat(t)},e.Location.prototype={lat:0,lon:0,toString:function(){return"("+this.lat.toFixed(3)+", "+this.lon.toFixed(3)+")"},copy:function(){return new e.Location(this.lat,this.lon)}},e.Location.distance=function(e,t,n){n||(n=6378e3);var r=Math.PI/180,i=e.lat*r,s=e.lon*r,o=t.lat*r,u=t.lon*r,a=Math.cos(i)*Math.cos(s)*Math.cos(o)*Math.cos(u),f=Math.cos(i)*Math.sin(s)*Math.cos(o)*Math.sin(u),l=Math.sin(i)*Math.sin(o);return Math.acos(a+f+l)*n},e.Location.interpolate=function(t,n,r){if(t.lat===n.lat&&t.lon===n.lon)return new e.Location(t.lat,t.lon);var i=Math.PI/180,s=t.lat*i,o=t.lon*i,u=n.lat*i,a=n.lon*i,f=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-u)/2),2)+Math.cos(s)*Math.cos(u)*Math.pow(Math.sin((o-a)/2),2))),l=Math.sin((1-r)*f)/Math.sin(f),c=Math.sin(r*f)/Math.sin(f),h=l*Math.cos(s)*Math.cos(o)+c*Math.cos(u)*Math.cos(a),p=l*Math.cos(s)*Math.sin(o)+c*Math.cos(u)*Math.sin(a),d=l*Math.sin(s)+c*Math.sin(u),v=Math.atan2(d,Math.sqrt(Math.pow(h,2)+Math.pow(p,2))),m=Math.atan2(p,h);return new e.Location(v/i,m/i)},e.Location.bearing=function(e,t){var n=Math.PI/180,r=e.lat*n,i=e.lon*n,s=t.lat*n,o=t.lon*n,u=Math.atan2(Math.sin(i-o)*Math.cos(s),Math.cos(r)*Math.sin(s)-Math.sin(r)*Math.cos(s)*Math.cos(i-o))/-(Math.PI/180);return u<0?u+360:u},e.Extent=function(t,n,r,i){if(t instanceof e.Location&&n instanceof e.Location){var s=t,o=n;t=s.lat,n=s.lon,r=o.lat,i=o.lon}isNaN(r)&&(r=t),isNaN(i)&&(i=n),this.north=Math.max(t,r),this.south=Math.min(t,r),this.east=Math.max(i,n),this.west=Math.min(i,n)},e.Extent.prototype={north:0,south:0,east:0,west:0,copy:function(){return new e.Extent(this.north,this.west,this.south,this.east)},toString:function(e){return isNaN(e)&&(e=3),[this.north.toFixed(e),this.west.toFixed(e),this.south.toFixed(e),this.east.toFixed(e)].join(", ")},northWest:function(){return new e.Location(this.north,this.west)},southEast:function(){return new e.Location(this.south,this.east)},northEast:function(){return new e.Location(this.north,this.east)},southWest:function(){return new e.Location(this.south,this.west)},center:function(){return new e.Location(this.south+(this.north-this.south)/2,this.east+(this.west-this.east)/2)},encloseLocation:function(e){e.lat>this.north&&(this.north=e.lat),e.lat<this.south&&(this.south=e.lat),e.lon>this.east&&(this.east=e.lon),e.lon<this.west&&(this.west=e.lon)},encloseLocations:function(e){var t=e.length;for(var n=0;n<t;n++)this.encloseLocation(e[n])},setFromLocations:function(e){var t=e.length,n=e[0];this.north=this.south=n.lat,this.east=this.west=n.lon;for(var r=1;r<t;r++)this.encloseLocation(e[r])},encloseExtent:function(e){e.north>this.north&&(this.north=e.north),e.south<this.south&&(this.south=e.south),e.east>this.east&&(this.east=e.east),e.west<this.west&&(this.west=e.west)},containsLocation:function(e){return e.lat>=this.south&&e.lat<=this.north&&e.lon>=this.west&&e.lon<=this.east},toArray:function(){return[this.northWest(),this.southEast()]}},e.Extent.fromString=function(t){var n=t.split(/\s*,\s*/);if(n.length!=4)throw"Invalid extent string (expecting 4 comma-separated numbers)";return new e.Extent(parseFloat(n[0]),parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3]))},e.Extent.fromArray=function(t){var n=new e.Extent;return n.setFromLocations(t),n},e.Transformation=function(e,t,n,r,i,s){this.ax=e,this.bx=t,this.cx=n,this.ay=r,this.by=i,this.cy=s},e.Transformation.prototype={ax:0,bx:0,cx:0,ay:0,by:0,cy:0,transform:function(t){return new e.Point(this.ax*t.x+this.bx*t.y+this.cx,this.ay*t.x+this.by*t.y+this.cy)},untransform:function(t){return new e.Point((t.x*this.by-t.y*this.bx-this.cx*this.by+this.cy*this.bx)/(this.ax*this.by-this.ay*this.bx),(t.x*this.ay-t.y*this.ax-this.cx*this.ay+this.cy*this.ax)/(this.bx*this.ay-this.by*this.ax))}},e.deriveTransformation=function(t,n,r,i,s,o,u,a,f,l,c,h){var p=e.linearSolution(t,n,r,s,o,u,f,l,c),d=e.linearSolution(t,n,i,s,o,a,f,l,h);return new e.Transformation(p[0],p[1],p[2],d[0],d[1],d[2])},e.linearSolution=function(e,t,n,r,i,s,o,u,a){e=parseFloat(e),t=parseFloat(t),n=parseFloat(n),r=parseFloat(r),i=parseFloat(i),s=parseFloat(s),o=parseFloat(o),u=parseFloat(u),a=parseFloat(a);var f=((s-a)*(t-i)-(n-s)*(i-u))/((r-o)*(t-i)-(e-r)*(i-u)),l=((s-a)*(e-r)-(n-s)*(r-o))/((i-u)*(e-r)-(t-i)*(r-o)),c=n-e*f-t*l;return[f,l,c]},e.Projection=function(t,n){n||(n=new e.Transformation(1,0,0,0,1,0)),this.zoom=t,this.transformation=n},e.Projection.prototype={zoom:0,transformation:null,rawProject:function(e){throw"Abstract method not implemented by subclass."},rawUnproject:function(e){throw"Abstract method not implemented by subclass."},project:function(e){return e=this.rawProject(e),this.transformation&&(e=this.transformation.transform(e)),e},unproject:function(e){return this.transformation&&(e=this.transformation.untransform(e)),e=this.rawUnproject(e),e},locationCoordinate:function(t){var n=new e.Point(Math.PI*t.lon/180,Math.PI*t.lat/180);return n=this.project(n),new e.Coordinate(n.y,n.x,this.zoom)},coordinateLocation:function(t){t=t.zoomTo(this.zoom);var n=new e.Point(t.column,t.row);return n=this.unproject(n),new e.Location(180*n.y/Math.PI,180*n.x/Math.PI)}},e.LinearProjection=function(t,n){e.Projection.call(this,t,n)},e.LinearProjection.prototype={rawProject:function(t){return new e.Point(t.x,t.y)},rawUnproject:function(t){return new e.Point(t.x,t.y)}},e.extend(e.LinearProjection,e.Projection),e.MercatorProjection=function(t,n){e.Projection.call(this,t,n)},e.MercatorProjection.prototype={rawProject:function(t){return new e.Point(t.x,Math.log(Math.tan(.25*Math.PI+.5*t.y)))},rawUnproject:function(t){return new e.Point(t.x,2*Math.atan(Math.pow(Math.E,t.y))-.5*Math.PI)}},e.extend(e.MercatorProjection,e.Projection),e.MapProvider=function(e){e&&(this.getTile=e)},e.MapProvider.prototype={tileLimits:[new e.Coordinate(0,0,0),(new e.Coordinate(1,1,0)).zoomTo(18)],getTileUrl:function(e){throw"Abstract method not implemented by subclass."},getTile:function(e){throw"Abstract method not implemented by subclass."},releaseTile:function(e){},setZoomRange:function(e,t){this.tileLimits[0]=this.tileLimits[0].zoomTo(e),this.tileLimits[1]=this.tileLimits[1].zoomTo(t)},sourceCoordinate:function(t){var n=this.tileLimits[0].zoomTo(t.zoom).container(),r=this.tileLimits[1].zoomTo(t.zoom),i=Math.pow(2,t.zoom),s;return r=new e.Coordinate(Math.ceil(r.row),Math.ceil(r.column),Math.floor(r.zoom)),t.column<0?s=(t.column%i+i)%i:s=t.column%i,t.row<n.row||t.row>=r.row?null:s<n.column||s>=r.column?null:new e.Coordinate(t.row,s,t.zoom)}},e.Template=function(t,n){function s(e,t,n){var r="";for(var i=1;i<=n;i++)r+=(e>>n-i&1)<<1|t>>n-i&1;return r||"0"}var r=t.match(/{(Q|quadkey)}/);r&&(t=t.replace("{subdomains}","{S}").replace("{zoom}","{Z}").replace("{quadkey}","{Q}"));var i=n&&n.length&&t.indexOf("{S}")>=0,o=function(e){var o=this.sourceCoordinate(e);if(!o)return null;var u=t;if(i){var a=parseInt(o.zoom+o.row+o.column,10)%n.length;u=u.replace("{S}",n[a])}return r?u.replace("{Z}",o.zoom.toFixed(0)).replace("{Q}",s(o.row,o.column,o.zoom)):u.replace("{Z}",o.zoom.toFixed(0)).replace("{X}",o.column.toFixed(0)).replace("{Y}",o.row.toFixed(0))};e.MapProvider.call(this,o)},e.Template.prototype={getTile:function(e){return this.getTileUrl(e)}},e.extend(e.Template,e.MapProvider),e.TemplatedLayer=function(t,n,r){return new e.Layer(new e.Template(t,n),null,r)},e.getMousePoint=function(t,n){var r=new e.Point(t.clientX,t.clientY);r.x+=document.body.scrollLeft+document.documentElement.scrollLeft,r.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var i=n.parent;i;i=i.offsetParent)r.x-=i.offsetLeft,r.y-=i.offsetTop;return r},e.MouseWheelHandler=function(){function o(t){var o=0;i=i||(new Date).getTime();try{r.scrollTop=1e3,r.dispatchEvent(t),o=1e3-r.scrollTop}catch(u){o=t.wheelDelta||-t.detail*5}var a=(new Date).getTime()-i,f=e.getMousePoint(t,n);return Math.abs(o)>0&&a>200&&!s?(n.zoomByAbout(o>0?1:-1,f),i=(new Date).getTime()):s&&n.zoomByAbout(o*.001,f),e.cancelEvent(t)}var t={},n,r,i,s=!1;return t.init=function(i){n=i,r=document.body.appendChild(document.createElement("div")),r.style.cssText="visibility:hidden;top:0;height:0;width:0;overflow-y:scroll";var s=r.appendChild(document.createElement("div"));return s.style.height="2000px",e.addEvent(n.parent,"mousewheel",o),t},t.precise=function(e){return arguments.length?(s=e,t):s},t.remove=function(){e.removeEvent(n.parent,"mousewheel",o),r.parentNode.removeChild(r)},t},e.DoubleClickHandler=function(){function r(t){var r=e.getMousePoint(t,n);return n.zoomByAbout(t.shiftKey?-1:1,r),e.cancelEvent(t)}var t={},n;return t.init=function(i){return n=i,e.addEvent(n.parent,"dblclick",r),t},t.remove=function(){e.removeEvent(n.parent,"dblclick",r)},t},e.DragHandler=function(){function i(t){if(t.shiftKey||t.button==2)return;return e.addEvent(document,"mouseup",s),e.addEvent(document,"mousemove",o),n=new e.Point(t.clientX,t.clientY),r.parent.style.cursor="move",e.cancelEvent(t)}function s(t){return e.removeEvent(document,"mouseup",s),e.removeEvent(document,"mousemove",o),n=null,r.parent.style.cursor="",e.cancelEvent(t)}function o(t){return n&&(r.panBy(t.clientX-n.x,t.clientY-n.y),n.x=t.clientX,n.y=t.clientY,n.t=+(new Date)),e.cancelEvent(t)}var t={},n,r;return t.init=function(n){return r=n,e.addEvent(r.parent,"mousedown",i),t},t.remove=function(){e.removeEvent(r.parent,"mousedown",i)},t},e.MouseHandler=function(){var t={},n,r;return t.init=function(i){return n=i,r=[e.DragHandler().init(n),e.DoubleClickHandler().init(n),e.MouseWheelHandler().init(n)],t},t.remove=function(){for(var e=0;e<r.length;e++)r[e].remove();return t},t},e.TouchHandler=function(){function c(){var e=document.createElement("div");return e.setAttribute("ongesturestart","return;"),typeof e.ongesturestart=="function"}function h(e){for(var t=0;t<e.touches.length;t+=1){var n=e.touches[t];if(n.identifier in o){var r=o[n.identifier];r.x=n.clientX,r.y=n.clientY,r.scale=e.scale}else o[n.identifier]={scale:e.scale,startPos:{x:n.clientX,y:n.clientY},x:n.clientX,y:n.clientY,time:(new Date).getTime()}}}function p(e,t){return e&&e.touch&&t.identifier==e.touch.identifier}function d(e){h(e)}function v(t){switch(t.touches.length){case 1:w(t.touches[0]);break;case 2:E(t)}return h(t),e.cancelEvent(t)}function m(t){var n=(new Date).getTime();t.touches.length===0&&f&&S(l);for(var s=0;s<t.changedTouches.length;s+=1){var u=t.changedTouches[s],a=o[u.identifier];if(!a||a.wasPinch)continue;var c={x:u.clientX,y:u.clientY},h=n-a.time,p=e.Point.distance(c,a.startPos);p>i||(h>r?(c.end=n,c.duration=h,g(c)):(c.time=n,y(c)))}var d={};for(var v=0;v<t.touches.length;v++)d[t.touches[v].identifier]=!0;for(var m in o)m in d||delete d[m];return e.cancelEvent(t)}function g(e){}function y(e){if(u.length&&e.time-u[0].time<s){b(e),u=[];return}u=[e]}function b(t){var r=n.getZoom(),i=Math.round(r)+1,s=i-r,o=new e.Point(t.x,t.y);n.zoomByAbout(s,o)}function w(e){var t={x:e.clientX,y:e.clientY},r=o[e.identifier];n.panBy(t.x-r.x,t.y-r.y)}function E(t){var r=t.touches[0],i=t.touches[1],s=new e.Point(r.clientX,r.clientY),u=new e.Point(i.clientX,i.clientY),a=o[r.identifier],c=o[i.identifier];a.wasPinch=!0,c.wasPinch=!0;var h=e.Point.interpolate(s,u,.5);n.zoomByAbout(Math.log(t.scale)/Math.LN2-Math.log(a.scale)/Math.LN2,h);var p=e.Point.interpolate(a,c,.5);n.panBy(h.x-p.x,h.y-p.y),f=!0,l=h}function S(e){if(a){var t=n.getZoom(),r=Math.round(t);n.zoomByAbout(r-t,e)}f=!1}var t={},n,r=250,i=30,s=350,o={},u=[],a=!0,f=!1,l=null;return t.init=function(r){return n=r,c()?(e.addEvent(n.parent,"touchstart",d),e.addEvent(n.parent,"touchmove",v),e.addEvent(n.parent,"touchend",m),t):t},t.remove=function(){return c()?(e.removeEvent(n.parent,"touchstart",d),e.removeEvent(n.parent,"touchmove",v),e.removeEvent(n.parent,"touchend",m),t):t},t},e.CallbackManager=function(e,t){this.owner=e,this.callbacks={};for(var n=0;n<t.length;n++)this.callbacks[t[n]]=[]},e.CallbackManager.prototype={owner:null,callbacks:null,addCallback:function(e,t){typeof t=="function"&&this.callbacks[e]&&this.callbacks[e].push(t)},removeCallback:function(e,t){if(typeof t=="function"&&this.callbacks[e]){var n=this.callbacks[e],r=n.length;for(var i=0;i<r;i++)if(n[i]===t){n.splice(i,1);break}}},dispatchCallback:function(e,t){if(this.callbacks[e])for(var n=0;n<this.callbacks[e].length;n+=1)try{this.callbacks[e][n](this.owner,t)}catch(r){}}},e.RequestManager=function(){this.loadingBay=document.createDocumentFragment(),this.requestsById={},this.openRequestCount=0,this.maxOpenRequests=4,this.requestQueue=[],this.callbackManager=new e.CallbackManager(this,["requestcomplete","requesterror"])},e.RequestManager.prototype={loadingBay:null,requestsById:null,requestQueue:null,openRequestCount:null,maxOpenRequests:null,callbackManager:null,addCallback:function(e,t){this.callbackManager.addCallback(e,t)},removeCallback:function(e,t){this.callbackManager.removeCallback(e,t)},dispatchCallback:function(e,t){this.callbackManager.dispatchCallback(e,t)},clear:function(){this.clearExcept({})},clearRequest:function(e){e in this.requestsById&&delete this.requestsById[e];for(var t=0;t<this.requestQueue.length;t++){var n=this.requestQueue[t];n&&n.id==e&&(this.requestQueue[t]=null)}},clearExcept:function(e){for(var t=0;t<this.requestQueue.length;t++){var n=this.requestQueue[t];n&&!(n.id in e)&&(this.requestQueue[t]=null)}var r=this.loadingBay.childNodes;for(var i=r.length-1;i>=0;i--){var s=r[i];s.id in e||(this.loadingBay.removeChild(s),this.openRequestCount--,s.src=s.coord=s.onload=s.onerror=null)}for(var o in this.requestsById)if(!(o in e)&&this.requestsById.hasOwnProperty(o)){var u=this.requestsById[o];delete this.requestsById[o],u!==null&&(u=u.id=u.coord=u.url=null)}},hasRequest:function(e){return e in this.requestsById},requestTile:function(e,t,n){if(!(e in this.requestsById)){var r={id:e,coord:t.copy(),url:n};this.requestsById[e]=r,n&&this.requestQueue.push(r)}},getProcessQueue:function(){if(!this._processQueue){var e=this;this._processQueue=function(){e.processQueue()}}return this._processQueue},processQueue:function(e){e&&this.requestQueue.length>8&&this.requestQueue.sort(e);while(this.openRequestCount<this.maxOpenRequests&&this.requestQueue.length>0){var t=this.requestQueue.pop();if(t){this.openRequestCount++;var n=document.createElement("img");n.id=t.id,n.style.position="absolute",n.coord=t.coord,this.loadingBay.appendChild(n),n.onload=n.onerror=this.getLoadComplete(),n.src=t.url,t=t.id=t.coord=t.url=null}}},_loadComplete:null,getLoadComplete:function(){if(!this._loadComplete){var e=this;this._loadComplete=function(t){t=t||window.event;var n=t.srcElement||t.target;n.onload=n.onerror=null,e.loadingBay.removeChild(n),e.openRequestCount--,delete e.requestsById[n.id],t.type==="load"&&(n.complete||n.readyState&&n.readyState=="complete")?e.dispatchCallback("requestcomplete",n):(e.dispatchCallback("requesterror",{element:n,url:""+n.src}),n.src=null),setTimeout(e.getProcessQueue(),0)}}return this._loadComplete}},e.Layer=function(t,n,r){this.parent=n||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=r,this.levels={},this.requestManager=new e.RequestManager,this.requestManager.addCallback("requestcomplete",this.getTileComplete()),this.requestManager.addCallback("requesterror",this.getTileError()),t&&this.setProvider(t)},e.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 e=this;this._tileComplete=function(t,n){e.tiles[n.id]=n,e.positionTile(n)}}return this._tileComplete},getTileError:function(){if(!this._tileError){var e=this;this._tileError=function(t,n){n.element.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",e.tiles[n.element.id]=n.element,e.positionTile(n.element)}}return this._tileError},draw:function(){function n(e,n){if(e&&n){var r=e.coord,i=n.coord;if(r.zoom==i.zoom){var s=Math.abs(t.row-r.row-.5)+Math.abs(t.column-r.column-.5),o=Math.abs(t.row-i.row-.5)+Math.abs(t.column-i.column-.5);return s<o?1:s>o?-1:0}return r.zoom<i.zoom?1:r.zoom>i.zoom?-1:0}return e?1:n?-1:0}if(!this.enabled||!this.map)return;var t=this.map.coordinate.zoomTo(Math.round(this.map.coordinate.zoom)),r=Math.round(this.map.coordinate.zoom),i=this.map.pointCoordinate(new e.Point(0,0)).zoomTo(r).container(),s=this.map.pointCoordinate(this.map.dimensions).zoomTo(r).container().right().down(),o={},u=this.createOrGetLevel(i.zoom),a=i.copy();for(a.column=i.column;a.column<=s.column;a.column++)for(a.row=i.row;a.row<=s.row;a.row++){var f=this.inventoryVisibleTile(u,a);while(f.length)o[f.pop()]=!0}for(var l in this.levels)if(this.levels.hasOwnProperty(l)){var c=parseInt(l,10);if(c>=i.zoom-5&&c<i.zoom+2)continue;var h=this.levels[l];h.style.display="none";var p=this.tileElementsInLevel(h);while(p.length)this.provider.releaseTile(p[0].coord),this.requestManager.clearRequest(p[0].coord.toKey()),h.removeChild(p[0]),p.shift()}var d=i.zoom-5,v=i.zoom+2;for(var m=d;m<v;m++)this.adjustVisibleLevel(this.levels[m],m,o);this.requestManager.clearExcept(o),this.requestManager.processQueue(n)},inventoryVisibleTile:function(e,t){var n=t.toKey(),r=[n];if(n in this.tiles){var i=this.tiles[n];return i.parentNode!=e&&(e.appendChild(i),"reAddTile"in this.provider&&this.provider.reAddTile(n,t,i)),r}if(!this.requestManager.hasRequest(n)){var s=this.provider.getTile(t);typeof s=="string"?this.addTileImage(n,t,s):s&&this.addTileElement(n,t,s)}var o=!1,u=t.zoom;for(var a=1;a<=u;a++){var f=t.zoomBy(-a).container(),l=f.toKey();if(l in this.tiles){r.push(l),o=!0;break}}if(!o){var c=t.zoomBy(1);r.push(c.toKey()),c.column+=1,r.push(c.toKey()),c.row+=1,r.push(c.toKey()),c.column-=1,r.push(c.toKey())}return r},tileElementsInLevel:function(e){var t=[];for(var n=e.firstChild;n;n=n.nextSibling)n.nodeType==1&&t.push(n);return t},adjustVisibleLevel:function(t,n,r){if(!t)return;var i=1,s=this.map.coordinate.copy();if(!(t.childNodes.length>0))return t.style.display="none",!1;t.style.display="block",i=Math.pow(2,this.map.coordinate.zoom-n),s=s.zoomTo(n);var o=this.map.tileSize.x*i,u=this.map.tileSize.y*i,a=new e.Point(this.map.dimensions.x/2,this.map.dimensions.y/2),f=this.tileElementsInLevel(t);while(f.length){var l=f.pop();r[l.id]?e.moveElement(l,{x:Math.round(a.x+(l.coord.column-s.column)*o),y:Math.round(a.y+(l.coord.row-s.row)*u),scale:i,width:this.map.tileSize.x,height:this.map.tileSize.y}):(this.provider.releaseTile(l.coord),this.requestManager.clearRequest(l.coord.toKey()),t.removeChild(l))}},createOrGetLevel:function(e){if(e in this.levels)return this.levels[e];var t=document.createElement("div");return t.id=this.parent.id+"-zoom-"+e,t.style.cssText="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; margin: 0; padding: 0;",t.style.zIndex=e,this.parent.appendChild(t),this.levels[e]=t,t},addTileImage:function(e,t,n){this.requestManager.requestTile(e,t,n)},addTileElement:function(e,t,n){n.id=e,n.coord=t.copy(),this.positionTile(n)},positionTile:function(t){var n=this.map.coordinate.zoomTo(t.coord.zoom);t.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;",t.ondragstart=function(){return!1};var r=Math.pow(2,this.map.coordinate.zoom-t.coord.zoom);e.moveElement(t,{x:Math.round(this.map.dimensions.x/2+(t.coord.column-n.column)*this.map.tileSize.x),y:Math.round(this.map.dimensions.y/2+(t.coord.row-n.row)*this.map.tileSize.y),scale:r,width:this.map.tileSize.x,height:this.map.tileSize.y});var i=this.levels[t.coord.zoom];i.appendChild(t),t.className="map-tile-loaded",Math.round(this.map.coordinate.zoom)==t.coord.zoom&&(i.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 e=this;this._redraw=function(){e.draw(),e._redrawTimer=0}}return this._redraw},setProvider:function(e){var t=this.provider===null;if(!t){this.requestManager.clear();for(var n in this.levels)if(this.levels.hasOwnProperty(n)){var r=this.levels[n];while(r.firstChild)this.provider.releaseTile(r.firstChild.coord),r.removeChild(r.firstChild)}}this.tiles={},this.provider=e,t||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}},e.Map=function(t,n,r,i){if(typeof t=="string"){t=document.getElementById(t);if(!t)throw"The ID provided to modest maps could not be found."}this.parent=t,this.parent.style.padding="0",this.parent.style.overflow="hidden";var s=e.getStyle(this.parent,"position");s!="relative"&&s!="absolute"&&(this.parent.style.position="relative"),this.layers=[],n||(n=[]),n instanceof Array||(n=[n]);for(var o=0;o<n.length;o++)this.addLayer(n[o]);this.projection=new e.MercatorProjection(0,e.deriveTransformation(-Math.PI,Math.PI,0,0,Math.PI,Math.PI,1,0,-Math.PI,-Math.PI,0,1)),this.tileSize=new e.Point(256,256),this.coordLimits=[new e.Coordinate(0,-Infinity,0),(new e.Coordinate(1,Infinity,0)).zoomTo(18)],this.coordinate=new e.Coordinate(.5,.5,0),r?(this.autoSize=!1,this.parent.style.width=Math.round(r.x)+"px",this.parent.style.height=Math.round(r.y)+"px"):(r=new e.Point(this.parent.offsetWidth,this.parent.offsetHeight),this.autoSize=!0,e.addEvent(window,"resize",this.windowResize())),this.dimensions=r,this.callbackManager=new e.CallbackManager(this,["zoomed","panned","centered","extentset","resized","drawn"]);if(i===undefined)this.eventHandlers=[e.MouseHandler().init(this),e.TouchHandler().init(this)];else{this.eventHandlers=i;if(i instanceof Array)for(var u=0;u<i.length;u++)i[u].init(this)}},e.Map.prototype={parent:null,dimensions:null,projection:null,coordinate:null,tileSize:null,coordLimits:null,layers:null,callbackManager:null,eventHandlers:null,autoSize:null,toString:function(){return"Map(#"+this.parent.id+")"},addCallback:function(e,t){return this.callbackManager.addCallback(e,t),this},removeCallback:function(e,t){return this.callbackManager.removeCallback(e,t),this},dispatchCallback:function(e,t){return this.callbackManager.dispatchCallback(e,t),this},windowResize:function(){if(!this._windowResize){var t=this;this._windowResize=function(n){t.dimensions=new e.Point(t.parent.offsetWidth,t.parent.offsetHeight),t.draw(),t.dispatchCallback("resized",[t.dimensions])}}return this._windowResize},setZoomRange:function(e,t){return this.coordLimits[0]=this.coordLimits[0].zoomTo(e),this.coordLimits[1]=this.coordLimits[1].zoomTo(t),this},zoomBy:function(t){return this.coordinate=this.enforceLimits(this.coordinate.zoomBy(t)),e.getFrame(this.getRedraw()),this.dispatchCallback("zoomed",t),this},zoomIn:function(){return this.zoomBy(1)},zoomOut:function(){return this.zoomBy(-1)},setZoom:function(e){return this.zoomBy(e-this.coordinate.zoom)},zoomByAbout:function(e,t){var n=this.pointLocation(t);this.coordinate=this.enforceLimits(this.coordinate.zoomBy(e));var r=this.locationPoint(n);return this.dispatchCallback("zoomed",e),this.panBy(t.x-r.x,t.y-r.y)},panBy:function(t,n){return this.coordinate.column-=t/this.tileSize.x,this.coordinate.row-=n/this.tileSize.y,this.coordinate=this.enforceLimits(this.coordinate),e.getFrame(this.getRedraw()),this.dispatchCallback("panned",[t,n]),this},panLeft:function(){return this.panBy(100,0)},panRight:function(){return this.panBy(-100,0)},panDown:function(){return this.panBy(0,-100)},panUp:function(){return this.panBy(0,100)},setCenter:function(e){return this.setCenterZoom(e,this.coordinate.zoom)},setCenterZoom:function(t,n){return this.coordinate=this.projection.locationCoordinate(t).zoomTo(parseFloat(n)||0),this.coordinate=this.enforceLimits(this.coordinate),e.getFrame(this.getRedraw()),this.dispatchCallback("centered",[t,n]),this},extentCoordinate:function(t,n){t instanceof e.Extent&&(t=t.toArray());var r,i;for(var s=0;s<t.length;s++){var o=this.projection.locationCoordinate(t[s]);r?(r.row=Math.min(r.row,o.row),r.column=Math.min(r.column,o.column),r.zoom=Math.min(r.zoom,o.zoom),i.row=Math.max(i.row,o.row),i.column=Math.max(i.column,o.column),i.zoom=Math.max(i.zoom,o.zoom)):(r=o.copy(),i=o.copy())}var u=this.dimensions.x+1,a=this.dimensions.y+1,f=(i.column-r.column)/(u/this.tileSize.x),l=Math.log(f)/Math.log(2),c=r.zoom-(n?l:Math.ceil(l)),h=(i.row-r.row)/(a/this.tileSize.y),p=Math.log(h)/Math.log(2),d=r.zoom-(n?p:Math.ceil(p)),v=Math.min(c,d);v=Math.min(v,this.coordLimits[1].zoom),v=Math.max(v,this.coordLimits[0].zoom);var m=(r.row+i.row)/2,g=(r.column+i.column)/2,y=r.zoom;return(new e.Coordinate(m,g,y)).zoomTo(v)},setExtent:function(t,n){return this.coordinate=this.extentCoordinate(t,n),this.coordinate=this.enforceLimits(this.coordinate),e.getFrame(this.getRedraw()),this.dispatchCallback("extentset",t),this},setSize:function(t){return this.dimensions=new e.Point(t.x,t.y),this.parent.style.width=Math.round(this.dimensions.x)+"px",this.parent.style.height=Math.round(this.dimensions.y)+"px",this.autoSize&&(e.removeEvent(window,"resize",this.windowResize()),this.autoSize=!1),this.draw(),this.dispatchCallback("resized",this.dimensions),this},coordinatePoint:function(t){t.zoom!=this.coordinate.zoom&&(t=t.zoomTo(this.coordinate.zoom));var n=new e.Point(this.dimensions.x/2,this.dimensions.y/2);return n.x+=this.tileSize.x*(t.column-this.coordinate.column),n.y+=this.tileSize.y*(t.row-this.coordinate.row),n},pointCoordinate:function(e){var t=this.coordinate.copy();return t.column+=(e.x-this.dimensions.x/2)/this.tileSize.x,t.row+=(e.y-this.dimensions.y/2)/this.tileSize.y,t},locationCoordinate:function(e){return this.projection.locationCoordinate(e)},coordinateLocation:function(e){return this.projection.coordinateLocation(e)},locationPoint:function(e){return this.coordinatePoint(this.locationCoordinate(e))},pointLocation:function(e){return this.coordinateLocation(this.pointCoordinate(e))},getExtent:function(){return new e.Extent(this.pointLocation(new e.Point(0,0)),this.pointLocation(this.dimensions))},extent:function(e,t){return e?this.setExtent(e,t):this.getExtent()},getCenter:function(){return this.projection.coordinateLocation(this.coordinate)},center:function(e){return e?this.setCenter(e):this.getCenter()},getZoom:function(){return this.coordinate.zoom},zoom:function(e){return e!==undefined?this.setZoom(e):this.getZoom()},getLayers:function(){return this.layers.slice()},getLayer:function(e){for(var t=0;t<this.layers.length;t++)if(e==this.layers[t].name)return this.layers[t]},getLayerAt:function(e){return this.layers[e]},addLayer:function(t){return this.layers.push(t),this.parent.appendChild(t.parent),t.map=this,this.coordinate&&e.getFrame(this.getRedraw()),this},removeLayer:function(e){for(var t=0;t<this.layers.length;t++)if(e==this.layers[t]||e==this.layers[t].name){this.removeLayerAt(t);break}return this},setLayerAt:function(t,n){if(t<0||t>=this.layers.length)throw new Error("invalid index in setLayerAt(): "+t);if(this.layers[t]!=n){if(t<this.layers.length){var r=this.layers[t];this.parent.insertBefore(n.parent,r.parent),r.destroy()}else this.parent.appendChild(n.parent);this.layers[t]=n,n.map=this,e.getFrame(this.getRedraw())}return this},insertLayerAt:function(t,n){if(t<0||t>this.layers.length)throw new Error("invalid index in insertLayerAt(): "+t);if(t==this.layers.length)this.layers.push(n),this.parent.appendChild(n.parent);else{var r=this.layers[t];this.parent.insertBefore(n.parent,r.parent),this.layers.splice(t,0,n)}return n.map=this,e.getFrame(this.getRedraw()),this},removeLayerAt:function(e){if(e<0||e>=this.layers.length)throw new Error("invalid index in removeLayer(): "+e);var t=this.layers[e];return this.layers.splice(e,1),t.destroy(),this},swapLayersAt:function(e,t){if(e<0||e>=this.layers.length||t<0||t>=this.layers.length)throw new Error("invalid index in swapLayersAt(): "+index);var n=
this.layers[e],r=this.layers[t],i=document.createElement("div");return this.parent.replaceChild(i,r.parent),this.parent.replaceChild(r.parent,n.parent),this.parent.replaceChild(n.parent,i),this.layers[e]=r,this.layers[t]=n,this},enableLayer:function(e){var t=this.getLayer(e);return t&&t.enable(),this},enableLayerAt:function(e){var t=this.getLayerAt(e);return t&&t.enable(),this},disableLayer:function(e){var t=this.getLayer(e);return t&&t.disable(),this},disableLayerAt:function(e){var t=this.getLayerAt(e);return t&&t.disable(),this},enforceZoomLimits:function(e){var t=this.coordLimits;if(t){var n=t[0].zoom,r=t[1].zoom;e.zoom<n?e=e.zoomTo(n):e.zoom>r&&(e=e.zoomTo(r))}return e},enforcePanLimits:function(t){if(this.coordLimits){t=t.copy();var n=this.coordLimits[0].zoomTo(t.zoom),r=this.coordLimits[1].zoomTo(t.zoom),i=this.pointCoordinate(new e.Point(0,0)).zoomTo(t.zoom),s=this.pointCoordinate(this.dimensions).zoomTo(t.zoom);r.row-n.row<s.row-i.row?t.row=(r.row+n.row)/2:i.row<n.row?t.row+=n.row-i.row:s.row>r.row&&(t.row-=s.row-r.row),r.column-n.column<s.column-i.column?t.column=(r.column+n.column)/2:i.column<n.column?t.column+=n.column-i.column:s.column>r.column&&(t.column-=s.column-r.column)}return t},enforceLimits:function(e){return this.enforcePanLimits(this.enforceZoomLimits(e))},draw:function(){this.coordinate=this.enforceLimits(this.coordinate);if(this.dimensions.x<=0||this.dimensions.y<=0){if(!this.autoSize)return;var t=this.parent.offsetWidth,n=this.parent.offsetHeight;this.dimensions=new e.Point(t,n);if(t<=0||n<=0)return}for(var r=0;r<this.layers.length;r++)this.layers[r].draw();this.dispatchCallback("drawn")},_redrawTimer:undefined,requestRedraw:function(){this._redrawTimer||(this._redrawTimer=setTimeout(this.getRedraw(),1e3))},_redraw:null,getRedraw:function(){if(!this._redraw){var e=this;this._redraw=function(){e.draw(),e._redrawTimer=0}}return this._redraw},destroy:function(){for(var t=0;t<this.layers.length;t++)this.layers[t].destroy();this.layers=[],this.projection=null;for(var n=0;n<this.eventHandlers.length;n++)this.eventHandlers[n].remove();this.autoSize&&e.removeEvent(window,"resize",this.windowResize())}},e.mapByCenterZoom=function(t,n,r,i){var s=e.coerceLayer(n),o=new e.Map(t,s,!1);return o.setCenterZoom(r,i).draw(),o},e.mapByExtent=function(t,n,r,i){var s=e.coerceLayer(n),o=new e.Map(t,s,!1);return o.setExtent([r,i]).draw(),o},typeof module!="undefined"&&module.exports&&(module.exports={Point:e.Point,Projection:e.Projection,MercatorProjection:e.MercatorProjection,LinearProjection:e.LinearProjection,Transformation:e.Transformation,Location:e.Location,MapProvider:e.MapProvider,Template:e.Template,Coordinate:e.Coordinate,deriveTransformation:e.deriveTransformation})})(MM);
|