@nextgis/ngw-map 1.8.1 → 1.8.2
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/ngw-map.cjs.js +1 -1
- package/lib/ngw-map.esm-browser.js +6 -4
- package/lib/ngw-map.esm-browser.js.map +1 -1
- package/lib/ngw-map.esm-browser.prod.js +1 -1
- package/lib/ngw-map.esm-browser.prod.js.map +1 -1
- package/lib/ngw-map.esm-bundler.js +1 -1
- package/lib/ngw-map.global.js +7 -4
- package/lib/ngw-map.global.js.map +1 -1
- package/lib/ngw-map.global.prod.js +1 -1
- package/lib/ngw-map.global.prod.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e,t={exports:{}},r="object"==typeof Reflect?Reflect:null,s=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}t.exports=o,t.exports.once=function(e,t){return new Promise((function(r,s){function i(r){e.removeListener(t,o),s(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}m(e,t,o,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&m(e,"error",t,r)}(e,i,{once:!0})}))},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var n=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function h(e,t,r,s){var i,o,n,h;if(a(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),n=o[t]),void 0===n)n=o[t]=r,++e._eventsCount;else if("function"==typeof n?n=o[t]=s?[r,n]:[n,r]:s?n.unshift(r):n.push(r),(i=c(e))>0&&n.length>i&&!n.warned){n.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+n.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=n.length,h=l,console&&console.warn&&console.warn(h)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,r){var s={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=l.bind(s);return i.listener=r,s.wrapFn=i,i}function u(e,t,r){var s=e._events;if(void 0===s)return[];var i=s[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):y(i,i.length)}function d(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function y(e,t){for(var r=new Array(t),s=0;s<t;++s)r[s]=e[s];return r}function m(e,t,r,s){if("function"==typeof e.on)s.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(o){s.once&&e.removeEventListener(t,i),r(o)}))}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return n},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");n=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var n;if(t.length>0&&(n=t[0]),n instanceof Error)throw n;var a=new Error("Unhandled error."+(n?" ("+n.message+")":""));throw a.context=n,a}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)s(c,this,t);else{var h=c.length,l=y(c,h);for(r=0;r<h;++r)s(l[r],this,t)}return!0},o.prototype.on=o.prototype.addListener=function(e,t){return h(this,e,t,!1)},o.prototype.prependListener=function(e,t){return h(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,p(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,p(this,e,t)),this},o.prototype.off=o.prototype.removeListener=function(e,t){var r,s,i,o,n;if(a(t),void 0===(s=this._events))return this;if(void 0===(r=s[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){n=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(s[e]=r[0]),void 0!==s.removeListener&&this.emit("removeListener",e,n||t)}return this},o.prototype.removeAllListeners=function(e){var t,r,s;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,o=Object.keys(r);for(s=0;s<o.length;++s)"removeListener"!==(i=o[s])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this},o.prototype.listeners=function(e){return u(this,e,!0)},o.prototype.rawListeners=function(e){return u(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},o.prototype.listenerCount=d,o.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]};class f extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,f.prototype)}}class g{constructor(e={}){this.options=e,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(e){this._promises.has(e)&&(this._promises.delete(e),this._onStop())}get(e){return this._promises.get(e)}add(e,t){const r=t||e,s=this._promises.get(r);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),s||(this._promises.set(r,e),e.finally((()=>{this.remove(r)})),e)}abort(){this.isLoaded&&(this._promises.forEach((e=>{e.cancel&&e.cancel()})),this._promises.clear(),this._onStop())}waitFunc(e,t=""){const r=this.get(t=t||e.name);return r||this.add(e(),t)}WaitForMe(e=""){const t=this.get.bind(this),r=this.add.bind(this);return function(s,i,o){const n=o.value;return e=e||i,o.value=function(...s){const i=t(e);if(i)return i;return r(n.apply(this,s),e)},o}}GetOrCreateDecorator(e=""){return this.WaitForMe(e)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}class _ extends Error{constructor(){super(),this.name="TimeoutError",Object.setPrototypeOf(this,_.prototype)}}const v=(e,t,r,s)=>{try{e(r(s))}catch(e){t(e)}};let w=0;class b{constructor(e,t){this.id=w++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise(((e,t)=>{this._setCanceledCallback=t=>e(t||new f)}));const r=[this._cancelPromise,new Promise(((t,r)=>e((e=>{e instanceof b?this.attach(e):this._isPending=!1,t(e)}),(e=>{this._isPending=!1,r(e)}),(e=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(e)}))))];t&&r.push(new Promise(((e,r)=>{setTimeout((()=>{if(this._isPending)try{this.cancel()}finally{r(new _)}}),t)}))),this._promise=Promise.race(r)}static createControl(e){return new g(e)}static resolve(e){return new b((t=>t(e)))}static reject(e){return new b(((t,r)=>r(e)))}static all(e){return new b(((t,r)=>{Promise.all(e).then(t).catch(r)})).catch((t=>{if(t instanceof this.CancelError)for(const t of e)"cancel"in t&&t.cancel();throw t}))}attach(e){this._isCanceled?e.cancel():this._children.push(e)}then(e,t){const r=new b(((r,s)=>{if(this._promise){const i=e=>{t?v(r,s,t,e):s(e)};this._promise.then((t=>{this._isCanceled?i(t):e?v(r,s,e,t):r(t)}),i)}}));return r._parentPromise=this,this._children.push(r),r}catch(e){return this._isCanceled&&e&&e(new f),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new f:e)}cancel(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;const e=this._getTopParent();if(e&&e.cancel(),this._children&&this._children.forEach((e=>e.cancel())),this._isPending){if(this._cancelHandlers.length)try{for(const e of this._cancelHandlers)e()}catch(e){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let e=this._parentPromise,t=!!e;for(;t;)e&&e._parentPromise?(e=e._parentPromise,t=!!e):t=!1;return e}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}b.CancelError=f,b.TimeoutError=_,b.PromiseControl=g,Object.setPrototypeOf(b.prototype,Promise.prototype);var L=b;function O(e,t,r={}){const s=function(e,t=[]){for(;null!==e;e=Object.getPrototypeOf(e)){const r=Object.getOwnPropertyNames(e);for(let e=0;e<r.length;e++)-1==t.indexOf(r[e])&&t.push(r[e])}return t}(e.prototype);const i=void 0===r.replace||r.replace;t.forEach((t=>{Object.getOwnPropertyNames(t.prototype).forEach((r=>{const o=-1!==s.indexOf(r);if(!i&&!o||i){const s=Object.getOwnPropertyDescriptor(t.prototype,r);s&&Object.defineProperty(e.prototype,r,s)}}))}))}function E(e){return null!=e}function C(e,t,r=!1){let s=e;const i=t,o=Array.isArray(i);let n=o&&[]||{};return o&&Array.isArray(i)?r?(s=s||[],n=n.concat(s),i.forEach(((e,t)=>{void 0===n[t]?n[t]=e:"object"==typeof e?n[t]=C(s[t],e,r):-1===s.indexOf(e)&&n.push(e)}))):n=i:(s&&"object"==typeof s&&Object.keys(s).forEach((function(e){n[e]=s[e]})),Object.keys(i).forEach((function(e){n[e]="object"==typeof i[e]&&i[e]&&"object"==typeof s[e]&&"object"==typeof i[e]?C(s[e],i[e],r):i[e]}))),n}function I(e){if(!e.lngLat&&e.latLng){e.lngLat=[e.latLng.lng,e.latLng.lat]}return e}function P(e){return{type:"Polygon",coordinates:[A(e)]}}function A(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}const M=Math.PI/180,x=180/Math.PI;function k(e,t){t=t>85.06?85.06:t<-85.06?-85.06:t;const r=20037508.34*e/180;let s=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return s=20037508.34*s/180,[r,s]}function S(e,t,r,s){if(e instanceof Array)return t instanceof Array&&t.sort().join("")===e.sort().join("");if(e instanceof Date)return t instanceof Date&&""+e==""+t;if(e instanceof Function){if(!(t instanceof Function))return!1}else if(e instanceof Object)return t instanceof Object&&(e===r?t===s:N(e,t));return e===t}function N(e,t){const r=Object.keys(e).sort(),s=Object.keys(t).sort();if(r.length!==s.length)return!1;if(r.join("")!==s.join(""))return!1;for(let i=0;i<r.length;i++){if(!S(e[r[i]],t[s[i]],e,t))return!1}return!0}function T(e){const t={};return Object.keys(e).forEach((r=>{e[r]instanceof Array||e[r]!==Object(e[r])?void 0!==e[r]&&(t[r]=e[r]):t[r]=T(e[r])})),t}function B(e){return"[object Object]"===Object.prototype.toString.call(e)}function R(e){return e.replace(/([^:]\/)\/+/g,"$1")}function F(e){return"function"==typeof e}const j={get:function(e,t){return e.properties&&e.properties[t[0]]},match:function(e,t){const[r,...s]=t;let i=r;Array.isArray(r)&&(i=z(e,r));const o=s.splice(-1,s.length%2)[0];for(let e=0;e<s.length-1;e+=2){if(s[e]===i)return s[e+1]}return o}};function z(e,t){const[r,...s]=t,i=j[r];if(i)return i(e,s)}function D(e){return t=>z(t,e)}const $=["iconSize","iconAnchor"];function G(e,t,r){if((t=String(t))===(e=String(e)))return!0;if(r&&t.toUpperCase()===e.toUpperCase())return!0;const s=`^${i=t,i.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}$`.replace(/%/g,".*").replace("_",".");var i;return null!==new RegExp(s,r?"i":"").exec(e)}const U={gt:(e,t)=>e>t,lt:(e,t)=>e<t,ge:(e,t)=>e>=t,le:(e,t)=>e<=t,eq:(e,t)=>e===t,ne:(e,t)=>e!==t,in:(e,t)=>-1!==t.indexOf(e),notin:(e,t)=>-1===t.indexOf(e),like:(e,t)=>G(e,t),ilike:(e,t)=>G(e,t,!0)};function V(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function Z(e){return V(e)}function q(e,t){const r="string"==typeof t[0]?t[0]:"all",s=t=>{if(V(t)){const[r,s,i]=t,o=U[s];if(o){if(("like"===s||"ilike"===s)&&"string"==typeof r){let t="";const s=r.replace(/^%?(\w+)%?$/,((s,o)=>(t=e[o],r.replace(o,i))));return o(t,s)}return o(e[r],i)}return!1}return q(e,t)},i=t.filter((e=>Array.isArray(e)));return"any"===r?i.some(s):i.every(s)}function W(e){let t={};const r=[];return e.forEach((e=>{e&&(Array.isArray(e)?r.push(e):t=e)})),e=>{const s=r.find((t=>function(e,t){const r={...e.properties};return!!r&&(r.$id=e.id,q(r,t))}(e,t[0])));return s?{...t,...s[1]}:t}}function H(e,t,r){if(!e)throw new Error("paint is empty");let s={...t};if(F(e)){const s=s=>{const i=H(e(s),t,r);return i.type=e.type,i};return s.type=e.type,s}if(function(e){return!!Array.isArray(e)}(e))return s=>H(W(e)(s),t,r);if("get-paint"===e.type){const i=function(e,t){if("function"==typeof e.from)return e.from(e.options);if("string"==typeof e.from&&t){const r=t[e.from];if(r)return r(e.options)}}(e,r);i&&(s=H(i,t,r))}else{if("icon"===e.type)return e;{const i=function(e){let t=!1;const r={};for(const s in e)if(-1===$.indexOf(s)){const i=s,o=e[i];Array.isArray(o)&&(t=!0,r[i]=D(o))}if(t)return t=>{const s={};for(const e in r)s[e]=r[e](t);return{...e,...s}}}(e);if(i)return e=>H(i(e),t,r);s={...s,...e},s.fill=void 0===s.fill||s.fill,s.stroke=void 0!==s.stroke?s.stroke:!s.fill||!(!s.strokeColor&&!s.strokeOpacity)}}return F(s)||("color"in s&&(s.strokeColor||(s.strokeColor=s.color),s.fillColor||(s.fillColor=s.color)),"opacity"in s&&(void 0===s.strokeOpacity&&(s.strokeOpacity=s.opacity),void 0===s.fillOpacity&&(s.fillOpacity=s.opacity))),s}function J(e){const t={};for(let r=0;r<e.length;r++)t[e[r]]=1+(t[e[r]]||0);let r;for(const e in t){t[e]>((void 0!==r?t[r]:0)||0)&&(r=e)}return r}function Q(e){let t;if("FeatureCollection"===e.type){t=J(e.features.map((e=>e.geometry.type)))}else if("GeometryCollection"===e.type){t=J(e.geometries.map((e=>e.type)))}else t="Feature"===e.type?e.geometry.type:e.type;return t}const K={polygon:"path",line:"path",point:"circle"},Y={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon"};function X(e){if(e.data){const t=Y[Q(e.data)],r=e.paint;r&&"[object Object]"===Object.prototype.toString.call(r)&&(r.type=r.type?r.type:"polygon"===t||"line"===t?"path":"html"in r||"className"in r?"icon":K[t]),e.type=e.type||t}return e}class ee{constructor(){this.backspace=8,this.tab=9,this.enter=13,this.shift=16,this.ctrl=17,this.alt=18,this["pause/break"]=19,this.caps_lock=20,this.escape=27,this.page_up=33,this.page_down=34,this.end=35,this.home=36,this.left_arrow=37,this.up_arrow=38,this.right_arrow=39,this.down_arrow=40,this.insert=45,this.delete=46,this.left_window_key=91,this.right_window_key=92,this.select_key=93,this.numpad_0=96,this.numpad_1=97,this.numpad_2=98,this.numpad_3=99,this.numpad_4=100,this.numpad_5=101,this.numpad_6=102,this.numpad_7=103,this.numpad_8=104,this.numpad_9=105,this.multiply=106,this.add=107,this.subtract=109,this.decimal_point=110,this.divide=111,this.f1=112,this.f2=113,this.f3=114,this.f4=115,this.f5=116,this.f6=117,this.f7=118,this.f8=119,this.f9=120,this.f10=121,this.f11=122,this.f12=123,this.num_lock=144,this.scroll_lock=145,this["semi-colon"]=186,this.equal_sign=187,this[","]=188,this["-"]=189,this["."]=190,this["/"]=191,this["`"]=192,this["["]=219,this["\\"]=220,this["]"]=221,this["'"]=222}}class te{constructor(e,t){this.webMap=e,t&&(t.value&&this.setValue(t.value),t.name&&(this.name=t.name),t.event&&(this.event=t.event))}getValue(){return this.value}setValue(e){this.value=e}}class re extends te{constructor(){super(...arguments),this.name="center",this.event="moveend"}getValue(){return this.webMap.getCenter()}setValue(e){this.webMap.setCenter(e)}toString(e){const t=e.map((e=>e.toFixed(5)));return t[0]+"_"+t[1]}parse(e){return e.split("_").map(Number)}}class se extends te{constructor(){super(...arguments),this.name="zoom",this.event="zoomend"}getValue(){const e=this.webMap.getZoom();return void 0!==e?Math.round(e):void 0}setValue(e){this.webMap.setZoom(e)}toString(e){return String(e)}parse(e){return Number(e)}}let ie=0;const oe={minZoom:0,maxZoom:20,paint:{color:"blue",opacity:.4,strokeOpacity:1,stroke:!0,radius:8,weight:1},selectedPaint:{color:"darkblue",opacity:.4,strokeOpacity:1,stroke:!0,radius:12,weight:1},create:!0};class ne{constructor(e){this.options=oe,this.emitter=new t.exports.EventEmitter,this.keys=ne.keys,this.runtimeParams=[],this.getPaintFunctions=ne.getPaintFunctions,this.mapState=[re,se],this.id=ie++,this._initMapState={},this._mapState=[],this._eventsStatus={},this._mapEvents={},this.mapAdapter=e.mapAdapter,this._starterKits=e.starterKits||[],e&&(this.options=C(oe||{},e)),this.options.runtimeParams&&(this.runtimeParams=this.options.runtimeParams),this._addEventsListeners(),this.options.tileJson&&this._setTileJsonOptions(this.options.tileJson),this.options.create&&this.create()}getId(){return this.id}async create(){return this.getEventStatus("create")||(await this._setInitMapState(this.mapState),await this._setupMap(),this._emitStatusEvent("create",this)),this}setRuntimeParams(e){this.runtimeParams.push(e)}destroy(){this._removeEventListeners(),function(e){for(const t in e)delete e[t]}(this._emitStatusEvent),this.mapAdapter.destroy&&this.mapAdapter.destroy()}getState(){const e={};return this._mapState.forEach((t=>{e[t.name]=t.getValue()})),e}getRuntimeParams(){const e={};return this._mapState.forEach((t=>{for(const r of this.runtimeParams){const s=r.get(t.name);if(void 0!==s){e[t.name]=t.parse(s);break}}})),e}getContainer(){if(this.mapAdapter.getContainer)return this.mapAdapter.getContainer();if(this.options.target){if(this.options.target instanceof HTMLElement)return this.options.target;if("string"==typeof this.options.target){const e=document.getElementById(this.options.target);if(e)return e}}}setCursor(e){this.mapAdapter.setCursor&&this.mapAdapter.setCursor(e)}getCursor(){if(this.mapAdapter.getCursor)return this.mapAdapter.getCursor();const e=this.getContainer();return e?e.style.cursor:void 0}setCenter(e){return this.mapAdapter.setCenter(e),this}getCenter(){return this.mapAdapter.getCenter()}getBounds(){if(this.mapAdapter.getBounds)return this.mapAdapter.getBounds()}getBoundsPolygon(){const e=this.getBounds();if(e){return{type:"Feature",properties:{},geometry:P(e)}}}setZoom(e){return this.mapAdapter.setZoom(e),this}getZoom(){return this.mapAdapter.getZoom()}zoomIn(){if(this.mapAdapter.zoomIn)this.mapAdapter.zoomIn();else{const e=this.getZoom();if(e){this.setZoom(e+1)}}}zoomOut(){if(this.mapAdapter.zoomOut)this.mapAdapter.zoomOut();else{const e=this.getZoom();if(e){this.setZoom(e-1)}}}setView(e,t){this.mapAdapter.setView&&e&&E(t)?this.mapAdapter.setView(e,t):(e&&this.mapAdapter.setCenter(e),E(t)&&this.mapAdapter.setZoom(t))}fitBounds(e,t){return e.every((e=>E(e)))&&(e[1]<-85.06&&(e[1]=-85.06),e[3]>85.06&&(e[3]=85.06),this.mapAdapter.fitBounds(e,t)),this}getEventStatus(e){const t=this._eventsStatus[e];return null!=t&&t}onLoad(e="create"){return new Promise((t=>{this.getEventStatus(e)?t(this):this.emitter.once(e,(()=>{t(this)}))}))}onMapLoad(e){return new Promise((t=>{var r;const s=()=>{const r=this.mapAdapter;e&&e(r),r&&t(r)},i=null===(r=this.mapAdapter.isLoaded)||void 0===r||r;this.mapAdapter.map&&i?s():this.mapAdapter.emitter.once("create",(()=>{s()}))}))}getLayerAdapters(){return this.mapAdapter.layerAdapters}getLayerAdapter(e){return this.mapAdapter.layerAdapters[e]}locate(e,t){if(this.mapAdapter&&this.mapAdapter.locate)return this.mapAdapter.locate(e,t);return{stop:()=>({})}}stopGetCoordFromMapClick(){this._coordFromMapClickPromise&&this._coordFromMapClickPromise.cancel()}getCoordFromMapClick(){return this._coordFromMapClickPromise?this.getCoordFromMapClick():(this._coordFromMapClickPromise=new L(((e,t,r)=>{const s=this.getCursor()||"grab";this._removeEventListeners({include:["click"]}),this.setCursor("crosshair");const i=()=>{this.setCursor(s),this._addEventsListeners({include:["click"]}),this.mapAdapter.emitter.off("click",o),this._coordFromMapClickPromise=void 0},o=t=>{i(),I(t),e(t.lngLat)};this.mapAdapter.emitter.once("click",o),r(i)})),this._coordFromMapClickPromise)}_emitStatusEvent(e,t){const r=e;this._eventsStatus[r]=!0,this.emitter.emit(r,t)}async _addLayerProviders(){}async _onLoadSync(){}async _setupMap(){if(!this.mapAdapter)throw new Error("WebMap `mapAdapter` option is not set");return await this.mapAdapter.create(this.options),this._zoomToInitialExtent(),await this._addLayerProviders(),await this._onLoadSync(),this._emitStatusEvent("build-map",this.mapAdapter),this}_setTileJsonOptions(e){e.center&&(this.options.center=e.center),e.bounds&&(this.options.bounds=e.bounds),E(e.maxzoom)&&(this.options.maxZoom=e.maxzoom,this.options.zoom=e.maxzoom),E(e.minzoom)&&(this.options.minZoom=e.minzoom,this.options.zoom=e.minzoom),E(e.maxzoom)&&E(e.minzoom)&&(this.options.zoom=(e.maxzoom+e.minzoom)/2)}_zoomToInitialExtent(){const{center:e,zoom:t,bounds:r}=this.options;this._extent?this.fitBounds(this._extent):e&&t?this.setView(e,t):r&&this.fitBounds(r)}_setInitMapState(e){for(const t of e){const e=new t(this);this._mapState.push(e);for(const t of this.runtimeParams){const r=t.get(e.name);if(void 0!==r){const t=e.parse(r);this._initMapState[e.name]=t,Object.defineProperty(this.options,e.name,{value:t,configurable:!0,enumerable:!0});break}}}}_addEventsListeners(e){let t=["preclick","click","zoomstart","zoom","zoomend","movestart","move","moveend"];e&&e.include&&(t=t.filter((t=>e.include.includes(t)))),t.forEach((e=>{this._mapEvents[e]=t=>{if(this.runtimeParams.length){const t=this._mapState.find((t=>t.event===e));if(t){const e=t.toString(t.getValue());this.runtimeParams.forEach((r=>{r.set(t.name,e)}))}}this._eventsStatus&&this.emitter.emit(e,t)};const t=this._mapEvents[e];t&&this.mapAdapter.emitter.on(e,t)}))}_removeEventListeners(e){let t=Object.entries(this._mapEvents);e&&e.include&&(t=t.filter((t=>e.include.includes(t[0])))),t.forEach((([e,t])=>{t&&this.mapAdapter.emitter.removeListener(e,t)}))}}ne.keys=new class{constructor(){this.keyCodeAlias=new ee,this.keys={},this._windowOnFocus=this.windowOnFocus.bind(this),this._keysPressed=this.keysPressed.bind(this),this._keysReleased=this.keysReleased.bind(this),this.addKeyboardEventsListener()}pressed(e){const t=this.keyCodeAlias[e];return!!t&&this.keys[t]}addKeyboardEventsListener(){"undefined"!=typeof window&&(window.addEventListener("focus",this._windowOnFocus,!1),window.addEventListener("keydown",this._keysPressed,!1),window.addEventListener("keyup",this._keysReleased,!1))}removeKeyboardEventsListener(){"undefined"!=typeof window&&(window.removeEventListener("focus",this._windowOnFocus,!1),window.removeEventListener("keydown",this._keysPressed,!1),window.removeEventListener("keyup",this._keysReleased,!1))}keysPressed(e){e.stopPropagation(),this.keys[e.keyCode]||(this.keys[e.keyCode]=!0)}keysReleased(e){e.stopPropagation(),this.keys[e.keyCode]=!1}windowOnFocus(){this.keys={}}};class ae extends ne{constructor(e){super(e),this._layersIdCounter=1,this._layersOrderCounter=1,this._baselayers=[],this._layers={},this._selectedLayers=[];const t=this.options.tileJson;t&&this.emitter.once("build-map",(()=>this.addTileJsonLayer(t)))}async fitLayer(e,t){const r=this.getLayer(e),s=r&&(r.getBounds||r.getExtent);if(s){const e=await s.call(r);e&&this.fitBounds(e,t)}}isBaseLayer(e){const t=this.getLayer(e);if(t&&t.id)return-1!==this._baselayers.indexOf(t.id)}getBaseLayers(){const e=[];return this._baselayers.forEach((t=>{const r=this._layers[t];r&&e.push(r)})),e}getBaseLayersIds(){return this._baselayers}getLayer(e){return"string"==typeof e?this._layers[e]:e}getLayerId(e){const t=this.getLayer(e);if(t&&t.options)return t.options.id;throw new Error("No id for layer")}getLayers(){return Object.keys(this._layers)}allLayers(){return this._layers}orderedLayers(){return Object.values(this._layers).sort(((e,t)=>e.order&&t.order?e.order-t.order:0))}findLayer(e){for(const t in this._layers){const r=this._layers[t];if(e(r))return r}}isLayerVisible(e){const t=this.getLayer(e);return!(!t||void 0===t.options.visibility)&&t.options.visibility}async addBaseLayer(e,t){return await this.addLayer(e,{...t,baselayer:!0},void 0)}async addLayer(e,t={},r){var s,i;const o=this._layersIdCounter++,n=E(r)?r:void 0!==t.order?t.order:this.reserveOrder();let a;"string"==typeof e?a=this.getLayerAdapter(e):"function"==typeof e?a=e:"then"in e&&(a=await e);const c=t;this._updateGeoJsonOptions(c);const{maxZoom:h,minZoom:l}=this.options,p=null===(s=(t={id:String(o),order:n,maxZoom:h,minZoom:l,...t}).visibility)||void 0===s||s;if(t.visibility=!1,t.baselayer&&(t.order=0),this.options.onBeforeAddLayer){const e=this.options.onBeforeAddLayer({options:t,adapter:a});e&&(e.options&&(t=e.options),e.adapter&&(a=e.adapter))}if(void 0!==a){const e=new a(this.mapAdapter.map,t);let r;e.options={...t,...e.options},e.options.baselayer&&(t.baselayer=!0,t.order=0,e.options.order=0),e.options.id&&(r=String(e.options.id),this._layers[r]=e),this._emitLayerEvent("layer:preadd",r||"",e),await this.onMapLoad(),e.map=this.mapAdapter.map;const s=await e.addLayer(e.options);if(e.layer=s,e.id=e.options.id||String(o),e.options.id=e.id,t.baselayer&&(e.options.order=0),e.order=null!==(i=e.options.order)&&void 0!==i?i:n,r&&delete this._layers[r],r=String(e.id),this._layers[r])throw Error(`layer with id '${r}' already exist`);r&&(this._layers[r]=e,c.filter&&this.filterLayer(e,c.filter),t.baselayer&&this._baselayers.push(r),p&&await this.showLayer(r));const h=t.opacity;void 0!==h&&h<=1&&this.setLayerOpacity(e,h);const l=s&&(e.getBounds||e.getExtent);if(t.fit&&l){const t=await l.call(e);t&&await this.fitBounds(t)}return this._emitLayerEvent("layer:add",r,e),e}return Promise.reject("No adapter")}async addLayerFromAsyncAdapter(e,t,r){const s=r||void 0!==t.order?t.order:this.reserveOrder(),i=e(),o=await i;return o?this.addLayer(o,t,s):Promise.reject("No adapter")}removeLayers(e){for(const t in this._layers){let r=!0;e&&(r=e(t,this._layers[t])),r&&(this.removeLayer(t),delete this._layers[t])}}reserveOrder(){return this._layersOrderCounter++}removeOverlays(){this.removeLayers(((e,t)=>!(t&&t.options&&t.options.baselayer)))}removeLayer(e){const t=this.getLayer(e),r=t&&this.getLayerId(t);if(t&&r){if(this.emitter.emit("layer:preremove",t),t.beforeRemove&&t.beforeRemove(),t.removeLayer?t.removeLayer():this.mapAdapter.removeLayer(t.layer),t.options&&t.options.baselayer){const e=this._baselayers.indexOf(r);e&&this._baselayers.splice(e,1)}delete this._layers[r],this.emitter.emit("layer:remove",t)}}addGeoJsonLayer(e={},t){return(e=e||{}).multiselect=void 0!==e.multiselect&&e.multiselect,e.unselectOnSecondClick=void 0===e.unselectOnSecondClick||e.unselectOnSecondClick,t||(e=X(e)),e.paint=e.paint||{},this.addLayer(t||"GEOJSON",e)}addFeatureLayer(e={}){return this.addGeoJsonLayer(e)}addTileLayer(e,t){return this.addLayer("TILE",{...t,url:e})}addImageLayer(e,t){return this.addLayer("IMAGE",{...t,url:e})}showLayer(e,t={}){return this.toggleLayer(e,!0,t)}hideLayer(e,t={}){return this.toggleLayer(e,!1,t)}toggleLayer(e,t,r={}){const s=this.getLayer(e),i=void 0!==t?t:!(s&&s.options.visibility),o=void 0!==r.silent&&r.silent,n=async e=>{const t=String(e.id),r=i?"layer:show":"layer:hide";if(o||(this._emitLayerEvent(i?"layer:preshow":"layer:prehide",t,e),this._emitLayerEvent("layer:pretoggle",t,e)),i&&this.mapAdapter){const t=e.options.baselayer?0:e.options.order;if(e.options.baselayer&&this._baselayers.length){const t=this._baselayers.filter((t=>t!==e.id&&this.isLayerVisible(t)));for(const e of t)await this.hideLayer(e)}e.showLayer?e.showLayer.call(e,e.layer):void 0!==e.layer&&this.mapAdapter.showLayer(e.layer),void 0!==t&&this.mapAdapter.setLayerOrder(e.layer,t,this._layers)}else e.hideLayer?e.hideLayer.call(e,e.layer):void 0!==e.layer&&this.mapAdapter.hideLayer(e.layer);o||(this._emitLayerEvent(r,t,e),this._emitLayerEvent("layer:toggle",t,e)),e.options.visibility=i};return s&&s.options.visibility!==i?this.onMapLoad().then((()=>n(s))):Promise.resolve()}updateLayer(e){const t=this.getLayer(e);t&&(t.updateLayer?t.updateLayer():this.isLayerVisible(t)&&(this.hideLayer(t,{silent:!0}),this.showLayer(t,{silent:!0})))}setLayerOpacity(e,t){const r=this.getLayer(e);r&&(r.setOpacity?r.setOpacity(t):this.mapAdapter.setLayerOpacity&&this.mapAdapter.setLayerOpacity(r.layer,t))}selectLayer(e,t){const r=this.getLayer(e);if(r){const e=r;e&&e.select&&e.select(t);const s=this.getLayerId(r);s&&this._selectedLayers.push(s)}}unSelectLayer(e,t){const r=this.getLayer(e);if(r){const e=r&&r;e.unselect&&e.unselect(t);const s=this.getLayerId(r);if(s){const e=this._selectedLayers.indexOf(s);-1!==e&&this._selectedLayers.splice(e,1)}}}unSelectLayers(){const e=Object.values(this.allLayers());let t;for(t of e)t.unselect&&t.unselect()}filterLayer(e,t){const r=this.getLayer(e);return r.filter?r.filter(t):[]}propertiesFilter(e,t,r){const s=this.getLayer(e);if(!s)return;const i=s;i.propertiesFilter?i.propertiesFilter(t,r):i.filter&&this.filterLayer(i,(e=>!e.feature||!e.feature.properties||q(e.feature.properties,t)))}removeLayerFilter(e){const t=this.getLayer(e);t.removeFilter?t.removeFilter():t.filter&&t.filter((()=>!0))}setLayerData(e,t){const r=this.getLayer(e);if(r){if(r.setData)return r.setData(t);if(r.clearLayer&&r.addData)return r.clearLayer(),r.addData(t)}return Promise.resolve()}addLayerData(e,t){const r=this.getLayer(e);r.addData&&r.addData(t)}clearLayerData(e,t){const r=this.getLayer(e);r&&r.clearLayer&&r.clearLayer(t)}getAttributions(e){const t=[];for(const r in this._layers){const s=this._layers[r];let i=!(void 0===e.onlyVisible||e.onlyVisible)||s.options.visibility;if(i&&e.onlyBaselayer&&(i=this._baselayers.includes(r)),i){const e=s.options&&s.options.attribution;e&&t.push(e)}}return t}getActiveBaseLayer(){const e=this.getBaseLayers().find((e=>this.isLayerVisible(e)));if(e)return this.getLayer(e)}addTileJsonLayer(e){return this.addLayer("TILE",{url:e.tiles[0],maxZoom:e.maxzoom,minZoom:e.minzoom,subdomains:e.scheme,attribution:e.attribution})}async _onLayerClick(e){return this._emitLayerEvent("layer:click",e.layer.id||"",e),Promise.resolve(e)}async _onLayerSelect(e){return this._emitLayerEvent("layer:select",e.layer.id||"",e),Promise.resolve(e)}_updateGeoJsonOptions(e){const{onSelect:t,onLayerSelect:r,onClick:s,onLayerClick:i,onMouseOut:o,onMouseOver:n}=e,a=s||i;e.onClick=e=>(a&&a(e),this._onLayerClick(e)),e.onMouseOut=e=>{const t=e.layer.id;o&&o(e),E(t)&&this._emitLayerEvent("layer:mouseout",t,e)},e.onMouseOver=e=>{const t=e.layer.id;n&&n(e),E(t)&&this._emitLayerEvent("layer:mouseover",t,e)};const c=t||r;e.onSelect=e=>(c&&c(e),this._onLayerSelect(e)),e.nativePaint||(this.options.paint&&(e.paint=H(e.paint||{},this.options.paint,this.getPaintFunctions)),e.selectedPaint&&this.options.selectedPaint&&(e.selectedPaint=H(e.selectedPaint,this.options.selectedPaint,this.getPaintFunctions)))}_emitLayerEvent(e,t,r){if(E(t)&&e.startsWith("layer:")){const s=e.replace("layer:","layer-"+t+":");this.emitter.emit(s,r)}this.emitter.emit(e,r)}}function ce(e,t){const r=document.createElement("div");let s=!1;t.getStatus?s=t.getStatus():t.status&&(s=t.status);const i=t.title||"",o=t.html;function n(){i&&(r.title="string"==typeof i?i:s?i.on:i.off,r.setAttribute("aria-label",r.title))}function a(e){e instanceof HTMLElement?(r.innerHTML="",r.appendChild(e)):"string"==typeof e&&(r.innerHTML=e)}function c(){o&&("string"==typeof o||o instanceof HTMLElement?a(o):a(s?o.on:o.off),r.setAttribute("aria-label",r.title))}function h(e,t){e.split(" ").forEach((e=>{t?r.classList.add(e):r.classList.remove(e)}))}function l(){t.addClassOn&&h(t.addClassOn,s),t.addClassOff&&h(t.addClassOff,!s)}n(),c(),t.addClass&&h(t.addClass,!0),l();const p=e=>{void 0!==e&&(s=e),c(),n(),l()},u=e=>{if(s=void 0!==e?e:!s,t.onClick){const e=t.onClick(s);Promise.resolve(e).then((()=>p())).catch((()=>s=!s))}else p()},d=e({html:r,onClick:u});return d.onClick=u,d.changeStatus=p,d}class he extends ae{constructor(){super(...arguments),this._loadControlQueue={"top-right":[],"bottom-right":[],"top-left":[],"bottom-left":[]},this._isControlLoading={"top-right":!1,"bottom-right":!1,"top-left":!1,"bottom-left":!1}}async addControl(e,t,r){let s;if(t=null!=t?t:"top-left",s="string"==typeof e?this.getControl(e,r):e,s)return new Promise((e=>{this._setControlQueue(t,(async()=>{const r=await s,i=this.mapAdapter.addControl(r,t);e(i)}))}))}async createControl(e,t){if(await this.onLoad("build-map"),this.mapAdapter.createControl)return this.mapAdapter.createControl(e,t)}async createButtonControl(e){if(await this.onLoad("build-map"),this.mapAdapter.createButtonControl)return this.mapAdapter.createButtonControl(e)}async createToggleControl(e){return await this.onLoad("build-map"),this.mapAdapter.createToggleControl?this.mapAdapter.createToggleControl(e):this.mapAdapter.createButtonControl?ce(this.mapAdapter.createButtonControl,e):void 0}removeControl(e){"remove"in e?e.remove():this.mapAdapter.removeControl&&Promise.resolve(e).then((e=>{this.mapAdapter.removeControl(e)}))}getControl(e,t){const r=this.mapAdapter.controlAdapters[e];if(r)return new r(t);{const r=he.controls[e];if(r)return r(this,t)}}getControlContainer(){if(this.mapAdapter.getControlContainer)return this.mapAdapter.getControlContainer()}_setControlQueue(e,t){this._loadControlQueue[e].push(t),this._isControlLoading[e]||this._applyControls(e)}async _applyControls(e){if(this._loadControlQueue[e].length){this._isControlLoading[e]=!0;const t=this._loadControlQueue[e][0];await t(),this._loadControlQueue[e].splice(0,1),this._applyControls(e)}else this._isControlLoading[e]=!1}}he.controls={CONTROL:(e,t)=>e.createControl(t.control,t.options),BUTTON:(e,t)=>e.createButtonControl(t),TOGGLE:(e,t)=>e.createToggleControl(t)};const le={};function pe(e){return le[e]}class ue extends he{constructor(e){super(e),this._addControls(),le[this.id]=this}static get(e){return pe(e)}async _addLayerProviders(){for await(const e of this._starterKits)if(e.getLayerAdapters){const t=await e.getLayerAdapters.call(e);if(t)for await(const e of t){const t=await e.createAdapter(this);t&&(this.mapAdapter.layerAdapters[e.name]=t)}}}async _onLoadSync(){for await(const e of this._starterKits)if(e.onLoadSync)try{await e.onLoadSync.call(e,this)}catch(e){console.error(e)}}_addControls(){this.options.controls&&this.options.controls.forEach((e=>{let t=e,r={};"string"==typeof e&&this.options.controlsOptions&&this.options.controlsOptions[e]&&(r=this.options.controlsOptions[e],void 0!==r.control&&(t=r.control));const{position:s,...i}=r;this.addControl(t,s||"top-left",i)})),this._emitStatusEvent("controls:create")}}async function de(e){return new ue(e).onLoad()}class ye{constructor(){return this.cache=[],ye.instance?ye.instance:(ye.instance=this,this)}clean(){this.cache.length=0}all(){return this.cache}add(e,t,r){const s=this._find(e,r);if(s)return s.value;{let s;s=t instanceof Function?t():t;const i=r&&JSON.parse(JSON.stringify(T(r)));return this.cache.push({key:e,value:s,options:i}),s instanceof Promise?(s.catch((t=>{throw this.delete(e,r),t})),s):s}}match(e,t){const r=this._find(e,t);if(r)return r.value}matchAll(e,t){return e?this.cache.filter((r=>this._filter(r,e,t))).map((e=>e.value)):this.cache.map((e=>e.value))}delete(e,t){const r=this.cache.filter((r=>this._filter(r,e,t)));for(const e of r){const t=this.cache.indexOf(e);this.cache.splice(t,1)}}_find(e,t){return this.cache.find((r=>this._filter(r,e,t)))}_filter(e,t,r){return e.key===t&&(!r||N(e.options||{},T(r)))}}var me=ye;class fe extends Error{constructor(e){super(),this.name="NgwError",Object.assign(this,e),Object.setPrototypeOf(this,fe.prototype)}}class ge extends Error{constructor(e){super(),this.name="NetworkError",Object.setPrototypeOf(this,ge.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}let _e;_e=(e,t,r={},s,i)=>{r.method=r.method||"GET";const o=new XMLHttpRequest;o.open(r.method||"GET",e,!0),"blob"===r.responseType&&(o.responseType=r.responseType);const n=()=>{try{return JSON.parse(o.responseText)}catch(e){return o.responseText}};o.onload=()=>{-1!==[401,403,404,500].indexOf(o.status)&&s(new fe(n())),((e=!1)=>{const i=e?s:t;"blob"===r.responseType?i(o.response):o.responseText?i(n()):s({message:""})})()},o.onerror=t=>{s(0===o.status?new ge(e):t)},o.upload.onprogress=function(e){if(e.lengthComputable){const t=e.loaded/e.total*100;r.onProgress&&r.onProgress(t,e)}};const a=r.headers;if(a)for(const e in a){const t=a[e];"string"==typeof t&&o.setRequestHeader(e,t)}let c;if(void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),r.file){if(c=new FormData,c.append("file",r.file),r.data)for(const e in c)c.append(e,c[e])}else c=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;i&&i((()=>{o.abort()})),o.send(c)};const ve=/\{ *([\w_-]+) *\}/g;function we(e,t){return e.replace(ve,((e,r)=>{let s=t[r];if(void 0===s)throw new Error("No value provided for letiable "+e);return"function"==typeof s&&(s=s(t)),s}))}class be extends fe{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,be.prototype)}}class Le extends fe{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,Le.prototype)}}const Oe=[];function Ee(e){Oe.push(e)}function Ce(e){return"[object Object]"===Object.prototype.toString.call(e)}function Ie(e,t=""){t=t?t+"__":"";const r={};return Object.entries(e).forEach((([e,s])=>{if(Ce(s)){const t=Ie(s,e);Object.assign(r,t)}else E(s)&&(r[t+e]=s)})),r}class Pe{constructor(e){this.connector=e,this.cache=new me}getOne(e,t){return(new me).add("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},t):"number"==typeof e?this._fetchResourceById(e,t):Ce(e)?this._fetchResourceBy(e,t):L.resolve(void 0)),{resource:e})}getOneOrFail(e){return this.getOne(e).then((e=>{if(e)return e;throw new be}))}getId(e){return"number"==typeof e?L.resolve(e):"string"==typeof e||Ce(e)?this.getOne(e).then((e=>{if(e)return e.resource.id})):L.resolve(void 0)}getIdOrFail(e){return this.getId(e).then((e=>{if(void 0===e)throw new Error;return e}))}getMany(e,t){return this._resourceCacheFilter(e).then((r=>{if(!r.length){const r={};return e.keyname?r.keyname=e.keyname:Object.assign(r,Ie(e)),this.connector.get("resource.search",t,{serialization:"full",...r}).then((e=>(e&&e.forEach((e=>{this.cache.add("resource.item",L.resolve(e),{id:e.resource.id})})),e)))}return r}))}getParent(e){return this.connector.getResource(e).then((e=>e?this.connector.getResource(e.resource.parent.id):L.resolve(void 0)))}getChildrenOf(e){return this.getId(e).then((e=>this.connector.get("resource.collection",{cache:!0},{parent:e}).then((e=>{for(const t of e)this.cache.add("resource.item",L.resolve(t),{id:t.resource.id});return e}))))}update(e,t){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.put("resource.item",{data:t},{id:e})}))}delete(e){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.delete("resource.item",null,{id:e}).then((()=>{this.cache.delete("resource.item",{id:e})}))}))}_fetchResourceById(e,t){return this.cache.add("resource.item",(()=>this.connector.get("resource.item",t,{id:e})),{id:e}).catch((e=>{if(!(e instanceof be))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return L.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:E(e.id)&&E(t.resource.id)?e.id===t.resource.id:N(e,t.resource)})),[])))}}let Ae=0;class Me{constructor(e){this.options=e,this.id=Ae++,this.emitter=new t.exports.EventEmitter,this.routeStr="/api/component/pyramid/route";const r=function(e){return Oe.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return N(t.options.auth,e.auth)}}))}(e);if(r)return r;this.options.route&&(this.routeStr=this.options.route),this.resources=new Pe(this),Ee(this)}static create(e){return new this(e)}setNgw(e){this.logout(),this.options.baseUrl=e,Ee(this)}connect(){const e=new me,t=this.options.auth;return e.add("route",(()=>new L(((e,r)=>{const s=()=>this.makeQuery(this.routeStr,{},{}).then((t=>{e(t)})).catch((e=>{r(e)}));if(t){const{login:e,password:i}=t;if(e&&i)return this.getUserInfo({login:e,password:i}).then((()=>{s()})).catch((e=>r(e)))}return s()}))),{id:this.id,auth:t,baseUrl:this.options.baseUrl})}login(e){return this.logout(),Ee(this),this.getUserInfo(e)}logout(){!function(e){const t=Oe.indexOf(e);-1!==t&&Oe.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()}getUserInfo(e){if(this.user&&this.user.id)return L.resolve(this.user);e&&(this.options.auth=e);const t={headers:this.getAuthorizationHeaders(e)};return this.makeQuery("/api/component/auth/current_user",{},t).then((e=>(this.user=e,this.emitter.emit("login",e),e))).catch((e=>{throw this.emitter.emit("login:error",e),e}))}getAuthorizationHeaders(e){const t=this.makeClientId(e);if(t)return{Authorization:"Basic "+t}}makeClientId(e){if(e=e||this.options.auth){const{login:t,password:r}=e,s=unescape(encodeURIComponent(`${t}:${r}`));return window.btoa(s)}}apiRequest(e,t={},r={}){const{method:s,headers:i,withCredentials:o,responseType:n}=r,a=T(t),c=()=>function(e){const t=e.params;return new L(((r,s)=>{e.connector.connect().then((i=>{let o=i&&i[e.name];if(o){o=[...o];let i=o.shift();if(o.length){const e={};for(let r=0;r<o.length;r++){const s=o[r];if(e[r]="{"+s+"}",void 0===t[s])throw new Error("`"+s+"` url api argument is not specified")}i&&(i=we(i,e))}if(t){const e=[],r=t.paramList;Array.isArray(r)&&(delete t.paramList,r.forEach((t=>{e.push(`${t[0]}=${t[1]}`)})));for(const r in t)-1===o.indexOf(r)&&e.push(`${r}=${t[r]}`);e.length&&(i=i+"?"+e.join("&"))}i?r(e.connector.makeQuery(i,t,e.requestOptions)):s(new Error("request url is not set"))}else r(void 0)})).catch((e=>{s(e)}))}))}({name:e,params:a,requestOptions:r,connector:this});if(r.cache&&"GET"===s){return(new me).add(e,c,{params:a,...T({headers:i,withCredentials:o,responseType:n,baseUrl:this.options.baseUrl,auth:this.options.auth})})}return c()}post(e,t,r){return(t=t||{}).method="POST",this.apiRequest(e,r,t)}get(e,t,r){return(t=t||{}).method="GET",this.apiRequest(e,r,t)}patch(e,t,r){return(t=t||{}).method="PATCH",this.apiRequest(e,r,t)}put(e,t,r){return(t=t||{}).method="PUT",this.apiRequest(e,r,t)}delete(e,t,r){return(t=t||{}).method="DELETE",this.apiRequest(e,r,t)}makeQuery(e,t,r={}){if(e=(this.options.baseUrl?this.options.baseUrl:"")+e)return t&&(e=we(e,t)),e=R(e),this._loadData(e,r);throw new Error("Empty `url` not allowed")}getResource(e){return this.resources.getOne(e)}getResourceOrFail(e){return this.resources.getOneOrFail(e)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e){return this.resources.getId(e)}getResourceIdOrFail(e){return this.resources.getIdOrFail(e)}getResourcesBy(e){return this.resources.getMany(e)}getResourceParent(e){return this.resources.getParent(e)}getResourceChildren(e){return this.resources.getChildrenOf(e)}updateResource(e,t){return this.resources.update(e,t)}deleteResource(e){return this.resources.delete(e)}_loadData(e,t){return t.responseType=t.responseType||"json",new L(((r,s,i)=>{this.user&&((t=t||{}).headers={...this.getAuthorizationHeaders(),...t.headers}),_e(e,r,t,s,i)})).catch((e=>{if(e instanceof L.CancelError);else{const t=this._handleHttpError(e);if(t)throw t}}))}_handleHttpError(e){if(e&&e instanceof fe){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new be(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new Le(e)}return e}}Me.errors={NgwError:fe,ResourceNotFoundError:be};var xe=Me;const ke=["fields","intersects","limit","orderBy","strategy"];function Se(e){const t={};return ke.forEach((r=>{const s=e[r];void 0!==s&&(t[r]=s)})),t}function Ne(e){const t=e.extent_bottom,r=e.extent_left,s=e.extent_top,i=e.extent_right;if(t&&r&&s&&i){const e=[r,t,i,s];return e[3]>82&&(e[3]=82),e[1]<-82&&(e[1]=-82),e}}function Te({resourceId:e,connector:t,cache:r=!0}){return t.get("layer.extent",{cache:r},{id:e}).then((e=>{if(e){const{maxLat:t,maxLon:r,minLat:s,minLon:i}=e.extent;return[i,s,r,t]}}))}function Be(e,t){if(e.webmap)return L.resolve(Ne(e.webmap));{const r=e.resource;return r.cls&&-1!==r.cls.indexOf("style")?t.getResource(r.parent.id).then((e=>{if(e)return Te({resourceId:e.resource.id,connector:t})})):Te({resourceId:r.id,connector:t})}}async function Re(e,t){const r=e.resource,s=r;let{keyname:i,resourceId:o}=e;if(r&&("string"==typeof r?i=r:o="number"==typeof r?r:s.resource&&void 0!==s.resource&&"resource"in s?r.resource.id:await Re(r,t)),!o&&i){const e=await t.getResource(i);e&&(o=e.resource.id)}return o}const Fe={srs:4326,geom_format:"geojson"};function je(e){return{id:e.id,type:"Feature",properties:e.fields,geometry:e.geom}}function ze(e,t){const{extensions:r,geom:s,fields:i,srs:o}=t;e.extensions=r?r.join(","):"",void 0!==i&&(e.fields=Array.isArray(i)?i.join(","):""),void 0!==s&&(e.geom=s?"yes":"no",s||(delete e.srs,delete e.geom_format)),E(o)&&(e.srs=o)}function De(e,t=[],r=[]){const{filters:s}=e,i="string"==typeof s[0]?s[0]:"all",o=s.filter((e=>Array.isArray(e))),n=e=>{const[t,r,s]=e;return[`${"id"!==t?"fld_":""}${t}__${r}`,s]};if("any"===i)o.forEach((s=>{Z(s)?t.push($e({...e,paramList:[...r,n(s)]})):De({...e,filters:s},t,[...r])}));else if("all"===i){const s=[],i=[];for(const e of o)Z(e)?s.push(n(e)):i.push(e);if(i.length)for(const o of i)De({...e,filters:o},t,[...r,...s]);else t.push($e({...e,paramList:[...r,...s]}))}return L.all(t).then((t=>{const r=t.reduce(((e,t)=>e.concat(t)),[]);return e.offset||e.limit?r.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:r.length):r}))}function $e(e){const t={...Fe},{connector:r,limit:s,offset:i,intersects:o,orderBy:n,resourceId:a,paramList:c}=e;if(s?s!==Number.POSITIVE_INFINITY&&(t.limit=s):t.limit=7e3,i&&(t.offset=i),ze(t,e),n&&(t.order_by=n.join(",")),Array.isArray(o)){const e=(h=o,Array.isArray(h)&&4===h.length&&h.every((e=>"number"==typeof e))?A(o):o);t.intersects=`POLYGON((${e.map((([e,t])=>{const[r,s]=k(e,t);return r+" "+s})).join(", ")}))`}else"string"==typeof o&&(t.intersects=o);var h;c&&(t.paramList=c);const l={id:a,...t};return r.get("feature_layer.feature.collection",{cache:e.cache},l)}function Ge(e){let t;for(t in e){const r=e[t];if(B(r)){const s=r;if(E(s.year)&&E(s.month)&&E(s.day)){const r=[s.year,s.month-1,s.day];"hour"in s&&[s.hour,s.minute,s.second].forEach((e=>{r.push(e)})),e[t]=new Date(...r).toISOString()}}}return e}function Ue(e){const t=e.filters;return t?De({...e,filters:t}).then((e=>(e.filter((e=>q(Ge({...e.fields}),t))),e))):$e(e)}function Ve(e){return function(e){return Ue(e).then((e=>{const t=[];return e.forEach((e=>{t.push(je(e))})),t}))}(e).then((e=>({type:"FeatureCollection",features:e})))}async function Ze(e){var r,s;const{item:i,webMap:o,Adapter:n,connector:a,layerOptions:c,addLayerOptionsPriority:h}=e,l=null==h||h,p=c,u=n||o.mapAdapter.layerAdapters.GEOJSON;let d,y,m=!1;const f=await Re(p,a);(null===(s=null===(r=p.adapterOptions)||void 0===r?void 0:r.popupOptions)||void 0===s?void 0:s.fromProperties)&&(p.adapterOptions.popupOptions.createPopupContent=({feature:e})=>e&&function(e,t){{const r=document.createElement("div");if(t&&t.feature_layer)t.feature_layer.fields.forEach((t=>{if(t.grid_visibility){const s=e.properties&&e.properties[t.keyname];if(s){const e=document.createElement("div");r.appendChild(e),e.innerHTML=`<span>${t.display_name}</span>: ${s}<span></span>`}}}));else if(e.properties)for(const t in e.properties){const s=document.createElement("div");r.appendChild(s),s.innerHTML=`<span>${t}</span>: ${e.properties[t]}<span></span>`}return r}}(e,i));const g=async(e,t)=>(v(),d={filters:e,options:t},y=Ve({resourceId:f,filters:e,connector:a,cache:!0,...t}),await y);let _=!1;const v=()=>{y&&(y.cancel(),y=void 0)};return class extends u{constructor(){super(...arguments),this.emitter=new t.exports.EventEmitter}async addLayer(e){let t=!e.data;const r=void 0===e.waitFullLoad||e.waitFullLoad;void 0!==p.id&&(e.id=p.id),i&&i.vector_layer&&(e.type=bt[i.vector_layer.geometry_type]),p.adapterOptions&&(e=l?{...p.adapterOptions,...e}:{...e,...p.adapterOptions}),e.data&&0===Object.keys(e.data).length&&(e.data=void 0,t=!1);const s=super.addLayer(e);let o;return this.options.strategy=e.strategy||void 0,d={filters:e.propertiesFilter,options:Se(e)},t&&(o=this.updateLayer()),r&&o&&await o,"BBOX"!==this.options.strategy||m||this._addBboxEventListener(),s}getExtent(){return this.getBounds()}async getBounds(){const e=this.getLayers&&this.getLayers().length;return"BBOX"===this.options.strategy||e?Be(i,a):super.getBounds?super.getBounds():void 0}beforeRemove(){_=!0,this._removeMoveEventListener(),this._removeBboxEventListener(),this.__disableMapMoveListener=void 0,this.__enableMapMoveListener=void 0,this.__onMapMove=void 0,this.__onMapMoveStart=void 0,v()}getCount(){return void 0!==this._count?this._count:a.get("feature_layer.feature.count",{cache:!0},{id:f}).then((e=>{if(e)return this._count=e.total_count,this._count}))}async updateLayer(e){if(e=e||d||{},"BBOX"===this.options.strategy&&(await o.onLoad("create"),e.options=e.options||{},e.options.intersects=o.getBounds()),!_){try{const t=await g(e.filters,{...e.options,srs:this.options.srs}),r=await this.getCount();m=r===t.features.length,await o.setLayerData(this,t),this.emitter.emit("updated")}catch(e){if(e instanceof Error&&"CancelError"!==e.name)throw e}super.updateLayer&&super.updateLayer()}}async propertiesFilter(e,t){if(v(),this.filter&&m)this.filter((t=>{const r=t.feature&&t.feature.properties&&Ge({...t.feature.properties});return!r||q(r,e)}));else if(this.setData){this.clearLayer&&this.clearLayer();const r=await g(e,{...t,srs:this.options.srs});this.setData(r)}}removeFilter(){d=void 0,this.propertiesFilter([]),this.filter&&this.filter((()=>!0))}_addBboxEventListener(){this.__enableMapMoveListener=e=>{e===this&&(this._removeMoveEventListener(),this.updateLayer(),this._addMoveEventListener())},this.__disableMapMoveListener=e=>{e===this&&this._removeMoveEventListener()},o.emitter.on("layer:show",this.__enableMapMoveListener),o.emitter.on("layer:hide",this.__disableMapMoveListener),this.__enableMapMoveListener(this)}_removeBboxEventListener(){this.__enableMapMoveListener&&o.emitter.on("layer:show",this.__enableMapMoveListener),this.__disableMapMoveListener&&o.emitter.on("layer:hide",this.__disableMapMoveListener)}_addMoveEventListener(){this.__onMapMove=function(e,t=10){let r;function s(...i){s.clear(),r=setTimeout((()=>{r=null,e.apply(this,i)}),t)}return s.clear=function(){r&&(clearTimeout(r),r=null)},s}((()=>this.updateLayer())),this.__onMapMoveStart=v,o.emitter.on("movestart",this.__onMapMoveStart),o.emitter.on("moveend",this.__onMapMove)}_removeMoveEventListener(){this.__onMapMove&&o.emitter.removeListener("moveend",this.__onMapMove),this.__onMapMoveStart&&o.emitter.removeListener("movestart",this.__onMapMoveStart)}}}function qe({options:e,webMap:t,baseUrl:r}){let s,i=e.adapter||"IMAGE";const o=t&&t.getLayerAdapters(),n=e.resource,a=e.tileNoData?e.tileNoData:200;if("number"==typeof n){if("IMAGE"===i){if(!o||o.IMAGE)return s=r+"/api/component/render/image",{url:s,resourceId:n,headers:e.headers,params:{resource:n,nd:a},updateWmsParams:e=>wt({nd:a,...e},n)};i="TILE"}if("WMS"===i){s=`${r}/api/resource/${n}/wms`;const t=e.adapterOptions;return{url:s,format:"image/png",version:"1.1.1",layers:t&&t.layers,headers:e.headers}}if("MVT"===i)return s=r+"/api/component/feature_layer/mvt?x={x}&y={y}&z={z}&resource="+n+"&simplification="+(e.simplification||0),{url:s};if("TERRAIN"===i)return s=r+`/api/resource/${n}/terrain_provider`,{url:s,adapter:i};if("MODEL_3D"===i)return s=r+`/api/component/model_3d/${n}/data.glb`,{url:s};if("TILE"===i)return s=r+"/api/component/render/tile?z={z}&x={x}&y={y}&resource="+n+"&nd="+a,{url:s,adapter:i}}else{if(void 0!==n)throw new Error("Option `resource` must be number, not "+typeof n);console.log("Option `resource` not set")}}async function We({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.cls;let o=e.adapter||i&&{wmsserver_service:"WMS",tmsclient_layer:"IMAGE"}[i]||"IMAGE";if(void 0!==o&&(e.adapter=o),"IMAGE"===o){const e=t.getLayerAdapters();!e||e.IMAGE||(o="TILE")}const n=t.mapAdapter.layerAdapters[o];if(n){const i=await Re(e,r);return class extends n{constructor(o,n){var a;super(o,n),this.map=o,this.item=s,this.resourceId=i;const c=qe({options:e,webMap:t,baseUrl:r.options.baseUrl||""});if(c){const t={...c,setViewDelay:null===(a=e.adapterOptions)||void 0===a?void 0:a.setViewDelay,params:{resource:i},layers:String(i),resourceId:i};e.adapterOptions&&E(e.adapterOptions.setViewDelay)&&(t.setViewDelay=e.adapterOptions.setViewDelay),this.options={...this.options,...t}}}addLayer(e){return super.addLayer({...this.options,...e})}async getIdentificationIds(){const e=this.item&&this.item.resource.parent.id;if(E(e))return[e]}}}throw new Error(o+" not supported yet. Only TILE")}function He(e,t,r,s){return!!Ke(e,t,r,Ye,s)}function Je(e,t,r,s){return Ke(e,t,r,Xe,s)}function Qe(e,t="children"){let r=[];const s=("function"==typeof t?t:e=>e[t])(e);return s&&(Array.isArray(s)?r=s:r.push(s)),s?r:void 0}function Ke(e,t=(e=>!!e),r="children",s,i){const o="function"==typeof t?t:e=>q(e,t);return s(e,i?e=>o(i(e)):o,r)}function Ye(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(t(e))return e;const s=Qe(e,r);s&&(i=s)}for(let e=0;e<i.length;e++)if(i[e]){const o=Ye(i[e],t,r,s);if(o)return o}}function Xe(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{t(e)&&s.push(e);const o=Qe(e,r);o&&(i=o)}for(let e=0;e<i.length;e++)i[e]&&Xe(i[e],t,r,s);return s}function et(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(!t(e))return!1;const s=Qe(e,r);s&&(i=s)}for(let e=0;e<i.length;e++)if(i[e]){if(!et(i[e],t,r,s))return!1}return!0}class tt{constructor(e){this._children=[],this.item=e}setParent(e){this._parent=e}addChild(e){this._children.push(e)}getParent(){return this._parent}getParents(e){const t=this.getParent();return t?Je(t,e,(e=>e.tree.getParent())):[]}getRoot(){let e=this.getParent(),t=e;for(;e;)e=e.tree.getParent(),e&&(t=e);return t}find(e){return Ke(this._children,e,(e=>e.tree.getChildren()),Ye,t);var t}every(e){return!!Ke(this._children,e,(e=>e.tree.getChildren()),et,t);var t}some(e){return He(this._children,e,(e=>e.tree.getChildren()))}all(e){return this.getDescendants(e)}getDescendants(e){return Je(this._children,e,(e=>e.tree.getChildren()))}getChildren(){return[...this._children]}}class rt{constructor(e,r,s){this.emitter=new t.exports.EventEmitter,this._blocked=!1,this.item=r,this.options=Object.assign({},s),this.name=e,this._value=this.getProperty()}getProperty(){return"function"==typeof this.options.getProperty?this.options.getProperty.call(this,this.item):this.options.value}getParents(){return this.item.tree.getParents()||[]}getParent(){return this.item.tree.getParent()}getChildren(){return this.item.tree.getChildren()}isGroup(){return this.item.tree.getDescendants().length}isBlocked(){if(void 0===this._blocked){const e=this.item.tree.getParents();if(e){const t=e.find((e=>{const t=e.properties&&e.properties.property(this.name);return!!t&&!t.get()}));this._blocked=!!t}else this._blocked=!1}return this._blocked}set(e,t){this._value=this._prepareValue(e),this.update(this._value,t),this._fireChangeEvent(this._value,t)}get(){return this.getValue()}update(e,t){this._callOnSet(e,t)}getContainer(){return this._container}destroy(){if(this._container){const e=this._container.parentNode;e&&e.removeChild(this._container)}this._removeEventsListener&&this._removeEventsListener()}getValue(){return void 0!==this._value?this._value:this.getProperty()}_prepareValue(e){return e}_callOnSet(e,t){this.options.onSet&&this.options.onSet.call(this,e,t,this.item)}_fireChangeEvent(e,t){if(this.emitter){e=void 0!==e?e:this.getValue(),this.emitter.emit("change",{value:e,options:t});this.item.tree.getParents().forEach((r=>{const s=r.properties&&r.properties.property(this.name);s&&s.emitter.emit("change-tree",{value:e,options:t,item:this.item})}))}}}class st extends rt{constructor(e,t,r){super(e,t,{...st.options,...r}),this.set(this.get())}update(e,t){if(e){if(t&&t.bubble||this.options.bubble){this.unBlock(t);const r=this.getParent(),s=r&&r.properties&&r.properties.property(this.name);s&&s.set(e,Object.assign({},t,{bubble:!0,propagation:!1}))}this.isBlocked()||this._turnOn(t)}else this._turnOff(t);(t&&t.propagation||this.options.propagation)&&this._propagation(e,t)}getHierarchyValue(){return this.get()&&this.getParents().every((e=>{const t=e.properties&&e.properties.get(this.name);return t&&t.get()}))}block(e){this._blocked=!0,this._block(e)}unBlock(e){this._blocked=!1,this.getValue()&&this._unBlock(e)}blockChild(e){this.item.tree.getDescendants().forEach((t=>this._blockChild(t,e)))}unblockChild(e){this.item.tree.getChildren().forEach((t=>this._unBlockChild(t,e)))}_prepareValue(e){return e}_turnOff(e){this.options.turnOff&&this.options.turnOff.call(this,e),this._callOnSet(!1,e),this.options.hierarchy&&this.isGroup()&&this.blockChild(e)}_turnOn(e){this.options.turnOn&&this.options.turnOn.call(this,e),this._callOnSet(!0,e),this.options.hierarchy&&this.isGroup()&&this.unblockChild(e)}_block(e){this._turnOff(e)}_unBlock(e){this._turnOn(e)}_blockChild(e,t){const r=e.properties&&e.properties.property(this.name);r&&r.block&&r.block(t)}_unBlockChild(e,t){const r=e.properties&&e.properties.property(this.name);r&&r.unBlock&&r.unBlock(t)}_propagation(e,t){if(this.isGroup()){const r=this.item.tree.getChildren();for(let s=0;s<r.length;s++){const i=r[s],o=i.properties&&i.properties.property(this.name);o&&o.set(e,{...t,propagation:!0,bubble:!1})}}}}st.options={hierarchy:!0,bubble:!1,propagation:!1,label:"Toggle"};class it{constructor(e,t){this.item=e,this.options={},this._properties={},this._propertiesList=[],t&&t.forEach(this._setPropertyHandler.bind(this))}add(e){this._setPropertyHandler(e)}_setPropertyHandler(e){const t=it.handlers;let r=e.handler;if(!r&&e.type)switch(e.type){case"boolean":r=t.CheckProperty;break;case"string":r=t.BaseProperty;break;default:r=t.BaseProperty}if(r&&e.name){const t={...e||{}};this._properties[e.name]=new r(e.name,this.item,t),this._propertiesList.push(e.name)}}update(){this.list().forEach((e=>{e.update()}))}get(e){const t=this.property(e);if(t)return t.get()}set(e,t,r){const s=this.property(e);if(s)return s.set(t,r)}property(e){return this._properties[e]}list(){return this._propertiesList.map((e=>this._properties[e]))}destroy(){for(const e in this._properties){const t=this.property(e);t&&t.destroy&&t.destroy()}this._properties={},this._propertiesList=[]}}it.handlers={CheckProperty:st};let ot=0;class nt extends class{constructor(e){this.options={},this.id=ot,ot+=1,this.options={...e},this.tree=new tt(this)}initProperties(){this.properties=new it(this,this.options.properties)}}{constructor(e,r,s,i,o,n){if(super({...nt.options,...s}),this.webMap=e,this.emitter=new t.exports.EventEmitter,this._rootDescendantsCount=0,i&&(this.connector=i),o&&this.tree.setParent(o),this.item=r,"root"===this.item.item_type)this._rootDescendantsCount=this._sumUp(this.item.children);else{const e=this.tree.getRoot();e&&(this._rootDescendantsCount=e._rootDescendantsCount)}this.initProperties(),n||this._init(r)}static async create(e,t,r,s,i){const o=new nt(e,t,r,s,i,!0);return await o._init(t),o}initItem(e){const t=e,r=this.getItemOptions(e),s=e=>{t._layer=e,this.layer=e;this.properties.get("visibility")&&this.properties.set("visibility",!0),void 0!==r.opacity&&this.webMap.setLayerOpacity(e,r.opacity)};if("group"===e.item_type||"root"===e.item_type)return e.children&&e.children.length&&this.getChildren(e).forEach((e=>{const t=new nt(this.webMap,e,this.options,this.connector,this);this.tree.addChild(t)})),Promise.resolve();{let t;if("layer"===e.item_type)t=e.adapter||e.layer_adapter.toUpperCase();else if(nt.GetAdapterFromLayerType[e.item_type]){t=(0,nt.GetAdapterFromLayerType[e.item_type])(e,r,this.webMap,this.connector)}if(t)return this.webMap.addLayer(t,r).then((e=>{s(e)}))}return e._layer?Promise.resolve(s(e._layer)):Promise.reject("No layer added")}bringToFront(){}fit(){}getLayer(){return this.layer}getItemOptions(e){const t="layer"===e.item_type&&e.layer_transparency,r="number"==typeof t?(100-t)/100:void 0,s={visibility:!1,headers:this.options.headers,crossOrigin:this.options.crossOrigin,setViewDelay:this.options.setViewDelay,params:{resource:this.item.resourceId}};if(this.options.order){const t=String(this.options.drawOrderEnabled&&"draw_order_position"in e?this._rootDescendantsCount-e.draw_order_position:this.id).padStart(4,"0");s.order=Number((0|this.options.order)+"."+t)}if("layer"===e.item_type){const t=e.layer_max_scale_denom?this._mapScaleToZoomLevel(e.layer_max_scale_denom):this.webMap.options.maxZoom,r=e.layer_min_scale_denom?this._mapScaleToZoomLevel(e.layer_min_scale_denom):this.webMap.options.minZoom;!function(e,...t){for(const r of t)for(const t of Object.getOwnPropertyNames(r))e[t]=r[t]}(s,{updateWmsParams:e.updateWmsParams,url:e.url,headers:this.options.headers,ratio:this.options.ratio,maxZoom:t,minZoom:r,minScale:e.layer_min_scale_denom,maxScale:e.layer_max_scale_denom})}return void 0!==r&&(s.opacity=r),s}getChildren(e){return[...e.children].reverse()}_mapScaleToZoomLevel(e){return function(e,t=0){const r=t,s=function(){if(void 0===Lt){const e=document.createElement("div");e.style.cssText="position: absolute; left: -100%; top: -100%; width: 100cm;",document.body.appendChild(e);const t=e.offsetWidth;document.body.removeChild(e),Lt=t}return Lt}()*function(e){return 12756274*Math.PI*Math.cos(e*Math.PI/180)}(r)/e;return function(e){return Math.log(e/256)/Math.LN2}(s)}(e)}_init(e){this.initItem(e).then((()=>{this.emitter.emit("init")}))}_sumUp(e,t=0){for(const r of e)"layer"===r.item_type?(t+=1,r.draw_order_position=r.draw_order_position||t):"group"===r.item_type&&(t=this._sumUp(r.children,t));return t}}async function at({webMap:e,connector:t,item:r,adapterOptions:s={},idPrefix:i="first-show-adapter"}){return async function({webMap:e,adapterOptions:t={},onLayerAdded:r,createAdapter:s}){return class{constructor(){this.options={},this.layer=[],this._removed=!1,this._creatingInProgress=!1}addLayer(){return this.layer}removeLayer(){this._removed=!0,this.layer.forEach((t=>e.removeLayer(t)))}destroyed(){return this._removed}showLayer(){this.options.visibility=!0,this.layer.length?this.layer.forEach((t=>{e.showLayer(t)})):this.loadLayer()}async loadLayer(){if(!this.layer.length&&!this._creatingInProgress){this._creatingInProgress=!0;const i=await s(this);if(i){const s=new i(e.mapAdapter.map,{...t}),o=await s.addLayer({order:this.options.order,headers:this.options.headers,baselayer:this.options.baselayer});r&&r(s),Object.assign(s.options,t),s.layer=o,this._removed&&e.removeLayer(s),this.options.visibility&&await e.showLayer(s),this.layer.push(s),this._creatingInProgress=!1}}return this.layer}hideLayer(){this.options.visibility=!1,this.layer&&this.layer.forEach((t=>e.hideLayer(t)))}}}({webMap:e,adapterOptions:s,onLayerAdded:e=>{e.options.baselayer=!1,e.id=i+"-"+r.resource_id},createAdapter:()=>vt({resource:r.resource_id,adapterOptions:{name:r.display_name,opacity:r.opacity}},e,t)})}nt.GetAdapterFromLayerType={},nt.options={properties:[{type:"boolean",name:"visibility",getProperty(e){if(e){if("group"===e.item.item_type||"root"===e.item.item_type)return He(e.item,(e=>"layer_enabled"in e&&e.layer_enabled),(e=>e.children));if("layer"===e.item.item_type)return e.item.layer_enabled}return!1},onSet(e,t,r){r&&"layer"===r.item.item_type&&(r.layer&&(e?r.webMap.showLayer(r.layer):r.webMap.hideLayer(r.layer)),r.item.layer_enabled=e)}},{name:"opacity",handler:class extends rt{getProperty(){const e=this.item.layer;return e&&e&&e.options&&void 0!==e.options.opacity?e.options.opacity:1}update(e,t){if(t=t||{},this.isGroup()){this._value=this._prepareValue(e,t);const r=this.getChildren();for(const s of r){const r=s.properties.property(this.name);r&&(t.propagation?r.set(e,t):r.update(r.get(),t))}}const r=this.item.layer;if(r){const t=this.getParents().reduce(((e,t)=>{const r=t.properties.property(this.name);return e*(r?r.getValue():1)}),1);this.item.webMap.setLayerOpacity(r,this._prepareValue(e*t))}}_prepareValue(e,t){return t&&t.propagation&&this.isGroup()?1:Number(e)}}}]};class ct{constructor(e){this.options=e,this.resourceId=e.resourceId;const t=e.item;this.item=t,this.name=e.labelField&&t.fields?t.fields[e.labelField]:String(t.id)}extent(){return this._extent?L.resolve(this._extent):this.options.connector.get("feature_layer.feature.item_extent",null,{id:this.resourceId,fid:this.item.id}).then((e=>{const{minLat:t,minLon:r,maxLat:s,maxLon:i}=e.extent,o=[r,t,i,s];return this._extent=o,o}))}geoJson(){return this.item.geom?L.resolve(je(this.item)):It({resourceId:this.resourceId,featureId:this.item.id,connector:this.options.connector,geom:!0,fields:null,extensions:null}).then((e=>(this.item.geom=e.geom,je(this.item))))}}class ht{constructor(e,r){this.map=e,this.options=r,this.NgwWebmapItem=nt,this.pixelRadius=10,this.webmapClassName="webmap",this.emitter=new t.exports.EventEmitter;const s=r.resourceId;if(Array.isArray(s)?(this.resourceId=s[0],this.options.id=s[1]):this.resourceId=s,!this.resourceId)throw new Error("NGW `resourceId` is not defined")}async addLayer(e){return this.options={...this.options,...e},this.layer=await this._getWebMapLayerItem(),this.layer}removeLayer(){const e=this.options.webMap.mapAdapter;this.getDependLayers().forEach((t=>{"layer"in t&&e.removeLayer(t.layer.layer)})),delete this.layer,delete this.response,delete this._webmapLayersIds}async showLayer(){if(this.layer&&this.layer.properties)return this.layer.properties.property("visibility").set(!0)}async hideLayer(){if(this.layer&&this.layer.properties)return this.layer.properties.property("visibility").set(!1)}async setOpacity(e){if(this.layer&&this.layer.properties)return this.layer.properties.property("opacity").set(e)}getExtent(){return this.getBounds()}getBounds(){const e=this.response&&this.response.webmap;if(e)return Ne(e)}getDependLayers(){return this.layer&&this.layer.tree.getDescendants()||[]}getBookmarksResourceId(){const e=this.response&&this.response.webmap;if(e)return e.bookmark_resource.id}fetchBookmarks(){const e=this.getBookmarksResourceId(),t=this.options.connector;if(e)return t.getResourceOrFail(e).then((r=>{var s;const i=null===(s=r.feature_layer)||void 0===s?void 0:s.fields.find((e=>e.label_field)),o=i&&i.keyname;return Ue({connector:t,resourceId:e,geom:!1,fields:o?[o]:void 0}).then((r=>{const s=[];for(const i of r){const r=new ct({item:i,resourceId:e,labelField:o,connector:t});s.push(r)}return s}))}));throw new Error("Webmap was not loaded correctly, it is impossible to extract bookmarks")}async getIdentificationIds(){const e=[];let t=this._webmapLayersIds;if(t||(t=await this._getWebMapIds(),this._webmapLayersIds=t),t&&t.length){let t=this.getDependLayers();t=t.sort(((e,t)=>t.id-e.id)),t.forEach((t=>{const r=t.item,s=r.parentId;if(void 0!==s&&"layer"===r.item_type){const r=t.properties.property("visibility");r.get()&&!r.isBlocked()&&e.push(s)}}))}return e}async _getWebMapLayerItem(){if(this.resourceId){const e=await this.getWebMapConfig(this.resourceId);if(e&&e.root_item)return new Promise((t=>{const r={};if(this.options.connector&&this.options.connector.options.auth){const e=this.options.connector.getAuthorizationHeaders();e&&(r.headers=e)}r.setViewDelay=this.options.setViewDelay,r.order=this.options.order,r.ratio=this.options.ratio,r.crossOrigin=this.options.crossOrigin,r.drawOrderEnabled=e.draw_order_enabled;const s=new this.NgwWebmapItem(this.options.webMap,e.root_item,r,this.options.connector);s.emitter.on("init",(()=>t(s)))}))}}async getWebMapConfig(e){const t=await this.options.connector.getResource(e);if(t){this.response=t;const e=t[this.webmapClassName];if(t.basemap_webmap&&t.basemap_webmap.basemaps.length)this._setBasemaps(t.basemap_webmap);else if(this.options.defaultBasemap){this.options.webMap.addBaseLayer("OSM",{id:"webmap-default-baselayer",name:"OpenStreetMap"})}if(e)return this._extent=[e.extent_left,e.extent_bottom,e.extent_right,e.extent_top],this._updateItemsParams(e.root_item,this.options.webMap,t),e}}_setBasemaps(e){const t=this.options.webMap;let r=!1;e.basemaps.forEach((e=>{at({webMap:t,connector:this.options.connector,item:e,adapterOptions:{crossOrigin:this.options.crossOrigin}}).then((s=>{t.addBaseLayer(s,{id:Ct+e.resource_id,name:e.display_name,opacity:e.opacity,visibility:!r&&e.enabled}),e.enabled&&(r=!0)}))}))}_updateItemsParams(e,t,r){if(e)if("group"===e.item_type||"root"===e.item_type)e.children&&(e.children=e.children.map((e=>this._updateItemsParams(e,t,r)))),"root"===e.item_type&&(e.display_name=r.resource.display_name);else if("layer"===e.item_type){const r=R(this.options.connector.options.baseUrl+"/api/component/render/image"),s=e.layer_style_id;e.url=r,e.resourceId=s,e.updateWmsParams=e=>wt(e,s);const i=qe({options:{adapter:e.layer_adapter.toUpperCase(),resource:s},webMap:t,baseUrl:this.options.connector.options.baseUrl||""});e={...e,...i}}return e}async _getWebMapIds(){const e=this.layer;if(e&&"root"===e.item.item_type){const t=e.tree.getDescendants(),r=[];t.forEach((e=>{const t=e.item;if("layer"===t.item_type){const e=this.options.connector.getResource(t.layer_style_id).then((e=>{if(e){const r=Number(e.resource.parent.id);return t.parentId=r,r}}));r.push(e)}}));return(await Promise.all(r)).filter((e=>void 0!==e))}}}class lt{async getExtent(){return this.getBounds()}async getBounds(){return this._extent?this._extent:this.item?(this._extent=await Be(this.item,this.connector),this._extent):void 0}}const pt={tms:"TILE"};function ut(e){const t=("https:"===location.protocol?"https":"http")+"://";let r=e.url.replace(/^(https?|ftp):\/\//,t);return e.y_origin_top||(r=r.replace("{y}","{-y}")),{url:r,name:e.name,attribution:e.copyright_text,maxZoom:e.z_max,minZoom:e.z_min}}const dt="https://qms.nextgis.com";function yt(e,t=dt,r={}){t||(t=dt);class s{constructor(e,t){this.map=e;const s={...r,...t};this.options=s,this.options.baselayer=!0,s.qms&&(this.qms=s.qms)}async addLayer(r){if(!this.qms&&r.qmsId)try{this.qms=await function(e){return new Promise(((t,r)=>{const s=new XMLHttpRequest;s.onreadystatechange=()=>{if(4===s.readyState&&200===s.status&&s.responseText)try{t(JSON.parse(s.responseText))}catch(e){r(e)}},s.open("GET",R(e),!0),s.send()}))}(t+"/api/v1/geoservices/"+r.qmsId)}catch(e){console.error(e)}const i=this.qms;if(i){const t=pt[i.type||"tms"],a=e.mapAdapter.layerAdapters[t];if(a&&(o=s,n=a,["showLayer","hideLayer"].forEach((e=>{const t=Object.getOwnPropertyDescriptor(n.prototype,e);t&&Object.defineProperty(o.prototype,e,t)})),"TILE"===t)){if(r={order:0,maxZoom:e.options.maxZoom,minZoom:e.options.minZoom,...this.options,...ut(i)},i.origin_url){const[e,t]=function(e){const t=[];return[e=e.replace(/{switch:(.*?)}/,((e,r)=>("string"==typeof r&&r.split(",").forEach((e=>t.push(e))),"{s}"))),t]}(i.origin_url);t.length&&(r.subdomains=t,r.url=e)}this.options=r;return new a(this.map,r).addLayer(r)}}var o,n}}return s}class mt{constructor(e){this.options={url:"https://qms.nextgis.com"},this.options={...this.options,...e},this.url=this.options.url}getLayerAdapters(){return Promise.resolve([{name:"QMS",createAdapter:e=>Promise.resolve(this._createAdapter(e))}])}_createAdapter(e){return yt(e,this.url)}}mt.utils={createQmsAdapter:yt};const ft={},gt=["mapserver_style","qgis_vector_style","qgis_raster_style","wmsserver_service","raster_style","basemap_layer","vector_layer","raster_layer","webmap","tmsclient_layer"];async function _t({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.id,o=await r.getResourceChildren(i),n=o&&o[0];if(n)return vt({...e,resource:n.resource.id},t,r)}async function vt(e,t,r){let s,i;const o=e.adapter,n=await Re(e,r);if(n){const a=e.resource;if(i=a&&a.resource&&void 0!==a.resource.id?a:await r.getResource(n),!i)throw"Resource item is not found";{const a=i.resource.cls,c={layerOptions:{...e,resource:n},webMap:t,connector:r,item:i};if(-1!==gt.indexOf(a))if("webmap"===a)s=async function({layerOptions:e,webMap:t,connector:r}){const s=await Re(e,r);return class extends ht{constructor(e){super(e,{url:"",webMap:t,resourceId:s,connector:r})}}}(c);else if("vector_layer"===a)if(void 0!==o&&"GEOJSON"!==o){if("MVT"!==o)return _t(c);s=We(c)}else s=Ze(c);else{if("raster_layer"===a)return _t(c);if("basemap_layer"===a)s=async function({webMap:e,item:t}){if(t.basemap_layer){const r=t.basemap_layer.qms,s=t.basemap_layer.url;if(r){const t=JSON.parse(r);return Promise.resolve(mt.utils.createQmsAdapter(e,void 0,{qms:t,baselayer:!0}))}if(s){const t=e.mapAdapter.layerAdapters.TILE;if(t){class e extends t{async addLayer(e){return super.addLayer({...e,url:s})}}return e}}}}(c);else if("GEOJSON"===o){const t=await r.getResource(i.resource.parent.id);if(t){const r={...e,resource:i.resource.parent.id};s=Ze({...c,item:t,layerOptions:r})}}else s=We(c)}else{if(!ft[a])throw`Resource class '${a}' not yet supported.`;{const e=ft[a];let t;t=o&&"function"!=typeof t?e[o]:e,t&&(s=t(c))}}}}if(s)return s.then((e=>{if(e){const t=e;return i&&(t.prototype.item=i,t.prototype.resourceId=i.resource.id,t.prototype.connector=r),O(t,[lt],{replace:!1}),t}}))}function wt(e,t){const{bbox:r,width:s,height:i,nd:o}=e;return{resource:t,extent:r,size:s+","+i,timestamp:Date.now(),nd:o}}const bt={POINT:"point",LINESTRING:"line",POLYGON:"polygon",MULTIPOINT:"point",MULTILINESTRING:"line",MULTIPOLYGON:"polygon",POINTZ:"point",LINESTRINGZ:"line",POLYGONZ:"polygon",MULTIPOINTZ:"point",MULTILINESTRINGZ:"line",MULTIPOLYGONZ:"polygon"};let Lt;class Ot{constructor(e){if(this.options=e,this.options.connector)this.url=this.options.connector.options.baseUrl||"",this.connector=this.options.connector;else{if(!this.options.baseUrl)throw new Error("url is not defined");this.url=this.options.baseUrl,this.connector=new xe({baseUrl:this.url,auth:this.options.auth})}}static addClassAdapters(e,t){ft[e]=t}async onLoadSync(e){if(this.options.resourceId&&this.url){const t=[this.options.resourceId];if(t.length)for(const r of t){const t={resourceId:r,connector:this.connector,webMap:e};return await e.addLayer(ht,{visibility:!0,fit:!0,pixelRadius:this.options.pixelRadius,...t})}}}getLayerAdapters(){return Promise.resolve([this._getLayerAdapter()])}_getLayerAdapter(){return{name:"WEBMAP",createAdapter:e=>Promise.resolve(this._createAdapter(e))}}_createAdapter(e){return t={webMap:e,connector:this.connector,baseUrl:this.url},class extends ht{constructor(e,r){super(e,r={...t,...r})}};var t}}class Et{constructor(e){const t=e.feature;this.id=t.id,this.geom=t.geom,this.label=t.label,this.parent=t.parent,this.fields=t.fields,this.layerId=t.layerId,this.connector=e.connector}identify(e={}){return this._item?L.resolve(this._item):It({connector:this.connector,featureId:this.id,resourceId:this.layerId,fields:null,extensions:["attachment","description"],...e}).then((e=>(this._item=e,this.geom=e.geom,this.extensions=e.extensions,e)))}resource(){return this._resource?L.resolve(this._resource.feature_layer):this.connector.getResource(this.layerId).then((e=>(this._resource=e,this._resource.feature_layer)))}getBounds(){return this._extent?L.resolve(this._extent):function({resourceId:e,featureId:t,connector:r,cache:s=!0}){return r.get("feature_layer.feature.item_extent",{cache:s},{id:e,fid:t}).then((e=>{if(e){const{maxLat:t,maxLon:r,minLat:s,minLon:i}=e.extent;return[i,s,r,t]}}))}({connector:this.connector,featureId:this.id,resourceId:this.layerId})}geojson(){return this._geojson?L.resolve(this._geojson):this.identify().then((e=>e.toGeojson().then((e=>(this._geojson=e,e)))))}}const Ct="webmap-baselayer";function It(e){const t={...Fe};ze(t,e);const r={id:e.resourceId,fid:e.featureId,...t};return e.connector.get("feature_layer.feature.item",{cache:e.cache||!0},r).then((t=>({...t,toGeojson:()=>t.geom?L.resolve(je(t)):It({...e,geom:!0,fields:null,extensions:null}).then((e=>{const r=e.geom;return je({...t,geom:r})}))})))}function Pt(e){return It(e).then((e=>je(e)))}function At(e,t=!1){let r;const s=[],i=[];for(const t in e){const e=Number(t);isNaN(e)||s.push(e)}const o=e.resources;o&&s.sort(((e,t)=>o.indexOf(e)-o.indexOf(t)));for(let o=0;o<s.length;o++){const n=s[o],a=e[n];if("features"in a){const e=a.features,s=Number(n),o=e[0];if(o&&(r={featureId:o.id,resourceId:s,feature:o},i.push(r),!t))break}}return i}function Mt(e,t){I(e);const[r,s]=e.lngLat;let i=[];if(t.geom){const e="Feature"===t.geom.type?t.geom.geometry:"Polygon"===t.geom.type&&t.geom;e&&(i=e.coordinates[0])}i.length||(i=function(e,t,r=10,s=6){const i=r/6371*x,o=i/Math.cos(t*M),n=[];for(let r=0;r<s+1;r++){const a=Math.PI*(r/(s/2)),c=e+o*Math.cos(a),h=t+i*Math.sin(a);n.push([c,h])}return n}(r,s,t.radius));const o=[];i.forEach((([e,t])=>{const[r,s]=k(e,t);o.push(r+" "+s)}));const n=`POLYGON((${o.join(", ")}))`;return t.connector.post("feature_layer.identify",{data:{geom:n,srs:3857,layers:t.layers}})}const xt={brill:'<path d="m6 0-5 6 5 6 5-6z"/>',circle:'<circle cx="6" cy="6" r="6"/>',rect:'<rect width="12" height="12"/>',marker:'<path d="m6 0c-1.85 0-4 1.19-4 4.22 0 2.05 3.08 6.59 4 7.78 0.821-1.19 4-5.62 4-7.78 0-3.03-2.15-4.22-4-4.22z"/>',cross:'<path d="M 2.4,12 6,8.4 9.6,12 12,9.6 8.4,6 12,2.4 9.6,0 6,3.6 2.4,0 0,2.4 3.6,6 0,9.6 Z"/>',star:'<path d="m6 0.25 1.71 4.18 4.29-1.04e-4 -3.43 3.14 0.857 4.18-3.43-3.14-3.43 3.14 0.857-4.18-3.43-3.14 4.29-0.209z"/>',triangle:'<path d="m12 11.7h-12l6-11.2z"/>',plus:'<path d="m7.5 12v-4.5h4.5v-3h-4.5v-4.5h-3v4.5h-4.5v3h4.5v4.5z"/>',minus:'<path d="m12 7.5v-3h-12v3z"/>',asterisk:'<path d="m7.59 12v-3.27l2.83 1.64 1.58-2.74-2.85-1.64 2.83-1.64-1.56-2.74-2.83 1.64v-3.24h-3.17v3.24l-2.85-1.64-1.57 2.74 2.84 1.64-2.84 1.64 1.57 2.74 2.85-1.64v3.27z"/>'};function kt(e,t,r,s){if("number"==typeof t||"string"==typeof t)t=Number(t),e.push({...r,resource:t});else if(Array.isArray(t)){const[i,o]=t;e.push({...r,resource:i,id:o,...s})}else"object"==typeof t&&e.push({...r,...t,...s})}const St={target:"map",baseUrl:"",whitlabel:!1,controls:["ZOOM","ATTRIBUTION"],controlsOptions:{ZOOM:{position:"top-left"},ATTRIBUTION:{position:"bottom-right",customAttribution:['<a href="https://nextgis.com" target="_blank">©NextGIS</a>']}},pixelRadius:10};class Nt extends ue{constructor(e){super(function(e){const t=[new mt];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new xe({baseUrl:e.baseUrl||"",auth:e.auth}),(e=C(St,e)).center||e.bounds||(e.bounds=[-179,-90,180,90],e.maxBounds=e.bounds),e.connector&&t.push(new Ot({connector:e.connector,auth:e.auth})),{...e,starterKits:t,create:!1}}(e)),this.emitter=new t.exports.EventEmitter,this._ngwLayers={},this._promises={select:[],identify:[]},e.connector&&(this.connector=e.connector),this._createWebMap().then((()=>{const e=this.getContainer();e&&e.classList.add("ngw-map-container"),this.options.whitlabel&&this._whiteLabel()}))}async addControl(e,t,r){return await this.onLoad("controls:create"),super.addControl(e,t,r)}async addNgwLayer(e){await this.onMapLoad();const{keyname:t,resourceId:r}=e;(t||void 0!==r)&&console.warn(`DEPRECATED WARN: ${"set `resource` options instead of `keyname` or `resourceId`"}`);const s=e.resource;if(!t&&!r&&!s)throw new Error("resource, resourceId or keyname is required parameter to add NGW layer");if(E(this.options.baseUrl))try{E(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},E(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=function(e,t,r){const s=r.getAuthorizationHeaders();return s&&(e.headers=s),vt(e,t,r)}(e,this,this.connector),r={visibility:!0,...e,...e.adapterOptions},s=await this.addLayer(t,r),i=s&&this.getLayerId(s);if(s&&i&&(this._ngwLayers[i]={layer:s,resourceId:s.resourceId},s.options.name=s.options.name||s.item&&s.item.resource.display_name,s.options.baselayer)){if(this.getActiveBaseLayer())return s}return s}catch(e){const i=B(s)&&"id"in s?s.id:t||r||s;console.error(`Can't add NGW layer ${i}.`,e)}}fit(){const{center:e,zoom:t,bounds:r}=this.options;e?(this.setCenter(e),t&&this.setZoom(t)):r&&this.fitBounds(r)}fetchNgwLayerItem(e){return It({connector:this.connector,...e})}fetchNgwLayerItems(e){return Ue({connector:this.connector,...e})}fetchNgwLayerFeature(e){return Pt({connector:this.connector,...e})}fetchNgwLayerFeatures(e){return Ve({connector:this.connector,...e})}fetchIdentifyItem(e,t){const r=function(e){const{connector:t,identify:r}=e,s=At(r);return s&&s.length?It({connector:t,...e.requestOptions,...s[0]}):L.resolve(void 0)}({identify:e,connector:this.connector,requestOptions:t});return this._addPromise("identify",r),r}fetchIdentifyGeoJson(e,t=!1){const r=function(e){const{connector:t,identify:r}=e;for(const e in r){const t=Number(e);if(!isNaN(t)){const t=r[e];if("features"in t){const e=t.features.find((e=>e.geom));if(e&&e.geom){const t=e.geom;return L.resolve(je({...e,geom:t}))}}}}const s=At(r);return s&&s.length?Pt({connector:t,...s[0]}):L.resolve(void 0)}({identify:e,connector:this.connector,multiple:t});return r&&"then"in r?(this._addPromise("identify",r),r):L.resolve(r)}getIdentifyGeoJson(e,t=!1){return this.fetchIdentifyGeoJson(e,t)}async getNgwLayers(){return await this.onLoad(),this._ngwLayers}async getNgwLayerByResourceId(e){for(const t in this._ngwLayers){const r=this._ngwLayers[t];if(r.resourceId===e)return r&&r.layer;if(r.layer.getIdentificationIds){const t=await r.layer.getIdentificationIds();if(t&&t.some((t=>t===e)))return r.layer}if(r.layer.getDependLayers){const t=r.layer.getDependLayers().find((t=>t.item&&t.item.parentId===e));if(t)return t.layer}}}async fitLayer(e,t){let r;r="string"==typeof e||"number"==typeof e?String(r):e.id;const s=r&&this._ngwLayers[r];if(s)if(s.layer.getBounds){const e=await s.layer.getBounds();e&&this.fitBounds(e,t)}else{let e;if(s.layer.item)e=s.layer.item;else{const t=s.resourceId;e=await this.connector.getResource(t)}e&&Be(e,this.connector).then((e=>{e&&this.fitBounds(e,t)}))}else super.fitLayer(e,t)}async zoomToLayer(e){return this.fitLayer(e)}onLoad(e="ngw-map:create"){return super.onLoad(e)}removeLayer(e){const t=this.getLayer(e);if(t){const e=this.getLayerId(t);e&&delete this._ngwLayers[e],super.removeLayer(t)}}enableSelection(){this.$$selectFromNgwRaster||(this.$$selectFromNgwRaster=e=>{this.emitter.listenerCount("ngw:select")&&this._selectFromNgwRaster(e)},this.$$selectFromNgwVector=e=>{this.emitter.listenerCount("ngw:select")&&this._selectFromNgwVector(e)},this.emitter.on("click",this.$$selectFromNgwRaster),this.emitter.on("layer:click",this.$$selectFromNgwVector))}disableSelection(){this.$$selectFromNgwRaster&&(this.emitter.removeListener("click",this.$$selectFromNgwRaster),this.emitter.removeListener("click",this._selectFromNgwVector),this.$$selectFromNgwRaster=void 0,this.$$selectFromNgwVector=void 0)}getNgwLayerItem(e){return this.fetchNgwLayerItem(e)}getNgwLayerItems(e){return this.fetchNgwLayerItems(e)}getNgwLayerFeature(e){return this.fetchNgwLayerFeature(e)}getNgwLayerFeatures(e){return this.fetchNgwLayerFeatures(e)}cancelPromise(...e){this.cancelPromises(...e)}cancelPromises(...e){e.length||(e=Object.keys(this._promises)),e.forEach((e=>{const t=this._promises[e];t&&(t.forEach((e=>e.cancel())),this._promises[e]=[])}))}_addPromise(e,t){const r=this._promises[e];if(r&&-1===r.indexOf(t)){const e=()=>{const e=r.indexOf(t);-1!==e&&r.splice(e,1)};t.then(e),t.catch(e),r.push(t)}}_isFitFromResource(){const e=this._initMapState;return!e.zoom||!e.center}async _createWebMap(){await this.create(),this.options.qmsId&&this._addQmsBaseLayer(),this.options.osm&&this._addOsmBaseLayer();const e=[],t=this._isFitFromResource();this.options.webmapId&&kt(e,this.options.webmapId,{fit:t}),this.options.resources&&Array.isArray(this.options.resources)&&this.options.resources.forEach((r=>{const s={};t||(s.fit=!1),kt(e,r,{},s)}));for(const t of e)try{await this.addNgwLayer(t)}catch(e){console.log(e)}this._emitStatusEvent("ngw-map:create",this),this.enableSelection()}_addOsmBaseLayer(){this.addBaseLayer("OSM")}_addQmsBaseLayer(){let e,t;Array.isArray(this.options.qmsId)?(e=this.options.qmsId[0],t=this.options.qmsId[1]):e=Number(this.options.qmsId);const r={qmsId:e};t&&(r.id=t),this.addBaseLayer("QMS",r)}_selectFromNgwVector(e){const t=e.layer,r=t.item&&t.item.resource.id,s=e.feature;if(void 0!==r&&s){const e=s.id;if(e){const t={featureCount:1,[r]:{featureCount:1,features:[{id:Number(e),fields:s.properties||{},label:`#${r}`,layerId:Number(r),parent:"",geom:s.geometry}]}};return this._emitStatusEvent("ngw:select",this._prepareToIdentify({...t,resources:[r],sourceType:"vector"})),t}}}async _selectFromNgwRaster(e){this._emitStatusEvent("ngw:preselect");const t=[],r=Object.values(this._ngwLayers);r.sort(((e,t)=>e.layer.order&&t.layer.order?t.layer.order-e.layer.order:1)),r.forEach((e=>{const r=e.layer,s="function"==typeof r.getIdentificationIds&&r.getIdentificationIds;s&&r.options.selectable&&this.isLayerVisible(r)&&t.push(s.call(r))}));const s=Promise.all(t),i=await s,o=[];if(i.forEach((e=>{e&&e.forEach((e=>o.push(e)))})),!o.length)return void this._emitStatusEvent("ngw:select",null);const n=this.options.pixelRadius||10,a=this.getCenter();let c=this.getZoom();if(c=void 0!==c?c:20,!a||!c)return void this._emitStatusEvent("ngw:select",null);const h=function(e,t,r){return(r=null!=r?r:10)*(40075016.686*Math.abs(Math.cos(180*e[1]/Math.PI))/Math.pow(2,t+8))*5e-4}(a,c,n),l=Mt(e,{layers:o,connector:this.connector,radius:h}).then((t=>(this._emitStatusEvent("ngw:select",this._prepareToIdentify({...t,resources:o,sourceType:"raster",event:e})),t)));return this._addPromise("select",l),l}_prepareToIdentify(e){return{...e,getIdentifyItems:()=>At(e,!0).map((e=>new Et({feature:e.feature,connector:this.connector})))}}async _whiteLabel(){const e=this.getContainer();if(e){const t=await async function(e,t){var r;const s=await e.get("pyramid.settings",null,{component:"pyramid"});if(s&&s.company_logo&&s.company_logo.enabled){const i=document.createElement("a");i.style.position="absolute",i.style.bottom="0",i.style.right="0",i.style.padding=null!==(r=null==t?void 0:t.padding)&&void 0!==r?r:"10px",i.className="ngw-map-logo",t&&t.cssClass&&(i.className+=" "+t.cssClass);const o=new Image;o.style.maxHeight="100px",o.style.maxWidth="100px",o.src="";try{const t=await e.get("pyramid.company_logo",{responseType:"blob"}),r=(window.URL||window.webkitURL).createObjectURL(t);o.src=r}catch(e){console.log(e)}return null!==s.company_logo.link&&""!==s.company_logo.link.trim()&&(i.href=s.company_logo.link,i.target="_blank",-1!==s.company_logo.link.search(/:\/\/nextgis/)&&(o.alt="Get your own Web GIS at nextgis.com")),i.appendChild(o),i}}(this.connector,this.options.companyLogoOptions);t&&e.appendChild(t)}}}async function Tt(e){return new Nt(e).onLoad()}Nt.getIcon=function(e={}){const t=e.color||"blue",r=e.strokeColor||"white",s=e.size||12,i=s/2,o="number"==typeof e.stroke?e.stroke:.8,n=s/12,a=xt[e.shape||"circle"]||"circle",c=function(e,t,r=0,s){const i=r/2,o=`<svg\n version="1.1"\n xmlns="http://www.w3.org/2000/svg"\n width="${e}"\n height="${t}"\n viewBox="-${i} -${i} ${e+r} ${t+r}"\n >${s}</svg>`;return(new DOMParser).parseFromString(o,"image/svg+xml").documentElement}(s,s,o*n,"string"==typeof a?a:a(e)),h=c.firstChild,l=`scale(${n})`;return h.setAttribute("fill",t),o&&(h.setAttribute("stroke",r),h.setAttribute("stroke-width",String(o))),h.setAttribute("transform",l),{type:"icon",iconSize:[s,s],iconAnchor:[i,i],html:(new XMLSerializer).serializeToString(c),svg:c}};export{Nt as NgwMap,ue as WebMap,he as WebMapControls,ae as WebMapLayers,ne as WebMapMain,Tt as createNgwMap,ce as createToggleControl,de as createWebMap,Q as detectGeometryType,J as findMostFrequentGeomType,pe as getWebMap,X as updateGeoJsonAdapterOptions};
|
|
1
|
+
var e,t={exports:{}},r="object"==typeof Reflect?Reflect:null,s=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}t.exports=o,t.exports.once=function(e,t){return new Promise((function(r,s){function i(r){e.removeListener(t,o),s(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}m(e,t,o,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&m(e,"error",t,r)}(e,i,{once:!0})}))},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var n=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function h(e,t,r,s){var i,o,n,h;if(a(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),n=o[t]),void 0===n)n=o[t]=r,++e._eventsCount;else if("function"==typeof n?n=o[t]=s?[r,n]:[n,r]:s?n.unshift(r):n.push(r),(i=c(e))>0&&n.length>i&&!n.warned){n.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+n.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=n.length,h=l,console&&console.warn&&console.warn(h)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,r){var s={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=l.bind(s);return i.listener=r,s.wrapFn=i,i}function u(e,t,r){var s=e._events;if(void 0===s)return[];var i=s[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):y(i,i.length)}function d(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function y(e,t){for(var r=new Array(t),s=0;s<t;++s)r[s]=e[s];return r}function m(e,t,r,s){if("function"==typeof e.on)s.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(o){s.once&&e.removeEventListener(t,i),r(o)}))}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return n},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");n=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var n;if(t.length>0&&(n=t[0]),n instanceof Error)throw n;var a=new Error("Unhandled error."+(n?" ("+n.message+")":""));throw a.context=n,a}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)s(c,this,t);else{var h=c.length,l=y(c,h);for(r=0;r<h;++r)s(l[r],this,t)}return!0},o.prototype.on=o.prototype.addListener=function(e,t){return h(this,e,t,!1)},o.prototype.prependListener=function(e,t){return h(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,p(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,p(this,e,t)),this},o.prototype.off=o.prototype.removeListener=function(e,t){var r,s,i,o,n;if(a(t),void 0===(s=this._events))return this;if(void 0===(r=s[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){n=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(s[e]=r[0]),void 0!==s.removeListener&&this.emit("removeListener",e,n||t)}return this},o.prototype.removeAllListeners=function(e){var t,r,s;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,o=Object.keys(r);for(s=0;s<o.length;++s)"removeListener"!==(i=o[s])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this},o.prototype.listeners=function(e){return u(this,e,!0)},o.prototype.rawListeners=function(e){return u(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},o.prototype.listenerCount=d,o.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]};class f extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,f.prototype)}}class g{constructor(e={}){this.options=e,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(e){this._promises.has(e)&&(this._promises.delete(e),this._onStop())}get(e){return this._promises.get(e)}add(e,t){const r=t||e,s=this._promises.get(r);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),s||(this._promises.set(r,e),e.finally((()=>{this.remove(r)})),e)}abort(){this.isLoaded&&(this._promises.forEach((e=>{e.cancel&&e.cancel()})),this._promises.clear(),this._onStop())}waitFunc(e,t=""){const r=this.get(t=t||e.name);return r||this.add(e(),t)}WaitForMe(e=""){const t=this.get.bind(this),r=this.add.bind(this);return function(s,i,o){const n=o.value;return e=e||i,o.value=function(...s){const i=t(e);if(i)return i;return r(n.apply(this,s),e)},o}}GetOrCreateDecorator(e=""){return this.WaitForMe(e)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}class _ extends Error{constructor(){super(),this.name="TimeoutError",Object.setPrototypeOf(this,_.prototype)}}const v=(e,t,r,s)=>{try{e(r(s))}catch(e){t(e)}};let w=0;class b{constructor(e,t){this.id=w++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise(((e,t)=>{this._setCanceledCallback=t=>e(t||new f)}));const r=[this._cancelPromise,new Promise(((t,r)=>e((e=>{e instanceof b?this.attach(e):this._isPending=!1,t(e)}),(e=>{this._isPending=!1,r(e)}),(e=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(e)}))))];t&&r.push(new Promise(((e,r)=>{setTimeout((()=>{if(this._isPending)try{this.cancel()}finally{r(new _)}}),t)}))),this._promise=Promise.race(r)}static createControl(e){return new g(e)}static resolve(e){return new b((t=>t(e)))}static reject(e){return new b(((t,r)=>r(e)))}static all(e){return new b(((t,r)=>{Promise.all(e).then(t).catch(r)})).catch((t=>{if(t instanceof this.CancelError)for(const t of e)"cancel"in t&&t.cancel();throw t}))}attach(e){this._isCanceled?e.cancel():this._children.push(e)}then(e,t){const r=new b(((r,s)=>{if(this._promise){const i=e=>{t?v(r,s,t,e):s(e)};this._promise.then((t=>{this._isCanceled?i(t):e?v(r,s,e,t):r(t)}),i)}}));return r._parentPromise=this,this._children.push(r),r}catch(e){return this._isCanceled&&e&&e(new f),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new f:e)}cancel(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;const e=this._getTopParent();if(e&&e.cancel(),this._children&&this._children.forEach((e=>e.cancel())),this._isPending){if(this._cancelHandlers.length)try{for(const e of this._cancelHandlers)e()}catch(e){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let e=this._parentPromise,t=!!e;for(;t;)e&&e._parentPromise?(e=e._parentPromise,t=!!e):t=!1;return e}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}b.CancelError=f,b.TimeoutError=_,b.PromiseControl=g,Object.setPrototypeOf(b.prototype,Promise.prototype);var L=b;function O(e,t,r={}){const s=function(e,t=[]){for(;null!==e;e=Object.getPrototypeOf(e)){const r=Object.getOwnPropertyNames(e);for(let e=0;e<r.length;e++)-1==t.indexOf(r[e])&&t.push(r[e])}return t}(e.prototype);const i=void 0===r.replace||r.replace;t.forEach((t=>{Object.getOwnPropertyNames(t.prototype).forEach((r=>{const o=-1!==s.indexOf(r);if(!i&&!o||i){const s=Object.getOwnPropertyDescriptor(t.prototype,r);s&&Object.defineProperty(e.prototype,r,s)}}))}))}function E(e){return null!=e}function C(e,t,r=!1){let s=e;const i=t,o=Array.isArray(i);let n=o&&[]||{};return o&&Array.isArray(i)?r?(s=s||[],n=n.concat(s),i.forEach(((e,t)=>{void 0===n[t]?n[t]=e:"object"==typeof e?n[t]=C(s[t],e,r):-1===s.indexOf(e)&&n.push(e)}))):n=i:(s&&"object"==typeof s&&Object.keys(s).forEach((function(e){n[e]=s[e]})),Object.keys(i).forEach((function(e){n[e]="object"==typeof i[e]&&i[e]&&"object"==typeof s[e]&&"object"==typeof i[e]?C(s[e],i[e],r):i[e]}))),n}function I(e){if(!e.lngLat&&e.latLng){e.lngLat=[e.latLng.lng,e.latLng.lat]}return e}function P(e){return{type:"Polygon",coordinates:[A(e)]}}function A(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}const M=Math.PI/180,x=180/Math.PI;function k(e,t){t=t>85.06?85.06:t<-85.06?-85.06:t;const r=20037508.34*e/180;let s=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return s=20037508.34*s/180,[r,s]}function S(e,t,r,s){if(e instanceof Array)return t instanceof Array&&t.sort().join("")===e.sort().join("");if(e instanceof Date)return t instanceof Date&&""+e==""+t;if(e instanceof Function){if(!(t instanceof Function))return!1}else if(e instanceof Object)return t instanceof Object&&(e===r?t===s:N(e,t));return e===t}function N(e,t){const r=Object.keys(e).sort(),s=Object.keys(t).sort();if(r.length!==s.length)return!1;if(r.join("")!==s.join(""))return!1;for(let i=0;i<r.length;i++){if(!S(e[r[i]],t[s[i]],e,t))return!1}return!0}function T(e){const t={};return Object.keys(e).forEach((r=>{e[r]instanceof Array||e[r]!==Object(e[r])?void 0!==e[r]&&(t[r]=e[r]):t[r]=T(e[r])})),t}function B(e){return"[object Object]"===Object.prototype.toString.call(e)}function R(e){return e.replace(/([^:]\/)\/+/g,"$1")}function F(e){return"function"==typeof e}const j={get:function(e,t){return e.properties&&e.properties[t[0]]},match:function(e,t){const[r,...s]=t;let i=r;Array.isArray(r)&&(i=z(e,r));const o=s.splice(-1,s.length%2)[0];for(let e=0;e<s.length-1;e+=2){if(s[e]===i)return s[e+1]}return o}};function z(e,t){const[r,...s]=t,i=j[r];if(i)return i(e,s)}function D(e){return t=>z(t,e)}const $=["iconSize","iconAnchor"];function G(e,t,r){if((t=String(t))===(e=String(e)))return!0;if(r&&t.toUpperCase()===e.toUpperCase())return!0;const s=`^${i=t,i.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}$`.replace(/%/g,".*").replace("_",".");var i;return null!==new RegExp(s,r?"i":"").exec(e)}const U={gt:(e,t)=>e>t,lt:(e,t)=>e<t,ge:(e,t)=>e>=t,le:(e,t)=>e<=t,eq:(e,t)=>e===t,ne:(e,t)=>e!==t,in:(e,t)=>-1!==t.indexOf(e),notin:(e,t)=>-1===t.indexOf(e),like:(e,t)=>G(e,t),ilike:(e,t)=>G(e,t,!0)};function V(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function Z(e){return V(e)}function q(e,t){const r="string"==typeof t[0]?t[0]:"all",s=t=>{if(V(t)){const[r,s,i]=t,o=U[s];if(o){if(("like"===s||"ilike"===s)&&"string"==typeof r){let t="";const s=r.replace(/^%?(\w+)%?$/,((s,o)=>(t=e[o],r.replace(o,i))));return o(t,s)}return o(e[r],i)}return!1}return q(e,t)},i=t.filter((e=>Array.isArray(e)));return"any"===r?i.some(s):i.every(s)}function W(e){let t={};const r=[];return e.forEach((e=>{e&&(Array.isArray(e)?r.push(e):t=e)})),e=>{const s=r.find((t=>function(e,t){const r={...e.properties};return!!r&&(r.$id=e.id,q(r,t))}(e,t[0])));return s?{...t,...s[1]}:t}}function H(e,t,r){if(!e)throw new Error("paint is empty");let s={...t};if(F(e)){const s=s=>{const i=H(e(s),t,r);return i.type=e.type,i};return s.type=e.type,s}if(function(e){return!!Array.isArray(e)}(e))return s=>H(W(e)(s),t,r);if("get-paint"===e.type){const i=function(e,t){if("function"==typeof e.from)return e.from(e.options);if("string"==typeof e.from&&t){const r=t[e.from];if(r)return r(e.options)}}(e,r);i&&(s=H(i,t,r))}else{if("icon"===e.type)return e;{const i=function(e){let t=!1;const r={};for(const s in e)if(-1===$.indexOf(s)){const i=s,o=e[i];Array.isArray(o)&&(t=!0,r[i]=D(o))}if(t)return t=>{const s={};for(const e in r)s[e]=r[e](t);return{...e,...s}}}(e);if(i)return e=>H(i(e),t,r);s={...s,...e},s.fill=void 0===s.fill||s.fill,s.stroke=void 0!==s.stroke?s.stroke:!s.fill||!(!s.strokeColor&&!s.strokeOpacity)}}return F(s)||("color"in s&&(s.strokeColor||(s.strokeColor=s.color),s.fillColor||(s.fillColor=s.color)),"opacity"in s&&(void 0===s.strokeOpacity&&(s.strokeOpacity=s.opacity),void 0===s.fillOpacity&&(s.fillOpacity=s.opacity))),s}function J(e){const t={};for(let r=0;r<e.length;r++)t[e[r]]=1+(t[e[r]]||0);let r;for(const e in t){t[e]>((void 0!==r?t[r]:0)||0)&&(r=e)}return r}function Q(e){let t;if("FeatureCollection"===e.type){t=J(e.features.map((e=>e.geometry.type)))}else if("GeometryCollection"===e.type){t=J(e.geometries.map((e=>e.type)))}else t="Feature"===e.type?e.geometry.type:e.type;return t}const K={polygon:"path",line:"path",point:"circle"},Y={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon"};function X(e){if(e.data){const t=Y[Q(e.data)],r=e.paint;r&&"[object Object]"===Object.prototype.toString.call(r)&&(r.type=r.type?r.type:"polygon"===t||"line"===t?"path":"html"in r||"className"in r?"icon":K[t]),e.type=e.type||t}return e}class ee{constructor(){this.backspace=8,this.tab=9,this.enter=13,this.shift=16,this.ctrl=17,this.alt=18,this["pause/break"]=19,this.caps_lock=20,this.escape=27,this.page_up=33,this.page_down=34,this.end=35,this.home=36,this.left_arrow=37,this.up_arrow=38,this.right_arrow=39,this.down_arrow=40,this.insert=45,this.delete=46,this.left_window_key=91,this.right_window_key=92,this.select_key=93,this.numpad_0=96,this.numpad_1=97,this.numpad_2=98,this.numpad_3=99,this.numpad_4=100,this.numpad_5=101,this.numpad_6=102,this.numpad_7=103,this.numpad_8=104,this.numpad_9=105,this.multiply=106,this.add=107,this.subtract=109,this.decimal_point=110,this.divide=111,this.f1=112,this.f2=113,this.f3=114,this.f4=115,this.f5=116,this.f6=117,this.f7=118,this.f8=119,this.f9=120,this.f10=121,this.f11=122,this.f12=123,this.num_lock=144,this.scroll_lock=145,this["semi-colon"]=186,this.equal_sign=187,this[","]=188,this["-"]=189,this["."]=190,this["/"]=191,this["`"]=192,this["["]=219,this["\\"]=220,this["]"]=221,this["'"]=222}}class te{constructor(e,t){this.webMap=e,t&&(t.value&&this.setValue(t.value),t.name&&(this.name=t.name),t.event&&(this.event=t.event))}getValue(){return this.value}setValue(e){this.value=e}}class re extends te{constructor(){super(...arguments),this.name="center",this.event="moveend"}getValue(){return this.webMap.getCenter()}setValue(e){this.webMap.setCenter(e)}toString(e){const t=e.map((e=>e.toFixed(5)));return t[0]+"_"+t[1]}parse(e){return e.split("_").map(Number)}}class se extends te{constructor(){super(...arguments),this.name="zoom",this.event="zoomend"}getValue(){const e=this.webMap.getZoom();return void 0!==e?Math.round(e):void 0}setValue(e){this.webMap.setZoom(e)}toString(e){return String(e)}parse(e){return Number(e)}}let ie=0;const oe={minZoom:0,maxZoom:20,paint:{color:"blue",opacity:.4,strokeOpacity:1,stroke:!0,radius:8,weight:1},selectedPaint:{color:"darkblue",opacity:.4,strokeOpacity:1,stroke:!0,radius:12,weight:1},create:!0};class ne{constructor(e){this.options=oe,this.emitter=new t.exports.EventEmitter,this.keys=ne.keys,this.runtimeParams=[],this.getPaintFunctions=ne.getPaintFunctions,this.mapState=[re,se],this.id=ie++,this._initMapState={},this._mapState=[],this._eventsStatus={},this._mapEvents={},this.mapAdapter=e.mapAdapter,this._starterKits=e.starterKits||[],e&&(this.options=C(oe||{},e)),this.options.runtimeParams&&(this.runtimeParams=this.options.runtimeParams),this._addEventsListeners(),this.options.tileJson&&this._setTileJsonOptions(this.options.tileJson),this.options.create&&this.create()}getId(){return this.id}async create(){return this.getEventStatus("create")||(await this._setInitMapState(this.mapState),await this._setupMap(),this._emitStatusEvent("create",this)),this}setRuntimeParams(e){this.runtimeParams.push(e)}destroy(){this._removeEventListeners(),function(e){for(const t in e)delete e[t]}(this._emitStatusEvent),this.mapAdapter.destroy&&this.mapAdapter.destroy()}getState(){const e={};return this._mapState.forEach((t=>{e[t.name]=t.getValue()})),e}getRuntimeParams(){const e={};return this._mapState.forEach((t=>{for(const r of this.runtimeParams){const s=r.get(t.name);if(void 0!==s){e[t.name]=t.parse(s);break}}})),e}getContainer(){if(this.mapAdapter.getContainer)return this.mapAdapter.getContainer();if(this.options.target){if(this.options.target instanceof HTMLElement)return this.options.target;if("string"==typeof this.options.target){const e=document.getElementById(this.options.target);if(e)return e}}}setCursor(e){this.mapAdapter.setCursor&&this.mapAdapter.setCursor(e)}getCursor(){if(this.mapAdapter.getCursor)return this.mapAdapter.getCursor();const e=this.getContainer();return e?e.style.cursor:void 0}setCenter(e){return this.mapAdapter.setCenter(e),this}getCenter(){return this.mapAdapter.getCenter()}getBounds(){if(this.mapAdapter.getBounds)return this.mapAdapter.getBounds()}getBoundsPolygon(){const e=this.getBounds();if(e){return{type:"Feature",properties:{},geometry:P(e)}}}setZoom(e){return this.mapAdapter.setZoom(e),this}getZoom(){return this.mapAdapter.getZoom()}zoomIn(){if(this.mapAdapter.zoomIn)this.mapAdapter.zoomIn();else{const e=this.getZoom();if(e){this.setZoom(e+1)}}}zoomOut(){if(this.mapAdapter.zoomOut)this.mapAdapter.zoomOut();else{const e=this.getZoom();if(e){this.setZoom(e-1)}}}setView(e,t){this.mapAdapter.setView&&e&&E(t)?this.mapAdapter.setView(e,t):(e&&this.mapAdapter.setCenter(e),E(t)&&this.mapAdapter.setZoom(t))}fitBounds(e,t){return e.every((e=>E(e)))&&(e[1]<-85.06&&(e[1]=-85.06),e[3]>85.06&&(e[3]=85.06),this.mapAdapter.fitBounds(e,t)),this}getEventStatus(e){const t=this._eventsStatus[e];return null!=t&&t}onLoad(e="create"){return new Promise((t=>{this.getEventStatus(e)?t(this):this.emitter.once(e,(()=>{t(this)}))}))}onMapLoad(e){return new Promise((t=>{var r;const s=()=>{const r=this.mapAdapter;e&&e(r),r&&t(r)},i=null===(r=this.mapAdapter.isLoaded)||void 0===r||r;this.mapAdapter.map&&i?s():this.mapAdapter.emitter.once("create",(()=>{s()}))}))}getLayerAdapters(){return this.mapAdapter.layerAdapters}getLayerAdapter(e){return this.mapAdapter.layerAdapters[e]}locate(e,t){if(this.mapAdapter&&this.mapAdapter.locate)return this.mapAdapter.locate(e,t);return{stop:()=>({})}}stopGetCoordFromMapClick(){this._coordFromMapClickPromise&&this._coordFromMapClickPromise.cancel()}getCoordFromMapClick(){return this._coordFromMapClickPromise?this.getCoordFromMapClick():(this._coordFromMapClickPromise=new L(((e,t,r)=>{const s=this.getCursor()||"grab";this._removeEventListeners({include:["click"]}),this.setCursor("crosshair");const i=()=>{this.setCursor(s),this._addEventsListeners({include:["click"]}),this.mapAdapter.emitter.off("click",o),this._coordFromMapClickPromise=void 0},o=t=>{i(),I(t),e(t.lngLat)};this.mapAdapter.emitter.once("click",o),r(i)})),this._coordFromMapClickPromise)}_emitStatusEvent(e,t){const r=e;this._eventsStatus[r]=!0,this.emitter.emit(r,t)}async _addLayerProviders(){}async _onLoadSync(){}async _setupMap(){if(!this.mapAdapter)throw new Error("WebMap `mapAdapter` option is not set");return await this.mapAdapter.create(this.options),this._zoomToInitialExtent(),await this._addLayerProviders(),await this._onLoadSync(),this._emitStatusEvent("build-map",this.mapAdapter),this}_setTileJsonOptions(e){e.center&&(this.options.center=e.center),e.bounds&&(this.options.bounds=e.bounds),E(e.maxzoom)&&(this.options.maxZoom=e.maxzoom,this.options.zoom=e.maxzoom),E(e.minzoom)&&(this.options.minZoom=e.minzoom,this.options.zoom=e.minzoom),E(e.maxzoom)&&E(e.minzoom)&&(this.options.zoom=(e.maxzoom+e.minzoom)/2)}_zoomToInitialExtent(){const{center:e,zoom:t,bounds:r}=this.options;this._extent?this.fitBounds(this._extent):e&&t?this.setView(e,t):r&&this.fitBounds(r)}_setInitMapState(e){for(const t of e){const e=new t(this);this._mapState.push(e);for(const t of this.runtimeParams){const r=t.get(e.name);if(void 0!==r){const t=e.parse(r);this._initMapState[e.name]=t,Object.defineProperty(this.options,e.name,{value:t,configurable:!0,enumerable:!0});break}}}}_addEventsListeners(e){let t=["preclick","click","zoomstart","zoom","zoomend","movestart","move","moveend"];e&&e.include&&(t=t.filter((t=>e.include.includes(t)))),t.forEach((e=>{this._mapEvents[e]=t=>{if(this.runtimeParams.length){const t=this._mapState.find((t=>t.event===e));if(t){const e=t.toString(t.getValue());this.runtimeParams.forEach((r=>{r.set(t.name,e)}))}}this._eventsStatus&&this.emitter.emit(e,t)};const t=this._mapEvents[e];t&&this.mapAdapter.emitter.on(e,t)}))}_removeEventListeners(e){let t=Object.entries(this._mapEvents);e&&e.include&&(t=t.filter((t=>e.include.includes(t[0])))),t.forEach((([e,t])=>{t&&this.mapAdapter.emitter.removeListener(e,t)}))}}ne.keys=new class{constructor(){this.keyCodeAlias=new ee,this.keys={},this._windowOnFocus=this.windowOnFocus.bind(this),this._keysPressed=this.keysPressed.bind(this),this._keysReleased=this.keysReleased.bind(this),this.addKeyboardEventsListener()}pressed(e){const t=this.keyCodeAlias[e];return!!t&&this.keys[t]}addKeyboardEventsListener(){"undefined"!=typeof window&&(window.addEventListener("focus",this._windowOnFocus,!1),window.addEventListener("keydown",this._keysPressed,!1),window.addEventListener("keyup",this._keysReleased,!1))}removeKeyboardEventsListener(){"undefined"!=typeof window&&(window.removeEventListener("focus",this._windowOnFocus,!1),window.removeEventListener("keydown",this._keysPressed,!1),window.removeEventListener("keyup",this._keysReleased,!1))}keysPressed(e){e.stopPropagation(),this.keys[e.keyCode]||(this.keys[e.keyCode]=!0)}keysReleased(e){e.stopPropagation(),this.keys[e.keyCode]=!1}windowOnFocus(){this.keys={}}};class ae extends ne{constructor(e){super(e),this._layersIdCounter=1,this._layersOrderCounter=1,this._baselayers=[],this._layers={},this._selectedLayers=[];const t=this.options.tileJson;t&&this.emitter.once("build-map",(()=>this.addTileJsonLayer(t)))}async fitLayer(e,t){const r=this.getLayer(e),s=r&&(r.getBounds||r.getExtent);if(s){const e=await s.call(r);e&&this.fitBounds(e,t)}}isBaseLayer(e){const t=this.getLayer(e);if(t&&t.id)return-1!==this._baselayers.indexOf(t.id)}getBaseLayers(){const e=[];return this._baselayers.forEach((t=>{const r=this._layers[t];r&&e.push(r)})),e}getBaseLayersIds(){return this._baselayers}getLayer(e){return"string"==typeof e?this._layers[e]:e}getLayerId(e){const t=this.getLayer(e);if(t&&t.options)return t.options.id;throw new Error("No id for layer")}getLayers(){return Object.keys(this._layers)}allLayers(){return this._layers}orderedLayers(){return Object.values(this._layers).sort(((e,t)=>e.order&&t.order?e.order-t.order:0))}findLayer(e){for(const t in this._layers){const r=this._layers[t];if(e(r))return r}}isLayerVisible(e){const t=this.getLayer(e);return!(!t||void 0===t.options.visibility)&&t.options.visibility}async addBaseLayer(e,t){return await this.addLayer(e,{...t,baselayer:!0},void 0)}async addLayer(e,t={},r){var s,i;const o=this._layersIdCounter++,n=E(r)?r:void 0!==t.order?t.order:this.reserveOrder();let a;"string"==typeof e?a=this.getLayerAdapter(e):"function"==typeof e?a=e:"then"in e&&(a=await e);const c=t;this._updateGeoJsonOptions(c);const{maxZoom:h,minZoom:l}=this.options,p=null===(s=(t={id:String(o),order:n,maxZoom:h,minZoom:l,...t}).visibility)||void 0===s||s;if(t.visibility=!1,t.baselayer&&(t.order=0),this.options.onBeforeAddLayer){const e=this.options.onBeforeAddLayer({options:t,adapter:a});e&&(e.options&&(t=e.options),e.adapter&&(a=e.adapter))}if(void 0!==a){const e=new a(this.mapAdapter.map,t);let r;e.options={...t,...e.options},e.options.baselayer&&(t.baselayer=!0,t.order=0,e.options.order=0),e.options.id&&(r=String(e.options.id),this._layers[r]=e),this._emitLayerEvent("layer:preadd",r||"",e),await this.onMapLoad(),e.map=this.mapAdapter.map;const s=await e.addLayer(e.options);if(e.layer=s,e.id=e.options.id||String(o),e.options.id=e.id,t.baselayer&&(e.options.order=0),e.order=null!==(i=e.options.order)&&void 0!==i?i:n,r&&delete this._layers[r],r=String(e.id),this._layers[r])throw Error(`layer with id '${r}' already exist`);r&&(this._layers[r]=e,c.filter&&this.filterLayer(e,c.filter),t.baselayer&&this._baselayers.push(r),p&&await this.showLayer(r));const h=t.opacity;void 0!==h&&h<=1&&this.setLayerOpacity(e,h);const l=s&&(e.getBounds||e.getExtent);if(t.fit&&l){const t=await l.call(e);t&&await this.fitBounds(t)}return this._emitLayerEvent("layer:add",r,e),e}return Promise.reject("No adapter")}async addLayerFromAsyncAdapter(e,t,r){const s=r||void 0!==t.order?t.order:this.reserveOrder(),i=e(),o=await i;return o?this.addLayer(o,t,s):Promise.reject("No adapter")}removeLayers(e){for(const t in this._layers){let r=!0;e&&(r=e(t,this._layers[t])),r&&(this.removeLayer(t),delete this._layers[t])}}reserveOrder(){return this._layersOrderCounter++}removeOverlays(){this.removeLayers(((e,t)=>!(t&&t.options&&t.options.baselayer)))}removeLayer(e){const t=this.getLayer(e),r=t&&this.getLayerId(t);if(t&&r){if(this.emitter.emit("layer:preremove",t),t.beforeRemove&&t.beforeRemove(),t.removeLayer?t.removeLayer():this.mapAdapter.removeLayer(t.layer),t.options&&t.options.baselayer){const e=this._baselayers.indexOf(r);e&&this._baselayers.splice(e,1)}delete this._layers[r],this.emitter.emit("layer:remove",t)}}addGeoJsonLayer(e={},t){return(e=e||{}).multiselect=void 0!==e.multiselect&&e.multiselect,e.unselectOnSecondClick=void 0===e.unselectOnSecondClick||e.unselectOnSecondClick,t||(e=X(e)),e.paint=e.paint||{},this.addLayer(t||"GEOJSON",e)}addFeatureLayer(e={}){return this.addGeoJsonLayer(e)}addTileLayer(e,t){return this.addLayer("TILE",{...t,url:e})}addImageLayer(e,t){return this.addLayer("IMAGE",{...t,url:e})}showLayer(e,t={}){return this.toggleLayer(e,!0,t)}hideLayer(e,t={}){return this.toggleLayer(e,!1,t)}toggleLayer(e,t,r={}){const s=this.getLayer(e),i=void 0!==t?t:!(s&&s.options.visibility),o=void 0!==r.silent&&r.silent,n=async e=>{const t=String(e.id),r=i?"layer:show":"layer:hide";if(o||(this._emitLayerEvent(i?"layer:preshow":"layer:prehide",t,e),this._emitLayerEvent("layer:pretoggle",t,e)),i&&this.mapAdapter){const t=e.options.baselayer?0:e.options.order;if(e.options.baselayer&&this._baselayers.length){const t=this._baselayers.filter((t=>t!==e.id&&this.isLayerVisible(t)));for(const e of t)await this.hideLayer(e)}e.showLayer?e.showLayer.call(e,e.layer):void 0!==e.layer&&this.mapAdapter.showLayer(e.layer),void 0!==t&&this.mapAdapter.setLayerOrder(e.layer,t,this._layers)}else e.hideLayer?e.hideLayer.call(e,e.layer):void 0!==e.layer&&this.mapAdapter.hideLayer(e.layer);o||(this._emitLayerEvent(r,t,e),this._emitLayerEvent("layer:toggle",t,e)),e.options.visibility=i};return s&&s.options.visibility!==i?this.onMapLoad().then((()=>n(s))):Promise.resolve()}updateLayer(e){const t=this.getLayer(e);if(t){if(t.updateLayer)return Promise.resolve(t.updateLayer());if(this.isLayerVisible(t))return this.hideLayer(t,{silent:!0}).then((()=>this.showLayer(t,{silent:!0})))}return Promise.resolve()}setLayerOpacity(e,t){const r=this.getLayer(e);r&&(r.setOpacity?r.setOpacity(t):this.mapAdapter.setLayerOpacity&&this.mapAdapter.setLayerOpacity(r.layer,t))}selectLayer(e,t){const r=this.getLayer(e);if(r){const e=r;e&&e.select&&e.select(t);const s=this.getLayerId(r);s&&this._selectedLayers.push(s)}}unSelectLayer(e,t){const r=this.getLayer(e);if(r){const e=r&&r;e.unselect&&e.unselect(t);const s=this.getLayerId(r);if(s){const e=this._selectedLayers.indexOf(s);-1!==e&&this._selectedLayers.splice(e,1)}}}unSelectLayers(){const e=Object.values(this.allLayers());let t;for(t of e)t.unselect&&t.unselect()}filterLayer(e,t){const r=this.getLayer(e);return r.filter?r.filter(t):[]}propertiesFilter(e,t,r){const s=this.getLayer(e);if(!s)return;const i=s;i.propertiesFilter?i.propertiesFilter(t,r):i.filter&&this.filterLayer(i,(e=>!e.feature||!e.feature.properties||q(e.feature.properties,t)))}removeLayerFilter(e){const t=this.getLayer(e);t.removeFilter?t.removeFilter():t.filter&&t.filter((()=>!0))}setLayerData(e,t){const r=this.getLayer(e);if(r){if(r.setData)return r.setData(t);if(r.clearLayer&&r.addData)return r.clearLayer(),r.addData(t)}return Promise.resolve()}addLayerData(e,t){const r=this.getLayer(e);r.addData&&r.addData(t)}clearLayerData(e,t){const r=this.getLayer(e);r&&r.clearLayer&&r.clearLayer(t)}getAttributions(e){const t=[];for(const r in this._layers){const s=this._layers[r];let i=!(void 0===e.onlyVisible||e.onlyVisible)||s.options.visibility;if(i&&e.onlyBaselayer&&(i=this._baselayers.includes(r)),i){const e=s.options&&s.options.attribution;e&&t.push(e)}}return t}getActiveBaseLayer(){const e=this.getBaseLayers().find((e=>this.isLayerVisible(e)));if(e)return this.getLayer(e)}addTileJsonLayer(e){return this.addLayer("TILE",{url:e.tiles[0],maxZoom:e.maxzoom,minZoom:e.minzoom,subdomains:e.scheme,attribution:e.attribution})}async _onLayerClick(e){return this._emitLayerEvent("layer:click",e.layer.id||"",e),Promise.resolve(e)}async _onLayerSelect(e){return this._emitLayerEvent("layer:select",e.layer.id||"",e),Promise.resolve(e)}_updateGeoJsonOptions(e){const{onSelect:t,onLayerSelect:r,onClick:s,onLayerClick:i,onMouseOut:o,onMouseOver:n}=e,a=s||i;e.onClick=e=>(a&&a(e),this._onLayerClick(e)),e.onMouseOut=e=>{const t=e.layer.id;o&&o(e),E(t)&&this._emitLayerEvent("layer:mouseout",t,e)},e.onMouseOver=e=>{const t=e.layer.id;n&&n(e),E(t)&&this._emitLayerEvent("layer:mouseover",t,e)};const c=t||r;e.onSelect=e=>(c&&c(e),this._onLayerSelect(e)),e.nativePaint||(this.options.paint&&(e.paint=H(e.paint||{},this.options.paint,this.getPaintFunctions)),e.selectedPaint&&this.options.selectedPaint&&(e.selectedPaint=H(e.selectedPaint,this.options.selectedPaint,this.getPaintFunctions)))}_emitLayerEvent(e,t,r){if(E(t)&&e.startsWith("layer:")){const s=e.replace("layer:","layer-"+t+":");this.emitter.emit(s,r)}this.emitter.emit(e,r)}}function ce(e,t){const r=document.createElement("div");let s=!1;t.getStatus?s=t.getStatus():t.status&&(s=t.status);const i=t.title||"",o=t.html;function n(){i&&(r.title="string"==typeof i?i:s?i.on:i.off,r.setAttribute("aria-label",r.title))}function a(e){e instanceof HTMLElement?(r.innerHTML="",r.appendChild(e)):"string"==typeof e&&(r.innerHTML=e)}function c(){o&&("string"==typeof o||o instanceof HTMLElement?a(o):a(s?o.on:o.off),r.setAttribute("aria-label",r.title))}function h(e,t){e.split(" ").forEach((e=>{t?r.classList.add(e):r.classList.remove(e)}))}function l(){t.addClassOn&&h(t.addClassOn,s),t.addClassOff&&h(t.addClassOff,!s)}n(),c(),t.addClass&&h(t.addClass,!0),l();const p=e=>{void 0!==e&&(s=e),c(),n(),l()},u=e=>{if(s=void 0!==e?e:!s,t.onClick){const e=t.onClick(s);Promise.resolve(e).then((()=>p())).catch((()=>s=!s))}else p()},d=e({html:r,onClick:u});return d.onClick=u,d.changeStatus=p,d}class he extends ae{constructor(){super(...arguments),this._loadControlQueue={"top-right":[],"bottom-right":[],"top-left":[],"bottom-left":[]},this._isControlLoading={"top-right":!1,"bottom-right":!1,"top-left":!1,"bottom-left":!1}}async addControl(e,t,r){let s;if(t=null!=t?t:"top-left",s="string"==typeof e?this.getControl(e,r):e,s)return new Promise((e=>{this._setControlQueue(t,(async()=>{const r=await s,i=this.mapAdapter.addControl(r,t);e(i)}))}))}async createControl(e,t){if(await this.onLoad("build-map"),this.mapAdapter.createControl)return this.mapAdapter.createControl(e,t)}async createButtonControl(e){if(await this.onLoad("build-map"),this.mapAdapter.createButtonControl)return this.mapAdapter.createButtonControl(e)}async createToggleControl(e){return await this.onLoad("build-map"),this.mapAdapter.createToggleControl?this.mapAdapter.createToggleControl(e):this.mapAdapter.createButtonControl?ce(this.mapAdapter.createButtonControl,e):void 0}removeControl(e){"remove"in e?e.remove():this.mapAdapter.removeControl&&Promise.resolve(e).then((e=>{this.mapAdapter.removeControl(e)}))}getControl(e,t){const r=this.mapAdapter.controlAdapters[e];if(r)return new r(t);{const r=he.controls[e];if(r)return r(this,t)}}getControlContainer(){if(this.mapAdapter.getControlContainer)return this.mapAdapter.getControlContainer()}_setControlQueue(e,t){this._loadControlQueue[e].push(t),this._isControlLoading[e]||this._applyControls(e)}async _applyControls(e){if(this._loadControlQueue[e].length){this._isControlLoading[e]=!0;const t=this._loadControlQueue[e][0];await t(),this._loadControlQueue[e].splice(0,1),this._applyControls(e)}else this._isControlLoading[e]=!1}}he.controls={CONTROL:(e,t)=>e.createControl(t.control,t.options),BUTTON:(e,t)=>e.createButtonControl(t),TOGGLE:(e,t)=>e.createToggleControl(t)};const le={};function pe(e){return le[e]}class ue extends he{constructor(e){super(e),this._addControls(),le[this.id]=this}static get(e){return pe(e)}async _addLayerProviders(){for await(const e of this._starterKits)if(e.getLayerAdapters){const t=await e.getLayerAdapters.call(e);if(t)for await(const e of t){const t=await e.createAdapter(this);t&&(this.mapAdapter.layerAdapters[e.name]=t)}}}async _onLoadSync(){for await(const e of this._starterKits)if(e.onLoadSync)try{await e.onLoadSync.call(e,this)}catch(e){console.error(e)}}_addControls(){this.options.controls&&this.options.controls.forEach((e=>{let t=e,r={};"string"==typeof e&&this.options.controlsOptions&&this.options.controlsOptions[e]&&(r=this.options.controlsOptions[e],void 0!==r.control&&(t=r.control));const{position:s,...i}=r;this.addControl(t,s||"top-left",i)})),this._emitStatusEvent("controls:create")}}async function de(e){return new ue(e).onLoad()}class ye{constructor(){return this.cache=[],ye.instance?ye.instance:(ye.instance=this,this)}clean(){this.cache.length=0}all(){return this.cache}add(e,t,r){const s=this._find(e,r);if(s)return s.value;{let s;s=t instanceof Function?t():t;const i=r&&JSON.parse(JSON.stringify(T(r)));return this.cache.push({key:e,value:s,options:i}),s instanceof Promise?(s.catch((t=>{throw this.delete(e,r),t})),s):s}}match(e,t){const r=this._find(e,t);if(r)return r.value}matchAll(e,t){return e?this.cache.filter((r=>this._filter(r,e,t))).map((e=>e.value)):this.cache.map((e=>e.value))}delete(e,t){const r=this.cache.filter((r=>this._filter(r,e,t)));for(const e of r){const t=this.cache.indexOf(e);this.cache.splice(t,1)}}_find(e,t){return this.cache.find((r=>this._filter(r,e,t)))}_filter(e,t,r){return e.key===t&&(!r||N(e.options||{},T(r)))}}var me=ye;class fe extends Error{constructor(e){super(),this.name="NgwError",Object.assign(this,e),Object.setPrototypeOf(this,fe.prototype)}}class ge extends Error{constructor(e){super(),this.name="NetworkError",Object.setPrototypeOf(this,ge.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}let _e;_e=(e,t,r={},s,i)=>{r.method=r.method||"GET";const o=new XMLHttpRequest;o.open(r.method||"GET",e,!0),"blob"===r.responseType&&(o.responseType=r.responseType);const n=()=>{try{return JSON.parse(o.responseText)}catch(e){return o.responseText}};o.onload=()=>{-1!==[401,403,404,500].indexOf(o.status)&&s(new fe(n())),((e=!1)=>{const i=e?s:t;"blob"===r.responseType?i(o.response):o.responseText?i(n()):s({message:""})})()},o.onerror=t=>{s(0===o.status?new ge(e):t)},o.upload.onprogress=function(e){if(e.lengthComputable){const t=e.loaded/e.total*100;r.onProgress&&r.onProgress(t,e)}};const a=r.headers;if(a)for(const e in a){const t=a[e];"string"==typeof t&&o.setRequestHeader(e,t)}let c;if(void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),r.file){if(c=new FormData,c.append("file",r.file),r.data)for(const e in c)c.append(e,c[e])}else c=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;i&&i((()=>{o.abort()})),o.send(c)};const ve=/\{ *([\w_-]+) *\}/g;function we(e,t){return e.replace(ve,((e,r)=>{let s=t[r];if(void 0===s)throw new Error("No value provided for letiable "+e);return"function"==typeof s&&(s=s(t)),s}))}class be extends fe{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,be.prototype)}}class Le extends fe{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,Le.prototype)}}const Oe=[];function Ee(e){Oe.push(e)}function Ce(e){return"[object Object]"===Object.prototype.toString.call(e)}function Ie(e,t=""){t=t?t+"__":"";const r={};return Object.entries(e).forEach((([e,s])=>{if(Ce(s)){const t=Ie(s,e);Object.assign(r,t)}else E(s)&&(r[t+e]=s)})),r}class Pe{constructor(e){this.connector=e,this.cache=new me}getOne(e,t){return(new me).add("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},t):"number"==typeof e?this._fetchResourceById(e,t):Ce(e)?this._fetchResourceBy(e,t):L.resolve(void 0)),{resource:e})}getOneOrFail(e){return this.getOne(e).then((e=>{if(e)return e;throw new be}))}getId(e){return"number"==typeof e?L.resolve(e):"string"==typeof e||Ce(e)?this.getOne(e).then((e=>{if(e)return e.resource.id})):L.resolve(void 0)}getIdOrFail(e){return this.getId(e).then((e=>{if(void 0===e)throw new Error;return e}))}getMany(e,t){return this._resourceCacheFilter(e).then((r=>{if(!r.length){const r={};return e.keyname?r.keyname=e.keyname:Object.assign(r,Ie(e)),this.connector.get("resource.search",t,{serialization:"full",...r}).then((e=>(e&&e.forEach((e=>{this.cache.add("resource.item",L.resolve(e),{id:e.resource.id})})),e)))}return r}))}getParent(e){return this.connector.getResource(e).then((e=>e?this.connector.getResource(e.resource.parent.id):L.resolve(void 0)))}getChildrenOf(e){return this.getId(e).then((e=>this.connector.get("resource.collection",{cache:!0},{parent:e}).then((e=>{for(const t of e)this.cache.add("resource.item",L.resolve(t),{id:t.resource.id});return e}))))}update(e,t){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.put("resource.item",{data:t},{id:e})}))}delete(e){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.delete("resource.item",null,{id:e}).then((()=>{this.cache.delete("resource.item",{id:e})}))}))}_fetchResourceById(e,t){return this.cache.add("resource.item",(()=>this.connector.get("resource.item",t,{id:e})),{id:e}).catch((e=>{if(!(e instanceof be))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return L.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:E(e.id)&&E(t.resource.id)?e.id===t.resource.id:N(e,t.resource)})),[])))}}let Ae=0;class Me{constructor(e){this.options=e,this.id=Ae++,this.emitter=new t.exports.EventEmitter,this.routeStr="/api/component/pyramid/route";const r=function(e){return Oe.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return N(t.options.auth,e.auth)}}))}(e);if(r)return r;this.options.route&&(this.routeStr=this.options.route),this.resources=new Pe(this),Ee(this)}static create(e){return new this(e)}setNgw(e){this.logout(),this.options.baseUrl=e,Ee(this)}connect(){const e=new me,t=this.options.auth;return e.add("route",(()=>new L(((e,r)=>{const s=()=>this.makeQuery(this.routeStr,{},{}).then((t=>{e(t)})).catch((e=>{r(e)}));if(t){const{login:e,password:i}=t;if(e&&i)return this.getUserInfo({login:e,password:i}).then((()=>{s()})).catch((e=>r(e)))}return s()}))),{id:this.id,auth:t,baseUrl:this.options.baseUrl})}login(e){return this.logout(),Ee(this),this.getUserInfo(e)}logout(){!function(e){const t=Oe.indexOf(e);-1!==t&&Oe.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()}getUserInfo(e){if(this.user&&this.user.id)return L.resolve(this.user);e&&(this.options.auth=e);const t={headers:this.getAuthorizationHeaders(e)};return this.makeQuery("/api/component/auth/current_user",{},t).then((e=>(this.user=e,this.emitter.emit("login",e),e))).catch((e=>{throw this.emitter.emit("login:error",e),e}))}getAuthorizationHeaders(e){const t=this.makeClientId(e);if(t)return{Authorization:"Basic "+t}}makeClientId(e){if(e=e||this.options.auth){const{login:t,password:r}=e,s=unescape(encodeURIComponent(`${t}:${r}`));return window.btoa(s)}}apiRequest(e,t={},r={}){const{method:s,headers:i,withCredentials:o,responseType:n}=r,a=T(t),c=()=>function(e){const t=e.params;return new L(((r,s)=>{e.connector.connect().then((i=>{let o=i&&i[e.name];if(o){o=[...o];let i=o.shift();if(o.length){const e={};for(let r=0;r<o.length;r++){const s=o[r];if(e[r]="{"+s+"}",void 0===t[s])throw new Error("`"+s+"` url api argument is not specified")}i&&(i=we(i,e))}if(t){const e=[],r=t.paramList;Array.isArray(r)&&(delete t.paramList,r.forEach((t=>{e.push(`${t[0]}=${t[1]}`)})));for(const r in t)-1===o.indexOf(r)&&e.push(`${r}=${t[r]}`);e.length&&(i=i+"?"+e.join("&"))}i?r(e.connector.makeQuery(i,t,e.requestOptions)):s(new Error("request url is not set"))}else r(void 0)})).catch((e=>{s(e)}))}))}({name:e,params:a,requestOptions:r,connector:this});if(r.cache&&"GET"===s){return(new me).add(e,c,{params:a,...T({headers:i,withCredentials:o,responseType:n,baseUrl:this.options.baseUrl,auth:this.options.auth})})}return c()}post(e,t,r){return(t=t||{}).method="POST",this.apiRequest(e,r,t)}get(e,t,r){return(t=t||{}).method="GET",this.apiRequest(e,r,t)}patch(e,t,r){return(t=t||{}).method="PATCH",this.apiRequest(e,r,t)}put(e,t,r){return(t=t||{}).method="PUT",this.apiRequest(e,r,t)}delete(e,t,r){return(t=t||{}).method="DELETE",this.apiRequest(e,r,t)}makeQuery(e,t,r={}){if(e=(this.options.baseUrl?this.options.baseUrl:"")+e)return t&&(e=we(e,t)),e=R(e),this._loadData(e,r);throw new Error("Empty `url` not allowed")}getResource(e){return this.resources.getOne(e)}getResourceOrFail(e){return this.resources.getOneOrFail(e)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e){return this.resources.getId(e)}getResourceIdOrFail(e){return this.resources.getIdOrFail(e)}getResourcesBy(e){return this.resources.getMany(e)}getResourceParent(e){return this.resources.getParent(e)}getResourceChildren(e){return this.resources.getChildrenOf(e)}updateResource(e,t){return this.resources.update(e,t)}deleteResource(e){return this.resources.delete(e)}_loadData(e,t){return t.responseType=t.responseType||"json",new L(((r,s,i)=>{this.user&&((t=t||{}).headers={...this.getAuthorizationHeaders(),...t.headers}),_e(e,r,t,s,i)})).catch((e=>{if(e instanceof L.CancelError);else{const t=this._handleHttpError(e);if(t)throw t}}))}_handleHttpError(e){if(e&&e instanceof fe){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new be(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new Le(e)}return e}}Me.errors={NgwError:fe,ResourceNotFoundError:be};var xe=Me;const ke=["fields","intersects","limit","orderBy","strategy"];function Se(e){const t={};return ke.forEach((r=>{const s=e[r];void 0!==s&&(t[r]=s)})),t}function Ne(e){const t=e.extent_bottom,r=e.extent_left,s=e.extent_top,i=e.extent_right;if(t&&r&&s&&i){const e=[r,t,i,s];return e[3]>82&&(e[3]=82),e[1]<-82&&(e[1]=-82),e}}function Te({resourceId:e,connector:t,cache:r=!0}){return t.get("layer.extent",{cache:r},{id:e}).then((e=>{if(e){const{maxLat:t,maxLon:r,minLat:s,minLon:i}=e.extent;return[i,s,r,t]}}))}function Be(e,t){if(e.webmap)return L.resolve(Ne(e.webmap));{const r=e.resource;return r.cls&&-1!==r.cls.indexOf("style")?t.getResource(r.parent.id).then((e=>{if(e)return Te({resourceId:e.resource.id,connector:t})})):Te({resourceId:r.id,connector:t})}}async function Re(e,t){const r=e.resource,s=r;let{keyname:i,resourceId:o}=e;if(r&&("string"==typeof r?i=r:o="number"==typeof r?r:s.resource&&void 0!==s.resource&&"resource"in s?r.resource.id:await Re(r,t)),!o&&i){const e=await t.getResource(i);e&&(o=e.resource.id)}return o}const Fe={srs:4326,geom_format:"geojson"};function je(e){return{id:e.id,type:"Feature",properties:e.fields,geometry:e.geom}}function ze(e,t){const{extensions:r,geom:s,fields:i,srs:o}=t;e.extensions=r?r.join(","):"",void 0!==i&&(e.fields=Array.isArray(i)?i.join(","):""),void 0!==s&&(e.geom=s?"yes":"no",s||(delete e.srs,delete e.geom_format)),E(o)&&(e.srs=o)}function De(e,t=[],r=[]){const{filters:s}=e,i="string"==typeof s[0]?s[0]:"all",o=s.filter((e=>Array.isArray(e))),n=e=>{const[t,r,s]=e;return[`${"id"!==t?"fld_":""}${t}__${r}`,s]};if("any"===i)o.forEach((s=>{Z(s)?t.push($e({...e,paramList:[...r,n(s)]})):De({...e,filters:s},t,[...r])}));else if("all"===i){const s=[],i=[];for(const e of o)Z(e)?s.push(n(e)):i.push(e);if(i.length)for(const o of i)De({...e,filters:o},t,[...r,...s]);else t.push($e({...e,paramList:[...r,...s]}))}return L.all(t).then((t=>{const r=t.reduce(((e,t)=>e.concat(t)),[]);return e.offset||e.limit?r.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:r.length):r}))}function $e(e){const t={...Fe},{connector:r,limit:s,offset:i,intersects:o,orderBy:n,resourceId:a,paramList:c}=e;if(s?s!==Number.POSITIVE_INFINITY&&(t.limit=s):t.limit=7e3,i&&(t.offset=i),ze(t,e),n&&(t.order_by=n.join(",")),Array.isArray(o)){const e=(h=o,Array.isArray(h)&&4===h.length&&h.every((e=>"number"==typeof e))?A(o):o);t.intersects=`POLYGON((${e.map((([e,t])=>{const[r,s]=k(e,t);return r+" "+s})).join(", ")}))`}else"string"==typeof o&&(t.intersects=o);var h;c&&(t.paramList=c);const l={id:a,...t};return r.get("feature_layer.feature.collection",{cache:e.cache},l)}function Ge(e){let t;for(t in e){const r=e[t];if(B(r)){const s=r;if(E(s.year)&&E(s.month)&&E(s.day)){const r=[s.year,s.month-1,s.day];"hour"in s&&[s.hour,s.minute,s.second].forEach((e=>{r.push(e)})),e[t]=new Date(...r).toISOString()}}}return e}function Ue(e){const t=e.filters;return t?De({...e,filters:t}).then((e=>(e.filter((e=>q(Ge({...e.fields}),t))),e))):$e(e)}function Ve(e){return function(e){return Ue(e).then((e=>{const t=[];return e.forEach((e=>{t.push(je(e))})),t}))}(e).then((e=>({type:"FeatureCollection",features:e})))}async function Ze(e){var r,s;const{item:i,webMap:o,Adapter:n,connector:a,layerOptions:c,addLayerOptionsPriority:h}=e,l=null==h||h,p=c,u=n||o.mapAdapter.layerAdapters.GEOJSON;let d,y,m=!1;const f=await Re(p,a);(null===(s=null===(r=p.adapterOptions)||void 0===r?void 0:r.popupOptions)||void 0===s?void 0:s.fromProperties)&&(p.adapterOptions.popupOptions.createPopupContent=({feature:e})=>e&&function(e,t){{const r=document.createElement("div");if(t&&t.feature_layer)t.feature_layer.fields.forEach((t=>{if(t.grid_visibility){const s=e.properties&&e.properties[t.keyname];if(s){const e=document.createElement("div");r.appendChild(e),e.innerHTML=`<span>${t.display_name}</span>: ${s}<span></span>`}}}));else if(e.properties)for(const t in e.properties){const s=document.createElement("div");r.appendChild(s),s.innerHTML=`<span>${t}</span>: ${e.properties[t]}<span></span>`}return r}}(e,i));const g=async(e,t)=>(v(),d={filters:e,options:t},y=Ve({resourceId:f,filters:e,connector:a,cache:!0,...t}),await y);let _=!1;const v=()=>{y&&(y.cancel(),y=void 0)};return class extends u{constructor(){super(...arguments),this.emitter=new t.exports.EventEmitter}async addLayer(e){let t=!e.data;const r=void 0===e.waitFullLoad||e.waitFullLoad;void 0!==p.id&&(e.id=p.id),i&&i.vector_layer&&(e.type=bt[i.vector_layer.geometry_type]),p.adapterOptions&&(e=l?{...p.adapterOptions,...e}:{...e,...p.adapterOptions}),e.data&&0===Object.keys(e.data).length&&(e.data=void 0,t=!1);const s=super.addLayer(e);let o;return this.options.strategy=e.strategy||void 0,d={filters:e.propertiesFilter,options:Se(e)},t&&(o=this.updateLayer()),r&&o&&await o,"BBOX"!==this.options.strategy||m||this._addBboxEventListener(),s}getExtent(){return this.getBounds()}async getBounds(){const e=this.getLayers&&this.getLayers().length;return"BBOX"===this.options.strategy||e?Be(i,a):super.getBounds?super.getBounds():void 0}beforeRemove(){_=!0,this._removeMoveEventListener(),this._removeBboxEventListener(),this.__disableMapMoveListener=void 0,this.__enableMapMoveListener=void 0,this.__onMapMove=void 0,this.__onMapMoveStart=void 0,v()}getCount(){return void 0!==this._count?this._count:a.get("feature_layer.feature.count",{cache:!0},{id:f}).then((e=>{if(e)return this._count=e.total_count,this._count}))}async updateLayer(e){if(e=e||d||{},"BBOX"===this.options.strategy&&(await o.onLoad("create"),e.options=e.options||{},e.options.intersects=o.getBounds()),!_){try{const t=await g(e.filters,{...e.options,srs:this.options.srs}),r=await this.getCount();m=r===t.features.length,await o.setLayerData(this,t),this.emitter.emit("updated")}catch(e){if(e instanceof Error&&"CancelError"!==e.name)throw e}super.updateLayer&&super.updateLayer()}}async propertiesFilter(e,t){if(v(),this.filter&&m)this.filter((t=>{const r=t.feature&&t.feature.properties&&Ge({...t.feature.properties});return!r||q(r,e)}));else if(this.setData){this.clearLayer&&this.clearLayer();const r=await g(e,{...t,srs:this.options.srs});this.setData(r)}}removeFilter(){d=void 0,this.propertiesFilter([]),this.filter&&this.filter((()=>!0))}_addBboxEventListener(){this.__enableMapMoveListener=e=>{e===this&&(this._removeMoveEventListener(),this.updateLayer(),this._addMoveEventListener())},this.__disableMapMoveListener=e=>{e===this&&this._removeMoveEventListener()},o.emitter.on("layer:show",this.__enableMapMoveListener),o.emitter.on("layer:hide",this.__disableMapMoveListener),this.__enableMapMoveListener(this)}_removeBboxEventListener(){this.__enableMapMoveListener&&o.emitter.on("layer:show",this.__enableMapMoveListener),this.__disableMapMoveListener&&o.emitter.on("layer:hide",this.__disableMapMoveListener)}_addMoveEventListener(){this.__onMapMove=function(e,t=10){let r;function s(...i){s.clear(),r=setTimeout((()=>{r=null,e.apply(this,i)}),t)}return s.clear=function(){r&&(clearTimeout(r),r=null)},s}((()=>this.updateLayer())),this.__onMapMoveStart=v,o.emitter.on("movestart",this.__onMapMoveStart),o.emitter.on("moveend",this.__onMapMove)}_removeMoveEventListener(){this.__onMapMove&&o.emitter.removeListener("moveend",this.__onMapMove),this.__onMapMoveStart&&o.emitter.removeListener("movestart",this.__onMapMoveStart)}}}function qe({options:e,webMap:t,baseUrl:r}){let s,i=e.adapter||"IMAGE";const o=t&&t.getLayerAdapters(),n=e.resource,a=e.tileNoData?e.tileNoData:200;if("number"==typeof n){if("IMAGE"===i){if(!o||o.IMAGE)return s=r+"/api/component/render/image",{url:s,resourceId:n,headers:e.headers,params:{resource:n,nd:a},updateWmsParams:e=>wt({nd:a,...e},n)};i="TILE"}if("WMS"===i){s=`${r}/api/resource/${n}/wms`;const t=e.adapterOptions;return{url:s,format:"image/png",version:"1.1.1",layers:t&&t.layers,headers:e.headers}}if("MVT"===i)return s=r+"/api/component/feature_layer/mvt?x={x}&y={y}&z={z}&resource="+n+"&simplification="+(e.simplification||0),{url:s};if("TERRAIN"===i)return s=r+`/api/resource/${n}/terrain_provider`,{url:s,adapter:i};if("MODEL_3D"===i)return s=r+`/api/component/model_3d/${n}/data.glb`,{url:s};if("TILE"===i)return s=r+"/api/component/render/tile?z={z}&x={x}&y={y}&resource="+n+"&nd="+a,{url:s,adapter:i}}else{if(void 0!==n)throw new Error("Option `resource` must be number, not "+typeof n);console.log("Option `resource` not set")}}async function We({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.cls;let o=e.adapter||i&&{wmsserver_service:"WMS",tmsclient_layer:"IMAGE"}[i]||"IMAGE";if(void 0!==o&&(e.adapter=o),"IMAGE"===o){const e=t.getLayerAdapters();!e||e.IMAGE||(o="TILE")}const n=t.mapAdapter.layerAdapters[o];if(n){const i=await Re(e,r);return class extends n{constructor(o,n){var a;super(o,n),this.map=o,this.item=s,this.resourceId=i;const c=qe({options:e,webMap:t,baseUrl:r.options.baseUrl||""});if(c){const t={...c,setViewDelay:null===(a=e.adapterOptions)||void 0===a?void 0:a.setViewDelay,params:{resource:i},layers:String(i),resourceId:i};e.adapterOptions&&E(e.adapterOptions.setViewDelay)&&(t.setViewDelay=e.adapterOptions.setViewDelay),this.options={...this.options,...t}}}addLayer(e){return super.addLayer({...this.options,...e})}async getIdentificationIds(){const e=this.item&&this.item.resource.parent.id;if(E(e))return[e]}}}throw new Error(o+" not supported yet. Only TILE")}function He(e,t,r,s){return!!Ke(e,t,r,Ye,s)}function Je(e,t,r,s){return Ke(e,t,r,Xe,s)}function Qe(e,t="children"){let r=[];const s=("function"==typeof t?t:e=>e[t])(e);return s&&(Array.isArray(s)?r=s:r.push(s)),s?r:void 0}function Ke(e,t=(e=>!!e),r="children",s,i){const o="function"==typeof t?t:e=>q(e,t);return s(e,i?e=>o(i(e)):o,r)}function Ye(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(t(e))return e;const s=Qe(e,r);s&&(i=s)}for(let e=0;e<i.length;e++)if(i[e]){const o=Ye(i[e],t,r,s);if(o)return o}}function Xe(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{t(e)&&s.push(e);const o=Qe(e,r);o&&(i=o)}for(let e=0;e<i.length;e++)i[e]&&Xe(i[e],t,r,s);return s}function et(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(!t(e))return!1;const s=Qe(e,r);s&&(i=s)}for(let e=0;e<i.length;e++)if(i[e]){if(!et(i[e],t,r,s))return!1}return!0}class tt{constructor(e){this._children=[],this.item=e}setParent(e){this._parent=e}addChild(e){this._children.push(e)}getParent(){return this._parent}getParents(e){const t=this.getParent();return t?Je(t,e,(e=>e.tree.getParent())):[]}getRoot(){let e=this.getParent(),t=e;for(;e;)e=e.tree.getParent(),e&&(t=e);return t}find(e){return Ke(this._children,e,(e=>e.tree.getChildren()),Ye,t);var t}every(e){return!!Ke(this._children,e,(e=>e.tree.getChildren()),et,t);var t}some(e){return He(this._children,e,(e=>e.tree.getChildren()))}all(e){return this.getDescendants(e)}getDescendants(e){return Je(this._children,e,(e=>e.tree.getChildren()))}getChildren(){return[...this._children]}}class rt{constructor(e,r,s){this.emitter=new t.exports.EventEmitter,this._blocked=!1,this.item=r,this.options=Object.assign({},s),this.name=e,this._value=this.getProperty()}getProperty(){return"function"==typeof this.options.getProperty?this.options.getProperty.call(this,this.item):this.options.value}getParents(){return this.item.tree.getParents()||[]}getParent(){return this.item.tree.getParent()}getChildren(){return this.item.tree.getChildren()}isGroup(){return this.item.tree.getDescendants().length}isBlocked(){if(void 0===this._blocked){const e=this.item.tree.getParents();if(e){const t=e.find((e=>{const t=e.properties&&e.properties.property(this.name);return!!t&&!t.get()}));this._blocked=!!t}else this._blocked=!1}return this._blocked}set(e,t){this._value=this._prepareValue(e),this.update(this._value,t),this._fireChangeEvent(this._value,t)}get(){return this.getValue()}update(e,t){this._callOnSet(e,t)}getContainer(){return this._container}destroy(){if(this._container){const e=this._container.parentNode;e&&e.removeChild(this._container)}this._removeEventsListener&&this._removeEventsListener()}getValue(){return void 0!==this._value?this._value:this.getProperty()}_prepareValue(e){return e}_callOnSet(e,t){this.options.onSet&&this.options.onSet.call(this,e,t,this.item)}_fireChangeEvent(e,t){if(this.emitter){e=void 0!==e?e:this.getValue(),this.emitter.emit("change",{value:e,options:t});this.item.tree.getParents().forEach((r=>{const s=r.properties&&r.properties.property(this.name);s&&s.emitter.emit("change-tree",{value:e,options:t,item:this.item})}))}}}class st extends rt{constructor(e,t,r){super(e,t,{...st.options,...r}),this.set(this.get())}update(e,t){if(e){if(t&&t.bubble||this.options.bubble){this.unBlock(t);const r=this.getParent(),s=r&&r.properties&&r.properties.property(this.name);s&&s.set(e,Object.assign({},t,{bubble:!0,propagation:!1}))}this.isBlocked()||this._turnOn(t)}else this._turnOff(t);(t&&t.propagation||this.options.propagation)&&this._propagation(e,t)}getHierarchyValue(){return this.get()&&this.getParents().every((e=>{const t=e.properties&&e.properties.get(this.name);return t&&t.get()}))}block(e){this._blocked=!0,this._block(e)}unBlock(e){this._blocked=!1,this.getValue()&&this._unBlock(e)}blockChild(e){this.item.tree.getDescendants().forEach((t=>this._blockChild(t,e)))}unblockChild(e){this.item.tree.getChildren().forEach((t=>this._unBlockChild(t,e)))}_prepareValue(e){return e}_turnOff(e){this.options.turnOff&&this.options.turnOff.call(this,e),this._callOnSet(!1,e),this.options.hierarchy&&this.isGroup()&&this.blockChild(e)}_turnOn(e){this.options.turnOn&&this.options.turnOn.call(this,e),this._callOnSet(!0,e),this.options.hierarchy&&this.isGroup()&&this.unblockChild(e)}_block(e){this._turnOff(e)}_unBlock(e){this._turnOn(e)}_blockChild(e,t){const r=e.properties&&e.properties.property(this.name);r&&r.block&&r.block(t)}_unBlockChild(e,t){const r=e.properties&&e.properties.property(this.name);r&&r.unBlock&&r.unBlock(t)}_propagation(e,t){if(this.isGroup()){const r=this.item.tree.getChildren();for(let s=0;s<r.length;s++){const i=r[s],o=i.properties&&i.properties.property(this.name);o&&o.set(e,{...t,propagation:!0,bubble:!1})}}}}st.options={hierarchy:!0,bubble:!1,propagation:!1,label:"Toggle"};class it{constructor(e,t){this.item=e,this.options={},this._properties={},this._propertiesList=[],t&&t.forEach(this._setPropertyHandler.bind(this))}add(e){this._setPropertyHandler(e)}_setPropertyHandler(e){const t=it.handlers;let r=e.handler;if(!r&&e.type)switch(e.type){case"boolean":r=t.CheckProperty;break;case"string":r=t.BaseProperty;break;default:r=t.BaseProperty}if(r&&e.name){const t={...e||{}};this._properties[e.name]=new r(e.name,this.item,t),this._propertiesList.push(e.name)}}update(){this.list().forEach((e=>{e.update()}))}get(e){const t=this.property(e);if(t)return t.get()}set(e,t,r){const s=this.property(e);if(s)return s.set(t,r)}property(e){return this._properties[e]}list(){return this._propertiesList.map((e=>this._properties[e]))}destroy(){for(const e in this._properties){const t=this.property(e);t&&t.destroy&&t.destroy()}this._properties={},this._propertiesList=[]}}it.handlers={CheckProperty:st};let ot=0;class nt extends class{constructor(e){this.options={},this.id=ot,ot+=1,this.options={...e},this.tree=new tt(this)}initProperties(){this.properties=new it(this,this.options.properties)}}{constructor(e,r,s,i,o,n){if(super({...nt.options,...s}),this.webMap=e,this.emitter=new t.exports.EventEmitter,this._rootDescendantsCount=0,i&&(this.connector=i),o&&this.tree.setParent(o),this.item=r,"root"===this.item.item_type)this._rootDescendantsCount=this._sumUp(this.item.children);else{const e=this.tree.getRoot();e&&(this._rootDescendantsCount=e._rootDescendantsCount)}this.initProperties(),n||this._init(r)}static async create(e,t,r,s,i){const o=new nt(e,t,r,s,i,!0);return await o._init(t),o}initItem(e){const t=e,r=this.getItemOptions(e),s=e=>{t._layer=e,this.layer=e;this.properties.get("visibility")&&this.properties.set("visibility",!0),void 0!==r.opacity&&this.webMap.setLayerOpacity(e,r.opacity)};if("group"===e.item_type||"root"===e.item_type)return e.children&&e.children.length&&this.getChildren(e).forEach((e=>{const t=new nt(this.webMap,e,this.options,this.connector,this);this.tree.addChild(t)})),Promise.resolve();{let t;if("layer"===e.item_type)t=e.adapter||e.layer_adapter.toUpperCase();else if(nt.GetAdapterFromLayerType[e.item_type]){t=(0,nt.GetAdapterFromLayerType[e.item_type])(e,r,this.webMap,this.connector)}if(t)return this.webMap.addLayer(t,r).then((e=>{s(e)}))}return e._layer?Promise.resolve(s(e._layer)):Promise.reject("No layer added")}bringToFront(){}fit(){}getLayer(){return this.layer}getItemOptions(e){const t="layer"===e.item_type&&e.layer_transparency,r="number"==typeof t?(100-t)/100:void 0,s={visibility:!1,headers:this.options.headers,crossOrigin:this.options.crossOrigin,setViewDelay:this.options.setViewDelay,params:{resource:this.item.resourceId}};if(this.options.order){const t=String(this.options.drawOrderEnabled&&"draw_order_position"in e?this._rootDescendantsCount-e.draw_order_position:this.id).padStart(4,"0");s.order=Number((0|this.options.order)+"."+t)}if("layer"===e.item_type){const t=e.layer_max_scale_denom?this._mapScaleToZoomLevel(e.layer_max_scale_denom):this.webMap.options.maxZoom,r=e.layer_min_scale_denom?this._mapScaleToZoomLevel(e.layer_min_scale_denom):this.webMap.options.minZoom;!function(e,...t){for(const r of t)for(const t of Object.getOwnPropertyNames(r))e[t]=r[t]}(s,{updateWmsParams:e.updateWmsParams,url:e.url,headers:this.options.headers,ratio:this.options.ratio,maxZoom:t,minZoom:r,minScale:e.layer_min_scale_denom,maxScale:e.layer_max_scale_denom})}return void 0!==r&&(s.opacity=r),s}getChildren(e){return[...e.children].reverse()}_mapScaleToZoomLevel(e){return function(e,t=0){const r=t,s=function(){if(void 0===Lt){const e=document.createElement("div");e.style.cssText="position: absolute; left: -100%; top: -100%; width: 100cm;",document.body.appendChild(e);const t=e.offsetWidth;document.body.removeChild(e),Lt=t}return Lt}()*function(e){return 12756274*Math.PI*Math.cos(e*Math.PI/180)}(r)/e;return function(e){return Math.log(e/256)/Math.LN2}(s)}(e)}_init(e){this.initItem(e).then((()=>{this.emitter.emit("init")}))}_sumUp(e,t=0){for(const r of e)"layer"===r.item_type?(t+=1,r.draw_order_position=r.draw_order_position||t):"group"===r.item_type&&(t=this._sumUp(r.children,t));return t}}async function at({webMap:e,connector:t,item:r,adapterOptions:s={},idPrefix:i="first-show-adapter"}){return async function({webMap:e,adapterOptions:t={},onLayerAdded:r,createAdapter:s}){return class{constructor(){this.options={},this.layer=[],this._removed=!1,this._creatingInProgress=!1}addLayer(){return this.layer}removeLayer(){this._removed=!0,this.layer.forEach((t=>e.removeLayer(t)))}destroyed(){return this._removed}showLayer(){this.options.visibility=!0,this.layer.length?this.layer.forEach((t=>{e.showLayer(t)})):this.loadLayer()}async loadLayer(){if(!this.layer.length&&!this._creatingInProgress){this._creatingInProgress=!0;const i=await s(this);if(i){const s=new i(e.mapAdapter.map,{...t}),o=await s.addLayer({order:this.options.order,headers:this.options.headers,baselayer:this.options.baselayer});r&&r(s),Object.assign(s.options,t),s.layer=o,this._removed&&e.removeLayer(s),this.options.visibility&&await e.showLayer(s),this.layer.push(s),this._creatingInProgress=!1}}return this.layer}hideLayer(){this.options.visibility=!1,this.layer&&this.layer.forEach((t=>e.hideLayer(t)))}}}({webMap:e,adapterOptions:s,onLayerAdded:e=>{e.options.baselayer=!1,e.id=i+"-"+r.resource_id},createAdapter:()=>vt({resource:r.resource_id,adapterOptions:{name:r.display_name,opacity:r.opacity}},e,t)})}nt.GetAdapterFromLayerType={},nt.options={properties:[{type:"boolean",name:"visibility",getProperty(e){if(e){if("group"===e.item.item_type||"root"===e.item.item_type)return He(e.item,(e=>"layer_enabled"in e&&e.layer_enabled),(e=>e.children));if("layer"===e.item.item_type)return e.item.layer_enabled}return!1},onSet(e,t,r){r&&"layer"===r.item.item_type&&(r.layer&&(e?r.webMap.showLayer(r.layer):r.webMap.hideLayer(r.layer)),r.item.layer_enabled=e)}},{name:"opacity",handler:class extends rt{getProperty(){const e=this.item.layer;return e&&e&&e.options&&void 0!==e.options.opacity?e.options.opacity:1}update(e,t){if(t=t||{},this.isGroup()){this._value=this._prepareValue(e,t);const r=this.getChildren();for(const s of r){const r=s.properties.property(this.name);r&&(t.propagation?r.set(e,t):r.update(r.get(),t))}}const r=this.item.layer;if(r){const t=this.getParents().reduce(((e,t)=>{const r=t.properties.property(this.name);return e*(r?r.getValue():1)}),1);this.item.webMap.setLayerOpacity(r,this._prepareValue(e*t))}}_prepareValue(e,t){return t&&t.propagation&&this.isGroup()?1:Number(e)}}}]};class ct{constructor(e){this.options=e,this.resourceId=e.resourceId;const t=e.item;this.item=t,this.name=e.labelField&&t.fields?t.fields[e.labelField]:String(t.id)}extent(){return this._extent?L.resolve(this._extent):this.options.connector.get("feature_layer.feature.item_extent",null,{id:this.resourceId,fid:this.item.id}).then((e=>{const{minLat:t,minLon:r,maxLat:s,maxLon:i}=e.extent,o=[r,t,i,s];return this._extent=o,o}))}geoJson(){return this.item.geom?L.resolve(je(this.item)):It({resourceId:this.resourceId,featureId:this.item.id,connector:this.options.connector,geom:!0,fields:null,extensions:null}).then((e=>(this.item.geom=e.geom,je(this.item))))}}class ht{constructor(e,r){this.map=e,this.options=r,this.NgwWebmapItem=nt,this.pixelRadius=10,this.webmapClassName="webmap",this.emitter=new t.exports.EventEmitter;const s=r.resourceId;if(Array.isArray(s)?(this.resourceId=s[0],this.options.id=s[1]):this.resourceId=s,!this.resourceId)throw new Error("NGW `resourceId` is not defined")}async addLayer(e){return this.options={...this.options,...e},this.layer=await this._getWebMapLayerItem(),this.layer}removeLayer(){const e=this.options.webMap.mapAdapter;this.getDependLayers().forEach((t=>{"layer"in t&&e.removeLayer(t.layer.layer)})),delete this.layer,delete this.response,delete this._webmapLayersIds}async showLayer(){if(this.layer&&this.layer.properties)return this.layer.properties.property("visibility").set(!0)}async hideLayer(){if(this.layer&&this.layer.properties)return this.layer.properties.property("visibility").set(!1)}async setOpacity(e){if(this.layer&&this.layer.properties)return this.layer.properties.property("opacity").set(e)}getExtent(){return this.getBounds()}getBounds(){const e=this.response&&this.response.webmap;if(e)return Ne(e)}getDependLayers(){return this.layer&&this.layer.tree.getDescendants()||[]}getBookmarksResourceId(){const e=this.response&&this.response.webmap;if(e)return e.bookmark_resource.id}fetchBookmarks(){const e=this.getBookmarksResourceId(),t=this.options.connector;if(e)return t.getResourceOrFail(e).then((r=>{var s;const i=null===(s=r.feature_layer)||void 0===s?void 0:s.fields.find((e=>e.label_field)),o=i&&i.keyname;return Ue({connector:t,resourceId:e,geom:!1,fields:o?[o]:void 0}).then((r=>{const s=[];for(const i of r){const r=new ct({item:i,resourceId:e,labelField:o,connector:t});s.push(r)}return s}))}));throw new Error("Webmap was not loaded correctly, it is impossible to extract bookmarks")}async getIdentificationIds(){const e=[];let t=this._webmapLayersIds;if(t||(t=await this._getWebMapIds(),this._webmapLayersIds=t),t&&t.length){let t=this.getDependLayers();t=t.sort(((e,t)=>t.id-e.id)),t.forEach((t=>{const r=t.item,s=r.parentId;if(void 0!==s&&"layer"===r.item_type){const r=t.properties.property("visibility");r.get()&&!r.isBlocked()&&e.push(s)}}))}return e}async _getWebMapLayerItem(){if(this.resourceId){const e=await this.getWebMapConfig(this.resourceId);if(e&&e.root_item)return new Promise((t=>{const r={};if(this.options.connector&&this.options.connector.options.auth){const e=this.options.connector.getAuthorizationHeaders();e&&(r.headers=e)}r.setViewDelay=this.options.setViewDelay,r.order=this.options.order,r.ratio=this.options.ratio,r.crossOrigin=this.options.crossOrigin,r.drawOrderEnabled=e.draw_order_enabled;const s=new this.NgwWebmapItem(this.options.webMap,e.root_item,r,this.options.connector);s.emitter.on("init",(()=>t(s)))}))}}async getWebMapConfig(e){const t=await this.options.connector.getResource(e);if(t){this.response=t;const e=t[this.webmapClassName];if(t.basemap_webmap&&t.basemap_webmap.basemaps.length)this._setBasemaps(t.basemap_webmap);else if(this.options.defaultBasemap){this.options.webMap.addBaseLayer("OSM",{id:"webmap-default-baselayer",name:"OpenStreetMap"})}if(e)return this._extent=[e.extent_left,e.extent_bottom,e.extent_right,e.extent_top],this._updateItemsParams(e.root_item,this.options.webMap,t),e}}_setBasemaps(e){const t=this.options.webMap;let r=!1;e.basemaps.forEach((e=>{at({webMap:t,connector:this.options.connector,item:e,adapterOptions:{crossOrigin:this.options.crossOrigin}}).then((s=>{t.addBaseLayer(s,{id:Ct+e.resource_id,name:e.display_name,opacity:e.opacity,visibility:!r&&e.enabled}),e.enabled&&(r=!0)}))}))}_updateItemsParams(e,t,r){if(e)if("group"===e.item_type||"root"===e.item_type)e.children&&(e.children=e.children.map((e=>this._updateItemsParams(e,t,r)))),"root"===e.item_type&&(e.display_name=r.resource.display_name);else if("layer"===e.item_type){const r=R(this.options.connector.options.baseUrl+"/api/component/render/image"),s=e.layer_style_id;e.url=r,e.resourceId=s,e.updateWmsParams=e=>wt(e,s);const i=qe({options:{adapter:e.layer_adapter.toUpperCase(),resource:s},webMap:t,baseUrl:this.options.connector.options.baseUrl||""});e={...e,...i}}return e}async _getWebMapIds(){const e=this.layer;if(e&&"root"===e.item.item_type){const t=e.tree.getDescendants(),r=[];t.forEach((e=>{const t=e.item;if("layer"===t.item_type){const e=this.options.connector.getResource(t.layer_style_id).then((e=>{if(e){const r=Number(e.resource.parent.id);return t.parentId=r,r}}));r.push(e)}}));return(await Promise.all(r)).filter((e=>void 0!==e))}}}class lt{async getExtent(){return this.getBounds()}async getBounds(){return this._extent?this._extent:this.item?(this._extent=await Be(this.item,this.connector),this._extent):void 0}}const pt={tms:"TILE"};function ut(e){const t=("https:"===location.protocol?"https":"http")+"://";let r=e.url.replace(/^(https?|ftp):\/\//,t);return e.y_origin_top||(r=r.replace("{y}","{-y}")),{url:r,name:e.name,attribution:e.copyright_text,maxZoom:e.z_max,minZoom:e.z_min}}const dt="https://qms.nextgis.com";function yt(e,t=dt,r={}){t||(t=dt);class s{constructor(e,t){this.map=e;const s={...r,...t};this.options=s,this.options.baselayer=!0,s.qms&&(this.qms=s.qms)}async addLayer(r){if(!this.qms&&r.qmsId)try{this.qms=await function(e){return new Promise(((t,r)=>{const s=new XMLHttpRequest;s.onreadystatechange=()=>{if(4===s.readyState&&200===s.status&&s.responseText)try{t(JSON.parse(s.responseText))}catch(e){r(e)}},s.open("GET",R(e),!0),s.send()}))}(t+"/api/v1/geoservices/"+r.qmsId)}catch(e){console.error(e)}const i=this.qms;if(i){const t=pt[i.type||"tms"],a=e.mapAdapter.layerAdapters[t];if(a&&(o=s,n=a,["showLayer","hideLayer"].forEach((e=>{const t=Object.getOwnPropertyDescriptor(n.prototype,e);t&&Object.defineProperty(o.prototype,e,t)})),"TILE"===t)){if(r={order:0,maxZoom:e.options.maxZoom,minZoom:e.options.minZoom,...this.options,...ut(i)},i.origin_url){const[e,t]=function(e){const t=[];return[e=e.replace(/{switch:(.*?)}/,((e,r)=>("string"==typeof r&&r.split(",").forEach((e=>t.push(e))),"{s}"))),t]}(i.origin_url);t.length&&(r.subdomains=t,r.url=e)}this.options=r;return new a(this.map,r).addLayer(r)}}var o,n}}return s}class mt{constructor(e){this.options={url:"https://qms.nextgis.com"},this.options={...this.options,...e},this.url=this.options.url}getLayerAdapters(){return Promise.resolve([{name:"QMS",createAdapter:e=>Promise.resolve(this._createAdapter(e))}])}_createAdapter(e){return yt(e,this.url)}}mt.utils={createQmsAdapter:yt};const ft={},gt=["mapserver_style","qgis_vector_style","qgis_raster_style","wmsserver_service","raster_style","basemap_layer","vector_layer","raster_layer","webmap","tmsclient_layer"];async function _t({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.id,o=await r.getResourceChildren(i),n=o&&o[0];if(n)return vt({...e,resource:n.resource.id},t,r)}async function vt(e,t,r){let s,i;const o=e.adapter,n=await Re(e,r);if(n){const a=e.resource;if(i=a&&a.resource&&void 0!==a.resource.id?a:await r.getResource(n),!i)throw"Resource item is not found";{const a=i.resource.cls,c={layerOptions:{...e,resource:n},webMap:t,connector:r,item:i};if(-1!==gt.indexOf(a))if("webmap"===a)s=async function({layerOptions:e,webMap:t,connector:r}){const s=await Re(e,r);return class extends ht{constructor(e){super(e,{url:"",webMap:t,resourceId:s,connector:r})}}}(c);else if("vector_layer"===a)if(void 0!==o&&"GEOJSON"!==o){if("MVT"!==o)return _t(c);s=We(c)}else s=Ze(c);else{if("raster_layer"===a)return _t(c);if("basemap_layer"===a)s=async function({webMap:e,item:t}){if(t.basemap_layer){const r=t.basemap_layer.qms,s=t.basemap_layer.url;if(r){const t=JSON.parse(r);return Promise.resolve(mt.utils.createQmsAdapter(e,void 0,{qms:t,baselayer:!0}))}if(s){const t=e.mapAdapter.layerAdapters.TILE;if(t){class e extends t{async addLayer(e){return super.addLayer({...e,url:s})}}return e}}}}(c);else if("GEOJSON"===o){const t=await r.getResource(i.resource.parent.id);if(t){const r={...e,resource:i.resource.parent.id};s=Ze({...c,item:t,layerOptions:r})}}else s=We(c)}else{if(!ft[a])throw`Resource class '${a}' not yet supported.`;{const e=ft[a];let t;t=o&&"function"!=typeof t?e[o]:e,t&&(s=t(c))}}}}if(s)return s.then((e=>{if(e){const t=e;return i&&(t.prototype.item=i,t.prototype.resourceId=i.resource.id,t.prototype.connector=r),O(t,[lt],{replace:!1}),t}}))}function wt(e,t){const{bbox:r,width:s,height:i,nd:o}=e;return{resource:t,extent:r,size:s+","+i,timestamp:Date.now(),nd:o}}const bt={POINT:"point",LINESTRING:"line",POLYGON:"polygon",MULTIPOINT:"point",MULTILINESTRING:"line",MULTIPOLYGON:"polygon",POINTZ:"point",LINESTRINGZ:"line",POLYGONZ:"polygon",MULTIPOINTZ:"point",MULTILINESTRINGZ:"line",MULTIPOLYGONZ:"polygon"};let Lt;class Ot{constructor(e){if(this.options=e,this.options.connector)this.url=this.options.connector.options.baseUrl||"",this.connector=this.options.connector;else{if(!this.options.baseUrl)throw new Error("url is not defined");this.url=this.options.baseUrl,this.connector=new xe({baseUrl:this.url,auth:this.options.auth})}}static addClassAdapters(e,t){ft[e]=t}async onLoadSync(e){if(this.options.resourceId&&this.url){const t=[this.options.resourceId];if(t.length)for(const r of t){const t={resourceId:r,connector:this.connector,webMap:e};return await e.addLayer(ht,{visibility:!0,fit:!0,pixelRadius:this.options.pixelRadius,...t})}}}getLayerAdapters(){return Promise.resolve([this._getLayerAdapter()])}_getLayerAdapter(){return{name:"WEBMAP",createAdapter:e=>Promise.resolve(this._createAdapter(e))}}_createAdapter(e){return t={webMap:e,connector:this.connector,baseUrl:this.url},class extends ht{constructor(e,r){super(e,r={...t,...r})}};var t}}class Et{constructor(e){const t=e.feature;this.id=t.id,this.geom=t.geom,this.label=t.label,this.parent=t.parent,this.fields=t.fields,this.layerId=t.layerId,this.connector=e.connector}identify(e={}){return this._item?L.resolve(this._item):It({connector:this.connector,featureId:this.id,resourceId:this.layerId,fields:null,extensions:["attachment","description"],...e}).then((e=>(this._item=e,this.geom=e.geom,this.extensions=e.extensions,e)))}resource(){return this._resource?L.resolve(this._resource.feature_layer):this.connector.getResource(this.layerId).then((e=>(this._resource=e,this._resource.feature_layer)))}getBounds(){return this._extent?L.resolve(this._extent):function({resourceId:e,featureId:t,connector:r,cache:s=!0}){return r.get("feature_layer.feature.item_extent",{cache:s},{id:e,fid:t}).then((e=>{if(e){const{maxLat:t,maxLon:r,minLat:s,minLon:i}=e.extent;return[i,s,r,t]}}))}({connector:this.connector,featureId:this.id,resourceId:this.layerId})}geojson(){return this._geojson?L.resolve(this._geojson):this.identify().then((e=>e.toGeojson().then((e=>(this._geojson=e,e)))))}}const Ct="webmap-baselayer";function It(e){const t={...Fe};ze(t,e);const r={id:e.resourceId,fid:e.featureId,...t};return e.connector.get("feature_layer.feature.item",{cache:e.cache||!0},r).then((t=>({...t,toGeojson:()=>t.geom?L.resolve(je(t)):It({...e,geom:!0,fields:null,extensions:null}).then((e=>{const r=e.geom;return je({...t,geom:r})}))})))}function Pt(e){return It(e).then((e=>je(e)))}function At(e,t=!1){let r;const s=[],i=[];for(const t in e){const e=Number(t);isNaN(e)||s.push(e)}const o=e.resources;o&&s.sort(((e,t)=>o.indexOf(e)-o.indexOf(t)));for(let o=0;o<s.length;o++){const n=s[o],a=e[n];if("features"in a){const e=a.features,s=Number(n),o=e[0];if(o&&(r={featureId:o.id,resourceId:s,feature:o},i.push(r),!t))break}}return i}function Mt(e,t){I(e);const[r,s]=e.lngLat;let i=[];if(t.geom){const e="Feature"===t.geom.type?t.geom.geometry:"Polygon"===t.geom.type&&t.geom;e&&(i=e.coordinates[0])}i.length||(i=function(e,t,r=10,s=6){const i=r/6371*x,o=i/Math.cos(t*M),n=[];for(let r=0;r<s+1;r++){const a=Math.PI*(r/(s/2)),c=e+o*Math.cos(a),h=t+i*Math.sin(a);n.push([c,h])}return n}(r,s,t.radius));const o=[];i.forEach((([e,t])=>{const[r,s]=k(e,t);o.push(r+" "+s)}));const n=`POLYGON((${o.join(", ")}))`;return t.connector.post("feature_layer.identify",{data:{geom:n,srs:3857,layers:t.layers}})}const xt={brill:'<path d="m6 0-5 6 5 6 5-6z"/>',circle:'<circle cx="6" cy="6" r="6"/>',rect:'<rect width="12" height="12"/>',marker:'<path d="m6 0c-1.85 0-4 1.19-4 4.22 0 2.05 3.08 6.59 4 7.78 0.821-1.19 4-5.62 4-7.78 0-3.03-2.15-4.22-4-4.22z"/>',cross:'<path d="M 2.4,12 6,8.4 9.6,12 12,9.6 8.4,6 12,2.4 9.6,0 6,3.6 2.4,0 0,2.4 3.6,6 0,9.6 Z"/>',star:'<path d="m6 0.25 1.71 4.18 4.29-1.04e-4 -3.43 3.14 0.857 4.18-3.43-3.14-3.43 3.14 0.857-4.18-3.43-3.14 4.29-0.209z"/>',triangle:'<path d="m12 11.7h-12l6-11.2z"/>',plus:'<path d="m7.5 12v-4.5h4.5v-3h-4.5v-4.5h-3v4.5h-4.5v3h4.5v4.5z"/>',minus:'<path d="m12 7.5v-3h-12v3z"/>',asterisk:'<path d="m7.59 12v-3.27l2.83 1.64 1.58-2.74-2.85-1.64 2.83-1.64-1.56-2.74-2.83 1.64v-3.24h-3.17v3.24l-2.85-1.64-1.57 2.74 2.84 1.64-2.84 1.64 1.57 2.74 2.85-1.64v3.27z"/>'};function kt(e,t,r,s){if("number"==typeof t||"string"==typeof t)t=Number(t),e.push({...r,resource:t});else if(Array.isArray(t)){const[i,o]=t;e.push({...r,resource:i,id:o,...s})}else"object"==typeof t&&e.push({...r,...t,...s})}const St={target:"map",baseUrl:"",whitlabel:!1,controls:["ZOOM","ATTRIBUTION"],controlsOptions:{ZOOM:{position:"top-left"},ATTRIBUTION:{position:"bottom-right",customAttribution:['<a href="https://nextgis.com" target="_blank">©NextGIS</a>']}},pixelRadius:10};class Nt extends ue{constructor(e){super(function(e){const t=[new mt];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new xe({baseUrl:e.baseUrl||"",auth:e.auth}),(e=C(St,e)).center||e.bounds||(e.bounds=[-179,-90,180,90],e.maxBounds=e.bounds),e.connector&&t.push(new Ot({connector:e.connector,auth:e.auth})),{...e,starterKits:t,create:!1}}(e)),this.emitter=new t.exports.EventEmitter,this._ngwLayers={},this._promises={select:[],identify:[]},e.connector&&(this.connector=e.connector),this._createWebMap().then((()=>{const e=this.getContainer();e&&e.classList.add("ngw-map-container"),this.options.whitlabel&&this._whiteLabel()}))}async addControl(e,t,r){return await this.onLoad("controls:create"),super.addControl(e,t,r)}async addNgwLayer(e){await this.onMapLoad();const{keyname:t,resourceId:r}=e;(t||void 0!==r)&&console.warn(`DEPRECATED WARN: ${"set `resource` options instead of `keyname` or `resourceId`"}`);const s=e.resource;if(!t&&!r&&!s)throw new Error("resource, resourceId or keyname is required parameter to add NGW layer");if(E(this.options.baseUrl))try{E(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},E(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=function(e,t,r){const s=r.getAuthorizationHeaders();return s&&(e.headers=s),vt(e,t,r)}(e,this,this.connector),r={visibility:!0,...e,...e.adapterOptions},s=await this.addLayer(t,r),i=s&&this.getLayerId(s);if(s&&i&&(this._ngwLayers[i]={layer:s,resourceId:s.resourceId},s.options.name=s.options.name||s.item&&s.item.resource.display_name,s.options.baselayer)){if(this.getActiveBaseLayer())return s}return s}catch(e){const i=B(s)&&"id"in s?s.id:t||r||s;console.error(`Can't add NGW layer ${i}.`,e)}}fit(){const{center:e,zoom:t,bounds:r}=this.options;e?(this.setCenter(e),t&&this.setZoom(t)):r&&this.fitBounds(r)}fetchNgwLayerItem(e){return It({connector:this.connector,...e})}fetchNgwLayerItems(e){return Ue({connector:this.connector,...e})}fetchNgwLayerFeature(e){return Pt({connector:this.connector,...e})}fetchNgwLayerFeatures(e){return Ve({connector:this.connector,...e})}fetchIdentifyItem(e,t){const r=function(e){const{connector:t,identify:r}=e,s=At(r);return s&&s.length?It({connector:t,...e.requestOptions,...s[0]}):L.resolve(void 0)}({identify:e,connector:this.connector,requestOptions:t});return this._addPromise("identify",r),r}fetchIdentifyGeoJson(e,t=!1){const r=function(e){const{connector:t,identify:r}=e;for(const e in r){const t=Number(e);if(!isNaN(t)){const t=r[e];if("features"in t){const e=t.features.find((e=>e.geom));if(e&&e.geom){const t=e.geom;return L.resolve(je({...e,geom:t}))}}}}const s=At(r);return s&&s.length?Pt({connector:t,...s[0]}):L.resolve(void 0)}({identify:e,connector:this.connector,multiple:t});return r&&"then"in r?(this._addPromise("identify",r),r):L.resolve(r)}getIdentifyGeoJson(e,t=!1){return this.fetchIdentifyGeoJson(e,t)}async getNgwLayers(){return await this.onLoad(),this._ngwLayers}async getNgwLayerByResourceId(e){for(const t in this._ngwLayers){const r=this._ngwLayers[t];if(r.resourceId===e)return r&&r.layer;if(r.layer.getIdentificationIds){const t=await r.layer.getIdentificationIds();if(t&&t.some((t=>t===e)))return r.layer}if(r.layer.getDependLayers){const t=r.layer.getDependLayers().find((t=>t.item&&t.item.parentId===e));if(t)return t.layer}}}async fitLayer(e,t){let r;r="string"==typeof e||"number"==typeof e?String(r):e.id;const s=r&&this._ngwLayers[r];if(s)if(s.layer.getBounds){const e=await s.layer.getBounds();e&&this.fitBounds(e,t)}else{let e;if(s.layer.item)e=s.layer.item;else{const t=s.resourceId;e=await this.connector.getResource(t)}e&&Be(e,this.connector).then((e=>{e&&this.fitBounds(e,t)}))}else super.fitLayer(e,t)}async zoomToLayer(e){return this.fitLayer(e)}onLoad(e="ngw-map:create"){return super.onLoad(e)}removeLayer(e){const t=this.getLayer(e);if(t){const e=this.getLayerId(t);e&&delete this._ngwLayers[e],super.removeLayer(t)}}enableSelection(){this.$$selectFromNgwRaster||(this.$$selectFromNgwRaster=e=>{this.emitter.listenerCount("ngw:select")&&this._selectFromNgwRaster(e)},this.$$selectFromNgwVector=e=>{this.emitter.listenerCount("ngw:select")&&this._selectFromNgwVector(e)},this.emitter.on("click",this.$$selectFromNgwRaster),this.emitter.on("layer:click",this.$$selectFromNgwVector))}disableSelection(){this.$$selectFromNgwRaster&&(this.emitter.removeListener("click",this.$$selectFromNgwRaster),this.emitter.removeListener("click",this._selectFromNgwVector),this.$$selectFromNgwRaster=void 0,this.$$selectFromNgwVector=void 0)}getNgwLayerItem(e){return this.fetchNgwLayerItem(e)}getNgwLayerItems(e){return this.fetchNgwLayerItems(e)}getNgwLayerFeature(e){return this.fetchNgwLayerFeature(e)}getNgwLayerFeatures(e){return this.fetchNgwLayerFeatures(e)}cancelPromise(...e){this.cancelPromises(...e)}cancelPromises(...e){e.length||(e=Object.keys(this._promises)),e.forEach((e=>{const t=this._promises[e];t&&(t.forEach((e=>e.cancel())),this._promises[e]=[])}))}_addPromise(e,t){const r=this._promises[e];if(r&&-1===r.indexOf(t)){const e=()=>{const e=r.indexOf(t);-1!==e&&r.splice(e,1)};t.then(e),t.catch(e),r.push(t)}}_isFitFromResource(){const e=this._initMapState;return!e.zoom||!e.center}async _createWebMap(){await this.create(),this.options.qmsId&&this._addQmsBaseLayer(),this.options.osm&&this._addOsmBaseLayer();const e=[],t=this._isFitFromResource();this.options.webmapId&&kt(e,this.options.webmapId,{fit:t}),this.options.resources&&Array.isArray(this.options.resources)&&this.options.resources.forEach((r=>{const s={};t||(s.fit=!1),kt(e,r,{},s)}));for(const t of e)try{await this.addNgwLayer(t)}catch(e){console.log(e)}this._emitStatusEvent("ngw-map:create",this),this.enableSelection()}_addOsmBaseLayer(){this.addBaseLayer("OSM")}_addQmsBaseLayer(){let e,t;Array.isArray(this.options.qmsId)?(e=this.options.qmsId[0],t=this.options.qmsId[1]):e=Number(this.options.qmsId);const r={qmsId:e};t&&(r.id=t),this.addBaseLayer("QMS",r)}_selectFromNgwVector(e){const t=e.layer,r=t.item&&t.item.resource.id,s=e.feature;if(void 0!==r&&s){const e=s.id;if(e){const t={featureCount:1,[r]:{featureCount:1,features:[{id:Number(e),fields:s.properties||{},label:`#${r}`,layerId:Number(r),parent:"",geom:s.geometry}]}};return this._emitStatusEvent("ngw:select",this._prepareToIdentify({...t,resources:[r],sourceType:"vector"})),t}}}async _selectFromNgwRaster(e){this._emitStatusEvent("ngw:preselect");const t=[],r=Object.values(this._ngwLayers);r.sort(((e,t)=>e.layer.order&&t.layer.order?t.layer.order-e.layer.order:1)),r.forEach((e=>{const r=e.layer,s="function"==typeof r.getIdentificationIds&&r.getIdentificationIds;s&&r.options.selectable&&this.isLayerVisible(r)&&t.push(s.call(r))}));const s=Promise.all(t),i=await s,o=[];if(i.forEach((e=>{e&&e.forEach((e=>o.push(e)))})),!o.length)return void this._emitStatusEvent("ngw:select",null);const n=this.options.pixelRadius||10,a=this.getCenter();let c=this.getZoom();if(c=void 0!==c?c:20,!a||!c)return void this._emitStatusEvent("ngw:select",null);const h=function(e,t,r){return(r=null!=r?r:10)*(40075016.686*Math.abs(Math.cos(180*e[1]/Math.PI))/Math.pow(2,t+8))*5e-4}(a,c,n),l=Mt(e,{layers:o,connector:this.connector,radius:h}).then((t=>(this._emitStatusEvent("ngw:select",this._prepareToIdentify({...t,resources:o,sourceType:"raster",event:e})),t)));return this._addPromise("select",l),l}_prepareToIdentify(e){return{...e,getIdentifyItems:()=>At(e,!0).map((e=>new Et({feature:e.feature,connector:this.connector})))}}async _whiteLabel(){const e=this.getContainer();if(e){const t=await async function(e,t){var r;const s=await e.get("pyramid.settings",null,{component:"pyramid"});if(s&&s.company_logo&&s.company_logo.enabled){const i=document.createElement("a");i.style.position="absolute",i.style.bottom="0",i.style.right="0",i.style.padding=null!==(r=null==t?void 0:t.padding)&&void 0!==r?r:"10px",i.className="ngw-map-logo",t&&t.cssClass&&(i.className+=" "+t.cssClass);const o=new Image;o.style.maxHeight="100px",o.style.maxWidth="100px",o.src="";try{const t=await e.get("pyramid.company_logo",{responseType:"blob"}),r=(window.URL||window.webkitURL).createObjectURL(t);o.src=r}catch(e){console.log(e)}return null!==s.company_logo.link&&""!==s.company_logo.link.trim()&&(i.href=s.company_logo.link,i.target="_blank",-1!==s.company_logo.link.search(/:\/\/nextgis/)&&(o.alt="Get your own Web GIS at nextgis.com")),i.appendChild(o),i}}(this.connector,this.options.companyLogoOptions);t&&e.appendChild(t)}}}async function Tt(e){return new Nt(e).onLoad()}Nt.getIcon=function(e={}){const t=e.color||"blue",r=e.strokeColor||"white",s=e.size||12,i=s/2,o="number"==typeof e.stroke?e.stroke:.8,n=s/12,a=xt[e.shape||"circle"]||"circle",c=function(e,t,r=0,s){const i=r/2,o=`<svg\n version="1.1"\n xmlns="http://www.w3.org/2000/svg"\n width="${e}"\n height="${t}"\n viewBox="-${i} -${i} ${e+r} ${t+r}"\n >${s}</svg>`;return(new DOMParser).parseFromString(o,"image/svg+xml").documentElement}(s,s,o*n,"string"==typeof a?a:a(e)),h=c.firstChild,l=`scale(${n})`;return h.setAttribute("fill",t),o&&(h.setAttribute("stroke",r),h.setAttribute("stroke-width",String(o))),h.setAttribute("transform",l),{type:"icon",iconSize:[s,s],iconAnchor:[i,i],html:(new XMLSerializer).serializeToString(c),svg:c}};export{Nt as NgwMap,ue as WebMap,he as WebMapControls,ae as WebMapLayers,ne as WebMapMain,Tt as createNgwMap,ce as createToggleControl,de as createWebMap,Q as detectGeometryType,J as findMostFrequentGeomType,pe as getWebMap,X as updateGeoJsonAdapterOptions};
|
|
2
2
|
//# sourceMappingURL=ngw-map.esm-browser.prod.js.map
|