layer remove
This commit is contained in:
parent
9998e6c6e3
commit
c2399defdd
31
dist/leaflet.js
vendored
31
dist/leaflet.js
vendored
@ -19,11 +19,12 @@ document.onselectstart;document.onselectstart=L.Util.falseFn}},_enableTextSelect
|
||||
getCenter:function(){return new L.LatLng((this._southWest.lat+this._northEast.lat)/2,(this._southWest.lng+this._northEast.lng)/2)},getSouthWest:function(){return this._southWest},getNorthEast:function(){return this._northEast},getNorthWest:function(){return new L.LatLng(this._northEast.lat,this._southWest.lng)},getSouthEast:function(){return new L.LatLng(this._southWest.lat,this._northEast.lng)},contains:function(a){var b=this._southWest,c=this._northEast,d=a.getSouthWest();a=a.getNorthEast();return d.lat>=
|
||||
b.lat&&a.lat<=c.lat&&d.lng>=b.lng&&a.lng<=c.lng}});L.Projection={};L.Projection.Mercator={MAX_LATITUDE:function(){var a=Math.exp(2*Math.PI);return Math.asin((a-1)/(a+1))*L.LatLng.RAD_TO_DEG}(),project:function(a){var b=L.LatLng.DEG_TO_RAD,c=L.Projection.Mercator.MAX_LATITUDE,d=a.lng*b;a=Math.max(Math.min(c,a.lat),-c)*b;a=Math.log(Math.tan(Math.PI/4+a/2));return new L.Point(d,a)},unproject:function(a,b){var c=L.LatLng.DEG_TO_RAD,d=a.x/c;return new L.LatLng((2*Math.atan(Math.exp(a.y))-Math.PI/2)/c,d,b)}};L.Point=function(a,b,c){this.x=c?Math.round(a):a;this.y=c?Math.round(b):b};
|
||||
L.Point.prototype={add:function(a){return new L.Point(this.x+a.x,this.y+a.y)},subtract:function(a){return new L.Point(this.x-a.x,this.y-a.y)},divideBy:function(a,b){return new L.Point(this.x/a,this.y/a,b)},multiplyBy:function(a){return new L.Point(this.x*a,this.y*a)},distanceTo:function(a){var b=a.x-this.x;a=a.y-this.y;return Math.sqrt(b*b+a*a)},round:function(){return new L.Point(Math.round(this.x),Math.round(this.y))},toString:function(){return"Point( "+this.x+", "+this.y+" )"}};L.Bounds=L.Class.extend({initialize:function(a,b){for(var c=a instanceof Array?a:[a,b],d=0,e=c.length;d<e;d++)this.extend(c[d])},extend:function(a){if(!this.min&&!this.max){this.min=new L.Point(a.x,a.y);this.max=new L.Point(a.x,a.y)}else{this.min.x=Math.min(a.x,this.min.x);this.max.x=Math.max(a.x,this.max.x);this.min.y=Math.min(a.y,this.min.y);this.max.y=Math.max(a.y,this.max.y)}},getCenter:function(a){return new L.Point((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,a)},contains:function(a){return a.min.x>=
|
||||
this.min.x&&a.max.x<=this.max.x&&a.min.y>=this.min.y&&a.max.y<=this.max.y}});L.Transformation=L.Class.extend({initialize:function(a,b,c,d){this._a=a;this._b=b;this._c=c;this._d=d},transform:function(a,b){b=b||1;return new L.Point(b*(this._a*a.x+this._b),b*(this._c*a.y+this._d))},untransform:function(a,b){b=b||1;return new L.Point((a.x/b-this._b)/this._a,(a.y/b-this._d)/this._c)}});L.TileLayer=L.Class.extend({includes:L.Mixin.Events,options:{tileSize:256,minZoom:0,maxZoom:18,subdomains:"abc",copyright:"",unloadInvisibleTiles:L.Browser.mobileWebkit,updateWhenIdle:L.Browser.mobileWebkit},initialize:function(a,b){L.Util.extend(this.options,b);this._url=a;if(typeof this.options.subdomains=="string")this.options.subdomains=this.options.subdomains.split("")},onAdd:function(a){this._map=a;this._container=document.createElement("div");this._container.className="leaflet-layer";this._map.getPanes().tilePane.appendChild(this._container);
|
||||
this._tileImg=document.createElement("img");L.Util.extend(this._tileImg,{className:"leaflet-tile",galleryimg:"no"});a=this.options.tileSize;L.Util.extend(this._tileImg.style,{width:a+"px",height:a+"px",visibility:"hidden"});this._map.on("viewreset",this._reset,this);if(this.options.updateWhenIdle)this._map.on("moveend",this._update,this);else{this._update=L.Util.limitExecByInterval(this._update,100,this);this._map.on("move",this._update,this)}this._reset();this._update()},_reset:function(){this._tiles=
|
||||
{};this._container.innerHTML=""},_update:function(){var a=this._map.getPixelBounds(),b=this.options.tileSize,c=new L.Point(Math.floor(a.min.x/b),Math.floor(a.min.y/b));a=new L.Point(Math.floor(a.max.x/b),Math.floor(a.max.y/b));this._loadTiles(c,a);this.options.unloadInvisibleTiles&&this._unloadOtherTiles(c,a)},getTileUrl:function(a,b){return this._url.replace("{s}",this.options.subdomains[(a.x+a.y)%this.options.subdomains.length]).replace("{z}",b).replace("{x}",a.x).replace("{y}",a.y)},_loadTiles:function(a,
|
||||
b){for(var c=a.y;c<=b.y;c++)for(var d=a.x;d<=b.x;d++)d+":"+c in this._tiles||this._loadTile(new L.Point(d,c))},_unloadOtherTiles:function(a,b){var c,d,e;for(e in this._tiles){kArr=e.split(":");c=parseInt(kArr[0]);d=parseInt(kArr[1]);if(c<a.x||c>b.x||d<a.y||d>b.y){this._container.removeChild(this._tiles[e]);delete this._tiles[e]}}},_loadTile:function(a){var b=this._map.getPixelOrigin();b=a.multiplyBy(this.options.tileSize).subtract(b);var c=this._map.getZoom(),d=1<<c;a.x=(a.x%d+d)%d;if(!(a.y<0||a.y>=
|
||||
d)){d=this._tileImg.cloneNode(false);this._tiles[a.x+":"+a.y]=d;L.DomUtil.setPosition(d,b);d.onload=this._tileOnLoad;d.onselectstart=d.onmousemove=L.Util.falseFn;d._leaflet_layer=this;d.src=this.getTileUrl(a,c);this._container.appendChild(d)}},_tileOnLoad:function(){this.style.visibility="visible";this.className+=" leaflet-tile-loaded";this._leaflet_layer.fire("tileload",{tile:this})}});L.ImageOverlay=L.Class.extend({includes:L.Mixin.Events,initialize:function(a,b){this._url=a;this._bounds=b},onAdd:function(a){this._map=a;this._image=document.createElement("img");this._image.style.visibility="hidden";this._image.style.position="absolute";L.Util.extend(this._image,{className:"leaflet-image-layer",galleryimg:"no",onselectstart:L.Util.falseFn,onmousemove:L.Util.falseFn,onload:this._onImageLoad,src:this._url});this._map.getPanes().overlayPane.appendChild(this._image);this._map.on("viewreset",
|
||||
this.min.x&&a.max.x<=this.max.x&&a.min.y>=this.min.y&&a.max.y<=this.max.y}});L.Transformation=L.Class.extend({initialize:function(a,b,c,d){this._a=a;this._b=b;this._c=c;this._d=d},transform:function(a,b){b=b||1;return new L.Point(b*(this._a*a.x+this._b),b*(this._c*a.y+this._d))},untransform:function(a,b){b=b||1;return new L.Point((a.x/b-this._b)/this._a,(a.y/b-this._d)/this._c)}});L.TileLayer=L.Class.extend({includes:L.Mixin.Events,options:{tileSize:256,minZoom:0,maxZoom:18,subdomains:"abc",copyright:"",unloadInvisibleTiles:L.Browser.mobileWebkit,updateWhenIdle:L.Browser.mobileWebkit,errorTileUrl:""},initialize:function(a,b){L.Util.extend(this.options,b);this._url=a;if(typeof this.options.subdomains=="string")this.options.subdomains=this.options.subdomains.split("")},onAdd:function(a){this._map=a;this._container=document.createElement("div");this._container.className="leaflet-layer";
|
||||
a.getPanes().tilePane.appendChild(this._container);this._tileImg=document.createElement("img");this._tileImg.className="leaflet-tile";this._tileImg.galleryimg="no";var b=this.options.tileSize;this._tileImg.style.width=b+"px";this._tileImg.style.height=b+"px";a.on("viewreset",this._reset,this);if(this.options.updateWhenIdle)a.on("moveend",this._update,this);else{this._limitedUpdate=L.Util.limitExecByInterval(this._update,100,this);a.on("move",this._limitedUpdate,this)}this._reset();this._update()},
|
||||
onRemove:function(){this._map.getPanes().tilePane.removeChild(this._container);this._map.off("viewreset",this._reset);this.options.updateWhenIdle?this._map.off("moveend",this._update):this._map.off("move",this._limitedUpdate)},_reset:function(){this._tiles={};this._container.innerHTML=""},_update:function(){var a=this._map.getPixelBounds(),b=this.options.tileSize,c=new L.Point(Math.floor(a.min.x/b),Math.floor(a.min.y/b));a=new L.Point(Math.floor(a.max.x/b),Math.floor(a.max.y/b));this._loadTiles(c,
|
||||
a);this.options.unloadInvisibleTiles&&this._unloadOtherTiles(c,a)},getTileUrl:function(a,b){return this._url.replace("{s}",this.options.subdomains[(a.x+a.y)%this.options.subdomains.length]).replace("{z}",b).replace("{x}",a.x).replace("{y}",a.y)},_loadTiles:function(a,b){for(var c=a.y;c<=b.y;c++)for(var d=a.x;d<=b.x;d++)d+":"+c in this._tiles||this._loadTile(new L.Point(d,c))},_unloadOtherTiles:function(a,b){var c,d,e;for(e in this._tiles){kArr=e.split(":");c=parseInt(kArr[0]);d=parseInt(kArr[1]);
|
||||
if(c<a.x||c>b.x||d<a.y||d>b.y){this._container.removeChild(this._tiles[e]);delete this._tiles[e]}}},_loadTile:function(a){var b=this._map.getPixelOrigin();b=a.multiplyBy(this.options.tileSize).subtract(b);var c=this._map.getZoom(),d=1<<c;a.x=(a.x%d+d)%d;if(!(a.y<0||a.y>=d)){d=this._tileImg.cloneNode(false);this._tiles[a.x+":"+a.y]=d;L.DomUtil.setPosition(d,b);d.onload=this._tileOnLoad;d.onselectstart=d.onmousemove=L.Util.falseFn;d._leaflet_layer=this;d.src=this.getTileUrl(a,c);this._container.appendChild(d)}},
|
||||
_tileOnLoad:function(){this.className+=" leaflet-tile-loaded";this._leaflet_layer.fire("tileload",{tile:this})}});L.ImageOverlay=L.Class.extend({includes:L.Mixin.Events,initialize:function(a,b){this._url=a;this._bounds=b},onAdd:function(a){this._map=a;this._image=document.createElement("img");this._image.style.visibility="hidden";this._image.style.position="absolute";L.Util.extend(this._image,{className:"leaflet-image-layer",galleryimg:"no",onselectstart:L.Util.falseFn,onmousemove:L.Util.falseFn,onload:this._onImageLoad,src:this._url});this._map.getPanes().overlayPane.appendChild(this._image);this._map.on("viewreset",
|
||||
this._reset,this);this._reset()},_reset:function(){var a=this._map.latLngToLayerPoint(this._bounds.getNorthWest()),b=this._map.latLngToLayerPoint(this._bounds.getSouthEast()).subtract(a);L.DomUtil.setPosition(this._image,a);this._image.style.width=b.x+"px";this._image.style.height=b.y+"px"},_onImageLoad:function(){this.style.visibility=""}});L.Handler=L.Class.extend({initialize:function(a,b){this._map=a;b&&this.enable()},enabled:function(){return!!this._enabled}});L.Handler.MapDrag=L.Handler.extend({enable:function(){if(!this._enabled){if(!this._draggable){this._draggable=new L.Draggable(this._map._mapPane,this._map._container);var a=this._map.getSize();if(a.x*a.y>=7E5&&L.Browser.gecko)this._draggable._updatePosition=L.Util.deferExecByInterval(this._draggable._updatePosition,0,this._draggable);this._draggable.on("dragstart",this._onDragStart,this);this._draggable.on("drag",this._onDrag,this);this._draggable.on("dragend",this._onDragEnd,this)}this._draggable.enable();
|
||||
this._enabled=true}},disable:function(){if(this._enabled){this._draggable.disable();this._enabled=false}},_onDragStart:function(){this._map.fire("movestart");this._map.fire("dragstart")},_onDrag:function(){this._map.fire("move");this._map.fire("drag")},_onDragEnd:function(){this._map.fire("moveend");this._map.fire("dragend")}});L.Handler.TouchZoom=L.Handler.extend({enable:function(){if(!(!L.Browser.mobileWebkit||this._enabled)){L.DomEvent.addListener(this._map._container,"touchstart",this._onTouchStart,this);this._enabled=true}},disable:function(){if(this._enabled){L.DomEvent.removeListener(this._map._container,"touchstart",this._onTouchStart,this);this._enabled=false}},_onTouchStart:function(a){if(!(!a.touches||a.touches.length!=2)){var b=this._map.mouseEventToLayerPoint(a.touches[0]),c=this._map.mouseEventToLayerPoint(a.touches[1]),
|
||||
d=this._map.containerPointToLayerPoint(this._map.getSize().divideBy(2));this._startCenter=b.add(c).divideBy(2,true);this._startDist=b.distanceTo(c);this._startTransform=this._map._mapPane.style.webkitTransform;this._centerOffset=d.subtract(this._startCenter);L.DomEvent.addListener(document,"touchmove",this._onTouchMove,this);L.DomEvent.addListener(document,"touchend",this._onTouchEnd,this);L.DomEvent.preventDefault(a)}},_onTouchMove:function(a){if(!(!a.touches||a.touches.length!=2)){var b=this._map.mouseEventToLayerPoint(a.touches[0]),
|
||||
@ -31,14 +32,14 @@ c=this._map.mouseEventToLayerPoint(a.touches[1]);this._scale=b.distanceTo(c)/thi
|
||||
2||!this._scale)){a=this._map.getZoom()+Math.round(Math.log(this._scale)/Math.LN2);var b=this._centerOffset.subtract(this._delta).divideBy(this._scale);b=this._map.unproject(this._map.getPixelOrigin().add(this._startCenter).add(b));map.setView(b,a,true);this._scale=null;L.DomEvent.removeListener(document,"touchmove",this._onTouchMove);L.DomEvent.removeListener(document,"touchend",this._onTouchEnd)}}});L.Handler.ScrollWheelZoom=L.Handler.extend({enable:function(){if(!this._enabled){L.DomEvent.addListener(this._map._container,"mousewheel",this._onWheelScroll,this);this._delta=0;this._enabled=true}},disable:function(){if(this._enabled){L.DomEvent.removeListener(this._map._container,"mousewheel",this._onWheelScroll);this._enabled=false}},_onWheelScroll:function(a){this._delta+=L.DomEvent.getWheelDelta(a);this._lastMousePos=this._map.mouseEventToContainerPoint(a);clearTimeout(this._timer);this._timer=
|
||||
setTimeout(L.Util.bind(this._performZoom,this),50);L.DomEvent.preventDefault(a)},_performZoom:function(){var a=Math.round(this._delta);if(a){var b=this._getCenterForScrollWheelZoom(this._lastMousePos,a);a=this._map.getZoom()+a;this._map.setView(b,a);this._delta=0}},_getCenterForScrollWheelZoom:function(a,b){var c=this._map.getPixelBounds().getCenter(),d=this._map.getSize().divideBy(2);d=a.subtract(d).multiplyBy(1-Math.pow(2,-b));return this._map.unproject(c.add(d))}});L.Handler.DoubleClickZoom=L.Handler.extend({enable:function(){if(!this._enabled){this._map.on("dblclick",this._onDoubleClick,this._map);this._enabled=true}},disable:function(){if(this._enabled){this._map.off("dblclick",this._onDoubleClick,this._map);this._enabled=false}},_onDoubleClick:function(a){this.setView(a.position,this._zoom+1)}});L.Map=L.Class.extend({includes:L.Mixin.Events,options:{projection:L.Projection.Mercator,transformation:new L.Transformation(0.5/Math.PI,0.5,-0.5/Math.PI,0.5),scaling:function(a){return 256*(1<<a)},center:new L.LatLng(0,0),zoom:0,layers:[],dragging:true,touchZoom:L.Browser.mobileWebkit,scrollWheelZoom:!L.Browser.mobileWebkit,doubleClickZoom:true,updateWhenIdle:L.Browser.mobileWebkit},initialize:function(a,b){this._container=L.DomUtil.get(a);L.Util.extend(this.options,b);this._initLayout();var c=this.options.layers;
|
||||
c=c instanceof Array?c:[c];this._initLayers(c);if(L.DomEvent){this._initEvents();L.Handler&&this._initInteraction()}this.setView(this.options.center,this.options.zoom,true)},setView:function(a,b,c){b=this._limitZoom(b);var d=this._zoom!=b;if(!c&&this._layers){c=this._getNewTopLeftPoint(a).subtract(this._getTopLeftPoint());if(d?this._zoomToIfCenterInView(a,b,c):this._panByIfClose(c))return this}this._resetView(a,b);return this},setZoom:function(a){return this.setView(this.getCenter(),a)},zoomIn:function(){return this.setZoom(this._zoom+
|
||||
1)},zoomOut:function(){return this.setZoom(this,zoom-1)},fitBounds:function(a){var b=this.getBoundsZoom(a);return this.setView(a.getCenter(),b,true)},panTo:function(a){return this.setView(a,this._zoom)},panBy:function(a){this.fire("movestart");this._rawPanBy(a);this.fire("viewupdate");this.fire("move");this.fire("moveend")},addLayer:function(a){this._layers.push(a);a.onAdd(this);this._layersMaxZoom=Math.max(this._layersMaxZoom||0,a.options.maxZoom);this._layersMinZoom=Math.min(this._layersMinZoom||
|
||||
Infinity,a.options.minZoom);this.fire("layeradded",{layer:a});return this},invalidateSize:function(){this._sizeChanged=true;this.fire("viewupdate");return this},getCenter:function(a){var b=this.getSize().divideBy(2);return this.unproject(this._getTopLeftPoint().add(b),this._zoom,a)},getZoom:function(){return this._zoom},getMinZoom:function(){return isNaN(this.options.minZoom)?this._layersMinZoom||0:this.options.minZoom},getMaxZoom:function(){return isNaN(this.options.maxZoom)?this._layersMaxZoom||
|
||||
Infinity:this.options.maxZoom},getBoundsZoom:function(a){var b=this.getSize(),c=this.getMinZoom(),d=this.getMaxZoom(),e=a.getNorthEast();a=a.getSouthWest();var f,g;do{f=this.project(e,c);g=this.project(a,c);f=new L.Point(f.x-g.x,g.y-f.y);c++}while(f.x<=b.x&&f.y<=b.y&&c<=d);return c-1},getSize:function(){if(!this._size||this._sizeChanged){this._size=new L.Point(this._container.clientWidth,this._container.clientHeight);this._sizeChanged=false}return this._size},getPixelBounds:function(){var a=this._getTopLeftPoint(),
|
||||
b=this.getSize();return new L.Bounds(a,a.add(b))},getPixelOrigin:function(){return this._initialTopLeftPoint},mouseEventToContainerPoint:function(a){return L.DomEvent.getMousePosition(a,this._container)},mouseEventToLayerPoint:function(a){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(a))},mouseEventToLatLng:function(a){return this.layerPointToLatLng(this.mouseEventToLayerPoint(a))},containerPointToLayerPoint:function(a){return a.subtract(L.DomUtil.getPosition(this._mapPane))},
|
||||
layerPointToLatLng:function(a){return this.unproject(a.add(this._initialTopLeftPoint))},latLngToLayerPoint:function(a){return this.project(a).subtract(this._initialTopLeftPoint)},project:function(a,b){var c=this.options.projection.project(a),d=this.options.scaling(isNaN(b)?this._zoom:b);return this.options.transformation.transform(c,d)},unproject:function(a,b,c){b=this.options.scaling(isNaN(b)?this._zoom:b);return this.options.projection.unproject(this.options.transformation.untransform(a,b),c)},
|
||||
getPanes:function(){return this._panes},_initLayout:function(){this._container.className+=" leaflet-container";this._container.style.position=L.DomUtil.getStyle(this._container,"position")=="absolute"?"absolute":"relative";this._panes={};this._panes.mapPane=this._mapPane=this._createPane("leaflet-map-pane");this._panes.tilePane=this._createPane("leaflet-tile-pane");this._panes.overlayPane=this._createPane("leaflet-overlay-pane")},_createPane:function(a){var b=document.createElement("div");b.className=
|
||||
a;(this._mapPane||this._container).appendChild(b);return b},_resetView:function(a,b){var c=this._zoom!=b;this.fire("movestart");this._zoom=b;this._initialTopLeftPoint=this._getNewTopLeftPoint(a);L.DomUtil.setPosition(this._mapPane,new L.Point(0,0));this.fire("viewreset");this.fire("viewupdate");this.fire("move");c&&this.fire("zoomend");this.fire("moveend")},_initLayers:function(a){this._layers=[];for(var b=0,c=a.length;b<c;b++)this._addLayer(a[b])},_rawPanBy:function(a){var b=L.DomUtil.getPosition(this._mapPane);
|
||||
L.DomUtil.setPosition(this._mapPane,b.subtract(a))},_panByIfClose:function(a){if(this._offsetIsWithinView(a)){this.panBy(a);return true}return false},_zoomToIfCenterInView:function(a,b,c){if(this._offsetIsWithinView(c,0.5)){this._resetView(a,b);return true}return false},_initEvents:function(){L.DomEvent.addListener(this._container,"click",this._onMouseClick,this);L.DomEvent.addListener(this._container,"dblclick",this._fireMouseEvent,this)},_onMouseClick:function(a){this.dragging&&this.dragging._moved||
|
||||
this._fireMouseEvent(a)},_fireMouseEvent:function(a){this.hasEventListeners(a.type)&&this.fire(a.type,{position:this.mouseEventToLatLng(a),layerPoint:this.mouseEventToLayerPoint(a)})},_initInteraction:function(){var a={dragging:L.Handler.MapDrag,touchZoom:L.Handler.TouchZoom,doubleClickZoom:L.Handler.DoubleClickZoom,scrollWheelZoom:L.Handler.ScrollWheelZoom};for(var b in a)if(a.hasOwnProperty(b)&&a[b])this[b]=new a[b](this,this.options[b])},_getTopLeftPoint:function(){return this._initialTopLeftPoint.subtract(L.DomUtil.getPosition(this._mapPane))},
|
||||
_getNewTopLeftPoint:function(a){var b=this.getSize().divideBy(2,true);return this.project(a).subtract(b).round()},_offsetIsWithinView:function(a,b){var c=b||1,d=this.getSize();return Math.abs(a.x)<=d.width*c&&Math.abs(a.y)<=d.height*c},_limitZoom:function(a){var b=this.getMinZoom(),c=this.getMaxZoom();return Math.max(b,Math.min(c,a))}});L.Map.include({locate:function(){navigator.geolocation&&navigator.geolocation.getCurrentPosition(L.Util.bind(this._handleGeolocationResponse,this),L.Util.bind(this._handleGeolocationError,this));return this},_handleGeolocationError:function(a){this.fire("locationerror",{message:a.message})},_handleGeolocationResponse:function(a){var b=180*a.coords.accuracy/4E7,c=b*2,d=a.coords.latitude;a=a.coords.longitude;var e=new L.LatLng(d-b,a-c);b=new L.LatLng(d+b,a+c);b=new L.LatLngBounds(e,b);this.fitBounds(b);
|
||||
1)},zoomOut:function(){return this.setZoom(this,zoom-1)},fitBounds:function(a){var b=this.getBoundsZoom(a);return this.setView(a.getCenter(),b,true)},panTo:function(a){return this.setView(a,this._zoom)},panBy:function(a){this.fire("movestart");this._rawPanBy(a);this.fire("viewupdate");this.fire("move");this.fire("moveend")},addLayer:function(a){this._layers.push(a);a.onAdd(this);this._layersMaxZoom=Math.max(this._layersMaxZoom||0,a.options.maxZoom||Infinity);this._layersMinZoom=Math.min(this._layersMinZoom||
|
||||
Infinity,a.options.minZoom||0);this.fire("layeradd",{layer:a});return this},removeLayer:function(a){a.onRemove(this);for(var b=0,c=this._layers.length;b<c;b++)if(this._layers[b]===a){this._layers.splice(b,1);this.fire("layerremove",{layer:a});break}return this},invalidateSize:function(){this._sizeChanged=true;this.fire("viewupdate");return this},getCenter:function(a){var b=this.getSize().divideBy(2);return this.unproject(this._getTopLeftPoint().add(b),this._zoom,a)},getZoom:function(){return this._zoom},
|
||||
getMinZoom:function(){return isNaN(this.options.minZoom)?this._layersMinZoom||0:this.options.minZoom},getMaxZoom:function(){return isNaN(this.options.maxZoom)?this._layersMaxZoom||Infinity:this.options.maxZoom},getBoundsZoom:function(a){var b=this.getSize(),c=this.getMinZoom(),d=this.getMaxZoom(),e=a.getNorthEast();a=a.getSouthWest();var f,g;do{f=this.project(e,c);g=this.project(a,c);f=new L.Point(f.x-g.x,g.y-f.y);c++}while(f.x<=b.x&&f.y<=b.y&&c<=d);return c-1},getSize:function(){if(!this._size||
|
||||
this._sizeChanged){this._size=new L.Point(this._container.clientWidth,this._container.clientHeight);this._sizeChanged=false}return this._size},getPixelBounds:function(){var a=this._getTopLeftPoint(),b=this.getSize();return new L.Bounds(a,a.add(b))},getPixelOrigin:function(){return this._initialTopLeftPoint},mouseEventToContainerPoint:function(a){return L.DomEvent.getMousePosition(a,this._container)},mouseEventToLayerPoint:function(a){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(a))},
|
||||
mouseEventToLatLng:function(a){return this.layerPointToLatLng(this.mouseEventToLayerPoint(a))},containerPointToLayerPoint:function(a){return a.subtract(L.DomUtil.getPosition(this._mapPane))},layerPointToLatLng:function(a){return this.unproject(a.add(this._initialTopLeftPoint))},latLngToLayerPoint:function(a){return this.project(a).subtract(this._initialTopLeftPoint)},project:function(a,b){var c=this.options.projection.project(a),d=this.options.scaling(isNaN(b)?this._zoom:b);return this.options.transformation.transform(c,
|
||||
d)},unproject:function(a,b,c){b=this.options.scaling(isNaN(b)?this._zoom:b);return this.options.projection.unproject(this.options.transformation.untransform(a,b),c)},getPanes:function(){return this._panes},_initLayout:function(){this._container.className+=" leaflet-container";this._container.style.position=L.DomUtil.getStyle(this._container,"position")=="absolute"?"absolute":"relative";this._panes={};this._panes.mapPane=this._mapPane=this._createPane("leaflet-map-pane");this._panes.tilePane=this._createPane("leaflet-tile-pane");
|
||||
this._panes.overlayPane=this._createPane("leaflet-overlay-pane")},_createPane:function(a){var b=document.createElement("div");b.className=a;(this._mapPane||this._container).appendChild(b);return b},_resetView:function(a,b){var c=this._zoom!=b;this.fire("movestart");this._zoom=b;this._initialTopLeftPoint=this._getNewTopLeftPoint(a);L.DomUtil.setPosition(this._mapPane,new L.Point(0,0));this.fire("viewreset");this.fire("viewupdate");this.fire("move");c&&this.fire("zoomend");this.fire("moveend")},_initLayers:function(a){this._layers=
|
||||
[];for(var b=0,c=a.length;b<c;b++)this._addLayer(a[b])},_rawPanBy:function(a){var b=L.DomUtil.getPosition(this._mapPane);L.DomUtil.setPosition(this._mapPane,b.subtract(a))},_panByIfClose:function(a){if(this._offsetIsWithinView(a)){this.panBy(a);return true}return false},_zoomToIfCenterInView:function(a,b,c){if(this._offsetIsWithinView(c,0.5)){this._resetView(a,b);return true}return false},_initEvents:function(){L.DomEvent.addListener(this._container,"click",this._onMouseClick,this);L.DomEvent.addListener(this._container,
|
||||
"dblclick",this._fireMouseEvent,this)},_onMouseClick:function(a){this.dragging&&this.dragging._moved||this._fireMouseEvent(a)},_fireMouseEvent:function(a){this.hasEventListeners(a.type)&&this.fire(a.type,{position:this.mouseEventToLatLng(a),layerPoint:this.mouseEventToLayerPoint(a)})},_initInteraction:function(){var a={dragging:L.Handler.MapDrag,touchZoom:L.Handler.TouchZoom,doubleClickZoom:L.Handler.DoubleClickZoom,scrollWheelZoom:L.Handler.ScrollWheelZoom};for(var b in a)if(a.hasOwnProperty(b)&&
|
||||
a[b])this[b]=new a[b](this,this.options[b])},_getTopLeftPoint:function(){return this._initialTopLeftPoint.subtract(L.DomUtil.getPosition(this._mapPane))},_getNewTopLeftPoint:function(a){var b=this.getSize().divideBy(2,true);return this.project(a).subtract(b).round()},_offsetIsWithinView:function(a,b){var c=b||1,d=this.getSize();return Math.abs(a.x)<=d.width*c&&Math.abs(a.y)<=d.height*c},_limitZoom:function(a){var b=this.getMinZoom(),c=this.getMaxZoom();return Math.max(b,Math.min(c,a))}});L.Map.include({locate:function(){navigator.geolocation&&navigator.geolocation.getCurrentPosition(L.Util.bind(this._handleGeolocationResponse,this),L.Util.bind(this._handleGeolocationError,this));return this},_handleGeolocationError:function(a){this.fire("locationerror",{message:a.message})},_handleGeolocationResponse:function(a){var b=180*a.coords.accuracy/4E7,c=b*2,d=a.coords.latitude;a=a.coords.longitude;var e=new L.LatLng(d-b,a-c);b=new L.LatLng(d+b,a+c);b=new L.LatLngBounds(e,b);this.fitBounds(b);
|
||||
this.fire("locationfound",{latlng:new L.LatLng(d,a),bounds:b})}});
|
||||
|
@ -29,39 +29,46 @@ L.TileLayer = L.Class.extend({
|
||||
onAdd: function(map) {
|
||||
this._map = map;
|
||||
|
||||
// create a container div for tiles
|
||||
this._container = document.createElement('div');
|
||||
this._container.className = 'leaflet-layer';
|
||||
this._map.getPanes().tilePane.appendChild(this._container);
|
||||
map.getPanes().tilePane.appendChild(this._container);
|
||||
|
||||
// create an image to clone for tiles
|
||||
this._tileImg = document.createElement('img');
|
||||
|
||||
L.Util.extend(this._tileImg, {
|
||||
className: 'leaflet-tile',
|
||||
galleryimg: 'no'
|
||||
});
|
||||
this._tileImg.className = 'leaflet-tile';
|
||||
this._tileImg.galleryimg = 'no';
|
||||
|
||||
var tileSize = this.options.tileSize;
|
||||
this._tileImg.style.width = tileSize + 'px';
|
||||
this._tileImg.style.height = tileSize + 'px';
|
||||
|
||||
L.Util.extend(this._tileImg.style, {
|
||||
width: tileSize + 'px',
|
||||
height: tileSize + 'px',
|
||||
visibility: 'hidden'
|
||||
});
|
||||
|
||||
this._map.on('viewreset', this._reset, this);
|
||||
// set up events
|
||||
map.on('viewreset', this._reset, this);
|
||||
|
||||
if (this.options.updateWhenIdle) {
|
||||
this._map.on('moveend', this._update, this);
|
||||
map.on('moveend', this._update, this);
|
||||
} else {
|
||||
this._update = L.Util.limitExecByInterval(this._update, 100, this);
|
||||
this._map.on('move', this._update, this);
|
||||
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 100, this);
|
||||
map.on('move', this._limitedUpdate, this);
|
||||
}
|
||||
|
||||
this._reset();
|
||||
this._update();
|
||||
},
|
||||
|
||||
//TODO onRemove
|
||||
onRemove: function(map) {
|
||||
this._map.getPanes().tilePane.removeChild(this._container);
|
||||
|
||||
this._map.off('viewreset', this._reset);
|
||||
|
||||
if (this.options.updateWhenIdle) {
|
||||
this._map.off('moveend', this._update);
|
||||
} else {
|
||||
this._map.off('move', this._limitedUpdate);
|
||||
}
|
||||
},
|
||||
|
||||
_reset: function() {
|
||||
this._tiles = {};
|
||||
@ -151,7 +158,6 @@ L.TileLayer = L.Class.extend({
|
||||
},
|
||||
|
||||
_tileOnLoad: function() {
|
||||
this.style.visibility = 'visible';
|
||||
this.className += ' leaflet-tile-loaded';
|
||||
this._leaflet_layer.fire('tileload', {tile: this});
|
||||
}
|
||||
|
@ -110,15 +110,29 @@ L.Map = L.Class.extend({
|
||||
|
||||
layer.onAdd(this);
|
||||
|
||||
this._layersMaxZoom = Math.max(this._layersMaxZoom || 0, layer.options.maxZoom);
|
||||
this._layersMinZoom = Math.min(this._layersMinZoom || Infinity, layer.options.minZoom);
|
||||
this._layersMaxZoom = Math.max(this._layersMaxZoom || 0, layer.options.maxZoom || Infinity);
|
||||
this._layersMinZoom = Math.min(this._layersMinZoom || Infinity, layer.options.minZoom || 0);
|
||||
//TODO getMaxZoom, getMinZoom
|
||||
|
||||
this.fire('layeradded', {layer: layer});
|
||||
this.fire('layeradd', {layer: layer});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
removeLayer: function(layer) {
|
||||
layer.onRemove(this);
|
||||
|
||||
for (var i = 0, len = this._layers.length; i < len; i++) {
|
||||
if (this._layers[i] === layer) {
|
||||
this._layers.splice(i, 1);
|
||||
this.fire('layerremove', {layer: layer});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
invalidateSize: function() {
|
||||
this._sizeChanged = true;
|
||||
this.fire('viewupdate');
|
||||
|
Loading…
Reference in New Issue
Block a user