@nextgis/leaflet-map-adapter 1.19.2 → 1.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/leaflet-map-adapter.esm-browser.js +19 -7
- package/lib/leaflet-map-adapter.esm-browser.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-browser.prod.js +1 -1
- package/lib/leaflet-map-adapter.esm-browser.prod.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.js +19 -7
- package/lib/leaflet-map-adapter.esm-bundler.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.prod.js +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.prod.js.map +1 -1
- package/lib/leaflet-map-adapter.global.js +15 -7
- package/lib/leaflet-map-adapter.global.js.map +1 -1
- package/lib/leaflet-map-adapter.global.prod.js +1 -1
- package/lib/leaflet-map-adapter.global.prod.js.map +1 -1
- package/package.json +2 -2
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
* A collection of Leaflet utilities for working with Web Mapping services.
|
|
9
9
|
* (c) 2014-2016, Houston Engineering, Inc.
|
|
10
10
|
* MIT License
|
|
11
|
-
*/class A extends f.exports.Layer{constructor(t,e){super(e),this.defaultWmsParams={service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},this.options={crs:null,uppercase:!1,attribution:"",opacity:1,isBack:!1,minZoom:0,pane:"tilePane",headers:null,viewPortBuffer:0,setViewDelay:100},this._url=t;const i={},n={};let o;for(o in e)o in this.options?n[o]=e[o]:i[o]=e[o];f.exports.Util.setOptions(this,n),this.wmsParams=f.exports.Util.extend({},this.defaultWmsParams,i)}setParams(t){f.exports.Util.extend(this.wmsParams,t),this.update()}getAttribution(){return this.options.attribution||""}onAdd(){return this.update(),this}onRemove(t){return this._currentOverlay&&(this._currentOverlay.cancelLoad(),t.removeLayer(this._currentOverlay),delete this._currentOverlay),this._currentUrl&&delete this._currentUrl,this}getEvents(){return{moveend:y(this.update,this.options.setViewDelay)}}update(){if(!this._map)return;this.updateWmsParams();const t=this.getImageUrl();if(this._currentUrl===t)return;this._currentUrl=t;const e=this.options.viewPortBuffer||0,i=this._map.getBounds().pad(e),n=new B(t,i,{opacity:0,pane:this.options.pane,headers:this.options.headers});n.addTo(this._map),this._currentOverlay&&this._currentOverlay.cancelLoad(),n.once("load",(()=>{this._map&&(n._url===this._currentUrl?(this._currentOverlay&&this._map.removeLayer(this._currentOverlay),this._currentOverlay=n,n.setOpacity(void 0!==this.options.opacity?this.options.opacity:1),!0===this.options.isBack&&n.bringToBack(),!1===this.options.isBack&&n.bringToFront(),void 0!==this.options.zIndex&&n.setZIndex(this.options.zIndex)):this._map.removeLayer(n))}),this);const{minZoom:o,maxZoom:s}=this.options;(o&&this._map.getZoom()<o||s&&this._map.getZoom()>s)&&this._map.removeLayer(n)}setOpacity(t){this.options.opacity=t,this._currentOverlay&&this._currentOverlay.setOpacity(t)}bringToBack(){this.options.isBack=!0,this._currentOverlay&&this._currentOverlay.bringToBack()}bringToFront(){this.options.isBack=!1,this._currentOverlay&&this._currentOverlay.bringToFront()}setZIndex(t){this.options.zIndex=t,this._currentOverlay&&this._currentOverlay.setZIndex(t)}updateWmsParams(t){t||(t=this._map);const e=this.options.viewPortBuffer||0,i=t.getBounds().pad(e),n=t.getSize();if(0!==this.options.viewPortBuffer){const t=e+1;n.x=Math.ceil(n.x*t),n.y=Math.ceil(n.y*t)}const o=parseFloat(this.wmsParams.version),s=this.options.crs||t.options.crs,r=o>=1.3?"crs":"srs";if(s){const t=s.project(i.getNorthWest()),e=s.project(i.getSouthEast()),a={width:n.x,height:n.y};a[r]=s.code,a.bbox=(o>=1.3&&s===f.exports.CRS.EPSG4326?[e.y,t.x,t.y,e.x]:[t.x,e.y,e.x,t.y]).join(","),f.exports.Util.extend(this.wmsParams,a)}}getImageUrl(){const t=f.exports.Util.getParamString(this.wmsParams,this._url,this.options.uppercase||!1);return this._url+t}}function I(t){return class extends t{constructor(...t){super(...t),this.options.setViewDelay&&(this._update=y(((...t)=>{f.exports.GridLayer.prototype._update.call(this,...t)}),this.options.setViewDelay))}createTile(t,e){const i=this.getTileUrl(t),n=document.createElement("img");return n.abort=O(i,(t=>{n.src=t,e(null,n)}),this.options.headers),(this.options.crossOrigin||""===this.options.crossOrigin)&&(n.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),n.alt="",n.setAttribute("role","presentation"),n}_abortLoading(){const t=this._tiles,e=this._tileZoom;for(const i in t)if(t[i].coords.z!==e){const e=t[i].el;e.onload=f.exports.Util.falseFn,e.onerror=f.exports.Util.falseFn,e.complete||(e.abort&&e.abort(),e.src=f.exports.Util.emptyImageUrl,f.exports.DomUtil.remove(e),delete t[i])}}}}const R=I(class extends f.exports.TileLayer{constructor(t,e){super(t,e),Object.assign(this.options,e)}});class N extends E{addLayer(t){if(this.options=Object.assign(this.options,t),t){const{url:e,...i}=t;if(e){const t={pane:this.pane,attribution:i.attribution,minZoom:i.minZoom,maxZoom:i.maxZoom,...i.nativeOptions};let n;return i.subdomains&&(t.subdomains=i.subdomains),n=i.headers?new R(e,{...t,headers:i.headers,setViewDelay:i.setViewDelay}):new f.exports.TileLayer(e,t),n}}}}const D=I(class extends f.exports.TileLayer.WMS{constructor(t,e){super(t,e)}});function j(t){return[[t[3],t[0]],[t[1],t[2]]]}class W{constructor(){this.options={target:"map"},this.layerAdapters=W.layerAdapters,this.controlAdapters=W.controlAdapters,this.emitter=new e.exports.EventEmitter,this._unselectCb=[],this._universalEvents=["move","zoom","zoomend","zoomstart","moveend","movestart"],this._positionEvents=["mousemove","mouseout","mouseover"]}create(t){if(this.options={...t},this.options.target){const{zoom:t,center:e,maxZoom:i,minZoom:n,maxBounds:o,mapAdapterOptions:s}=this.options;this.map=this.options.map||new f.exports.Map(this.options.target,{attributionControl:!1,zoomControl:!1,maxBounds:o?j(o):void 0,maxZoom:i,minZoom:n,center:e&&[e[1],e[0]],zoom:t,...s});const r=this.map.createPane("order-0");this.map._addUnselectCb=t=>{this._addUnselectCb(t)},r.style.zIndex=String(0),this.emitter.emit("create",this),this._addMapListeners()}}destroy(){this.map&&this.map.remove(),this._stopWatchSizeChangeToUpdateMinZoom()}getContainer(){return this.map&&this.map.getContainer()}getControlContainer(){const t=this.map&&this.map._controlContainer;if(t)return t;throw new Error("Leaflet Map is not initialized yet")}setCursor(t){this.map&&(this.map.getContainer().style.cursor=t)}setView(t,e){const i=this.map;if(i)if(Array.isArray(t)){const i=t,[n,o]=i;this.map&&("number"==typeof e?this.map.setView([o,n],e,{animate:!1}):this.setCenter([n,o]))}else{const{zoom:e,center:n,maxBounds:o,bounds:s,minZoom:r,maxZoom:a}=t;if(n&&void 0!==e?this.setView(n,e):(void 0!==e&&this.setZoom(e),n&&this.setCenter(n)),s&&this.fitBounds(s),void 0!==o)if(o){const t=j(o);i.setMaxBounds(t),i.setMinZoom(i.getBoundsZoom(t)),this._watchSizeChangeToUpdateMinZoom(t)}else i.setMaxBounds(null),this._stopWatchSizeChangeToUpdateMinZoom();void 0!==a&&i.setMaxZoom(a),void 0!==r&&(this._stopWatchSizeChangeToUpdateMinZoom(),i.setMinZoom(r))}}setCenter(t){const[e,i]=t;this.map&&this.map.panTo([i,e])}getCenter(){const t=this.map;if(t){const e=t.getBounds().getCenter();return[e.lng,e.lat]}}setZoom(t){this.map&&this.map.setZoom(t)}getZoom(){var t;return null!==(t=this.map&&this.map.getZoom())&&void 0!==t?t:void 0}getBounds(){if(!this.map)return;const t=this.map.getBounds(),e=t.getSouthWest(),i=t.getNorthEast();return[e.lng,e.lat,i.lng,i.lat]}fitBounds(t,e={}){if(this.map){const{maxZoom:i,offset:n,padding:o}=e,s={};i&&(s.maxZoom=i),o&&(s.padding=[o,o]),n&&(s.padding=n),this.map.fitBounds(j(t),s)}}getLayerAdapter(t){return W.layerAdapters[t]}createControl(t,e){return v(t,e,this)}createButtonControl(t){return function(t,e){const i=document.createElement("a"),n=t.title||"";i.href="#",i.title=n,i.setAttribute("role","button"),i.setAttribute("aria-label",n),t.addClass&&i.classList.add(t.addClass),f.exports.DomEvent.disableClickPropagation(i),f.exports.DomEvent.on(i,"click",f.exports.DomEvent.stop),t.html instanceof HTMLElement?i.appendChild(t.html):"string"==typeof t.html&&(i.innerHTML=t.html);const o=e=>{e.stopPropagation(),t.onClick()};return v({onAdd:()=>(void 0!==t.onClick&&i.addEventListener("click",o),i),onRemove(){const e=i.parentNode;e&&e.removeChild(i),void 0!==t.onClick&&i.removeEventListener("click",o)}},{bar:!0},e)}(t,this)}addControl(t,e){if(t.options.position=e.replace("-",""),this.map)return this.map.addControl(t),t}removeControl(t){this.map&&this.map.removeControl(t)}removeLayer(t){t&&t.remove&&t.remove()}showLayer(t){this.map&&t.addTo(this.map)}hideLayer(t){t.remove()}setLayerOpacity(t,e){"setOpacity"in t&&t.setOpacity(e)}setLayerOrder(t,e,i){}onMapClick(t){const e=S(t);this.emitter.emit("preclick",e),this.emitter.emit("click",e)}locate(t,e){const i=this.map;if(i&&(i.locate(t),e)){const{locationfound:t,locationerror:n}=e,o=e=>{t({lngLat:[e.latlng.lng,e.latlng.lat]})};void 0!==t&&i.on("locationfound",o,this),n&&i.on("locationerror",n,this);return{stop:()=>{void 0!==t&&i.off("locationfound",o),n&&i.off("locationerror",n)}}}return{stop:()=>{}}}_addUnselectCb(t){for(const e of this._unselectCb)e();this._unselectCb.length=0,this._unselectCb.push(t)}_watchSizeChangeToUpdateMinZoom(t){this._stopWatchSizeChangeToUpdateMinZoom();const e=this.getContainer(),i=this.map;e&&i&&window.ResizeObserver&&(this._resizeObserver=new ResizeObserver((()=>{i.setMinZoom(i.getBoundsZoom(t))})),this._resizeObserver.observe(e))}_stopWatchSizeChangeToUpdateMinZoom(){const t=this.map;t&&t.setMinZoom(0),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0)}_addMapListeners(){const t=this.map;if(t){t.on("click",(t=>{this.onMapClick(t)}));for(const e of this._universalEvents)t.on(e,(()=>this.emitter.emit(e,this)),t);for(const e of this._positionEvents)t.on(e,(t=>this.emitter.emit(e,S(t))),t)}}}W.layerAdapters={GEOJSON:class extends E{constructor(t,e){super(t,e),this.selected=!1,this._layers=[],this._selectedLayers=[],this._filteredLayers=[],this._openedPopup=[],this.$updateTooltip=y((()=>{this.updateTooltip()}),300),this.$unselect=()=>{this.unselect()},this._events=new k(this),this._paint=new Z(this)}addLayer(t){return Object.assign(this.options,t),this.paint=t.paint,this.layer=new f.exports.FeatureGroup([],{...t.nativeOptions,pane:this.pane}),this.selectedPaint=t.selectedPaint,t.paint=this.paint,t.data&&this.addData(t.data),this._addMapListener(),this.layer}beforeRemove(){this._removeMapListener()}select(t){if(this.unselect(),t){const e=this._layers.filter(t);for(const t of e)this._selectLayer(t,"api")}else this.selected||(this.selected=!0,this.selectedPaint&&this._paint.setPaintEachLayer(this.selectedPaint))}unselect(t){if(t){this._layers.filter(t).forEach((t=>{this._unSelectLayer(t)}))}else if(this.selected){for(const t of this._openedPopup)this._removePopup(t[0]);this.paint&&this._paint.setPaintEachLayer(this.paint),this._selectedLayers.length=0,this.selected=!1}}getSelected(){return this._selectedLayers.map((t=>({target:this,feature:t.feature,layer:t,...z(t.feature)})))}getFiltered(){return this._filteredLayers}filter(t){this._filterFun=t;const e=this.layer,i=e&&e._map;if(e&&i){e.remove();const n=[];this._layers.forEach((({feature:i,layer:o})=>{if(o){!t||t({target:this,feature:i,layer:o,...z(i)})?(e.addLayer(o),n.push({target:this,feature:i,layer:o,...z(i)})):e.removeLayer(o)}})),this._filteredLayers=n,e.addTo(i)}return this._filteredLayers}cleanFilter(){this.filter()}getLayers(){return this._layers.map((({layer:t,feature:e})=>({feature:e,layer:t,visible:t&&!!t._map,target:this,...z(e)})))}clearLayer(t){this.unselect();const e=this.layer;if(e)if(t)for(let i=this._layers.length;i--;){const n=this._layers[i];if(n){const{feature:o,layer:s}=n;if(o&&s){t(o)&&(e.removeLayer(s),this._layers.splice(i,1))}}}else e.clearLayers(),this._layers=[]}setData(t){this.clearLayer(),this.addData(t)}addData(t){const e=this.options;let i;if(e){if(t){let n;if(e.type)n=e.type;else{const e=function(t){let e;e="FeatureCollection"===t.type?w(t.features.map((t=>t.geometry.type))):"GeometryCollection"===t.type?w(t.geometries.map((t=>t.type))):"Feature"===t.type?t.geometry.type:t.type;return e}(t);n=P[e]}if(this.type&&this.type!==n)return void console.warn("no other data type than layer can be added");this.type=n,t=function(t,e){if("FeatureCollection"===t.type)t.features=t.features.filter((t=>M(t.geometry.type,e)));else if("Feature"===t.type){if(!M(t.geometry.type,e))return!1}else"GeometryCollection"===t.type&&(t.geometries=t.geometries.filter((t=>M(t.type,e))));return t}(t,n),t&&(i=this._getGeoJsonOptions(e,n))}new f.exports.GeoJSON(t||void 0,i)}}openPopup(t,e){if(t){this._layers.filter(t).forEach((t=>{this._openPopup(t,e,"api")}))}}closePopup(t){(t?this._openedPopup.filter((e=>t(e[2]))):this._openedPopup).forEach((t=>{this._removePopup(t[0])}))}updateTooltip(t){t?this._updateTooltip(t):this.getLayers().forEach((t=>this._updateTooltip({feature:t.feature,layer:t.layer})))}getExtent(){return this.getBounds()}getBounds(){if(this.layer){const t=this.layer.getBounds();if(t.isValid())return x(t)}}setOpacity(t){this.options.opacity=t,this.setPaint(this.paint),this.setSelectedPaint(this.selectedPaint)}setPaint(t){if(t){this.paint=t;for(const e of this._layers)this._paint.setPaint(e,t)}}setSelectedPaint(t){if(t){this.selectedPaint=t;for(const e of this._selectedLayers)this._paint.setPaint(e,t)}}updatePaint(t){this.paint={...this.paint,...t};for(const e of this._layers)this._paint.setPaint(e,this.paint)}updateSelectedPaint(t){this.selectedPaint={...this.selectedPaint,...t};for(const e of this._selectedLayers)this._paint.setPaint(e,this.selectedPaint)}_getSelected(t){return this._selectedLayers.find((e=>e.layer===t))}_updateTooltip(t){const{feature:e,layer:i}=t;if(e&&i&&e.properties&&this.options.labelField){i.unbindTooltip();const t=e.properties[this.options.labelField];if(void 0!==t){const e=!this.options.labelOnHover;i.bindTooltip(String(t),{permanent:e,sticky:!1})}}}async _openPopup(t,e={},i,n){var o,s;const{feature:r,layer:a}=t,{minWidth:h,autoPan:l,maxWidth:u,closeButton:c}={minWidth:300,...e},d=null!=c?c:!this.options.selectOnHover;let p;const _=[],m=t=>{_.push(t)},f=()=>{p&&this._removePopup(p)};let v;if(v=e.createPopupContent?await e.createPopupContent({layer:a,feature:r,target:this,type:i,close:f,onClose:m,...z(r)}):e.popupContent,v&&a){const e={minWidth:h,autoPan:l,closeButton:d,closeOnClick:!1,autoClose:!1};g(u)&&(e.maxWidth=u),p=a.bindPopup(v,e);if(null===(s=null===(o=this.options.popupOptions)||void 0===o?void 0:o.unselectOnClose)||void 0===s||s){const t=a.getPopup();t&&t.once("remove",(()=>{f()}),this)}this._openedPopup.push([p,_,t]),p.openPopup(n)}}_removePopup(t){var e,i;if(this.map){t.closePopup().unbindPopup();const n=this._openedPopup.findIndex((e=>e[0]===t));if(-1!==n){const t=null===(i=null===(e=this.options.popupOptions)||void 0===e?void 0:e.unselectOnClose)||void 0===i||i,[,o,s]=this._openedPopup[n];for(const e of o)e(s);o.length=0,t&&this._unSelectLayer(s),this._openedPopup.splice(n,1)}}}_getGeoJsonOptions(t,e){const i=t.paint;let n={};return"function"==typeof i?"point"===e?n.pointToLayer=(t,e)=>{const n=i(t);return this._paint.createPaintToLayer(n)(t,e)}:n={style:t=>this._paint.preparePaint(t?{...b,...i(t)}:{...b,type:"path"})}:n=this._paint.createPaintOptions(i),n.onEachFeature=(t,e)=>{this._onEachFeature(t,e)},n}_onEachFeature(t,e){const i=this.layer;if(i){const n={target:this,feature:t,layer:e,...z(t)};e.options.pane=this.pane,this._layers.push(n);let o=!0;if(this._filterFun&&(o=this._filterFun(n)),o){const{popup:o,popupOptions:s,selectable:r,interactive:a,selectOnHover:h}=this.options;e.options.interactive=!g(a)||a,i.addLayer(e),r&&(h?(e.on("mouseover",(()=>{this._selectLayer(n,"hover")})),e.on("mouseout",(()=>{this._unSelectLayer(n)}))):e.on("click",(t=>this._selectOnLayerClick(t)),this)),this._events.handleMouseEvents(e),setTimeout((()=>{o&&this._openPopup({target:this,layer:e,feature:t,...z(t)},s,"api"),this._updateTooltip({layer:e,feature:t})}))}}}_selectOnLayerClick(t){f.exports.DomEvent.stopPropagation(t);const e=t.target,i=e.feature,n={target:this,layer:e,feature:i,...z(i)},o=this._getSelected(e);o?this.options&&this.options.unselectOnSecondClick&&this._unSelectLayer(o):this._selectLayer(n,"click",t.latlng)}_selectLayer(t,e,i){const{multiselect:n}=this.options;n||(this.map._addUnselectCb((()=>{this._unSelectLayer(t)})),this._selectedLayers.forEach((t=>this._unSelectLayer(t)))),this._selectedLayers.push(t),this.selected=!0;const{selectedPaint:o,popupOnSelect:s,popupOptions:r}=this.options;if(o&&t.layer&&this._paint.setPaint(t,o),s&&this._openPopup(t,r,e,i),this.options.onSelect){const i=t.feature?[t.feature]:[];this.options.onSelect({type:e,layer:this,features:i,...z(i)})}}_unSelectLayer(t){const e=this._selectedLayers.indexOf(t);-1!==e&&(this._selectedLayers.splice(e,1),this.options&&(this.options.paint&&this._paint.setPaint(t,this.options.paint),this.options.popupOnSelect&&t.layer&&this._removePopup(t.layer))),this.selected=this._selectedLayers.length>0}_addMapClickListener(){const t=this.map;if(t){const{unselectOnClick:e}=this.options;(null==e||e)&&t.on("click",this.$unselect)}}_removeMapClickListener(){this.map.off("zoomend",this.$updateTooltip),this.map.off("moveend",this.$updateTooltip),this.map.off("click",this.$unselect)}_addMapListener(){const t=this.map;if(t){const{labelField:e,labelOnHover:i}=this.options;this._addMapClickListener(),e&&!i&&(t.on("zoomend",this.$updateTooltip),t.on("moveend",this.$updateTooltip))}}_removeMapListener(){this._removeMapClickListener(),this.map.off("zoomend",this.$updateTooltip),this.map.off("moveend",this.$updateTooltip)}},IMAGE:class extends E{addLayer(t){const e=t&&t.url;if(e){const i=(t={transparent:!0,...t}).updateWmsParams;if(this.layer=new A(e,{pane:this.pane,headers:t.headers,setViewDelay:t.setViewDelay,...t,...t.params,...t.nativeOptions}),i){const t=this.layer.updateWmsParams;this.layer.updateWmsParams=function(e){t.call(this,e),this.wmsParams=i(this.wmsParams)}}return this.layer}}},TILE:N,WMS:class extends E{addLayer(t){Object.assign(this.options,t);const{url:e,...i}=t;if(e){const n={pane:this.pane,attribution:i.attribution,minZoom:i.minZoom,maxZoom:i.maxZoom,layers:t.layers,format:t.format,...t.nativeOptions};let o;return o=i.headers?new D(e,{...n,headers:i.headers}):new f.exports.TileLayer.WMS(e,n),o}}},OSM:class extends N{addLayer(t){return super.addLayer({name:"OpenStreetMap",attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',...t,url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"})}}},W.controlAdapters={ZOOM:f.exports.Control.Zoom,ATTRIBUTION:class extends f.exports.Control.Attribution{constructor(t){super(t);const e=t&&t.customAttribution;if(e){let t=[];Array.isArray(e)?t=e:e&&(t=[e]),t.forEach((t=>this.addAttribution(t)))}}}},W.Map=f.exports.Map;var F=W;export{F as default};
|
|
11
|
+
*/class A extends f.exports.Layer{constructor(t,e){super(e),this.defaultWmsParams={service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},this.options={crs:null,uppercase:!1,attribution:"",opacity:1,isBack:!1,minZoom:0,pane:"tilePane",headers:null,viewPortBuffer:0,setViewDelay:100},this._url=t;const i={},n={};let o;for(o in e)o in this.options?n[o]=e[o]:i[o]=e[o];f.exports.Util.setOptions(this,n),this.wmsParams=f.exports.Util.extend({},this.defaultWmsParams,i)}setParams(t){f.exports.Util.extend(this.wmsParams,t),this.update()}getAttribution(){return this.options.attribution||""}onAdd(){return this.update(),this}onRemove(t){return this._currentOverlay&&(this._currentOverlay.cancelLoad(),t.removeLayer(this._currentOverlay),delete this._currentOverlay),this._currentUrl&&delete this._currentUrl,this}getEvents(){return{moveend:y(this.update,this.options.setViewDelay)}}update(){if(!this._map)return;this.updateWmsParams();const t=this.getImageUrl();if(this._currentUrl===t)return;this._currentUrl=t;const e=this.options.viewPortBuffer||0,i=this._map.getBounds().pad(e),n=new B(t,i,{opacity:0,pane:this.options.pane,headers:this.options.headers});n.addTo(this._map),this._currentOverlay&&this._currentOverlay.cancelLoad(),n.once("load",(()=>{this._map&&(n._url===this._currentUrl?(this._currentOverlay&&this._map.removeLayer(this._currentOverlay),this._currentOverlay=n,n.setOpacity(void 0!==this.options.opacity?this.options.opacity:1),!0===this.options.isBack&&n.bringToBack(),!1===this.options.isBack&&n.bringToFront(),void 0!==this.options.zIndex&&n.setZIndex(this.options.zIndex)):this._map.removeLayer(n))}),this);const{minZoom:o,maxZoom:s}=this.options;(o&&this._map.getZoom()<o||s&&this._map.getZoom()>s)&&this._map.removeLayer(n)}setOpacity(t){this.options.opacity=t,this._currentOverlay&&this._currentOverlay.setOpacity(t)}bringToBack(){this.options.isBack=!0,this._currentOverlay&&this._currentOverlay.bringToBack()}bringToFront(){this.options.isBack=!1,this._currentOverlay&&this._currentOverlay.bringToFront()}setZIndex(t){this.options.zIndex=t,this._currentOverlay&&this._currentOverlay.setZIndex(t)}updateWmsParams(t){t||(t=this._map);const e=this.options.viewPortBuffer||0,i=t.getBounds().pad(e),n=t.getSize();if(0!==this.options.viewPortBuffer){const t=e+1;n.x=Math.ceil(n.x*t),n.y=Math.ceil(n.y*t)}const o=parseFloat(this.wmsParams.version),s=this.options.crs||t.options.crs,r=o>=1.3?"crs":"srs";if(s){const t=s.project(i.getNorthWest()),e=s.project(i.getSouthEast()),a={width:n.x,height:n.y};a[r]=s.code,a.bbox=(o>=1.3&&s===f.exports.CRS.EPSG4326?[e.y,t.x,t.y,e.x]:[t.x,e.y,e.x,t.y]).join(","),f.exports.Util.extend(this.wmsParams,a)}}getImageUrl(){const t=f.exports.Util.getParamString(this.wmsParams,this._url,this.options.uppercase||!1);return this._url+t}}function I(t){return class extends t{constructor(...t){super(...t),this.options.setViewDelay&&(this._update=y(((...t)=>{f.exports.GridLayer.prototype._update.call(this,...t)}),this.options.setViewDelay))}createTile(t,e){const i=this.getTileUrl(t),n=document.createElement("img");return n.abort=O(i,(t=>{n.src=t,e(null,n)}),this.options.headers),(this.options.crossOrigin||""===this.options.crossOrigin)&&(n.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),n.alt="",n.setAttribute("role","presentation"),n}_abortLoading(){const t=this._tiles,e=this._tileZoom;for(const i in t)if(t[i].coords.z!==e){const e=t[i].el;e.onload=f.exports.Util.falseFn,e.onerror=f.exports.Util.falseFn,e.complete||(e.abort&&e.abort(),e.src=f.exports.Util.emptyImageUrl,f.exports.DomUtil.remove(e),delete t[i])}}}}const R=I(class extends f.exports.TileLayer{constructor(t,e){super(t,e),Object.assign(this.options,e)}});class N extends E{addLayer(t){if(this.options=Object.assign(this.options,t),t){const{url:e,...i}=t;if(e){const t={pane:this.pane,attribution:i.attribution,minZoom:i.minZoom,maxZoom:i.maxZoom,...i.nativeOptions};let n;return i.subdomains&&(t.subdomains=i.subdomains),n=i.headers?new R(e,{...t,headers:i.headers,setViewDelay:i.setViewDelay}):new f.exports.TileLayer(e,t),n}}}}const D=I(class extends f.exports.TileLayer.WMS{constructor(t,e){super(t,e)}});function j(t){return[[t[3],t[0]],[t[1],t[2]]]}class W{constructor(){this.options={target:"map"},this.layerAdapters=W.layerAdapters,this.controlAdapters=W.controlAdapters,this.emitter=new e.exports.EventEmitter,this._unselectCb=[],this._universalEvents=["move","zoom","zoomend","zoomstart","moveend","movestart"],this._positionEvents=["mousemove","mouseout","mouseover"]}create(t){if(this.options={...t},this.options.target){const{zoom:t,center:e,maxZoom:i,minZoom:n,maxBounds:o,mapAdapterOptions:s}=this.options;this.map=this.options.map||new f.exports.Map(this.options.target,{attributionControl:!1,zoomControl:!1,maxBounds:o?j(o):void 0,maxZoom:i,minZoom:n,center:e&&[e[1],e[0]],zoom:t,...s});const r=this.map.createPane("order-0");this.map._addUnselectCb=t=>{this._addUnselectCb(t)},r.style.zIndex=String(0),this.emitter.emit("create",this),this._addMapListeners()}}destroy(){this.map&&this.map.remove(),this._stopWatchSizeChangeToUpdateMinZoom()}getContainer(){return this.map&&this.map.getContainer()}getControlContainer(){const t=this.map&&this.map._controlContainer;if(t)return t;throw new Error("Leaflet Map is not initialized yet")}setCursor(t){this.map&&(this.map.getContainer().style.cursor=t)}setView(t,e){const i=this.map;if(i)if(Array.isArray(t)){const i=t,[n,o]=i;this.map&&("number"==typeof e?this.map.setView([o,n],e,{animate:!1}):this.setCenter([n,o]))}else{const{zoom:e,center:n,maxBounds:o,bounds:s,minZoom:r,maxZoom:a}=t;if(n&&void 0!==e?this.setView(n,e):(void 0!==e&&this.setZoom(e),n&&this.setCenter(n)),s&&this.fitBounds(s),void 0!==o)if(o){const t=j(o);i.setMaxBounds(t),i.setMinZoom(i.getBoundsZoom(t)),this._watchSizeChangeToUpdateMinZoom(t)}else i.setMaxBounds(null),this._stopWatchSizeChangeToUpdateMinZoom();void 0!==a&&i.setMaxZoom(a),void 0!==r&&(this._stopWatchSizeChangeToUpdateMinZoom(),i.setMinZoom(r))}}setCenter(t){const[e,i]=t;this.map&&this.map.panTo([i,e])}getCenter(){const t=this.map;if(t){const e=t.getBounds().getCenter();return[e.lng,e.lat]}}setZoom(t){this.map&&this.map.setZoom(t)}getZoom(){var t;return null!==(t=this.map&&this.map.getZoom())&&void 0!==t?t:void 0}getBounds(){if(!this.map)return;const t=this.map.getBounds(),e=t.getSouthWest(),i=t.getNorthEast();return[e.lng,e.lat,i.lng,i.lat]}fitBounds(t,e={}){if(this.map){const{maxZoom:i,offset:n,padding:o}=e,s={};i&&(s.maxZoom=i),o&&(s.padding=[o,o]),n&&(s.padding=n),this.map.fitBounds(j(t),s)}}getLayerAdapter(t){return W.layerAdapters[t]}createControl(t,e){return v(t,e,this)}createButtonControl(t){return function(t,e){const i=document.createElement("a"),n=t.title||"";i.href="#",i.title=n,i.setAttribute("role","button"),i.setAttribute("aria-label",n),t.addClass&&i.classList.add(t.addClass),f.exports.DomEvent.disableClickPropagation(i),f.exports.DomEvent.on(i,"click",f.exports.DomEvent.stop),t.html instanceof HTMLElement?i.appendChild(t.html):"string"==typeof t.html&&(i.innerHTML=t.html);const o=e=>{e.stopPropagation(),t.onClick()};return v({onAdd:()=>(void 0!==t.onClick&&i.addEventListener("click",o),i),onRemove(){const e=i.parentNode;e&&e.removeChild(i),void 0!==t.onClick&&i.removeEventListener("click",o)}},{bar:!0},e)}(t,this)}addControl(t,e){if(t.options.position=e.replace("-",""),this.map)return this.map.addControl(t),t}removeControl(t){this.map&&this.map.removeControl(t)}removeLayer(t){t&&t.remove&&t.remove()}showLayer(t){this.map&&t.addTo(this.map)}hideLayer(t){t.remove()}setLayerOpacity(t,e){"setOpacity"in t&&t.setOpacity(e)}setLayerOrder(t,e,i){}onMapClick(t){const e=S(t);this.emitter.emit("preclick",e),this.emitter.emit("click",e)}locate(t,e){const i=this.map;if(i&&(i.locate(t),e)){const{locationfound:t,locationerror:n}=e,o=e=>{t({lngLat:[e.latlng.lng,e.latlng.lat]})};void 0!==t&&i.on("locationfound",o,this),n&&i.on("locationerror",n,this);return{stop:()=>{void 0!==t&&i.off("locationfound",o),n&&i.off("locationerror",n)}}}return{stop:()=>{}}}_addUnselectCb(t){for(const e of this._unselectCb)e();this._unselectCb.length=0,this._unselectCb.push(t)}_watchSizeChangeToUpdateMinZoom(t){this._stopWatchSizeChangeToUpdateMinZoom();const e=this.getContainer(),i=this.map;e&&i&&window.ResizeObserver&&(this._resizeObserver=new ResizeObserver((()=>{i.setMinZoom(i.getBoundsZoom(t))})),this._resizeObserver.observe(e))}_stopWatchSizeChangeToUpdateMinZoom(){const t=this.map;t&&t.setMinZoom(0),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0)}_addMapListeners(){const t=this.map;if(t){t.on("click",(t=>{this.onMapClick(t)}));for(const e of this._universalEvents)t.on(e,(()=>this.emitter.emit(e,this)),t);for(const e of this._positionEvents)t.on(e,(t=>this.emitter.emit(e,S(t))),t)}}}W.layerAdapters={GEOJSON:class extends E{constructor(t,e){super(t,e),this.selected=!1,this._layers=[],this._selectedLayers=[],this._filteredLayers=[],this._openedPopup=[],this.$updateTooltip=y((()=>{this.updateTooltip()}),300),this.$unselect=()=>{this.unselect()},this._events=new k(this),this._paint=new Z(this)}addLayer(t){return Object.assign(this.options,t),this.paint=t.paint,this.layer=new f.exports.FeatureGroup([],{...t.nativeOptions,pane:this.pane}),this.selectedPaint=t.selectedPaint,t.paint=this.paint,t.data&&this.addData(t.data),this._addMapListener(),this.layer}beforeRemove(){this._removeMapListener()}select(t){if(this.unselect(),t){const e=this._layers.filter(t);for(const t of e)this._selectLayer(t,"api")}else this.selected||(this.selected=!0,this.selectedPaint&&this._paint.setPaintEachLayer(this.selectedPaint))}unselect(t){if(t){this._layers.filter(t).forEach((t=>{this._unSelectLayer(t)}))}else if(this.selected){for(const t of this._openedPopup)this._removePopup(t[0]);this.paint&&this._paint.setPaintEachLayer(this.paint),this._selectedLayers.length=0,this.selected=!1}}getSelected(){return this._selectedLayers.map((t=>({target:this,feature:t.feature,layer:t,...z(t.feature)})))}getFiltered(){return this._filteredLayers}filter(t){this._filterFun=t;const e=this.layer,i=e&&e._map;if(e&&i){e.remove();const n=[];this._layers.forEach((({feature:i,layer:o})=>{if(o){!t||t({target:this,feature:i,layer:o,...z(i)})?(e.addLayer(o),n.push({target:this,feature:i,layer:o,...z(i)})):e.removeLayer(o)}})),this._filteredLayers=n,e.addTo(i)}return this._filteredLayers}cleanFilter(){this.filter()}getLayers(){return this._layers.map((({layer:t,feature:e})=>({feature:e,layer:t,visible:t&&!!t._map,target:this,...z(e)})))}clearLayer(t){this.unselect();const e=this.layer;if(e)if(t)for(let i=this._layers.length;i--;){const n=this._layers[i];if(n){const{feature:o,layer:s}=n;if(o&&s){t(o)&&(e.removeLayer(s),this._layers.splice(i,1))}}}else e.clearLayers(),this._layers=[]}setData(t){this.clearLayer(),this.addData(t)}addData(t){const e=this.options;let i;if(e){if(t){let n;if(e.type)n=e.type;else{const e=function(t){let e;e="FeatureCollection"===t.type?w(t.features.map((t=>t.geometry.type))):"GeometryCollection"===t.type?w(t.geometries.map((t=>t.type))):"Feature"===t.type?t.geometry.type:t.type;return e}(t);n=P[e]}if(this.type&&this.type!==n)return void console.warn("no other data type than layer can be added");this.type=n,t=function(t,e){if("FeatureCollection"===t.type)t.features=t.features.filter((t=>M(t.geometry.type,e)));else if("Feature"===t.type){if(!M(t.geometry.type,e))return!1}else"GeometryCollection"===t.type&&(t.geometries=t.geometries.filter((t=>M(t.type,e))));return t}(t,n),t&&(i=this._getGeoJsonOptions(e,n))}new f.exports.GeoJSON(t||void 0,i)}}openPopup(t,e){if(t){this._layers.filter(t).forEach((t=>{this._openPopup(t,e,"api")}))}}closePopup(t){(t?this._openedPopup.filter((e=>t(e[2]))):this._openedPopup).forEach((t=>{this._removePopup(t[0])}))}updateTooltip(t){t?this._updateTooltip(t):this.getLayers().forEach((t=>this._updateTooltip({feature:t.feature,layer:t.layer})))}getExtent(){return this.getBounds()}getBounds(){if(this.layer){const t=this.layer.getBounds();if(t.isValid())return x(t)}}setOpacity(t){this.options.opacity=t,this.setPaint(this.paint),this.setSelectedPaint(this.selectedPaint)}setPaint(t){if(t){this.paint=t;for(const e of this._layers)this._paint.setPaint(e,t)}}setSelectedPaint(t){if(t){this.selectedPaint=t;for(const e of this._selectedLayers)this._paint.setPaint(e,t)}}updatePaint(t){this.paint={...this.paint,...t};for(const e of this._layers)this._paint.setPaint(e,this.paint)}updateSelectedPaint(t){this.selectedPaint={...this.selectedPaint,...t};for(const e of this._selectedLayers)this._paint.setPaint(e,this.selectedPaint)}_getSelected(t){return this._selectedLayers.find((e=>e.layer===t))}_updateTooltip(t){const{feature:e,layer:i}=t,{label:n,labelField:o,labelOnHover:s}=this.options;if(i){let r;if(i.unbindTooltip(),e.properties&&o?r=e.properties[o]:n&&(r=n({target:this,...t,...z(e)})),r){const t=!s;i.bindTooltip(String(r),{permanent:t,sticky:!1})}}}async _openPopup(t,e={},i,n){var o,s;const{feature:r,layer:a}=t,{minWidth:h,autoPan:l,maxWidth:u,closeButton:c}={minWidth:300,...e},d=null!=c?c:!this.options.selectOnHover;let p;const _=[],m=t=>{_.push(t)},f=()=>{p&&this._removePopup(p)};let v;if(v=e.createPopupContent?await e.createPopupContent({layer:a,feature:r,target:this,type:i,close:f,onClose:m,...z(r)}):e.popupContent,v&&a){const e={minWidth:h,autoPan:l,closeButton:d,closeOnClick:!1,autoClose:!1};g(u)&&(e.maxWidth=u),p=a.bindPopup(v,e);if(null===(s=null===(o=this.options.popupOptions)||void 0===o?void 0:o.unselectOnClose)||void 0===s||s){const t=a.getPopup();t&&t.once("remove",(()=>{f()}),this)}this._openedPopup.push([p,_,t]),p.openPopup(n)}}_removePopup(t){var e,i;if(this.map){t.closePopup().unbindPopup();const n=this._openedPopup.findIndex((e=>e[0]===t));if(-1!==n){const t=null===(i=null===(e=this.options.popupOptions)||void 0===e?void 0:e.unselectOnClose)||void 0===i||i,[,o,s]=this._openedPopup[n];for(const e of o)e(s);o.length=0,t&&this._unSelectLayer(s),this._openedPopup.splice(n,1)}}}_getGeoJsonOptions(t,e){const i=t.paint;let n={};return"function"==typeof i?"point"===e?n.pointToLayer=(t,e)=>{const n=i(t);return this._paint.createPaintToLayer(n)(t,e)}:n={style:t=>this._paint.preparePaint(t?{...b,...i(t)}:{...b,type:"path"})}:n=this._paint.createPaintOptions(i),n.onEachFeature=(t,e)=>{this._onEachFeature(t,e)},n}_onEachFeature(t,e){const i=this.layer;if(i){const n={target:this,feature:t,layer:e,...z(t)};e.options.pane=this.pane,this._layers.push(n);let o=!0;if(this._filterFun&&(o=this._filterFun(n)),o){const{popup:o,popupOptions:s,selectable:r,interactive:a,selectOnHover:h}=this.options;e.options.interactive=!g(a)||a,i.addLayer(e),r&&(h?(e.on("mouseover",(()=>{this._selectLayer(n,"hover")})),e.on("mouseout",(()=>{this._unSelectLayer(n)}))):e.on("click",(t=>this._selectOnLayerClick(t)),this)),this._events.handleMouseEvents(e),setTimeout((()=>{o&&this._openPopup({target:this,layer:e,feature:t,...z(t)},s,"api"),this._updateTooltip({layer:e,feature:t})}))}}}_selectOnLayerClick(t){f.exports.DomEvent.stopPropagation(t);const e=t.target,i=e.feature,n={target:this,layer:e,feature:i,...z(i)},o=this._getSelected(e);o?this.options&&this.options.unselectOnSecondClick&&this._unSelectLayer(o):this._selectLayer(n,"click",t.latlng)}_selectLayer(t,e,i){const{multiselect:n}=this.options;n||(this.map._addUnselectCb((()=>{this._unSelectLayer(t)})),this._selectedLayers.forEach((t=>this._unSelectLayer(t)))),this._selectedLayers.push(t),this.selected=!0;const{selectedPaint:o,popupOnSelect:s,popupOptions:r}=this.options;if(o&&t.layer&&this._paint.setPaint(t,o),s&&this._openPopup(t,r,e,i),this.options.onSelect){const i=t.feature?[t.feature]:[];this.options.onSelect({type:e,layer:this,features:i,...z(i)})}}_unSelectLayer(t){const e=this._selectedLayers.indexOf(t);-1!==e&&(this._selectedLayers.splice(e,1),this.options&&(this.options.paint&&this._paint.setPaint(t,this.options.paint),this.options.popupOnSelect&&t.layer&&this._removePopup(t.layer))),this.selected=this._selectedLayers.length>0}_addMapClickListener(){const t=this.map;if(t){const{unselectOnClick:e}=this.options;(null==e||e)&&t.on("click",this.$unselect)}}_removeMapClickListener(){this.map.off("zoomend",this.$updateTooltip),this.map.off("moveend",this.$updateTooltip),this.map.off("click",this.$unselect)}_addMapListener(){const t=this.map;if(t){const{label:e,labelField:i,labelOnHover:n}=this.options;this._addMapClickListener(),!i&&!e||n||(t.on("zoomend",this.$updateTooltip),t.on("moveend",this.$updateTooltip))}}_removeMapListener(){this._removeMapClickListener(),this.map.off("zoomend",this.$updateTooltip),this.map.off("moveend",this.$updateTooltip)}},IMAGE:class extends E{addLayer(t){const e=t&&t.url;if(e){const i=(t={transparent:!0,...t}).updateWmsParams;if(this.layer=new A(e,{pane:this.pane,headers:t.headers,setViewDelay:t.setViewDelay,...t,...t.params,...t.nativeOptions}),i){const t=this.layer.updateWmsParams;this.layer.updateWmsParams=function(e){t.call(this,e),this.wmsParams=i(this.wmsParams)}}return this.layer}}},TILE:N,WMS:class extends E{addLayer(t){Object.assign(this.options,t);const{url:e,...i}=t;if(e){const n={pane:this.pane,attribution:i.attribution,minZoom:i.minZoom,maxZoom:i.maxZoom,layers:t.layers,format:t.format,...t.nativeOptions};let o;return o=i.headers?new D(e,{...n,headers:i.headers}):new f.exports.TileLayer.WMS(e,n),o}}},OSM:class extends N{addLayer(t){return super.addLayer({name:"OpenStreetMap",attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',...t,url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"})}}},W.controlAdapters={ZOOM:f.exports.Control.Zoom,ATTRIBUTION:class extends f.exports.Control.Attribution{constructor(t){super(t);const e=t&&t.customAttribution;if(e){let t=[];Array.isArray(e)?t=e:e&&(t=[e]),t.forEach((t=>this.addAttribution(t)))}}}},W.Map=f.exports.Map;var F=W;export{F as default};
|
|
12
12
|
//# sourceMappingURL=leaflet-map-adapter.esm-browser.prod.js.map
|