@nextgis/leaflet-map-adapter 1.16.8 → 1.17.0

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.
@@ -1,8 +1,8 @@
1
- import{EventEmitter as t}from"events";import{Control as e,DomEvent as o,GeoJSON as n,FeatureGroup as r,DivIcon as i,Marker as a,CircleMarker as s,ImageOverlay as p,Util as u,CRS as c,Layer as l,GridLayer as h,DomUtil as f,TileLayer as y,Map as d}from"leaflet";import{defined as m,debounce as v}from"@nextgis/utils";import{isPaintCallback as _,isPaint as g}from"@nextgis/paint";var b=function(t,e){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},b(t,e)};function P(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}b(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var O=function(){return O=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},O.apply(this,arguments)};function L(t,e){var o={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++)e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(o[n[r]]=t[n[r]])}return o}function w(t,e,o,n){return new(o||(o=Promise))((function(r,i){function a(t){try{p(n.next(t))}catch(e){i(e)}}function s(t){try{p(n.throw(t))}catch(e){i(e)}}function p(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(a,s)}p((n=n.apply(t,e||[])).next())}))}function C(t,e){var o,n,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;a;)try{if(o=1,n&&(r=2&i[0]?n.return:i[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,i[1])).done)return r;switch(n=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(s){i=[6,s],n=0}finally{o=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function x(t,e,o){if(o||2===arguments.length)for(var n,r=0,i=e.length;r<i;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}function M(t){var e=t.containerPoint,o=t.latlng;return{latLng:o,lngLat:[o.lng,o.lat],pixel:{left:e.x,top:e.y},source:t}}function T(t,n,r){return void 0===n&&(n={}),new(e.extend({onAdd:function(){var e=document.createElement("div"),i=t.onAdd(r);return e.classList.add("leaflet-control"),n.bar&&e.classList.add("leaflet-bar"),n.addClass&&e.classList.add(n.addClass),n.margin||n.bar||(e.style.marginBottom="0px",e.style.marginTop="0px",e.style.marginLeft="0px",e.style.marginRight="0px"),i&&e.appendChild(i),o.disableClickPropagation(e),e},onRemove:function(){t.onRemove()}}))}var S=function(t){function e(e){var o=t.call(this,e)||this,n=e&&e.customAttribution;if(n){var r=[];Array.isArray(n)?r=n:n&&(r=[n]),r.forEach((function(t){return o.addAttribution(t)}))}return o}return P(e,t),e}(e.Attribution);function k(t){var e=t.getNorthEast(),o=t.getSouthWest();return[o.lng,o.lat,e.lng,e.lat]}var E={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon",GeometryCollection:"polygon"},Z={stroke:!1,opacity:1},B={};for(var z in E){var A=E[z],U=B[A]||[];U.push(z),B[A]=U}function I(t,e){return-1!==(B[e]||[]).indexOf(t)}function W(t){var e=new n;return(Array.isArray(t)?t:[t]).forEach((function(t){return e.addData(t)})),e.getBounds()}function F(t){return{getBounds:function(){return function(t){return k(W(t))}(t)},getCenter:function(){return function(t){var e=W(t).getCenter();return[e.lng,e.lat]}(t)}}}function j(t){for(var e={},o=0;o<t.length;o++)e[t[o]]=1+(e[t[o]]||0);var n="";for(var r in e){e[r]>(n?e[n]:0)&&(n=r)}return n}var D=function(){function t(t,e){if(this.map=t,this.options=e,this.pane="order-0",void 0!==e.order){var o="order-"+e.order,n=t.getPane(o);n||(n=t.createPane(o)),n.style.zIndex=String(Math.round(100*e.order)),this.pane=o}}return t.prototype.addLayer=function(t){Object.assign(this.options,t)},t}(),R=function(t){function e(e,o){var n=t.call(this,e,o)||this;return n.selected=!1,n._layers=[],n._selectedLayers=[],n._filteredLayers=[],n._openedPopup=[],n.$updateTooltip=v((function(){n.updateTooltip()}),300),n.$unselect=function(){n.unselect()},n}return P(e,t),e.prototype.addLayer=function(t){return Object.assign(this.options,t),this.paint=t.paint,this.layer=new r([],O(O({},t.nativeOptions),{pane:this.pane})),this.selectedPaint=t.selectedPaint,t.paint=this.paint,t.data&&this.addData(t.data),this._addMapListener(),this.layer},e.prototype.beforeRemove=function(){this._removeMapListener()},e.prototype.select=function(t){if(this.unselect(),t)for(var e=0,o=this._layers.filter(t);e<o.length;e++){this._selectLayer(o[e],"api")}else this.selected||(this.selected=!0,this.selectedPaint&&this._setPaintEachLayer(this.selectedPaint))},e.prototype.unselect=function(t){var e=this;if(t)this._layers.filter(t).forEach((function(t){e._unSelectLayer(t)}));else if(this.selected){for(var o=0,n=this._openedPopup;o<n.length;o++){this._removePopup(n[o][0])}this.paint&&this._setPaintEachLayer(this.paint),this._selectedLayers.length=0,this.selected=!1}},e.prototype.getSelected=function(){var t=this;return this._selectedLayers.map((function(e){return O({target:t,feature:e.feature,layer:e},F(e.feature))}))},e.prototype.getFiltered=function(){return this._filteredLayers},e.prototype.filter=function(t){var e=this;this._filterFun=t;var o=this.layer,n=o&&o._map;if(o&&n){o.remove();var r=[];this._layers.forEach((function(n){var i=n.feature,a=n.layer;a&&(!t||t(O({target:e,feature:i,layer:a},F(i)))?(o.addLayer(a),r.push(O({target:e,feature:i,layer:a},F(i)))):o.removeLayer(a))})),this._filteredLayers=r,o.addTo(n)}return this._filteredLayers},e.prototype.cleanFilter=function(){this.filter()},e.prototype.getLayers=function(){var t=this;return this._layers.map((function(e){var o=e.layer,n=e.feature;return O({feature:n,layer:o,visible:o&&!!o._map,target:t},F(n))}))},e.prototype.clearLayer=function(t){this.unselect();var e=this.layer;if(e)if(t)for(var o=this._layers.length;o--;){var n=this._layers[o];if(n){var r=n.feature,i=n.layer;if(r&&i)t(r)&&(e.removeLayer(i),this._layers.splice(o,1))}}else e.clearLayers(),this._layers=[]},e.prototype.setData=function(t){this.clearLayer(),this.addData(t)},e.prototype.addData=function(t){var e,o=this.options;if(o){if(t){var r=void 0;if(o.type)r=o.type;else{var i=function(t){var e;e="FeatureCollection"===t.type?j(t.features.map((function(t){return t.geometry.type}))):"GeometryCollection"===t.type?j(t.geometries.map((function(t){return t.type}))):"Feature"===t.type?t.geometry.type:t.type;return e}(t);r=E[i]}if(this.type&&this.type!==r)return void console.warn("no other data type than layer can be added");this.type=r,t=function(t,e){if("FeatureCollection"===t.type)(o=t).features=o.features.filter((function(t){return I(t.geometry.type,e)}));else if("Feature"===t.type){if(!I(t.geometry.type,e))return!1}else if("GeometryCollection"===t.type){var o;(o=t).geometries=o.geometries.filter((function(t){return I(t.type,e)}))}return t}(t,r),t&&(e=this._getGeoJsonOptions(o,r))}new n(t||void 0,e)}},e.prototype.openPopup=function(t,e){var o=this;t&&this._layers.filter(t).forEach((function(t){o._openPopup(t,e,"api")}))},e.prototype.closePopup=function(t){var e=this;(t?this._openedPopup.filter((function(e){return t(e[2])})):this._openedPopup).forEach((function(t){e._removePopup(t[0])}))},e.prototype.updateTooltip=function(t){var e=this;t?this._updateTooltip(t):this.getLayers().forEach((function(t){return e._updateTooltip({feature:t.feature,layer:t.layer})}))},e.prototype.getExtent=function(){return this.getBounds()},e.prototype.getBounds=function(){if(this.layer){var t=this.layer.getBounds();if(t.isValid())return k(t)}},e.prototype.setOpacity=function(t){this.options.opacity=t,this.setPaint(this.paint),this.setSelectedPaint(this.selectedPaint)},e.prototype.setPaint=function(t){if(t){this.paint=t;for(var e=0,o=this._layers;e<o.length;e++){this._setPaint(o[e],t)}}},e.prototype.setSelectedPaint=function(t){if(t){this.selectedPaint=t;for(var e=0,o=this._selectedLayers;e<o.length;e++){this._setPaint(o[e],t)}}},e.prototype.updatePaint=function(t){this.paint=O(O({},this.paint),t);for(var e=0,o=this._layers;e<o.length;e++){this._setPaint(o[e],this.paint)}},e.prototype.updateSelectedPaint=function(t){this.selectedPaint=O(O({},this.selectedPaint),t);for(var e=0,o=this._selectedLayers;e<o.length;e++){this._setPaint(o[e],this.selectedPaint)}},e.prototype._updateTooltip=function(t){var e=t.feature,o=t.layer;if(e&&o&&e.properties&&this.options.labelField){o.unbindTooltip();var n=e.properties[this.options.labelField];if(void 0!==n){var r=!this.options.labelOnHover;o.bindTooltip(String(n),{permanent:r,sticky:!1})}}},e.prototype._openPopup=function(t,e,o,n){var r,i;return void 0===e&&(e={}),w(this,void 0,void 0,(function(){var a,s,p,u,c,l,h,f,y,d,v,_,g,b,P,L=this;return C(this,(function(w){switch(w.label){case 0:return a=t.feature,s=t.layer,p=O({minWidth:300},e),u=p.minWidth,c=p.autoPan,l=p.maxWidth,f=null!=(h=p.closeButton)?h:!this.options.selectOnHover,d=[],v=function(t){d.push(t)},_=function(){y&&L._removePopup(y)},e.createPopupContent?[4,e.createPopupContent(O({layer:s,feature:a,target:this,type:o,close:_,onClose:v},F(a)))]:[3,2];case 1:return g=w.sent(),[3,3];case 2:g=e.popupContent,w.label=3;case 3:return g&&s&&(b={minWidth:u,autoPan:c,closeButton:f,closeOnClick:!1,autoClose:!1},m(l)&&(b.maxWidth=l),y=s.bindPopup(g,b),(null===(i=null===(r=this.options.popupOptions)||void 0===r?void 0:r.unselectOnClose)||void 0===i||i)&&(P=s.getPopup())&&P.once("remove",(function(){_()}),this),this._openedPopup.push([y,d,t]),y.openPopup(n)),[2]}}))}))},e.prototype._removePopup=function(t){var e,o;if(this.map){t.closePopup().unbindPopup();var n=this._openedPopup.findIndex((function(e){return e[0]===t}));if(-1!==n){for(var r=null===(o=null===(e=this.options.popupOptions)||void 0===e?void 0:e.unselectOnClose)||void 0===o||o,i=this._openedPopup[n],a=i[1],s=i[2],p=0,u=a;p<u.length;p++){(0,u[p])(s)}a.length=0,r&&this._unSelectLayer(s),this._openedPopup.splice(n,1)}}},e.prototype._setPaintEachLayer=function(t){var e=this;this._layers.forEach((function(o){e._setPaint(o,t)}))},e.prototype._setPaint=function(t,e){var o=void 0,n=t.layer,r=t.feature;if(n&&r&&(_(e)?o=e(r):g(e)&&(o=e),o))if("point"===this.type&&"icon"===o.type){var i=n,a=this._createDivIcon(o);i.setIcon(a)}else"setStyle"in n&&n.setStyle(this._preparePaint(o))},e.prototype._preparePaint=function(t){if("get-paint"!==t.type){var e="line"===this.type?[["color","strokeColor"],["opacity","strokeOpacity"],["weight","weight"]]:[["color","strokeColor"],["opacity","strokeOpacity"],["stroke","stroke"],["fillColor","fillColor"],["fillOpacity","fillOpacity"],["fill","fill"],["weight","weight"]],o={};"radius"in t&&"number"==typeof t.radius&&(o.radius=t.radius);for(var n=0,r=e;n<r.length;n++){var i=r[n],a=i[0],s=i[1],p=t[s];m(this.options.opacity)&&-1!==s.toLowerCase().indexOf("opacity")&&(p=Number(p)*this.options.opacity),void 0!==p&&Object.defineProperty(o,a,{enumerable:!0,value:p})}return o}return Z},e.prototype._getGeoJsonOptions=function(t,e){var o=this,n=t.paint,r={};return"function"==typeof n?"point"===e?r.pointToLayer=function(t,e){var r=n(t);return o._createPaintToLayer(r)(t,e)}:r={style:function(t){return o._preparePaint(O(O({},Z),t?n(t):{type:"path"}))}}:r=this._createPaintOptions(n,e),r.onEachFeature=function(t,e){o._onEachFeature(t,e)},r},e.prototype._onEachFeature=function(t,e){var o=this,n=this.layer;if(n){var r=O({target:this,feature:t,layer:e},F(t));e.options.pane=this.pane,this._layers.push(r);var i=!0;if(this._filterFun&&(i=this._filterFun(r)),i){var a=this.options,s=a.popup,p=a.popupOptions,u=a.selectable,c=a.interactive,l=a.selectOnHover;e.options.interactive=!m(c)||c,n.addLayer(e),u&&(l?(e.on("mouseover",(function(){o._selectLayer(r,"hover")})),e.on("mouseout",(function(){o._unSelectLayer(r)}))):e.on("click",(function(t){return o._selectOnLayerClick(t)}),this)),this._handleMouseEvents(e),setTimeout((function(){s&&o._openPopup(O({target:o,layer:e,feature:t},F(t)),p,"api"),o._updateTooltip({layer:e,feature:t})}))}}},e.prototype._handleMouseEvents=function(t){var e=this,o=this.options,n=o.onMouseOut,r=o.onMouseOver,i=o.onClick||o.onLayerClick;i&&t.on("click",(function(o){var n=!!e._getSelected(t);i(O({selected:n},e._createMouseEvent(o)))}),this),n&&t.on("mouseout",(function(t){n(e._createMouseEvent(t))}),this),r&&t.on("mouseover",(function(t){r(e._createMouseEvent(t))}),this)},e.prototype._createMouseEvent=function(t){return function(t){var e=t.source,o=e.target.feature;return O({layer:t.layer,feature:o,event:M(e),source:e},F(o))}({layer:this,source:t})},e.prototype._getSelected=function(t){return this._selectedLayers.find((function(e){return e.layer===t}))},e.prototype._selectOnLayerClick=function(t){o.stopPropagation(t);var e=t.target,n=e.feature,r=O({target:this,layer:e,feature:n},F(n)),i=this._getSelected(e);i?this.options&&this.options.unselectOnSecondClick&&this._unSelectLayer(i):this._selectLayer(r,"click",t.latlng)},e.prototype._selectLayer=function(t,e,o){var n=this;this.options.multiselect||(this.map._addUnselectCb((function(){n._unSelectLayer(t)})),this._selectedLayers.forEach((function(t){return n._unSelectLayer(t)}))),this._selectedLayers.push(t),this.selected=!0;var r=this.options,i=r.selectedPaint,a=r.popupOnSelect,s=r.popupOptions;if(i&&t.layer&&this._setPaint(t,i),a&&this._openPopup(t,s,e,o),this.options.onSelect){var p=t.feature?[t.feature]:[];this.options.onSelect(O({type:e,layer:this,features:p},F(p)))}},e.prototype._unSelectLayer=function(t){var e=this._selectedLayers.indexOf(t);-1!==e&&(this._selectedLayers.splice(e,1),this.options&&(this.options.paint&&this._setPaint(t,this.options.paint),this.options.popupOnSelect&&t.layer&&this._removePopup(t.layer))),this.selected=this._selectedLayers.length>0},e.prototype._createDivIcon=function(t){var e=L(t,[]);return new i(O({className:""},e))},e.prototype._createPaintToLayer=function(t){var e=this;if(t&&t.type)if("icon"===t.type){if(t.className||t.html)return function(o,n){var r=e._createDivIcon(t);return new a(n,{icon:r})}}else if("pin"===t.type)return function(t,e){return new a(e)};return function(o,n){return new s(n,e._preparePaint(O(O({},Z),t)))}},e.prototype._createPaintOptions=function(t,e){var o={},n=t&&this._preparePaint(t)||{};return t&&(o.style=function(){return n}),"point"===e?o.pointToLayer=this._createPaintToLayer(t):"line"===e&&(n.stroke=!0),o},e.prototype._addMapClickListener=function(){var t=this.map;if(t){var e=this.options.unselectOnClick;(null==e||e)&&t.on("click",this.$unselect)}},e.prototype._removeMapClickListener=function(){this.map.off("zoomend",this.$updateTooltip),this.map.off("moveend",this.$updateTooltip),this.map.off("click",this.$unselect)},e.prototype._addMapListener=function(){var t=this.map;if(t){var e=this.options,o=e.labelField,n=e.labelOnHover;this._addMapClickListener(),o&&!n&&(t.on("zoomend",this.$updateTooltip),t.on("moveend",this.$updateTooltip))}},e.prototype._removeMapListener=function(){this._removeMapClickListener(),this.map.off("zoomend",this.$updateTooltip),this.map.off("moveend",this.$updateTooltip)},e}(D);function V(t,e,o){var n=new XMLHttpRequest;for(var r in n.open("GET",t),n.responseType="arraybuffer",o)n.setRequestHeader(r,o[r]);return n.onload=function(){var t=new Uint8Array(this.response),o=new Blob([t],{type:"image/png"}),n=(window.URL||window.webkitURL).createObjectURL(o);e(n)},n.send(),function(){n.abort()}}var G=function(t){function e(e,o,n){var r=t.call(this,e,o,n)||this;return r._abort=[],r}return P(e,t),e.prototype.cancelLoad=function(){this._abort&&(this._abort.forEach((function(t){return t()})),this._abort=[])},e.prototype._initImage=function(){t.prototype._initImage.call(this);var e=this.options.headers;if(e){var o=this._image,n=o.src;o.src="",this._abort.push(V(n,(function(t){o.src=t}),e))}},e}(p),$=function(t){function e(e,o){var n=t.call(this,o)||this;n.defaultWmsParams={service:"WMS",request:"GetMap",version:"1.1.1",layers:"",styles:"",format:"image/jpeg",transparent:!1},n.options={crs:null,uppercase:!1,attribution:"",opacity:1,isBack:!1,minZoom:0,pane:"tilePane",headers:null,viewPortBuffer:0,setViewDelay:100},n._url=e;var r,i={},a={};for(r in o)r in n.options?a[r]=o[r]:i[r]=o[r];return u.setOptions(n,a),n.wmsParams=u.extend({},n.defaultWmsParams,i),n}return P(e,t),e.prototype.setParams=function(t){u.extend(this.wmsParams,t),this.update()},e.prototype.getAttribution=function(){return this.options.attribution||""},e.prototype.onAdd=function(){return this.update(),this},e.prototype.onRemove=function(t){return this._currentOverlay&&(this._currentOverlay.cancelLoad(),t.removeLayer(this._currentOverlay),delete this._currentOverlay),this._currentUrl&&delete this._currentUrl,this},e.prototype.getEvents=function(){return{moveend:v(this.update,this.options.setViewDelay)}},e.prototype.update=function(){var t=this;if(this._map){this.updateWmsParams();var e=this.getImageUrl();if(this._currentUrl!==e){this._currentUrl=e;var o=this.options.viewPortBuffer||0,n=this._map.getBounds().pad(o),r=new G(e,n,{opacity:0,pane:this.options.pane,headers:this.options.headers});r.addTo(this._map),this._currentOverlay&&this._currentOverlay.cancelLoad(),r.once("load",(function(){t._map&&(r._url===t._currentUrl?(t._currentOverlay&&t._map.removeLayer(t._currentOverlay),t._currentOverlay=r,r.setOpacity(void 0!==t.options.opacity?t.options.opacity:1),!0===t.options.isBack&&r.bringToBack(),!1===t.options.isBack&&r.bringToFront(),void 0!==t.options.zIndex&&r.setZIndex(t.options.zIndex)):t._map.removeLayer(r))}),this);var i=this.options,a=i.minZoom,s=i.maxZoom;(a&&this._map.getZoom()<a||s&&this._map.getZoom()>s)&&this._map.removeLayer(r)}}},e.prototype.setOpacity=function(t){this.options.opacity=t,this._currentOverlay&&this._currentOverlay.setOpacity(t)},e.prototype.bringToBack=function(){this.options.isBack=!0,this._currentOverlay&&this._currentOverlay.bringToBack()},e.prototype.bringToFront=function(){this.options.isBack=!1,this._currentOverlay&&this._currentOverlay.bringToFront()},e.prototype.setZIndex=function(t){this.options.zIndex=t,this._currentOverlay&&this._currentOverlay.setZIndex(t)},e.prototype.updateWmsParams=function(t){t||(t=this._map);var e=this.options.viewPortBuffer||0,o=t.getBounds().pad(e),n=t.getSize();if(0!==this.options.viewPortBuffer){var r=e+1;n.x=Math.ceil(n.x*r),n.y=Math.ceil(n.y*r)}var i=parseFloat(this.wmsParams.version),a=this.options.crs||t.options.crs,s=i>=1.3?"crs":"srs";if(a){var p=a.project(o.getNorthWest()),l=a.project(o.getSouthEast()),h={width:n.x,height:n.y};h[s]=a.code,h.bbox=(i>=1.3&&a===c.EPSG4326?[l.y,p.x,p.y,l.x]:[p.x,l.y,l.x,p.y]).join(","),u.extend(this.wmsParams,h)}},e.prototype.getImageUrl=function(){var t=u.getParamString(this.wmsParams,this._url,this.options.uppercase||!1);return this._url+t},e}(l),N=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return P(e,t),e.prototype.addLayer=function(t){var e=t&&t.url;if(e){var o=(t=O({transparent:!0},t)).updateWmsParams;if(this.layer=new $(e,O(O(O({pane:this.pane,headers:t.headers,setViewDelay:t.setViewDelay},t),t.params),t.nativeOptions)),o){var n=this.layer.updateWmsParams;this.layer.updateWmsParams=function(t){n.call(this,t),this.wmsParams=o(this.wmsParams)}}return this.layer}},e}(D);
1
+ import{EventEmitter as t}from"events";import{Control as e,DomEvent as s,GeoJSON as i,FeatureGroup as o,DivIcon as n,Marker as r,CircleMarker as a,ImageOverlay as l,Layer as p,Util as c,CRS as h,GridLayer as u,DomUtil as d,TileLayer as m,Map as y}from"leaflet";import{debounce as f,defined as _}from"@nextgis/utils";import{isPaintCallback as g,isPaint as v}from"@nextgis/paint";function P(t){const e=t.containerPoint,s=t.latlng,{lat:i,lng:o}=s;return{latLng:s,lngLat:[o,i],pixel:{left:e.x,top:e.y},source:t}}function L(t,i={},o){return new(e.extend({onAdd(){const e=document.createElement("div"),n=t.onAdd(o);return e.classList.add("leaflet-control"),i.bar&&e.classList.add("leaflet-bar"),i.addClass&&e.classList.add(i.addClass),i.margin||i.bar||(e.style.marginBottom="0px",e.style.marginTop="0px",e.style.marginLeft="0px",e.style.marginRight="0px"),n&&e.appendChild(n),s.disableClickPropagation(e),e},onRemove(){t.onRemove()}}))}function b(t){const e=t.getNorthEast(),s=t.getSouthWest();return[s.lng,s.lat,e.lng,e.lat]}const O={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon",GeometryCollection:"polygon"},C={stroke:!1,opacity:1},w={};for(const R in O){const t=O[R],e=w[t]||[];e.push(R),w[t]=e}function x(t,e){return-1!==(w[e]||[]).indexOf(t)}function M(t){const e=new i;return(Array.isArray(t)?t:[t]).forEach((t=>e.addData(t))),e.getBounds()}function T(t){return{getBounds:()=>function(t){return b(M(t))}(t),getCenter:()=>function(t){const{lat:e,lng:s}=M(t).getCenter();return[s,e]}(t)}}function k(t){const e={};for(let i=0;i<t.length;i++)e[t[i]]=1+(e[t[i]]||0);let s="";for(const i in e){e[i]>(s?e[s]:0)&&(s=i)}return s}class S{constructor(t,e){if(this.map=t,this.options=e,this.pane="order-0",void 0!==e.order){const s="order-"+e.order;let i=t.getPane(s);i||(i=t.createPane(s)),i.style.zIndex=String(Math.round(100*e.order)),this.pane=s}}addLayer(t){Object.assign(this.options,t)}}function Z(t,e,s){const i=new XMLHttpRequest;i.open("GET",t),i.responseType="arraybuffer";for(const o in s)i.setRequestHeader(o,s[o]);return i.onload=function(){const t=new Uint8Array(this.response),s=new Blob([t],{type:"image/png"}),i=(window.URL||window.webkitURL).createObjectURL(s);e(i)},i.send(),()=>{i.abort()}}class E extends l{constructor(t,e,s){super(t,e,s),this._abort=[]}cancelLoad(){this._abort&&(this._abort.forEach((t=>t())),this._abort=[])}_initImage(){super._initImage();const t=this.options.headers;if(t){const e=this._image,s=e.src;e.src="",this._abort.push(Z(s,(t=>{e.src=t}),t))}}}
2
2
  /*!
3
3
  * leaflet.wms.js
4
4
  * A collection of Leaflet utilities for working with Web Mapping services.
5
5
  * (c) 2014-2016, Houston Engineering, Inc.
6
6
  * MIT License
7
- */function H(t,e){var o;function n(){for(var r=this,i=[],a=0;a<arguments.length;a++)i[a]=arguments[a];n.clear(),o=setTimeout((function(){o=null,t.apply(r,i)}),e)}return void 0===e&&(e=10),n.clear=function(){o&&(clearTimeout(o),o=null)},n}function q(t){return function(t){function e(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];var n=t.apply(this,e)||this;return n.options.setViewDelay&&(n._update=H((function(){for(var t,e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];(t=h.prototype._update).call.apply(t,x([n],e,!1))}),n.options.setViewDelay)),n}return P(e,t),e.prototype.createTile=function(t,e){var o=this.getTileUrl(t),n=document.createElement("img");return n.abort=V(o,(function(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},e.prototype._abortLoading=function(){var t=this._tiles,e=this._tileZoom;for(var o in t)if(t[o].coords.z!==e){var n=t[o].el;n.onload=u.falseFn,n.onerror=u.falseFn,n.complete||(n.abort&&n.abort(),n.src=u.emptyImageUrl,f.remove(n),delete t[o])}},e}(t)}var J=q(function(t){function e(e,o){var n=t.call(this,e,o)||this;return Object.assign(n.options,o),n}return P(e,t),e}(y)),X=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return P(e,t),e.prototype.addLayer=function(t){if(this.options=Object.assign(this.options,t),t){var e=t.url,o=L(t,["url"]);if(e){var n=O({pane:this.pane,attribution:o.attribution,minZoom:o.minZoom,maxZoom:o.maxZoom},o.nativeOptions);o.subdomains&&(n.subdomains=o.subdomains);return o.headers?new J(e,O(O({},n),{headers:o.headers,setViewDelay:o.setViewDelay})):new y(e,n)}}},e}(D),K=q(function(t){function e(e,o){return t.call(this,e,o)||this}return P(e,t),e}(y.WMS)),Q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return P(e,t),e.prototype.addLayer=function(t){Object.assign(this.options,t);var e=t.url,o=L(t,["url"]);if(e){var n=O({pane:this.pane,attribution:o.attribution,minZoom:o.minZoom,maxZoom:o.maxZoom,layers:t.layers,format:t.format},t.nativeOptions);return o.headers?new K(e,O(O({},n),{headers:o.headers})):new y.WMS(e,n)}},e}(D),Y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return P(e,t),e.prototype.addLayer=function(e){return t.prototype.addLayer.call(this,O(O({name:"OpenStreetMap",attribution:'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'},e),{url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}))},e}(X);function tt(t){return[[t[3],t[0]],[t[1],t[2]]]}var et=function(){function n(){this.options={target:"map"},this.layerAdapters=n.layerAdapters,this.controlAdapters=n.controlAdapters,this.emitter=new t,this._unselectCb=[],this._universalEvents=["move","zoom","zoomend","zoomstart","moveend","movestart"],this._positionEvents=["mousemove","mouseout","mouseover"]}return n.prototype.create=function(t){var e=this;if(this.options=O({},t),this.options.target){var o=this.options,n=o.zoom,r=o.center,i=o.maxZoom,a=o.minZoom,s=o.maxBounds,p=o.mapAdapterOptions;this.map=this.options.map||new d(this.options.target,O({attributionControl:!1,zoomControl:!1,maxBounds:s?tt(s):void 0,maxZoom:i,minZoom:a,center:r&&[r[1],r[0]],zoom:n},p));var u=this.map.createPane("order-0");this.map._addUnselectCb=function(t){e._addUnselectCb(t)},u.style.zIndex=String(0),this.emitter.emit("create",this),this._addMapListeners()}},n.prototype.destroy=function(){this.map&&this.map.remove(),this._stopWatchSizeChangeToUpdateMinZoom()},n.prototype.getContainer=function(){return this.map&&this.map.getContainer()},n.prototype.getControlContainer=function(){var t=this.map&&this.map._controlContainer;if(t)return t;throw new Error("Leaflet Map is not initialized yet")},n.prototype.setCursor=function(t){this.map&&(this.map.getContainer().style.cursor=t)},n.prototype.setView=function(t,e){var o=this.map;if(o)if(Array.isArray(t)){var n=t[0],r=t[1];this.map&&("number"==typeof e?this.map.setView([r,n],e,{animate:!1}):this.setCenter([n,r]))}else{var i=t.zoom,a=t.center,s=t.maxBounds,p=t.bounds,u=t.minZoom,c=t.maxZoom;if(a&&void 0!==i?this.setView(a,i):(void 0!==i&&this.setZoom(i),a&&this.setCenter(a)),p&&this.fitBounds(p),void 0!==s)if(s){var l=tt(s);o.setMaxBounds(l),o.setMinZoom(o.getBoundsZoom(l)),this._watchSizeChangeToUpdateMinZoom(l)}else o.setMaxBounds(null),this._stopWatchSizeChangeToUpdateMinZoom();void 0!==c&&o.setMaxZoom(c),void 0!==u&&(this._stopWatchSizeChangeToUpdateMinZoom(),o.setMinZoom(u))}},n.prototype.setCenter=function(t){this.map&&this.map.panTo([t[1],t[0]])},n.prototype.getCenter=function(){var t=this.map;if(t){var e=t.getBounds().getCenter();return[e.lng,e.lat]}},n.prototype.setZoom=function(t){this.map&&this.map.setZoom(t)},n.prototype.getZoom=function(){var t;return null!==(t=this.map&&this.map.getZoom())&&void 0!==t?t:void 0},n.prototype.getBounds=function(){if(this.map){var t=this.map.getBounds(),e=t.getSouthWest(),o=t.getNorthEast();return[e.lng,e.lat,o.lng,o.lat]}},n.prototype.fitBounds=function(t,e){if(void 0===e&&(e={}),this.map){var o=e.maxZoom,n=e.offset,r=e.padding,i={};o&&(i.maxZoom=o),r&&(i.padding=[r,r]),n&&(i.padding=n),this.map.fitBounds(tt(t),i)}},n.prototype.getLayerAdapter=function(t){return n.layerAdapters[t]},n.prototype.createControl=function(t,e){return T(t,e,this)},n.prototype.createButtonControl=function(t){return function(t,e){var n=document.createElement("a"),r=t.title||"";n.href="#",n.title=r,n.setAttribute("role","button"),n.setAttribute("aria-label",r),t.addClass&&n.classList.add(t.addClass),o.disableClickPropagation(n),o.on(n,"click",o.stop),t.html instanceof HTMLElement?n.appendChild(t.html):"string"==typeof t.html&&(n.innerHTML=t.html);var i=function(e){e.stopPropagation(),t.onClick()};return T({onAdd:function(){return void 0!==t.onClick&&n.addEventListener("click",i),n},onRemove:function(){var e=n.parentNode;e&&e.removeChild(n),void 0!==t.onClick&&n.removeEventListener("click",i)}},{bar:!0},e)}(t,this)},n.prototype.addControl=function(t,e){if(t.options.position=e.replace("-",""),this.map)return this.map.addControl(t),t},n.prototype.removeControl=function(t){this.map&&this.map.removeControl(t)},n.prototype.removeLayer=function(t){t&&t.remove&&t.remove()},n.prototype.showLayer=function(t){this.map&&t.addTo(this.map)},n.prototype.hideLayer=function(t){t.remove()},n.prototype.setLayerOpacity=function(t,e){"setOpacity"in t&&t.setOpacity(e)},n.prototype.setLayerOrder=function(t,e,o){},n.prototype.onMapClick=function(t){var e=M(t);this.emitter.emit("preclick",e),this.emitter.emit("click",e)},n.prototype.locate=function(t,e){var o=this.map;if(o&&(o.locate(t),e)){var n=e.locationfound,r=e.locationerror,i=function(t){n({lngLat:[t.latlng.lng,t.latlng.lat]})};void 0!==n&&o.on("locationfound",i,this),r&&o.on("locationerror",r,this);return{stop:function(){void 0!==n&&o.off("locationfound",i),r&&o.off("locationerror",r)}}}return{stop:function(){}}},n.prototype._addUnselectCb=function(t){for(var e=0,o=this._unselectCb;e<o.length;e++){(0,o[e])()}this._unselectCb.length=0,this._unselectCb.push(t)},n.prototype._watchSizeChangeToUpdateMinZoom=function(t){this._stopWatchSizeChangeToUpdateMinZoom();var e=this.getContainer(),o=this.map;e&&o&&window.ResizeObserver&&(this._resizeObserver=new ResizeObserver((function(){o.setMinZoom(o.getBoundsZoom(t))})),this._resizeObserver.observe(e))},n.prototype._stopWatchSizeChangeToUpdateMinZoom=function(){var t=this.map;t&&t.setMinZoom(0),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0)},n.prototype._addMapListeners=function(){var t=this,e=this.map;if(e){e.on("click",(function(e){t.onMapClick(e)}));for(var o=function(o){e.on(o,(function(){return t.emitter.emit(o,t)}),e)},n=0,r=this._universalEvents;n<r.length;n++){o(r[n])}for(var i=function(o){e.on(o,(function(e){return t.emitter.emit(o,M(e))}),e)},a=0,s=this._positionEvents;a<s.length;a++){i(s[a])}}},n.layerAdapters={GEOJSON:R,IMAGE:N,TILE:X,WMS:Q,OSM:Y},n.controlAdapters={ZOOM:e.Zoom,ATTRIBUTION:S},n.Map=d,n}(),ot=et;export{ot as default};
7
+ */class B extends p{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 s={},i={};let o;for(o in e)o in this.options?i[o]=e[o]:s[o]=e[o];c.setOptions(this,i),this.wmsParams=c.extend({},this.defaultWmsParams,s)}setParams(t){c.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:f(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,s=this._map.getBounds().pad(e),i=new E(t,s,{opacity:0,pane:this.options.pane,headers:this.options.headers});i.addTo(this._map),this._currentOverlay&&this._currentOverlay.cancelLoad(),i.once("load",(()=>{this._map&&(i._url===this._currentUrl?(this._currentOverlay&&this._map.removeLayer(this._currentOverlay),this._currentOverlay=i,i.setOpacity(void 0!==this.options.opacity?this.options.opacity:1),!0===this.options.isBack&&i.bringToBack(),!1===this.options.isBack&&i.bringToFront(),void 0!==this.options.zIndex&&i.setZIndex(this.options.zIndex)):this._map.removeLayer(i))}),this);const{minZoom:o,maxZoom:n}=this.options;(o&&this._map.getZoom()<o||n&&this._map.getZoom()>n)&&this._map.removeLayer(i)}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,s=t.getBounds().pad(e),i=t.getSize();if(0!==this.options.viewPortBuffer){const t=e+1;i.x=Math.ceil(i.x*t),i.y=Math.ceil(i.y*t)}const o=parseFloat(this.wmsParams.version),n=this.options.crs||t.options.crs,r=o>=1.3?"crs":"srs";if(n){const t=n.project(s.getNorthWest()),e=n.project(s.getSouthEast()),a={width:i.x,height:i.y};a[r]=n.code,a.bbox=(o>=1.3&&n===h.EPSG4326?[e.y,t.x,t.y,e.x]:[t.x,e.y,e.x,t.y]).join(","),c.extend(this.wmsParams,a)}}getImageUrl(){const t=c.getParamString(this.wmsParams,this._url,this.options.uppercase||!1);return this._url+t}}function z(t){return class extends t{constructor(...t){super(...t),this.options.setViewDelay&&(this._update=function(t,e=10){let s;function i(...o){i.clear(),s=setTimeout((()=>{s=null,t.apply(this,o)}),e)}return i.clear=function(){s&&(clearTimeout(s),s=null)},i}(((...t)=>{u.prototype._update.call(this,...t)}),this.options.setViewDelay))}createTile(t,e){const s=this.getTileUrl(t),i=document.createElement("img");return i.abort=Z(s,(t=>{i.src=t,e(null,i)}),this.options.headers),(this.options.crossOrigin||""===this.options.crossOrigin)&&(i.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),i.alt="",i.setAttribute("role","presentation"),i}_abortLoading(){const t=this._tiles,e=this._tileZoom;for(const s in t)if(t[s].coords.z!==e){const e=t[s].el;e.onload=c.falseFn,e.onerror=c.falseFn,e.complete||(e.abort&&e.abort(),e.src=c.emptyImageUrl,d.remove(e),delete t[s])}}}}const A=z(class extends m{constructor(t,e){super(t,e),Object.assign(this.options,e)}});class U extends S{addLayer(t){if(this.options=Object.assign(this.options,t),t){const{url:e,...s}=t;if(e){const t={pane:this.pane,attribution:s.attribution,minZoom:s.minZoom,maxZoom:s.maxZoom,...s.nativeOptions};let i;return s.subdomains&&(t.subdomains=s.subdomains),i=s.headers?new A(e,{...t,headers:s.headers,setViewDelay:s.setViewDelay}):new m(e,t),i}}}}const W=z(class extends m.WMS{constructor(t,e){super(t,e)}});function I(t){return[[t[3],t[0]],[t[1],t[2]]]}class F{constructor(){this.options={target:"map"},this.layerAdapters=F.layerAdapters,this.controlAdapters=F.controlAdapters,this.emitter=new t,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:s,minZoom:i,maxBounds:o,mapAdapterOptions:n}=this.options;this.map=this.options.map||new y(this.options.target,{attributionControl:!1,zoomControl:!1,maxBounds:o?I(o):void 0,maxZoom:s,minZoom:i,center:e&&[e[1],e[0]],zoom:t,...n});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 s=this.map;if(s)if(Array.isArray(t)){const s=t,[i,o]=s;this.map&&("number"==typeof e?this.map.setView([o,i],e,{animate:!1}):this.setCenter([i,o]))}else{const{zoom:e,center:i,maxBounds:o,bounds:n,minZoom:r,maxZoom:a}=t;if(i&&void 0!==e?this.setView(i,e):(void 0!==e&&this.setZoom(e),i&&this.setCenter(i)),n&&this.fitBounds(n),void 0!==o)if(o){const t=I(o);s.setMaxBounds(t),s.setMinZoom(s.getBoundsZoom(t)),this._watchSizeChangeToUpdateMinZoom(t)}else s.setMaxBounds(null),this._stopWatchSizeChangeToUpdateMinZoom();void 0!==a&&s.setMaxZoom(a),void 0!==r&&(this._stopWatchSizeChangeToUpdateMinZoom(),s.setMinZoom(r))}}setCenter(t){const[e,s]=t;this.map&&this.map.panTo([s,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(),s=t.getNorthEast();return[e.lng,e.lat,s.lng,s.lat]}fitBounds(t,e={}){if(this.map){const{maxZoom:s,offset:i,padding:o}=e,n={};s&&(n.maxZoom=s),o&&(n.padding=[o,o]),i&&(n.padding=i),this.map.fitBounds(I(t),n)}}getLayerAdapter(t){return F.layerAdapters[t]}createControl(t,e){return L(t,e,this)}createButtonControl(t){return function(t,e){const i=document.createElement("a"),o=t.title||"";i.href="#",i.title=o,i.setAttribute("role","button"),i.setAttribute("aria-label",o),t.addClass&&i.classList.add(t.addClass),s.disableClickPropagation(i),s.on(i,"click",s.stop),t.html instanceof HTMLElement?i.appendChild(t.html):"string"==typeof t.html&&(i.innerHTML=t.html);const n=e=>{e.stopPropagation(),t.onClick()};return L({onAdd:()=>(void 0!==t.onClick&&i.addEventListener("click",n),i),onRemove(){const e=i.parentNode;e&&e.removeChild(i),void 0!==t.onClick&&i.removeEventListener("click",n)}},{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,s){}onMapClick(t){const e=P(t);this.emitter.emit("preclick",e),this.emitter.emit("click",e)}locate(t,e){const s=this.map;if(s&&(s.locate(t),e)){const{locationfound:t,locationerror:i}=e,o=e=>{t({lngLat:[e.latlng.lng,e.latlng.lat]})};void 0!==t&&s.on("locationfound",o,this),i&&s.on("locationerror",i,this);return{stop:()=>{void 0!==t&&s.off("locationfound",o),i&&s.off("locationerror",i)}}}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(),s=this.map;e&&s&&window.ResizeObserver&&(this._resizeObserver=new ResizeObserver((()=>{s.setMinZoom(s.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,P(t))),t)}}}F.layerAdapters={GEOJSON:class extends S{constructor(t,e){super(t,e),this.selected=!1,this._layers=[],this._selectedLayers=[],this._filteredLayers=[],this._openedPopup=[],this.$updateTooltip=f((()=>{this.updateTooltip()}),300),this.$unselect=()=>{this.unselect()}}addLayer(t){return Object.assign(this.options,t),this.paint=t.paint,this.layer=new o([],{...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._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._setPaintEachLayer(this.paint),this._selectedLayers.length=0,this.selected=!1}}getSelected(){return this._selectedLayers.map((t=>({target:this,feature:t.feature,layer:t,...T(t.feature)})))}getFiltered(){return this._filteredLayers}filter(t){this._filterFun=t;const e=this.layer,s=e&&e._map;if(e&&s){e.remove();const i=[];this._layers.forEach((({feature:s,layer:o})=>{if(o){!t||t({target:this,feature:s,layer:o,...T(s)})?(e.addLayer(o),i.push({target:this,feature:s,layer:o,...T(s)})):e.removeLayer(o)}})),this._filteredLayers=i,e.addTo(s)}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,...T(e)})))}clearLayer(t){this.unselect();const e=this.layer;if(e)if(t)for(let s=this._layers.length;s--;){const i=this._layers[s];if(i){const{feature:o,layer:n}=i;if(o&&n){t(o)&&(e.removeLayer(n),this._layers.splice(s,1))}}}else e.clearLayers(),this._layers=[]}setData(t){this.clearLayer(),this.addData(t)}addData(t){const e=this.options;let s;if(e){if(t){let i;if(e.type)i=e.type;else{const e=function(t){let e;e="FeatureCollection"===t.type?k(t.features.map((t=>t.geometry.type))):"GeometryCollection"===t.type?k(t.geometries.map((t=>t.type))):"Feature"===t.type?t.geometry.type:t.type;return e}(t);i=O[e]}if(this.type&&this.type!==i)return void console.warn("no other data type than layer can be added");this.type=i,t=function(t,e){if("FeatureCollection"===t.type)t.features=t.features.filter((t=>x(t.geometry.type,e)));else if("Feature"===t.type){if(!x(t.geometry.type,e))return!1}else"GeometryCollection"===t.type&&(t.geometries=t.geometries.filter((t=>x(t.type,e))));return t}(t,i),t&&(s=this._getGeoJsonOptions(e,i))}new i(t||void 0,s)}}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 b(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._setPaint(e,t)}}setSelectedPaint(t){if(t){this.selectedPaint=t;for(const e of this._selectedLayers)this._setPaint(e,t)}}updatePaint(t){this.paint={...this.paint,...t};for(const e of this._layers)this._setPaint(e,this.paint)}updateSelectedPaint(t){this.selectedPaint={...this.selectedPaint,...t};for(const e of this._selectedLayers)this._setPaint(e,this.selectedPaint)}_updateTooltip(t){const{feature:e,layer:s}=t;if(e&&s&&e.properties&&this.options.labelField){s.unbindTooltip();const t=e.properties[this.options.labelField];if(void 0!==t){const e=!this.options.labelOnHover;s.bindTooltip(String(t),{permanent:e,sticky:!1})}}}async _openPopup(t,e={},s,i){var o,n;const{feature:r,layer:a}=t,{minWidth:l,autoPan:p,maxWidth:c,closeButton:h}={minWidth:300,...e},u=null!=h?h:!this.options.selectOnHover;let d;const m=[],y=t=>{m.push(t)},f=()=>{d&&this._removePopup(d)};let g;if(g=e.createPopupContent?await e.createPopupContent({layer:a,feature:r,target:this,type:s,close:f,onClose:y,...T(r)}):e.popupContent,g&&a){const e={minWidth:l,autoPan:p,closeButton:u,closeOnClick:!1,autoClose:!1};_(c)&&(e.maxWidth=c),d=a.bindPopup(g,e);if(null===(n=null===(o=this.options.popupOptions)||void 0===o?void 0:o.unselectOnClose)||void 0===n||n){const t=a.getPopup();t&&t.once("remove",(()=>{f()}),this)}this._openedPopup.push([d,m,t]),d.openPopup(i)}}_removePopup(t){var e,s;if(this.map){t.closePopup().unbindPopup();const i=this._openedPopup.findIndex((e=>e[0]===t));if(-1!==i){const t=null===(s=null===(e=this.options.popupOptions)||void 0===e?void 0:e.unselectOnClose)||void 0===s||s,[,o,n]=this._openedPopup[i];for(const e of o)e(n);o.length=0,t&&this._unSelectLayer(n),this._openedPopup.splice(i,1)}}}_setPaintEachLayer(t){this._layers.forEach((e=>{this._setPaint(e,t)}))}_setPaint(t,e){let s;const{layer:i,feature:o}=t;if(i&&o&&(g(e)?s=e(o):v(e)&&(s=e),s))if("point"===this.type&&"icon"===s.type){const t=i,e=this._createDivIcon(s);t.setIcon(e)}else"setStyle"in i&&i.setStyle(this._preparePaint(s))}_preparePaint(t){if("get-paint"!==t.type){const e="line"===this.type?[["color","strokeColor"],["opacity","strokeOpacity"],["weight","weight"]]:[["color","strokeColor"],["opacity","strokeOpacity"],["stroke","stroke"],["fillColor","fillColor"],["fillOpacity","fillOpacity"],["fill","fill"],["weight","weight"]],s={};"radius"in t&&"number"==typeof t.radius&&(s.radius=t.radius);for(const[i,o]of e){let e=t[o];_(this.options.opacity)&&-1!==o.toLowerCase().indexOf("opacity")&&(e=Number(e)*this.options.opacity),void 0!==e&&Object.defineProperty(s,i,{enumerable:!0,value:e})}return s}return C}_getGeoJsonOptions(t,e){const s=t.paint;let i={};return"function"==typeof s?"point"===e?i.pointToLayer=(t,e)=>{const i=s(t);return this._createPaintToLayer(i)(t,e)}:i={style:t=>this._preparePaint(t?{...C,...s(t)}:{...C,type:"path"})}:i=this._createPaintOptions(s,e),i.onEachFeature=(t,e)=>{this._onEachFeature(t,e)},i}_onEachFeature(t,e){const s=this.layer;if(s){const i={target:this,feature:t,layer:e,...T(t)};e.options.pane=this.pane,this._layers.push(i);let o=!0;if(this._filterFun&&(o=this._filterFun(i)),o){const{popup:o,popupOptions:n,selectable:r,interactive:a,selectOnHover:l}=this.options;e.options.interactive=!_(a)||a,s.addLayer(e),r&&(l?(e.on("mouseover",(()=>{this._selectLayer(i,"hover")})),e.on("mouseout",(()=>{this._unSelectLayer(i)}))):e.on("click",(t=>this._selectOnLayerClick(t)),this)),this._handleMouseEvents(e),setTimeout((()=>{o&&this._openPopup({target:this,layer:e,feature:t,...T(t)},n,"api"),this._updateTooltip({layer:e,feature:t})}))}}}_handleMouseEvents(t){const{onClick:e,onLayerClick:s,onMouseOut:i,onMouseOver:o}=this.options,n=e||s;n&&t.on("click",(e=>{const s=!!this._getSelected(t);n({selected:s,...this._createMouseEvent(e)})}),this),i&&t.on("mouseout",(t=>{i(this._createMouseEvent(t))}),this),o&&t.on("mouseover",(t=>{o(this._createMouseEvent(t))}),this)}_createMouseEvent(t){return function({layer:t,source:e}){const s=e.target.feature;return{layer:t,feature:s,event:P(e),source:e,...T(s)}}({layer:this,source:t})}_getSelected(t){return this._selectedLayers.find((e=>e.layer===t))}_selectOnLayerClick(t){s.stopPropagation(t);const e=t.target,i=e.feature,o={target:this,layer:e,feature:i,...T(i)},n=this._getSelected(e);n?this.options&&this.options.unselectOnSecondClick&&this._unSelectLayer(n):this._selectLayer(o,"click",t.latlng)}_selectLayer(t,e,s){const{multiselect:i}=this.options;i||(this.map._addUnselectCb((()=>{this._unSelectLayer(t)})),this._selectedLayers.forEach((t=>this._unSelectLayer(t)))),this._selectedLayers.push(t),this.selected=!0;const{selectedPaint:o,popupOnSelect:n,popupOptions:r}=this.options;if(o&&t.layer&&this._setPaint(t,o),n&&this._openPopup(t,r,e,s),this.options.onSelect){const s=t.feature?[t.feature]:[];this.options.onSelect({type:e,layer:this,features:s,...T(s)})}}_unSelectLayer(t){const e=this._selectedLayers.indexOf(t);-1!==e&&(this._selectedLayers.splice(e,1),this.options&&(this.options.paint&&this._setPaint(t,this.options.paint),this.options.popupOnSelect&&t.layer&&this._removePopup(t.layer))),this.selected=this._selectedLayers.length>0}_createDivIcon(t){const{...e}=t;return new n({className:"",...e})}_createPaintToLayer(t){if(t&&t.type)if("icon"===t.type){if(t.className||t.html)return(e,s)=>{const i=this._createDivIcon(t);return new r(s,{icon:i})}}else if("pin"===t.type)return(t,e)=>new r(e);return(e,s)=>new a(s,this._preparePaint({...C,...t}))}_createPaintOptions(t,e){const s={},i=t&&this._preparePaint(t)||{};return t&&(s.style=()=>i),"point"===e?s.pointToLayer=this._createPaintToLayer(t):"line"===e&&(i.stroke=!0),s}_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:s}=this.options;this._addMapClickListener(),e&&!s&&(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 S{addLayer(t){const e=t&&t.url;if(e){const s=(t={transparent:!0,...t}).updateWmsParams;if(this.layer=new B(e,{pane:this.pane,headers:t.headers,setViewDelay:t.setViewDelay,...t,...t.params,...t.nativeOptions}),s){const t=this.layer.updateWmsParams;this.layer.updateWmsParams=function(e){t.call(this,e),this.wmsParams=s(this.wmsParams)}}return this.layer}}},TILE:U,WMS:class extends S{addLayer(t){Object.assign(this.options,t);const{url:e,...s}=t;if(e){const i={pane:this.pane,attribution:s.attribution,minZoom:s.minZoom,maxZoom:s.maxZoom,layers:t.layers,format:t.format,...t.nativeOptions};let o;return o=s.headers?new W(e,{...i,headers:s.headers}):new m.WMS(e,i),o}}},OSM:class extends U{addLayer(t){return super.addLayer({name:"OpenStreetMap",attribution:'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',...t,url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"})}}},F.controlAdapters={ZOOM:e.Zoom,ATTRIBUTION:class extends e.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)))}}}},F.Map=y;var D=F;export{D as default};
8
8
  //# sourceMappingURL=leaflet-map-adapter.esm-bundler.prod.js.map