Leaflet/dist/leaflet.js

9 lines
110 KiB
JavaScript
Raw Normal View History

2010-09-23 20:56:29 +08:00
/*
2012-02-13 22:25:57 +08:00
Copyright (c) 2010-2012, CloudMade, Vladimir Agafonkin
2012-07-12 20:55:30 +08:00
Leaflet is an open-source JavaScript library for mobile-friendly interactive maps.
2012-11-02 21:16:17 +08:00
http://leafletjs.com
2010-09-23 20:56:29 +08:00
*/
2012-12-13 01:10:19 +08:00
var L,originalL;typeof exports!=void 0+""?L=exports:(originalL=window.L,L={},L.noConflict=function(){return window.L=originalL,this},window.L=L),L.version="0.5",L.Util={extend:function(t){var e,i,n,o,s=Array.prototype.slice.call(arguments,1);for(i=0,n=s.length;n>i;i++){o=s[i]||{};for(e in o)o.hasOwnProperty(e)&&(t[e]=o[e])}return t},bind:function(t,e){var i=arguments.length>2?Array.prototype.slice.call(arguments,2):null;return function(){return t.apply(e,i||arguments)}},stamp:function(){var t=0,e="_leaflet_id";return function(i){return i[e]=i[e]||++t,i[e]}}(),limitExecByInterval:function(t,e,i){var n,o;return function s(){var a=arguments;return n?(o=!0,void 0):(n=!0,setTimeout(function(){n=!1,o&&(s.apply(i,a),o=!1)},e),t.apply(i,a),void 0)}},falseFn:function(){return!1},formatNum:function(t,e){var i=Math.pow(10,e||5);return Math.round(t*i)/i},splitWords:function(t){return t.replace(/^\s+|\s+$/g,"").split(/\s+/)},setOptions:function(t,e){return t.options=L.extend({},t.options,e),t.options},getParamString:function(t){var e=[];for(var i in t)t.hasOwnProperty(i)&&e.push(i+"="+t[i]);return"?"+e.join("&")},template:function(t,e){return t.replace(/\{ *([\w_]+) *\}/g,function(t,i){var n=e[i];if(!e.hasOwnProperty(i))throw Error("No value provided for variable "+t);return n})},emptyImageUrl:"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="},function(){function t(t){var e,i,n=["webkit","moz","o","ms"];for(e=0;n.length>e&&!i;e++)i=window[n[e]+t];return i}function e(t){var e=+new Date,n=Math.max(0,16-(e-i));return i=e+n,window.setTimeout(t,n)}var i=0,n=window.requestAnimationFrame||t("RequestAnimationFrame")||e,o=window.cancelAnimationFrame||t("CancelAnimationFrame")||t("CancelRequestAnimationFrame")||function(t){window.clearTimeout(t)};L.Util.requestAnimFrame=function(t,i,o,s){return t=L.bind(t,i),o&&n===e?(t(),void 0):n.call(window,t,s)},L.Util.cancelAnimFrame=function(t){t&&o.call(window,t)}}(),L.extend=L.Util.extend,L.bind=L.Util.bind,L.stamp=L.Util.stamp,L.setOptions=L.Util.setOptions,L.Class=function(){},L.Class.extend=function(t){var e=function(){this.initialize&&this.initialize.apply(this,arguments),this._initHooks&&this.callInitHooks()},i=function(){};i.prototype=this.prototype;var n=new i;n.constructor=e,e.prototype=n;for(var o in this)this.hasOwnProperty(o)&&"prototype"!==o&&(e[o]=this[o]);return t.statics&&(L.extend(e,t.statics),delete t.statics),t.includes&&(L.Util.extend.apply(null,[n].concat(t.includes)),delete t.includes),t.options&&n.options&&(t.options=L.extend({},n.options,t.options)),L.extend(n,t),this.prototype._initHooks&&(n._initHooks=this.prototype._initHooks.slice()),n.callInitHooks=function(){if(!this._initHooksCalled){this._initHooksCalled=!0;for(var t=0,e=this._initHooks.length;e>t;t++)this._initHooks[t].call(this)}},e},L.Class.include=function(t){L.extend(this.prototype,t)},L.Class.mergeOptions=function(t){L.extend(this.prototype.options,t)},L.Class.addInitHook=function(t){var e=Array.prototype.slice.call(arguments,1),i="function"==typeof t?t:function(){this[t].apply(this,e)};this.prototype._initHooks=this.prototype._initHooks||[],this.prototype._initHooks.push(i)};var key="_leaflet_events";L.Mixin={},L.Mixin.Events={addEventListener:function(t,e,i){var n,o,s,a=this[key]=this[key]||{};if("object"==typeof t){for(n in t)t.hasOwnProperty(n)&&this.addEventListener(n,t[n],e);return this}for(t=L.Util.splitWords(t),o=0,s=t.length;s>o;o++)a[t[o]]=a[t[o]]||[],a[t[o]].push({action:e,context:i||this});return this},hasEventListeners:function(t){return key in this&&t in this[key]&&this[key][t].length>0},removeEventListener:function(t,e,i){var n,o,s,a,r,h=this[key];if("object"==typeof t){for(n in t)t.hasOwnProperty(n)&&this.removeEventListener(n,t[n],e);return this}for(t=L.Util.splitWords(t),o=0,s=t.length;s>o;o++)if(this.hasEventListeners(t[o]))for(a=h[t[o]],r=a.length-1;r>=0;r--)e&&a[r].action!==e||i&&a[r].context!==i||a.splice(r,1);return this},fireEvent:function(t,e){if(!this.hasEventListeners(t))return this;for(var i=L.extend({type:t,target:this},e),n=this[key][t].slice(),o=0,s=n.length;s>o;o++)n[o].ac
},_addTile:function(t,e){var i=this._getTilePos(t),n=this._getTile();L.DomUtil.setPosition(n,i,L.Browser.chrome||L.Browser.android23),this._tiles[t.x+":"+t.y]=n,this._loadTile(n,t),n.parentNode!==this._container&&e.appendChild(n)},_getZoomForUrl:function(){var t=this.options,e=this._map.getZoom();return t.zoomReverse&&(e=t.maxZoom-e),e+t.zoomOffset},_getTilePos:function(t){var e=this._map.getPixelOrigin(),i=this.options.tileSize;return t.multiplyBy(i).subtract(e)},getTileUrl:function(t){return this._adjustTilePoint(t),L.Util.template(this._url,L.extend({s:this._getSubdomain(t),z:this._getZoomForUrl(),x:t.x,y:t.y},this.options))},_getWrapTileNum:function(){return Math.pow(2,this._getZoomForUrl())},_adjustTilePoint:function(t){var e=this._getWrapTileNum();this.options.continuousWorld||this.options.noWrap||(t.x=(t.x%e+e)%e),this.options.tms&&(t.y=e-t.y-1)},_getSubdomain:function(t){var e=(t.x+t.y)%this.options.subdomains.length;return this.options.subdomains[e]},_createTileProto:function(){var t=this._tileImg=L.DomUtil.create("img","leaflet-tile");t.style.width=t.style.height=this.options.tileSize+"px",t.galleryimg="no"},_getTile:function(){if(this.options.reuseTiles&&this._unusedTiles.length>0){var t=this._unusedTiles.pop();return this._resetTile(t),t}return this._createTile()},_resetTile:function(){},_createTile:function(){var t=this._tileImg.cloneNode(!1);return t.onselectstart=t.onmousemove=L.Util.falseFn,t},_loadTile:function(t,e){t._layer=this,t.onload=this._tileOnLoad,t.onerror=this._tileOnError,t.src=this.getTileUrl(e)},_tileLoaded:function(){this._tilesToLoad--,this._tilesToLoad||this.fire("load")},_tileOnLoad:function(){var t=this._layer;this.src!==L.Util.emptyImageUrl&&(L.DomUtil.addClass(this,"leaflet-tile-loaded"),t.fire("tileload",{tile:this,url:this.src})),t._tileLoaded()},_tileOnError:function(){var t=this._layer;t.fire("tileerror",{tile:this,url:this.src});var e=t.options.errorTileUrl;e&&(this.src=e),t._tileLoaded()}}),L.tileLayer=function(t,e){return new L.TileLayer(t,e)},L.TileLayer.WMS=L.TileLayer.extend({defaultWmsParams:{service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},initialize:function(t,e){this._url=t;var i=L.extend({},this.defaultWmsParams);i.width=i.height=e.detectRetina&&L.Browser.retina?2*this.options.tileSize:this.options.tileSize;for(var n in e)this.options.hasOwnProperty(n)||(i[n]=e[n]);this.wmsParams=i,L.setOptions(this,e)},onAdd:function(t){var e=parseFloat(this.wmsParams.version)>=1.3?"crs":"srs";this.wmsParams[e]=t.options.crs.code,L.TileLayer.prototype.onAdd.call(this,t)},getTileUrl:function(t,e){this._adjustTilePoint(t);var i=this._map,n=i.options.crs,o=this.options.tileSize,s=t.multiplyBy(o),a=s.add(new L.Point(o,o)),r=n.project(i.unproject(s,e)),h=n.project(i.unproject(a,e)),l=[r.x,h.y,h.x,r.y].join(","),u=L.Util.template(this._url,{s:this._getSubdomain(t)});return u+L.Util.getParamString(this.wmsParams)+"&bbox="+l},setParams:function(t,e){return L.extend(this.wmsParams,t),e||this.redraw(),this}}),L.tileLayer.wms=function(t,e){return new L.TileLayer.WMS(t,e)},L.TileLayer.Canvas=L.TileLayer.extend({options:{async:!1},initialize:function(t){L.setOptions(this,t)},redraw:function(){var t=this._tiles;for(var e in t)t.hasOwnProperty(e)&&this._redrawTile(t[e])},_redrawTile:function(t){this.drawTile(t,t._tilePoint,this._map._zoom)},_createTileProto:function(){var t=this._canvasProto=L.DomUtil.create("canvas","leaflet-tile");t.width=t.height=this.options.tileSize},_createTile:function(){var t=this._canvasProto.cloneNode(!1);return t.onselectstart=t.onmousemove=L.Util.falseFn,t},_loadTile:function(t,e){t._layer=this,t._tilePoint=e,this._redrawTile(t),this.options.async||this.tileDrawn(t)},drawTile:function(){},tileDrawn:function(t){this._tileOnLoad.call(t)}}),L.tileLayer.canvas=function(t){return new L.TileLayer.Canvas(t)},L.ImageOverlay=L.Class.extend({includes:L.Mixin.Events,options:{opacity:1},initialize:function(t,e,i){this._url=t,this._bounds=L.latLngBounds(e),L.setOptions(this,i)},onAdd:function(t){this._map=t,this._image||this._init
n>c&&(n=c,s=L.LineUtil._sqClosestPointOnSegment(t,e,i))}return s&&(s.distance=Math.sqrt(n)),s},getBounds:function(){var t,e,i=new L.LatLngBounds,n=this.getLatLngs();for(t=0,e=n.length;e>t;t++)i.extend(n[t]);return i},_convertLatLngs:function(t){var e,i;for(e=0,i=t.length;i>e;e++){if(t[e]instanceof Array&&"number"!=typeof t[e][0])return;t[e]=L.latLng(t[e])}return t},_initEvents:function(){L.Path.prototype._initEvents.call(this)},_getPathPartStr:function(t){for(var e,i=L.Path.VML,n=0,o=t.length,s="";o>n;n++)e=t[n],i&&e._round(),s+=(n?"L":"M")+e.x+" "+e.y;return s},_clipPoints:function(){var t,e,i,n=this._originalPoints,o=n.length;if(this.options.noClip)return this._parts=[n],void 0;this._parts=[];var s=this._parts,a=this._map._pathViewport,r=L.LineUtil;for(t=0,e=0;o-1>t;t++)i=r.clipSegment(n[t],n[t+1],a,t),i&&(s[e]=s[e]||[],s[e].push(i[0]),(i[1]!==n[t+1]||t===o-2)&&(s[e].push(i[1]),e++))},_simplifyPoints:function(){for(var t=this._parts,e=L.LineUtil,i=0,n=t.length;n>i;i++)t[i]=e.simplify(t[i],this.options.smoothFactor)},_updatePath:function(){this._map&&(this._clipPoints(),this._simplifyPoints(),L.Path.prototype._updatePath.call(this))}}),L.polyline=function(t,e){return new L.Polyline(t,e)},L.PolyUtil={},L.PolyUtil.clipPolygon=function(t,e){var i,n,o,s,a,r,h,l,u,c=[1,4,2,8],d=L.LineUtil;for(n=0,h=t.length;h>n;n++)t[n]._code=d._getBitCode(t[n],e);for(s=0;4>s;s++){for(l=c[s],i=[],n=0,h=t.length,o=h-1;h>n;o=n++)a=t[n],r=t[o],a._code&l?r._code&l||(u=d._getEdgeIntersection(r,a,l,e),u._code=d._getBitCode(u,e),i.push(u)):(r._code&l&&(u=d._getEdgeIntersection(r,a,l,e),u._code=d._getBitCode(u,e),i.push(u)),i.push(a));t=i}return t},L.Polygon=L.Polyline.extend({options:{fill:!0},initialize:function(t,e){L.Polyline.prototype.initialize.call(this,t,e),t&&t[0]instanceof Array&&"number"!=typeof t[0][0]&&(this._latlngs=this._convertLatLngs(t[0]),this._holes=t.slice(1))},projectLatlngs:function(){if(L.Polyline.prototype.projectLatlngs.call(this),this._holePoints=[],this._holes){var t,e,i,n;for(t=0,i=this._holes.length;i>t;t++)for(this._holePoints[t]=[],e=0,n=this._holes[t].length;n>e;e++)this._holePoints[t][e]=this._map.latLngToLayerPoint(this._holes[t][e])}},_clipPoints:function(){var t=this._originalPoints,e=[];if(this._parts=[t].concat(this._holePoints),!this.options.noClip){for(var i=0,n=this._parts.length;n>i;i++){var o=L.PolyUtil.clipPolygon(this._parts[i],this._map._pathViewport);o.length&&e.push(o)}this._parts=e}},_getPathPartStr:function(t){var e=L.Polyline.prototype._getPathPartStr.call(this,t);return e+(L.Browser.svg?"z":"x")}}),L.polygon=function(t,e){return new L.Polygon(t,e)},function(){function t(t){return L.FeatureGroup.extend({initialize:function(t,e){this._layers={},this._options=e,this.setLatLngs(t)},setLatLngs:function(e){var i=0,n=e.length;for(this.eachLayer(function(t){n>i?t.setLatLngs(e[i++]):this.removeLayer(t)},this);n>i;)this.addLayer(new t(e[i++],this._options));return this}})}L.MultiPolyline=t(L.Polyline),L.MultiPolygon=t(L.Polygon),L.multiPolyline=function(t,e){return new L.MultiPolyline(t,e)},L.multiPolygon=function(t,e){return new L.MultiPolygon(t,e)}}(),L.Rectangle=L.Polygon.extend({initialize:function(t,e){L.Polygon.prototype.initialize.call(this,this._boundsToLatLngs(t),e)},setBounds:function(t){this.setLatLngs(this._boundsToLatLngs(t))},_boundsToLatLngs:function(t){return t=L.latLngBounds(t),[t.getSouthWest(),t.getNorthWest(),t.getNorthEast(),t.getSouthEast()]}}),L.rectangle=function(t,e){return new L.Rectangle(t,e)},L.Circle=L.Path.extend({initialize:function(t,e,i){L.Path.prototype.initialize.call(this,i),this._latlng=L.latLng(t),this._mRadius=e},options:{fill:!0},setLatLng:function(t){return this._latlng=L.latLng(t),this.redraw()},setRadius:function(t){return this._mRadius=t,this.redraw()},projectLatlngs:function(){var t=this._getLngRadius(),e=new L.LatLng(this._latlng.lat,this._latlng.lng-t),i=this._map.latLngToLayerPoint(e);this._point=this._map.latLngToLayerPoint(this._latlng),this._radius=Math.max(Math.round(this._point.x-i.x),1)},getBounds:function(){var t=this._getLngRadius(),e=360*(this._mRadiu
},addTo:function(t){this._map=t;var e=this._container=this.onAdd(t),i=this.getPosition(),n=t._controlCorners[i];return L.DomUtil.addClass(e,"leaflet-control"),-1!==i.indexOf("bottom")?n.insertBefore(e,n.firstChild):n.appendChild(e),this},removeFrom:function(t){var e=this.getPosition(),i=t._controlCorners[e];return i.removeChild(this._container),this._map=null,this.onRemove&&this.onRemove(t),this}}),L.control=function(t){return new L.Control(t)},L.Map.include({addControl:function(t){return t.addTo(this),this},removeControl:function(t){return t.removeFrom(this),this},_initControlPos:function(){function t(t,o){var s=i+t+" "+i+o;e[t+o]=L.DomUtil.create("div",s,n)}var e=this._controlCorners={},i="leaflet-",n=this._controlContainer=L.DomUtil.create("div",i+"control-container",this._container);t("top","left"),t("top","right"),t("bottom","left"),t("bottom","right")}}),L.Control.Zoom=L.Control.extend({options:{position:"topleft"},onAdd:function(t){var e="leaflet-control-zoom",i=L.DomUtil.create("div",e);return this._map=t,this._zoomInButton=this._createButton("+","Zoom in",e+"-in",i,this._zoomIn,this),this._zoomOutButton=this._createButton("-","Zoom out",e+"-out",i,this._zoomOut,this),t.on("zoomend",this._updateDisabled,this),i},onRemove:function(t){t.off("zoomend",this._updateDisabled,this)},_zoomIn:function(t){this._map.zoomIn(t.shiftKey?3:1)},_zoomOut:function(t){this._map.zoomOut(t.shiftKey?3:1)},_createButton:function(t,e,i,n,o,s){var a=L.DomUtil.create("a",i,n);return a.innerHTML=t,a.href="#",a.title=e,L.DomEvent.on(a,"click",L.DomEvent.stopPropagation).on(a,"mousedown",L.DomEvent.stopPropagation).on(a,"dblclick",L.DomEvent.stopPropagation).on(a,"click",L.DomEvent.preventDefault).on(a,"click",o,s),a},_updateDisabled:function(){var t=this._map,e="leaflet-control-zoom-disabled";L.DomUtil.removeClass(this._zoomInButton,e),L.DomUtil.removeClass(this._zoomOutButton,e),t._zoom===t.getMinZoom()&&L.DomUtil.addClass(this._zoomOutButton,e),t._zoom===t.getMaxZoom()&&L.DomUtil.addClass(this._zoomInButton,e)}}),L.Map.mergeOptions({zoomControl:!0}),L.Map.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new L.Control.Zoom,this.addControl(this.zoomControl))}),L.control.zoom=function(t){return new L.Control.Zoom(t)},L.Control.Attribution=L.Control.extend({options:{position:"bottomright",prefix:'Powered by <a href="http://leafletjs.com">Leaflet</a>'},initialize:function(t){L.setOptions(this,t),this._attributions={}},onAdd:function(t){return this._container=L.DomUtil.create("div","leaflet-control-attribution"),L.DomEvent.disableClickPropagation(this._container),t.on("layeradd",this._onLayerAdd,this).on("layerremove",this._onLayerRemove,this),this._update(),this._container},onRemove:function(t){t.off("layeradd",this._onLayerAdd).off("layerremove",this._onLayerRemove)},setPrefix:function(t){return this.options.prefix=t,this._update(),this},addAttribution:function(t){return t?(this._attributions[t]||(this._attributions[t]=0),this._attributions[t]++,this._update(),this):void 0},removeAttribution:function(t){return t?(this._attributions[t]--,this._update(),this):void 0},_update:function(){if(this._map){var t=[];for(var e in this._attributions)this._attributions.hasOwnProperty(e)&&this._attributions[e]&&t.push(e);var i=[];this.options.prefix&&i.push(this.options.prefix),t.length&&i.push(t.join(", ")),this._container.innerHTML=i.join(" &#8212; ")}},_onLayerAdd:function(t){t.layer.getAttribution&&this.addAttribution(t.layer.getAttribution())},_onLayerRemove:function(t){t.layer.getAttribution&&this.removeAttribution(t.layer.getAttribution())}}),L.Map.mergeOptions({attributionControl:!0}),L.Map.addInitHook(function(){this.options.attributionControl&&(this.attributionControl=(new L.Control.Attribution).addTo(this))}),L.control.attribution=function(t){return new L.Control.Attribution(t)},L.Control.Scale=L.Control.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0,updateWhenIdle:!1},onAdd:function(t){this._map=t;var e="leaflet-control-scale",i=L.DomUtil.create("div",e),n=this.options;return this._addScales(n,e,i),