@nextgis/ngw-map 1.11.8 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,16 @@
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(i){t(i)}};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 r of e)"cancel"in r&&r.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(t){}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 C(e){return null!=e}function E(e){return"string"==typeof e?!!e:C(e)}function I(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]=I(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]?I(s[e],i[e],r):i[e]}))),n}function P(e){if(!e.lngLat&&e.latLng){e.lngLat=[e.latLng.lng,e.latLng.lat]}return e}function A(e){return{type:"Polygon",coordinates:[x(e)]}}function x(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,k=180/Math.PI;function S(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 N(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:B(e,t));return e===t}function B(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(!N(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 R(e){return"[object Object]"===Object.prototype.toString.call(e)}function F(e){return e.replace(/([^:]\/)\/+/g,"$1")}function j(e){return"function"==typeof e}const D={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=$(e,r));const o=s.splice(-1,s.length%2)[0];for(let n=0;n<s.length-1;n+=2){if(s[n]===i)return s[n+1]}return o}};function $(e,t){const[r,...s]=t,i=D[r];if(i)return i(e,s)}function z(e){return t=>$(t,e)}const V=["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 Z(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function q(e,t){const r="string"==typeof t[0]?t[0]:"all",s=t=>{if(Z(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(j(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===V.indexOf(s)){const i=s,o=e[i];Array.isArray(o)&&(t=!0,r[i]=z(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 j(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 s=0;s<e.length;s++)t[e[s]]=1+(t[e[s]]||0);let r;for(const s in t){t[s]>((void 0!==r?t[r]:0)||0)&&(r=s)}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"},X={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon"};function Y(e){if(e.data){const t=X[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:"#0000ff",opacity:.4,strokeOpacity:1,stroke:!0,radius:8,weight:1},selectedPaint:{color:"#00008b",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=I(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:A(e)}}}setZoom(e){return this.mapAdapter.setZoom(e),this}getZoom(){const e=this.mapAdapter.getZoom();if("number"==typeof e)return e}zoomIn(){if(this.mapAdapter.zoomIn)this.mapAdapter.zoomIn();else{const e=this.getZoom();if(void 0!==e){this.setZoom(e+1)}}}zoomOut(){if(this.mapAdapter.zoomOut)this.mapAdapter.zoomOut();else{const e=this.getZoom();if(void 0!==e){this.setZoom(e-1)}}}setView(e,t){if(Array.isArray(e)){const r=e;this.mapAdapter.setView&&r&&C(t)?this.mapAdapter.setView(r,t):(r&&this.mapAdapter.setCenter(r),C(t)&&this.mapAdapter.setZoom(t))}else{const t=e;this.mapAdapter.setView&&this.mapAdapter.setView(t)}}fitBounds(e,t){return e.every((e=>C(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(),P(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),C(e.maxzoom)&&(this.options.maxZoom=e.maxzoom,this.options.zoom=e.maxzoom),C(e.minzoom)&&(this.options.minZoom=e.minzoom,this.options.zoom=e.minzoom),C(e.maxzoom)&&C(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){if(t.id)return null==t?void 0:t.id;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=C(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 h=null===(s=(t={id:String(o),order:n,...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),h&&await this.showLayer(r));const l=t.opacity;void 0!==l&&l<=1&&this.setLayerOpacity(e,l);const p=s&&(e.getBounds||e.getExtent);if(t.fit&&p){const t=await p.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=Y(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?await e.showLayer.call(e,e.layer):void 0!==e.layer&&await this.mapAdapter.showLayer(e.layer),void 0!==t&&this.mapAdapter.setLayerOrder(e.layer,t,this._layers)}else e.hideLayer?await e.hideLayer.call(e,e.layer):void 0!==e.layer&&await this.mapAdapter.hideLayer(e.layer);e.options.visibility=i,o||(this._emitLayerEvent(r,t,e),this._emitLayerEvent("layer:toggle",t,e))};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)}setLayerPaint(e,t){const r=this.getLayer(e);t&&r&&r.setPaint&&r.setPaint(t)}setLayerSelectedPaint(e,t){const r=this.getLayer(e);t&&r&&r.setSelectedPaint&&r.setSelectedPaint(t)}updateLayerPaint(e,t){const r=this.getLayer(e);t&&r&&r.updatePaint&&r.updatePaint(t)}updateLayerSelectedPaint(e,t){const r=this.getLayer(e);t&&r&&r.updateSelectedPaint&&r.updateSelectedPaint(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})}_emitLayerEvent(e,t,r){const s=String(e);if(C(t)&&s.startsWith("layer:")){const e=s.replace("layer:","layer-"+t+":");this.emitter.emit(e,r)}this.emitter.emit(e,r)}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),C(t)&&this._emitLayerEvent("layer:mouseout",t,e)},e.onMouseOver=e=>{const t=e.layer.id;n&&n(e),C(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)))}}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 t of this._starterKits)if(t.onLoadSync)try{await t.onLoadSync.call(t,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(e={}){var t;this.cache=[];const r=null!==(t=e.namespace)&&void 0!==t?t:"default";return ye.instance[r]?ye.instance[r]:(ye.instance[r]=this,this)}clean(){this.cache.length=0}all(){return this.cache}addFull(e,t,r){return this.add(e,t,r,!0)}add(e,t,r,s){const i=this._find(e,r);if(i)return i.value;{let i;i=t instanceof Function?t():t;const o=r&&JSON.parse(JSON.stringify(T(r))),n={key:e,value:i,props:o,options:o};return s&&!E(i)?i:(this.cache.push(n),i instanceof Promise?(i.catch((t=>{throw this.delete(e,r),t})),s&&i.then((t=>(E(t)||this.delete(e,r),t))),i):i)}}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){let r=[];"string"==typeof e?r=this.cache.filter((r=>this._filter(r,e,t))):r.push(e);for(const s of r){const e=this.cache.indexOf(s);this.cache.splice(e,1)}}_find(e,t){return this.cache.find((r=>this._filter(r,e,t)))}_filter(e,t,r){if(e.key===t){if(r){return B(e.props||e.options||{},T(r))}return!0}return!1}}ye.instance={};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}`}}function _e(e){return"[object Object]"===Object.prototype.toString.call(e)}let ve;ve=(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,422,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 h in a){const e=a[h];"string"==typeof e&&o.setRequestHeader(h,e)}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 h in r.data)c.append(h,c[h])}else c=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;i&&i((()=>{o.abort()})),o.send(c)};const we=/\{ *([\w_-]+) *\}/g;function be(e,t){return e.replace(we,((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 Le extends fe{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,Le.prototype)}}class Oe extends fe{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,Oe.prototype)}}const Ce=[];function Ee(e){Ce.push(e)}const Ie=["description"];function Pe(e,t=""){t=t?t+"__":"";const r={};for(const[s,i]of Object.entries(e))if(-1===Ie.indexOf(s))if(_e(i))if("owner_user"===s){const e=Pe(i,s);Object.assign(r,e)}else"parent"===s&&"id"in i&&(r.parent_id=i.id);else C(i)&&(r[t+s]=i);return r}class Ae{constructor(e){this.connector=e,this.cache=new me}getOne(e,t){const r=new me,s={},i={...t,cache:!1};"string"==typeof e?s.keyname=e:"number"==typeof e?s.id=e:_e(e)&&(s.id=e.id);return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},i):"number"==typeof e?this._fetchResourceById(e,i):_e(e)?this._fetchResourceBy(e,i):L.resolve(void 0)),s)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new Le}))}getId(e,t){return"number"==typeof e?L.resolve(e):"string"==typeof e||_e(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):L.resolve(void 0)}getIdOrFail(e,t){return this.getId(e,t).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,Pe(e)),this.connector.get("resource.search",t,{serialization:"full",...r}).then((e=>{if(e)for(const t of e)this.cache.add("resource.item",L.resolve(t),{id:t.resource.id});return e}))}return r}))}getParent(e,t){return this.getOne(e,t).then((e=>e?this.getOne(e.resource.parent.id,t):L.resolve(void 0)))}getChildrenOf(e,t){return this.getId(e).then((e=>this.connector.get("resource.collection",{cache:!0,...t},{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._cleanResourceItemCache(e)}))}))}async _cleanResourceItemCache(e){const t=this.cache.all(),r=[];for(const s of t){const t=s.options&&s.options.id;if(["resource.item","resource"].includes(s.key)&&void 0!==t)if("number"==typeof t)t===e&&r.push(s);else{await this.getId(t)===e&&r.push(s)}}for(const s of r)this.cache.delete(s)}_fetchResourceById(e,t){return this.cache.add("resource.item",(()=>this.connector.get("resource.item",t,{id:e})),{id:e}).catch((e=>{if(!(e instanceof Le))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:C(e.id)&&C(t.resource.id)?e.id===t.resource.id:B(e,t.resource)})),[])))}}let xe=0;class Me{constructor(e){this.options=e,this.id=xe++,this.emitter=new t.exports.EventEmitter,this.routeStr="/api/component/pyramid/route";const r=function(e){return Ce.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return B(t.options.auth,e.auth)}}))}(e);if(r)return r;this.options.route&&(this.routeStr=this.options.route),this.resources=new Ae(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=Ce.indexOf(e);-1!==t&&Ce.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=be(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 s in t)-1===o.indexOf(s)&&e.push(`${s}=${t[s]}`);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=be(e,t)),e=F(e),this._loadData(encodeURI(e),r);throw new Error("Empty `url` not allowed")}getResource(e,t){return this.resources.getOne(e,t)}getResourceOrFail(e,t){return this.resources.getOneOrFail(e,t)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e,t){return this.resources.getId(e,t)}getResourceIdOrFail(e,t){return this.resources.getIdOrFail(e,t)}getResourcesBy(e,t){return this.resources.getMany(e,t)}getResourceParent(e,t){return this.resources.getParent(e,t)}getResourceChildren(e,t){return this.resources.getChildrenOf(e,t)}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}),ve(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 Le(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new Oe(e)}return e}}Me.errors={NgwError:fe,ResourceNotFoundError:Le};var ke=Me;const Se=["fields","intersects","limit","orderBy","strategy"];function Ne(e){const t={};return Se.forEach((r=>{const s=e[r];void 0!==s&&(t[r]=s)})),t}function Be(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 Re(e,t){if(e.webmap)return L.resolve(Be(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 Fe(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 Fe(r,t)),!o&&i){const e=await t.getResource(i);e&&(o=e.resource.id)}return o}const je={srs:4326,geom_format:"geojson"};function De(e){return{id:e.id,type:"Feature",properties:e.fields,geometry:e.geom}}function $e(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)),C(o)&&(e.srs=o)}function ze(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;let i="",o="";return[`${"id"!==t?"fld_":""}${String(t).trim().replace(/^(%?)(.+?)(%?)$/,((e,t,r,s)=>(i=t,o=s,r)))}__${r}`,i+s+o]};if("any"===i)o.forEach((s=>{Z(s)?t.push(Ve({...e,paramList:[...r,n(s)]})):ze({...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)ze({...e,filters:o},t,[...r,...s]);else t.push(Ve({...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 Ve(e){const t={...je},{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),$e(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))?x(o):o);t.intersects=`POLYGON((${e.map((([e,t])=>{const[r,s]=S(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(R(r)){const s=r;if(C(s.year)&&C(s.month)&&C(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?ze({...e,filters:t}).then((e=>(e.filter((e=>q(Ge({...e.fields}),t))),e))):Ve(e)}function Ze(e){return function(e){return Ue(e).then((e=>{const t=[];return e.forEach((e=>{t.push(De(e))})),t}))}(e).then((e=>({type:"FeatureCollection",features:e})))}async function qe(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,d=[];let y,m,f=!1;const g=await Fe(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 _=async(e,t)=>(w(),y={filters:e,options:t},m=Ze({resourceId:g,filters:e,connector:a,cache:!0,...t}),await m);let v=!1;const w=()=>{m&&(m.cancel(),m=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=Lt[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=e.strategy||void 0;this.options.strategy=s;const o=super.addLayer(e);let n;return y={filters:e.propertiesFilter,options:Ne(e)},t&&(n=this.updateLayer()),r&&n&&await n,s&&s.startsWith("BBOX")&&!f&&this._addBboxEventListener(),o}getExtent(){return this.getBounds()}async getBounds(){const e=this.getLayers&&this.getLayers().length,t=this.options.strategy;return(null==t?void 0:t.startsWith("BBOX"))||e?function(e){return e.connector.getResource(e.resourceId).then((t=>{if(t)return Re(t,e.connector)}))}({connector:a,resourceId:i.resource.id}):super.getBounds?super.getBounds():void 0}beforeRemove(){v=!0,this._removeMoveEventListener(),this._removeBboxEventListener(),this.__disableMapMoveListener=void 0,this.__enableMapMoveListener=void 0,this.__onMapMove=void 0,this.__onMapMoveStart=void 0,w()}getCount(){return function({connector:e,resourceId:t,cache:r=!0}){return e.get("feature_layer.feature.count",{cache:r},{id:t}).then((e=>e.total_count))}({connector:a,resourceId:g,cache:!0})}async updateLayer(e){var t;if(e=e||y||{},null===(t=this.options.strategy)||void 0===t?void 0:t.startsWith("BBOX")){await o.onLoad("create"),e.options=e.options||{},e.options.intersects=o.getBounds();const{minZoom:t,maxZoom:r}=this.options,s=o.getZoom();if(void 0!==s){if(void 0!==t&&s<t)return;if(void 0!==r&&s>r)return;if(f)return}}if(!v){try{this.emitter.emit("preupdate",e),o._emitLayerEvent("layer:preupdate",p.id||"",e);const t=await _(e.filters,{...e.options,srs:this.options.srs});let r=t;const s=await this.getCount();if("BBOX+"===this.options.strategy){r={type:"FeatureCollection",features:[]};for(const e of t.features)-1===d.indexOf(String(e.id))&&(d.push(String(e.id)),r.features.push(e));f=void 0!==s&&d.length>=s,await o.addLayerData(this,r)}else f=void 0!==s&&t.features.length>=s,await o.setLayerData(this,t);this.emitter.emit("updated",t),o._emitLayerEvent("layer:updated",p.id||"",{data:t,newData:r,isFull:f})}catch(r){if(r instanceof Error&&"CancelError"!==r.name)throw r}super.updateLayer&&super.updateLayer()}}async propertiesFilter(e,t){if(w(),this.filter&&f)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 _(e,{...t,srs:this.options.srs});this.setData(r)}}removeFilter(){y=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=w,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 We({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=>bt({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 He({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 Fe(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=We({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&&C(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(C(e))return[e]}}}throw new Error(o+" not supported yet. Only TILE")}function Je(e,t,r,s){return!!Xe(e,t,r,Ye,s)}function Qe(e,t,r,s){return Xe(e,t,r,et,s)}function Ke(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 Xe(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=Ke(e,r);s&&(i=s)}for(let o=0;o<i.length;o++)if(i[o]){const e=Ye(i[o],t,r,s);if(e)return e}}function et(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{t(e)&&s.push(e);const o=Ke(e,r);o&&(i=o)}for(let o=0;o<i.length;o++)i[o]&&et(i[o],t,r,s);return s}function tt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(!t(e))return!1;const s=Ke(e,r);s&&(i=s)}for(let o=0;o<i.length;o++)if(i[o]){if(!tt(i[o],t,r,s))return!1}return!0}class rt{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?Qe(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 Xe(this._children,e,(e=>e.tree.getChildren()),Ye,t);var t}every(e){return!!Xe(this._children,e,(e=>e.tree.getChildren()),tt,t);var t}some(e){return Je(this._children,e,(e=>e.tree.getChildren()))}all(e){return this.getDescendants(e)}getDescendants(e){return Qe(this._children,e,(e=>e.tree.getChildren()))}getChildren(){return[...this._children]}}class st{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 it extends st{constructor(e,t,r){super(e,t,{...it.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})}}}}it.options={hierarchy:!0,bubble:!1,propagation:!1,label:"Toggle"};class ot{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=ot.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=[]}}ot.handlers={CheckProperty:it};let nt=0;class at extends class{constructor(e){this.options={},this.id=nt,nt+=1,this.options={...e},this.tree=new rt(this)}initProperties(){this.properties=new ot(this,this.options.properties)}}{constructor(e,r,s,i,o,n){if(super({...at.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 at(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 at(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(at.GetAdapterFromLayerType[e.item_type]){t=(0,at.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{maxZoom:t,minZoom:r}=this._getZoomRange(e);!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===Ot){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),Ot=t}return Ot}()*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)}_getZoomRange(e){const t=this.options.minZoom,r=this.options.maxZoom,s=e.layer_min_scale_denom?this._mapScaleToZoomLevel(e.layer_min_scale_denom):void 0,i=e.layer_max_scale_denom?this._mapScaleToZoomLevel(e.layer_max_scale_denom):void 0,o=[t,s].filter(Boolean),n=[r,i].filter(Boolean);return{minZoom:o.length?Math.max(...o):void 0,maxZoom:n.length?Math.min(...n):void 0}}_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 ct({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;for(const t of this.layer)e.removeLayer(t)}destroyed(){return this._removed}async showLayer(){if(this.options.visibility=!0,this.layer.length)for(const t of this.layer)await e.showLayer(t);else await this.loadLayer()}async hideLayer(){if(this.options.visibility=!1,this.layer)for(const t of this.layer)await e.hideLayer(t)}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.layer.push(s),this.options.visibility&&await e.showLayer(s),this._creatingInProgress=!1}}return this.layer}}}({webMap:e,adapterOptions:s,onLayerAdded:e=>{e.options.baselayer=!1,e.id=i+"-"+r.resource_id},createAdapter:()=>wt({resource:r.resource_id,adapterOptions:{name:r.display_name,opacity:r.opacity}},e,t)})}at.GetAdapterFromLayerType={},at.options={properties:[{type:"boolean",name:"visibility",getProperty(e){if(e){if("group"===e.item.item_type||"root"===e.item.item_type)return Je(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 st{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 ht{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(De(this.item)):Pt({resourceId:this.resourceId,featureId:this.item.id,connector:this.options.connector,geom:!0,fields:null,extensions:null}).then((e=>(this.item.geom=e.geom,De(this.item))))}}class lt{constructor(e,r){this.map=e,this.options=r,this.NgwWebmapItem=at,this.pixelRadius=10,this.webmapClassName="webmap",this.emitter=new t.exports.EventEmitter,this._webmapBaselayersIds=[];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){var t,r;this.options={...this.options,...e},this.layer=await this._getWebMapLayerItem();const s=null===(r=null===(t=this.response)||void 0===t?void 0:t.webmap)||void 0===r?void 0:r.extent_constrained;return this.options.useExtentConstrained&&this._extent&&s&&(this.options.webMap.setView({maxBounds:this._extent}),window.webmap=this.options.webMap),this.layer}removeLayer(){const e=this.options.webMap.mapAdapter;if(this.getDependLayers().forEach((t=>{"layer"in t&&e.removeLayer(t.layer.layer)})),this._webmapBaselayersIds.length){for(const e of this._webmapBaselayersIds)this.options.webMap.removeLayer(e);this._lastActiveBaselayer&&this.options.webMap.showLayer(this._lastActiveBaselayer)}this.options.useExtentConstrained&&this._extent&&this.options.webMap.setView({maxBounds:null}),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 Be(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 ht({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.minZoom=this.options.minZoom,r.maxZoom=this.options.maxZoom,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(this._setupBaselayers(t),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}}_setupBaselayers(e){var t;const r=this.options.webMap;if(null===(t=this.options.useBasemap)||void 0===t||t)if(e.basemap_webmap&&e.basemap_webmap.basemaps.length){const t=r.getActiveBaseLayer();this._lastActiveBaselayer=t?t.id:void 0,this._setBasemaps(e.basemap_webmap)}else this.options.defaultBasemap&&r.addBaseLayer("OSM",{id:"webmap-default-baselayer",name:"OpenStreetMap"})}_setBasemaps(e){const t=this.options.webMap;let r=!1;for(const s of e.basemaps)ct({webMap:t,connector:this.options.connector,item:s,adapterOptions:{crossOrigin:this.options.crossOrigin}}).then((e=>{t.addBaseLayer(e,{id:It+s.resource_id,name:s.display_name,opacity:s.opacity,visibility:!r&&s.enabled}).then((e=>{e.id&&this._webmapBaselayersIds.push(e.id)})),s.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=F(this.options.connector.options.baseUrl+"/api/component/render/image"),s=e.layer_style_id;e.url=r,e.resourceId=s,e.updateWmsParams=e=>bt(e,s);const i=We({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 pt{async getExtent(){return this.getBounds()}async getBounds(){return this._extent?this._extent:this.item?(this._extent=await Re(this.item,this.connector),this._extent):void 0}}const ut={tms:"TILE"};function dt(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 yt="https://qms.nextgis.com";function mt(e,t=yt,r={}){t||(t=yt);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",F(e),!0),s.send()}))}(t+"/api/v1/geoservices/"+r.qmsId)}catch(a){console.error(a)}const i=this.qms;if(i){const t=ut[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,...dt(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 ft{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 mt(e,this.url)}}ft.utils={createQmsAdapter:mt};const gt={},_t=["mapserver_style","qgis_vector_style","qgis_raster_style","wmsserver_service","raster_style","basemap_layer","vector_layer","raster_layer","webmap","tmsclient_layer"];async function vt({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 wt({...e,resource:n.resource.id},t,r)}async function wt(e,t,r){let s,i;const o=e.adapter,n=await Fe(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!==_t.indexOf(a))if("webmap"===a)s=async function({layerOptions:e,webMap:t,connector:r}){const s=await Fe(e,r);return class extends lt{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 vt(c);s=He(c)}else s=qe(c);else{if("raster_layer"===a)return vt(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(ft.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=qe({...c,item:t,layerOptions:r})}}else s=He(c)}else{if(!gt[a])throw`Resource class '${a}' not yet supported.`;{const e=gt[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,[pt],{replace:!1}),t}}))}function bt(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 Lt={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 Ot;class Ct{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 ke({baseUrl:this.url,auth:this.options.auth})}}static addClassAdapters(e,t){gt[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(lt,{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 lt{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):Pt({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 It="webmap-baselayer";function Pt(e){const t={...je};$e(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(De(t)):Pt({...e,geom:!0,fields:null,extensions:null}).then((e=>{const r=e.geom;return De({...t,geom:r})}))})))}function At(e){return Pt(e).then((e=>De(e)))}function xt(e,t=!1){let r;const s=[],i=[];for(const n in e){const e=Number(n);isNaN(e)||s.push(e)}const o=e.resources;o&&s.sort(((e,t)=>o.indexOf(e)-o.indexOf(t)));for(let n=0;n<s.length;n++){const o=s[n],a=e[o];if("features"in a){const e=a.features,s=Number(o),n=e[0];if(n&&(r={featureId:n.id,resourceId:s,feature:n},i.push(r),!t))break}}return i}function Mt(e,t){P(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*k,o=i/Math.cos(t*M),n=[];for(let a=0;a<s+1;a++){const r=Math.PI*(a/(s/2)),c=e+o*Math.cos(r),h=t+i*Math.sin(r);n.push([c,h])}return n}(r,s,t.radius));const o=[];i.forEach((([e,t])=>{const[r,s]=S(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 kt={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 St(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 Nt={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 Bt extends ue{constructor(e){super(function(e){const t=[new ft];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new ke({baseUrl:e.baseUrl||"",auth:e.auth}),(e=I(Nt,e)).center||e.bounds||(e.bounds=[-179,-90,180,90]),e.connector&&t.push(new Ct({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(C(this.options.baseUrl))try{C(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},C(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=function(e,t,r){const s=r.getAuthorizationHeaders();return s&&(e.headers=s),wt(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(i){const e=R(s)&&"id"in s?s.id:t||r||s;console.error(`Can't add NGW layer ${e}.`,i)}}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 Pt({connector:this.connector,...e})}fetchNgwLayerItems(e){return Ue({connector:this.connector,...e})}fetchNgwLayerFeature(e){return At({connector:this.connector,...e})}fetchNgwLayerFeatures(e){return Ze({connector:this.connector,...e})}fetchIdentifyItem(e,t){const r=function(e){const{connector:t,identify:r}=e,s=xt(r);return s&&s.length?Pt({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 i in r){const e=Number(i);if(!isNaN(e)){const e=r[i];if("features"in e){const t=e.features.find((e=>e.geom));if(t&&t.geom){const e=t.geom;return L.resolve(De({...t,geom:e}))}}}}const s=xt(r);return s&&s.length?At({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&&Re(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();if(this.options.webmapId&&St(e,this.options.webmapId,{fit:t}),this.options.resources&&Array.isArray(this.options.resources))for(const s of this.options.resources){const r={};t||(r.fit=!1),St(e,s,{},r)}for(const s of e)try{await this.addNgwLayer(s)}catch(r){console.warn(r)}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:()=>xt(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 o=document.createElement("a");o.style.position="absolute",o.style.bottom="0",o.style.right="0",o.style.padding=null!==(r=null==t?void 0:t.padding)&&void 0!==r?r:"10px",o.className="ngw-map-logo",t&&t.cssClass&&(o.className+=" "+t.cssClass);const n=new Image;n.style.maxHeight="100px",n.style.maxWidth="100px",n.src="";try{const t=await e.get("pyramid.company_logo",{responseType:"blob"}),r=(window.URL||window.webkitURL).createObjectURL(t);n.src=r}catch(i){console.warn(i)}return null!==s.company_logo.link&&""!==s.company_logo.link.trim()&&(o.href=s.company_logo.link,o.target="_blank",-1!==s.company_logo.link.search(/:\/\/nextgis/)&&(n.alt="Get your own Web GIS at nextgis.com")),o.appendChild(n),o}}(this.connector,this.options.companyLogoOptions);t&&e.appendChild(t)}}}async function Tt(e){return new Bt(e).onLoad()}Bt.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=kt[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{Bt 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,Y as updateGeoJsonAdapterOptions};
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+ var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(e,r)};function e(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function n(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(e){i(e)}}function a(t){try{u(n.throw(t))}catch(e){i(e)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(a){i=[6,a],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function i(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=i(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise((function(n,o){(function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)})(n,o,(e=t[r](e)).done,e.value)}))}}}var u,c={exports:{}},p="object"==typeof Reflect?Reflect:null,l=p&&"function"==typeof p.apply?p.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};u=p&&"function"==typeof p.ownKeys?p.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var h=Number.isNaN||function(t){return t!=t};function f(){f.init.call(this)}c.exports=f,c.exports.once=function(t,e){return new Promise((function(r,n){function o(r){t.removeListener(e,i),n(r)}function i(){"function"==typeof t.removeListener&&t.removeListener("error",o),r([].slice.call(arguments))}O(t,e,i,{once:!0}),"error"!==e&&function(t,e,r){"function"==typeof t.on&&O(t,"error",e,r)}(t,o,{once:!0})}))},f.EventEmitter=f,f.prototype._events=void 0,f.prototype._eventsCount=0,f.prototype._maxListeners=void 0;var d=10;function y(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function v(t){return void 0===t._maxListeners?f.defaultMaxListeners:t._maxListeners}function m(t,e,r,n){var o,i,s,a;if(y(r),void 0===(i=t._events)?(i=t._events=Object.create(null),t._eventsCount=0):(void 0!==i.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),i=t._events),s=i[e]),void 0===s)s=i[e]=r,++t._eventsCount;else if("function"==typeof s?s=i[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(o=v(t))>0&&s.length>o&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return t}function g(){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 _(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=g.bind(n);return o.listener=r,n.wrapFn=o,o}function b(t,e,r){var n=t._events;if(void 0===n)return[];var o=n[e];return void 0===o?[]:"function"==typeof o?r?[o.listener||o]:[o]:r?function(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}(o):L(o,o.length)}function w(t){var e=this._events;if(void 0!==e){var r=e[t];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function L(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function O(t,e,r,n){if("function"==typeof t.on)n.once?t.once(e,r):t.on(e,r);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,(function o(i){n.once&&t.removeEventListener(e,o),r(i)}))}}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return d},set:function(t){if("number"!=typeof t||t<0||h(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");d=t}}),f.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},f.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||h(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},f.prototype.getMaxListeners=function(){return v(this)},f.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var n="error"===t,o=this._events;if(void 0!==o)n=n&&void 0===o.error;else if(!n)return!1;if(n){var i;if(e.length>0&&(i=e[0]),i instanceof Error)throw i;var s=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw s.context=i,s}var a=o[t];if(void 0===a)return!1;if("function"==typeof a)l(a,this,e);else{var u=a.length,c=L(a,u);for(r=0;r<u;++r)l(c[r],this,e)}return!0},f.prototype.on=f.prototype.addListener=function(t,e){return m(this,t,e,!1)},f.prototype.prependListener=function(t,e){return m(this,t,e,!0)},f.prototype.once=function(t,e){return y(e),this.on(t,_(this,t,e)),this},f.prototype.prependOnceListener=function(t,e){return y(e),this.prependListener(t,_(this,t,e)),this},f.prototype.off=f.prototype.removeListener=function(t,e){var r,n,o,i,s;if(y(e),void 0===(n=this._events))return this;if(void 0===(r=n[t]))return this;if(r===e||r.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,r.listener||e));else if("function"!=typeof r){for(o=-1,i=r.length-1;i>=0;i--)if(r[i]===e||r[i].listener===e){s=r[i].listener,o=i;break}if(o<0)return this;0===o?r.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(r,o),1===r.length&&(n[t]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",t,s||e)}return this},f.prototype.removeAllListeners=function(t){var e,r,n;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[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[t]),this;if(0===arguments.length){var o,i=Object.keys(r);for(n=0;n<i.length;++n)"removeListener"!==(o=i[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=r[t]))this.removeListener(t,e);else if(void 0!==e)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this},f.prototype.listeners=function(t){return b(this,t,!0)},f.prototype.rawListeners=function(t){return b(this,t,!1)},f.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):w.call(t,e)},f.prototype.listenerCount=w,f.prototype.eventNames=function(){return this._eventsCount>0?u(this._events):[]};var C=function(t){function r(){var e=t.call(this)||this;return e.name="CancelError",Object.setPrototypeOf(e,r.prototype),e}return e(r,t),r}(Error),I=function(){function t(t){void 0===t&&(t={}),this.options=t,this._promises=new Map}return Object.defineProperty(t.prototype,"isLoaded",{get:function(){return this._promises.size>0},enumerable:!1,configurable:!0}),t.prototype.remove=function(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())},t.prototype.get=function(t){return this._promises.get(t)},t.prototype.add=function(t,e){var r=this,n=e||t,o=this._promises.get(n);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),o||(this._promises.set(n,t),t.finally((function(){r.remove(n)})),t)},t.prototype.abort=function(){this.isLoaded&&(this._promises.forEach((function(t){t.cancel&&t.cancel()})),this._promises.clear(),this._onStop())},t.prototype.waitFunc=function(t,e){void 0===e&&(e="");var r=this.get(e=e||t.name);return r||this.add(t(),e)},t.prototype.WaitForMe=function(t){void 0===t&&(t="");var e=this.get.bind(this),r=this.add.bind(this);return function(n,o,i){var s=i.value;return t=t||o,i.value=function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var i=e(t);if(i)return i;var a=r(s.apply(this,n),t);return a},i}},t.prototype.GetOrCreateDecorator=function(t){return void 0===t&&(t=""),this.WaitForMe(t)},t.prototype._onStop=function(){this.options.onStop&&!this.isLoaded&&this.options.onStop()},t}(),E=function(t){function r(){var e=t.call(this)||this;return e.name="TimeoutError",Object.setPrototypeOf(e,r.prototype),e}return e(r,t),r}(Error),P=function(t,e,r,n){try{t(r(n))}catch(o){e(o)}},A=0,M=function(){function t(e,r){var n=this;this.id=A++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((function(t,e){n._setCanceledCallback=function(e){return t(e||new C)}}));var o=[this._cancelPromise,new Promise((function(r,o){return e((function(e){e instanceof t?n.attach(e):n._isPending=!1,r(e)}),(function(t){n._isPending=!1,o(t)}),(function(t){if(!n._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");n._cancelHandlers.push(t)}))}))];r&&o.push(new Promise((function(t,e){setTimeout((function(){if(n._isPending)try{n.cancel()}finally{e(new E)}}),r)}))),this._promise=Promise.race(o)}return t.createControl=function(t){return new I(t)},t.resolve=function(e){return new t((function(t){return t(e)}))},t.reject=function(e){return new t((function(t,r){return r(e)}))},t.all=function(e){var r=this;return new t((function(t,r){Promise.all(e).then(t).catch(r)})).catch((function(t){if(t instanceof r.CancelError)for(var n=0,o=e;n<o.length;n++){var i=o[n];"cancel"in i&&i.cancel()}throw t}))},t.prototype.attach=function(t){this._isCanceled?t.cancel():this._children.push(t)},t.prototype.then=function(e,r){var n=this,o=new t((function(t,o){if(n._promise){var i=function(e){r?P(t,o,r,e):o(e)};n._promise.then((function(r){n._isCanceled?i(r):e?P(t,o,e,r):t(r)}),i)}}));return o._parentPromise=this,this._children.push(o),o},t.prototype.catch=function(t){return this._isCanceled&&t&&t(new C),this.then(void 0,t)},t.prototype.finally=function(t){return this._promise?this._promise.finally(t):Promise.reject(this._isCanceled?new C:t)},t.prototype.cancel=function(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;var t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach((function(t){return t.cancel()})),this._isPending){if(this._cancelHandlers.length)try{for(var e=0,r=this._cancelHandlers;e<r.length;e++){(0,r[e])()}}catch(n){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this},t.prototype._getTopParent=function(){for(var t=this._parentPromise,e=!!t;e;)e=!(!t||!t._parentPromise)&&!!(t=t._parentPromise);return t},t.prototype._destroy=function(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0},t.CancelError=C,t.TimeoutError=E,t.PromiseControl=I,t}();Object.setPrototypeOf(M.prototype,Promise.prototype);var x=M;function k(t,e,r){void 0===r&&(r={});var n=function(t,e){for(void 0===e&&(e=[]);null!==t;t=Object.getPrototypeOf(t))for(var r=Object.getOwnPropertyNames(t),n=0;n<r.length;n++)-1==e.indexOf(r[n])&&e.push(r[n]);return e}(t.prototype),o=void 0===r.replace||r.replace;e.forEach((function(e){Object.getOwnPropertyNames(e.prototype).forEach((function(r){var i=-1!==n.indexOf(r);if(!o&&!i||o){var s=Object.getOwnPropertyDescriptor(e.prototype,r);s&&Object.defineProperty(t.prototype,r,s)}}))}))}function S(t){return null!=t}function N(t){return"string"==typeof t?!!t:S(t)}function B(t,e,r){void 0===r&&(r=!1);var n=t,o=e,i=Array.isArray(o),s=i&&[]||{};return i&&Array.isArray(o)?r?(s=s.concat(n=n||[]),o.forEach((function(t,e){void 0===s[e]?s[e]=t:"object"==typeof t?s[e]=B(n[e],t,r):-1===n.indexOf(t)&&s.push(t)}))):s=o:(n&&"object"==typeof n&&Object.keys(n).forEach((function(t){s[t]=n[t]})),Object.keys(o).forEach((function(t){s[t]="object"==typeof o[t]&&o[t]&&"object"==typeof n[t]&&"object"==typeof o[t]?B(n[t],o[t],r):o[t]}))),s}function T(t){!t.lngLat&&t.latLng&&(t.lngLat=[t.latLng.lng,t.latLng.lat]);return t}function R(t){return{type:"Polygon",coordinates:[j(t)]}}function j(t){var e=[t[0],t[1]];return[e,[t[2],t[1]],[t[2],t[3]],[t[0],t[3]],e]}var F=Math.PI/180,D=180/Math.PI;function z(t,e){e=e>85.06?85.06:e<-85.06?-85.06:e;var r=20037508.34*t/180,n=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return[r,n=20037508.34*n/180]}function V(t,e,r,n){if(t instanceof Array)return e instanceof Array&&e.sort().join("")===t.sort().join("");if(t instanceof Date)return e instanceof Date&&""+t==""+e;if(t instanceof Function){if(!(e instanceof Function))return!1}else if(t instanceof Object)return e instanceof Object&&(t===r?e===n:G(t,e));return t===e}function G(t,e){var r=Object.keys(t).sort(),n=Object.keys(e).sort();if(r.length!==n.length)return!1;if(r.join("")!==n.join(""))return!1;for(var o=0;o<r.length;o++){if(!V(t[r[o]],e[n[o]],t,e))return!1}return!0}function U(t){var e={};return Object.keys(t).forEach((function(r){t[r]instanceof Array||t[r]!==Object(t[r])?void 0!==t[r]&&(e[r]=t[r]):e[r]=U(t[r])})),e}function Z(t){return"[object Object]"===Object.prototype.toString.call(t)}function q(t){return t.replace(/([^:]\/)\/+/g,"$1")}function W(t){return"function"==typeof t}var H={get:function(t,e){return t.properties&&t.properties[e[0]]},match:function(t,e){var r=e[0],n=e.slice(1),o=r;Array.isArray(r)&&(o=J(t,r));for(var i=n.splice(-1,n.length%2)[0],s=0;s<n.length-1;s+=2){if(n[s]===o)return n[s+1]}return i}};function J(t,e){var r=e[0],n=e.slice(1),o=H[r];if(o)return o(t,n)}function $(t){return function(e){return J(e,t)}}var Q=["iconSize","iconAnchor"];function K(t,e,r){if((e=String(e))===(t=String(t)))return!0;if(r&&e.toUpperCase()===t.toUpperCase())return!0;var n,o="^".concat((n=e,n.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")),"$").replace(/%/g,".*").replace("_",".");return null!==new RegExp(o,r?"i":"").exec(t)}var X={gt:function(t,e){return t>e},lt:function(t,e){return t<e},ge:function(t,e){return t>=e},le:function(t,e){return t<=e},eq:function(t,e){return t===e},ne:function(t,e){return t!==e},in:function(t,e){return-1!==e.indexOf(t)},notin:function(t,e){return-1===e.indexOf(t)},like:function(t,e){return K(t,e)},ilike:function(t,e){return K(t,e,!0)}};function Y(t){return 3===t.length&&"string"==typeof t[0]&&"string"==typeof t[1]}function tt(t,e){var r="string"==typeof e[0]?e[0]:"all",n=function(e){if(Y(e)){var r=e[0],n=e[1],o=e[2],i=X[n];if(i){if(("like"===n||"ilike"===n)&&"string"==typeof r){var s="",a=r.replace(/^%?(\w+)%?$/,(function(e,n){return s=t[n],r.replace(n,o)}));return i(s,a)}return i(t[r],o)}return!1}return tt(t,e)},o=e.filter((function(t){return Array.isArray(t)}));return"any"===r?o.some(n):o.every(n)}function et(t){var e={},n=[];return t.forEach((function(t){t&&(Array.isArray(t)?n.push(t):e=t)})),function(t){var o=n.find((function(e){return function(t,e){var n=r({},t.properties);return!!n&&(n.$id=t.id,tt(n,e))}(t,e[0])}));return o?r(r({},e),o[1]):e}}function rt(t,e,n){if(!t)throw new Error("paint is empty");var o=r({},e);if(W(t)){var i=function(r){var o=rt(t(r),e,n);return o.type=t.type,o};return i.type=t.type,i}if(function(t){return!!Array.isArray(t)}(t))return function(r){return rt(et(t)(r),e,n)};if("get-paint"===t.type){var s=function(t,e){if("function"==typeof t.from)return t.from(t.options);if("string"==typeof t.from&&e){var r=e[t.from];if(r)return r(t.options)}}(t,n);s&&(o=rt(s,e,n))}else{if("icon"===t.type)return t;var a=function(t){var e=!1,n={};for(var o in t)if(-1===Q.indexOf(o)){var i=o,s=t[i];Array.isArray(s)&&(e=!0,n[i]=$(s))}if(e)return function(e){var o={};for(var i in n)o[i]=n[i](e);return r(r({},t),o)}}(t);if(a)return function(t){return rt(a(t),e,n)};(o=r(r({},o),t)).fill=void 0===o.fill||o.fill,o.stroke=void 0!==o.stroke?o.stroke:!o.fill||!(!o.strokeColor&&!o.strokeOpacity)}return W(o)||("color"in o&&(o.strokeColor||(o.strokeColor=o.color),o.fillColor||(o.fillColor=o.color)),"opacity"in o&&(void 0===o.strokeOpacity&&(o.strokeOpacity=o.opacity),void 0===o.fillOpacity&&(o.fillOpacity=o.opacity))),o}function nt(t){for(var e,r={},n=0;n<t.length;n++)r[t[n]]=1+(r[t[n]]||0);for(var o in r){r[o]>((void 0!==e?r[e]:0)||0)&&(e=o)}return e}function ot(t){var e;if("FeatureCollection"===t.type)e=nt(t.features.map((function(t){return t.geometry.type})));else if("GeometryCollection"===t.type){e=nt(t.geometries.map((function(t){return t.type})))}else e="Feature"===t.type?t.geometry.type:t.type;return e}var it={polygon:"path",line:"path",point:"circle"},st={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon"};function at(t){if(t.data){var e=st[ot(t.data)],r=t.paint;r&&"[object Object]"===Object.prototype.toString.call(r)&&(r.type=r.type?r.type:"polygon"===e||"line"===e?"path":"html"in r||"className"in r?"icon":it[e]),t.type=t.type||e}return t}var ut=function(){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},ct=function(){function t(){this.keyCodeAlias=new ut,this.keys={},this._windowOnFocus=this.windowOnFocus.bind(this),this._keysPressed=this.keysPressed.bind(this),this._keysReleased=this.keysReleased.bind(this),this.addKeyboardEventsListener()}return t.prototype.pressed=function(t){var e=this.keyCodeAlias[t];return!!e&&this.keys[e]},t.prototype.addKeyboardEventsListener=function(){"undefined"!=typeof window&&(window.addEventListener("focus",this._windowOnFocus,!1),window.addEventListener("keydown",this._keysPressed,!1),window.addEventListener("keyup",this._keysReleased,!1))},t.prototype.removeKeyboardEventsListener=function(){"undefined"!=typeof window&&(window.removeEventListener("focus",this._windowOnFocus,!1),window.removeEventListener("keydown",this._keysPressed,!1),window.removeEventListener("keyup",this._keysReleased,!1))},t.prototype.keysPressed=function(t){t.stopPropagation(),this.keys[t.keyCode]||(this.keys[t.keyCode]=!0)},t.prototype.keysReleased=function(t){t.stopPropagation(),this.keys[t.keyCode]=!1},t.prototype.windowOnFocus=function(){this.keys={}},t}(),pt=function(){function t(t,e){this.webMap=t,e&&(e.value&&this.setValue(e.value),e.name&&(this.name=e.name),e.event&&(this.event=e.event))}return t.prototype.getValue=function(){return this.value},t.prototype.setValue=function(t){this.value=t},t}(),lt=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="center",e.event="moveend",e}return e(r,t),r.prototype.getValue=function(){return this.webMap.getCenter()},r.prototype.setValue=function(t){this.webMap.setCenter(t)},r.prototype.toString=function(t){var e=t.map((function(t){return t.toFixed(5)}));return e[0]+"_"+e[1]},r.prototype.parse=function(t){return t.split("_").map(Number)},r}(pt),ht=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="zoom",e.event="zoomend",e}return e(r,t),r.prototype.getValue=function(){var t=this.webMap.getZoom();return void 0!==t?Math.round(t):void 0},r.prototype.setValue=function(t){this.webMap.setZoom(t)},r.prototype.toString=function(t){return String(t)},r.prototype.parse=function(t){return Number(t)},r}(pt);var ft=0,dt={minZoom:0,maxZoom:20,paint:{color:"#0000ff",opacity:.4,strokeOpacity:1,stroke:!0,radius:8,weight:1},selectedPaint:{color:"#00008b",opacity:.4,strokeOpacity:1,stroke:!0,radius:12,weight:1},create:!0},yt=function(){function t(e){this.options=dt,this.emitter=new c.exports.EventEmitter,this.keys=t.keys,this.runtimeParams=[],this.getPaintFunctions=t.getPaintFunctions,this.mapState=[lt,ht],this.id=ft++,this._initMapState={},this._mapState=[],this._eventsStatus={},this._mapEvents={},this.mapAdapter=e.mapAdapter,this._starterKits=e.starterKits||[],e&&(this.options=B(dt||{},e)),this.options.runtimeParams&&(this.runtimeParams=this.options.runtimeParams),this._addEventsListeners(),this.options.tileJson&&this._setTileJsonOptions(this.options.tileJson),this.options.create&&this.create()}return t.prototype.getId=function(){return this.id},t.prototype.create=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return this.getEventStatus("create")?[3,3]:[4,this._setInitMapState(this.mapState)];case 1:return t.sent(),[4,this._setupMap()];case 2:t.sent(),this._emitStatusEvent("create",this),t.label=3;case 3:return[2,this]}}))}))},t.prototype.setRuntimeParams=function(t){this.runtimeParams.push(t)},t.prototype.destroy=function(){this._removeEventListeners(),function(t){for(var e in t)delete t[e]}(this._emitStatusEvent),this.mapAdapter.destroy&&this.mapAdapter.destroy()},t.prototype.getState=function(){var t={};return this._mapState.forEach((function(e){t[e.name]=e.getValue()})),t},t.prototype.getRuntimeParams=function(){var t=this,e={};return this._mapState.forEach((function(r){for(var n=0,o=t.runtimeParams;n<o.length;n++){var i=o[n].get(r.name);if(void 0!==i){e[r.name]=r.parse(i);break}}})),e},t.prototype.getContainer=function(){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){var t=document.getElementById(this.options.target);if(t)return t}}},t.prototype.setCursor=function(t){this.mapAdapter.setCursor&&this.mapAdapter.setCursor(t)},t.prototype.getCursor=function(){if(this.mapAdapter.getCursor)return this.mapAdapter.getCursor();var t=this.getContainer();return t?t.style.cursor:void 0},t.prototype.setCenter=function(t){return this.mapAdapter.setCenter(t),this},t.prototype.getCenter=function(){return this.mapAdapter.getCenter()},t.prototype.getBounds=function(){if(this.mapAdapter.getBounds)return this.mapAdapter.getBounds()},t.prototype.getBoundsPolygon=function(){var t=this.getBounds();if(t)return{type:"Feature",properties:{},geometry:R(t)}},t.prototype.setZoom=function(t){return this.mapAdapter.setZoom(t),this},t.prototype.getZoom=function(){var t=this.mapAdapter.getZoom();if("number"==typeof t)return t},t.prototype.zoomIn=function(){if(this.mapAdapter.zoomIn)this.mapAdapter.zoomIn();else{var t=this.getZoom();if(void 0!==t)this.setZoom(t+1)}},t.prototype.zoomOut=function(){if(this.mapAdapter.zoomOut)this.mapAdapter.zoomOut();else{var t=this.getZoom();if(void 0!==t)this.setZoom(t-1)}},t.prototype.setView=function(t,e){if(Array.isArray(t)){var r=t;this.mapAdapter.setView&&r&&S(e)?this.mapAdapter.setView(r,e):(r&&this.mapAdapter.setCenter(r),S(e)&&this.mapAdapter.setZoom(e))}else{this.mapAdapter.setView&&this.mapAdapter.setView(t)}},t.prototype.fitBounds=function(t,e){return t.every((function(t){return S(t)}))&&(t[1]<-85.06&&(t[1]=-85.06),t[3]>85.06&&(t[3]=85.06),this.mapAdapter.fitBounds(t,e)),this},t.prototype.getEventStatus=function(t){var e=this._eventsStatus[t];return null!=e&&e},t.prototype.onLoad=function(t){var e=this;return void 0===t&&(t="create"),new Promise((function(r){e.getEventStatus(t)?r(e):e.emitter.once(t,(function(){r(e)}))}))},t.prototype.onMapLoad=function(t){var e=this;return new Promise((function(r){var n,o=function(){var n=e.mapAdapter;t&&t(n),n&&r(n)},i=null===(n=e.mapAdapter.isLoaded)||void 0===n||n;e.mapAdapter.map&&i?o():e.mapAdapter.emitter.once("create",(function(){o()}))}))},t.prototype.getLayerAdapters=function(){return this.mapAdapter.layerAdapters},t.prototype.getLayerAdapter=function(t){return this.mapAdapter.layerAdapters[t]},t.prototype.locate=function(t,e){if(this.mapAdapter&&this.mapAdapter.locate)return this.mapAdapter.locate(t,e);return{stop:function(){return{}}}},t.prototype.stopGetCoordFromMapClick=function(){this._coordFromMapClickPromise&&this._coordFromMapClickPromise.cancel()},t.prototype.getCoordFromMapClick=function(){var t=this;return this._coordFromMapClickPromise?this.getCoordFromMapClick():(this._coordFromMapClickPromise=new x((function(e,r,n){var o=t.getCursor()||"grab";t._removeEventListeners({include:["click"]}),t.setCursor("crosshair");var i=function(){t.setCursor(o),t._addEventsListeners({include:["click"]}),t.mapAdapter.emitter.off("click",s),t._coordFromMapClickPromise=void 0},s=function(t){i(),T(t),e(t.lngLat)};t.mapAdapter.emitter.once("click",s),n(i)})),this._coordFromMapClickPromise)},t.prototype._emitStatusEvent=function(t,e){var r=t;this._eventsStatus[r]=!0,this.emitter.emit(r,e)},t.prototype._addLayerProviders=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){return[2]}))}))},t.prototype._onLoadSync=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){return[2]}))}))},t.prototype._setupMap=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:if(!this.mapAdapter)throw new Error("WebMap `mapAdapter` option is not set");return[4,this.mapAdapter.create(this.options)];case 1:return t.sent(),this._zoomToInitialExtent(),[4,this._addLayerProviders()];case 2:return t.sent(),[4,this._onLoadSync()];case 3:return t.sent(),this._emitStatusEvent("build-map",this.mapAdapter),[2,this]}}))}))},t.prototype._setTileJsonOptions=function(t){t.center&&(this.options.center=t.center),t.bounds&&(this.options.bounds=t.bounds),S(t.maxzoom)&&(this.options.maxZoom=t.maxzoom,this.options.zoom=t.maxzoom),S(t.minzoom)&&(this.options.minZoom=t.minzoom,this.options.zoom=t.minzoom),S(t.maxzoom)&&S(t.minzoom)&&(this.options.zoom=(t.maxzoom+t.minzoom)/2)},t.prototype._zoomToInitialExtent=function(){var t=this.options,e=t.center,r=t.zoom,n=t.bounds;this._extent?this.fitBounds(this._extent):e&&r?this.setView(e,r):n&&this.fitBounds(n)},t.prototype._setInitMapState=function(t){for(var e=0,r=t;e<r.length;e++){var n=new(0,r[e])(this);this._mapState.push(n);for(var o=0,i=this.runtimeParams;o<i.length;o++){var s=i[o].get(n.name);if(void 0!==s){var a=n.parse(s);this._initMapState[n.name]=a,Object.defineProperty(this.options,n.name,{value:a,configurable:!0,enumerable:!0});break}}}},t.prototype._addEventsListeners=function(t){var e=this,r=["preclick","click","zoomstart","zoom","zoomend","movestart","move","moveend"];t&&t.include&&(r=r.filter((function(e){return t.include.includes(e)}))),r.forEach((function(t){e._mapEvents[t]=function(r){if(e.runtimeParams.length){var n=e._mapState.find((function(e){return e.event===t}));if(n){var o=n.toString(n.getValue());e.runtimeParams.forEach((function(t){t.set(n.name,o)}))}}e._eventsStatus&&e.emitter.emit(t,r)};var r=e._mapEvents[t];r&&e.mapAdapter.emitter.on(t,r)}))},t.prototype._removeEventListeners=function(t){var e=this,r=Object.entries(this._mapEvents);t&&t.include&&(r=r.filter((function(e){return t.include.includes(e[0])}))),r.forEach((function(t){var r=t[1];r&&e.mapAdapter.emitter.removeListener(t[0],r)}))},t.keys=new ct,t}(),vt=function(t){function i(e){var r=t.call(this,e)||this;r._layersIdCounter=1,r._layersOrderCounter=1,r._baselayers=[],r._layers={},r._selectedLayers=[];var n=r.options.tileJson;return n&&r.emitter.once("build-map",(function(){return r.addTileJsonLayer(n)})),r}return e(i,t),i.prototype.fitLayer=function(t,e){return n(this,void 0,void 0,(function(){var r,n,i;return o(this,(function(o){switch(o.label){case 0:return r=this.getLayer(t),(n=r&&(r.getBounds||r.getExtent))?[4,n.call(r)]:[3,2];case 1:(i=o.sent())&&this.fitBounds(i,e),o.label=2;case 2:return[2]}}))}))},i.prototype.isBaseLayer=function(t){var e=this.getLayer(t);if(e&&e.id)return-1!==this._baselayers.indexOf(e.id)},i.prototype.getBaseLayers=function(){var t=this,e=[];return this._baselayers.forEach((function(r){var n=t._layers[r];n&&e.push(n)})),e},i.prototype.getBaseLayersIds=function(){return this._baselayers},i.prototype.getLayer=function(t){return"string"==typeof t?this._layers[t]:t},i.prototype.getLayerId=function(t){var e=this.getLayer(t);if(e){if(e.id)return null==e?void 0:e.id;if(e&&e.options)return e.options.id}throw new Error("No id for layer")},i.prototype.getLayers=function(){return Object.keys(this._layers)},i.prototype.allLayers=function(){return this._layers},i.prototype.orderedLayers=function(){return Object.values(this._layers).sort((function(t,e){return t.order&&e.order?t.order-e.order:0}))},i.prototype.findLayer=function(t){for(var e in this._layers){var r=this._layers[e];if(t(r))return r}},i.prototype.isLayerVisible=function(t){var e=this.getLayer(t);return!(!e||void 0===e.options.visibility)&&e.options.visibility},i.prototype.addBaseLayer=function(t,e){return n(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,this.addLayer(t,r(r({},e),{baselayer:!0}),void 0)];case 1:return[2,n.sent()]}}))}))},i.prototype.addLayer=function(t,e,i){var s,a;return void 0===e&&(e={}),n(this,void 0,void 0,(function(){var n,u,c,p,l,h,f,d,y,v,m,g;return o(this,(function(o){switch(o.label){case 0:return n=this._layersIdCounter++,u=S(i)?i:void 0!==e.order?e.order:this.reserveOrder(),"string"!=typeof t?[3,1]:(c=this.getLayerAdapter(t),[3,4]);case 1:return"function"!=typeof t?[3,2]:(c=t,[3,4]);case 2:return"then"in t?[4,t]:[3,4];case 3:c=o.sent(),o.label=4;case 4:return this._updateGeoJsonOptions(p=e),e=r({id:String(n),order:u},e),l=null===(s=e.visibility)||void 0===s||s,e.visibility=!1,e.baselayer&&(e.order=0),this.options.onBeforeAddLayer&&(h=this.options.onBeforeAddLayer({options:e,adapter:c}))&&(h.options&&(e=h.options),h.adapter&&(c=h.adapter)),void 0===c?[3,12]:((f=new c(this.mapAdapter.map,e)).options=r(r({},e),f.options),f.options.baselayer&&(e.baselayer=!0,e.order=0,f.options.order=0),d=void 0,f.options.id&&(d=String(f.options.id),this._layers[d]=f),this._emitLayerEvent("layer:preadd",d||"",f),[4,this.onMapLoad()]);case 5:return o.sent(),f.map=this.mapAdapter.map,[4,f.addLayer(f.options)];case 6:if(y=o.sent(),f.layer=y,f.id=f.options.id||String(n),f.options.id=f.id,e.baselayer&&(f.options.order=0),f.order=null!==(a=f.options.order)&&void 0!==a?a:u,d&&delete this._layers[d],d=String(f.id),this._layers[d])throw Error("layer with id '".concat(d,"' already exist"));return d?(this._layers[d]=f,p.filter&&this.filterLayer(f,p.filter),e.baselayer&&this._baselayers.push(d),l?[4,this.showLayer(d)]:[3,8]):[3,8];case 7:o.sent(),o.label=8;case 8:return void 0!==(v=e.opacity)&&v<=1&&this.setLayerOpacity(f,v),m=y&&(f.getBounds||f.getExtent),e.fit&&m?[4,m.call(f)]:[3,11];case 9:return(g=o.sent())?[4,this.fitBounds(g)]:[3,11];case 10:o.sent(),o.label=11;case 11:return e.onAdded&&e.onAdded(f),this._emitLayerEvent("layer:add",d,f),[2,f];case 12:return[2,Promise.reject("No adapter")]}}))}))},i.prototype.addLayerFromAsyncAdapter=function(t,e,r){return n(this,void 0,void 0,(function(){var n,i;return o(this,(function(o){switch(o.label){case 0:return n=r||void 0!==e.order?e.order:this.reserveOrder(),[4,t()];case 1:return(i=o.sent())?[2,this.addLayer(i,e,n)]:[2,Promise.reject("No adapter")]}}))}))},i.prototype.removeLayers=function(t){for(var e in this._layers){var r=!0;t&&(r=t(e,this._layers[e])),r&&(this.removeLayer(e),delete this._layers[e])}},i.prototype.reserveOrder=function(){return this._layersOrderCounter++},i.prototype.removeOverlays=function(){this.removeLayers((function(t,e){return!(e&&e.options&&e.options.baselayer)}))},i.prototype.removeLayer=function(t){var e=this.getLayer(t),r=e&&this.getLayerId(e);if(e&&r){if(this.emitter.emit("layer:preremove",e),e.beforeRemove&&e.beforeRemove(),e.removeLayer?e.removeLayer():this.mapAdapter.removeLayer(e.layer),e.options&&e.options.baselayer){var n=this._baselayers.indexOf(r);n&&this._baselayers.splice(n,1)}delete this._layers[r],this.emitter.emit("layer:remove",e)}},i.prototype.addGeoJsonLayer=function(t,e){return void 0===t&&(t={}),(t=t||{}).multiselect=void 0!==t.multiselect&&t.multiselect,t.unselectOnSecondClick=void 0===t.unselectOnSecondClick||t.unselectOnSecondClick,e||(t=at(t)),t.paint=t.paint||{},this.addLayer(e||"GEOJSON",t)},i.prototype.addFeatureLayer=function(t){return void 0===t&&(t={}),this.addGeoJsonLayer(t)},i.prototype.addTileLayer=function(t,e){return this.addLayer("TILE",r(r({},e),{url:t}))},i.prototype.addImageLayer=function(t,e){var n;return"string"==typeof t?n=t:(n=t.url,e=t),this.addLayer("IMAGE",r(r({},e),{url:n}))},i.prototype.showLayer=function(t,e){return void 0===e&&(e={}),this.toggleLayer(t,!0,e)},i.prototype.hideLayer=function(t,e){return void 0===e&&(e={}),this.toggleLayer(t,!1,e)},i.prototype.toggleLayer=function(t,e,r){var i=this;void 0===r&&(r={});var s=this.getLayer(t),a=void 0!==e?e:!(s&&s.options.visibility),u=void 0!==r.silent&&r.silent;return s&&s.options.visibility!==a?this.onMapLoad().then((function(){return t=s,n(i,void 0,void 0,(function(){var e,r,n,i,s,c,p,l=this;return o(this,(function(o){switch(o.label){case 0:if(e=String(t.id),r=a?"layer:preshow":"layer:prehide",n=a?"layer:show":"layer:hide",u||(this._emitLayerEvent(r,e,t),this._emitLayerEvent("layer:pretoggle",e,t)),!a||!this.mapAdapter)return[3,9];if(i=t.options.baselayer?0:t.options.order,!t.options.baselayer||!this._baselayers.length)return[3,4];s=this._baselayers.filter((function(e){return e!==t.id&&l.isLayerVisible(e)})),c=0,p=s,o.label=1;case 1:return c<p.length?[4,this.hideLayer(p[c])]:[3,4];case 2:o.sent(),o.label=3;case 3:return c++,[3,1];case 4:return t.showLayer?[4,t.showLayer.call(t,t.layer)]:[3,6];case 5:return o.sent(),[3,8];case 6:return void 0===t.layer?[3,8]:[4,this.mapAdapter.showLayer(t.layer)];case 7:o.sent(),o.label=8;case 8:return void 0!==i&&this.mapAdapter.setLayerOrder(t.layer,i,this._layers),[3,13];case 9:return t.hideLayer?[4,t.hideLayer.call(t,t.layer)]:[3,11];case 10:return o.sent(),[3,13];case 11:return void 0===t.layer?[3,13]:[4,this.mapAdapter.hideLayer(t.layer)];case 12:o.sent(),o.label=13;case 13:return t.options.visibility=a,u||(this._emitLayerEvent(n,e,t),this._emitLayerEvent("layer:toggle",e,t)),[2]}}))}));var t})):Promise.resolve()},i.prototype.updateLayer=function(t){var e=this,r=this.getLayer(t);if(r){if(r.updateLayer)return Promise.resolve(r.updateLayer());if(this.isLayerVisible(r))return this.hideLayer(r,{silent:!0}).then((function(){return e.showLayer(r,{silent:!0})}))}return Promise.resolve()},i.prototype.setLayerOpacity=function(t,e){var r=this.getLayer(t);r&&(r.setOpacity?r.setOpacity(e):this.mapAdapter.setLayerOpacity&&this.mapAdapter.setLayerOpacity(r.layer,e))},i.prototype.selectLayer=function(t,e){var r=this.getLayer(t);if(r){r&&r.select&&r.select(e);var n=this.getLayerId(r);n&&this._selectedLayers.push(n)}},i.prototype.unSelectLayer=function(t,e){var r=this.getLayer(t);if(r){var n=r&&r;n.unselect&&n.unselect(e);var o=this.getLayerId(r);if(o){var i=this._selectedLayers.indexOf(o);-1!==i&&this._selectedLayers.splice(i,1)}}},i.prototype.unSelectLayers=function(){for(var t,e=0,r=Object.values(this.allLayers());e<r.length;e++)(t=r[e]).unselect&&t.unselect()},i.prototype.filterLayer=function(t,e){var r=this.getLayer(t);return r.filter?r.filter(e):[]},i.prototype.propertiesFilter=function(t,e,r){var n=this.getLayer(t);if(n){var o=n;o.propertiesFilter?o.propertiesFilter(e,r):o.filter&&this.filterLayer(o,(function(t){return!t.feature||!t.feature.properties||tt(t.feature.properties,e)}))}},i.prototype.removeLayerFilter=function(t){var e=this.getLayer(t);e.removeFilter?e.removeFilter():e.filter&&e.filter((function(){return!0}))},i.prototype.setLayerData=function(t,e){var r=this.getLayer(t);if(r){if(r.setData)return r.setData(e);if(r.clearLayer&&r.addData)return r.clearLayer(),r.addData(e)}return Promise.resolve()},i.prototype.addLayerData=function(t,e){var r=this.getLayer(t);r.addData&&r.addData(e)},i.prototype.clearLayerData=function(t,e){var r=this.getLayer(t);r&&r.clearLayer&&r.clearLayer(e)},i.prototype.setLayerPaint=function(t,e){var r=this.getLayer(t);e&&r&&r.setPaint&&r.setPaint(e)},i.prototype.setLayerSelectedPaint=function(t,e){var r=this.getLayer(t);e&&r&&r.setSelectedPaint&&r.setSelectedPaint(e)},i.prototype.updateLayerPaint=function(t,e){var r=this.getLayer(t);e&&r&&r.updatePaint&&r.updatePaint(e)},i.prototype.updateLayerSelectedPaint=function(t,e){var r=this.getLayer(t);e&&r&&r.updateSelectedPaint&&r.updateSelectedPaint(e)},i.prototype.getAttributions=function(t){var e=[];for(var r in this._layers){var n=this._layers[r],o=!(void 0===t.onlyVisible||t.onlyVisible)||n.options.visibility;if(o&&t.onlyBaselayer&&(o=this._baselayers.includes(r)),o){var i=n.options&&n.options.attribution;i&&e.push(i)}}return e},i.prototype.getActiveBaseLayer=function(){var t=this,e=this.getBaseLayers().find((function(e){return t.isLayerVisible(e)}));if(e)return this.getLayer(e)},i.prototype.addTileJsonLayer=function(t){return this.addLayer("TILE",{url:t.tiles[0],maxZoom:t.maxzoom,minZoom:t.minzoom,subdomains:t.scheme,attribution:t.attribution})},i.prototype._emitLayerEvent=function(t,e,r){var n=String(t);if(S(e)&&n.startsWith("layer:")){var o=n.replace("layer:","layer-"+e+":");this.emitter.emit(o,r)}this.emitter.emit(t,r)},i.prototype._onLayerClick=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){return this._emitLayerEvent("layer:click",t.layer.id||"",t),[2,Promise.resolve(t)]}))}))},i.prototype._onLayerSelect=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){return this._emitLayerEvent("layer:select",t.layer.id||"",t),[2,Promise.resolve(t)]}))}))},i.prototype._updateGeoJsonOptions=function(t){var e=this,r=t.onSelect,n=t.onLayerSelect,o=t.onMouseOut,i=t.onMouseOver,s=t.onClick||t.onLayerClick;t.onClick=function(t){return s&&s(t),e._onLayerClick(t)},t.onMouseOut=function(t){var r=t.layer.id;o&&o(t),S(r)&&e._emitLayerEvent("layer:mouseout",r,t)},t.onMouseOver=function(t){var r=t.layer.id;i&&i(t),S(r)&&e._emitLayerEvent("layer:mouseover",r,t)};var a=r||n;t.onSelect=function(t){return a&&a(t),e._onLayerSelect(t)},t.nativePaint||(this.options.paint&&(t.paint=rt(t.paint||{},this.options.paint,this.getPaintFunctions)),t.selectedPaint&&this.options.selectedPaint&&(t.selectedPaint=rt(t.selectedPaint,this.options.selectedPaint,this.getPaintFunctions)))},i}(yt);function mt(t,e){var r=document.createElement("div"),n=!1;e.getStatus?n=e.getStatus():e.status&&(n=e.status);var o=e.title||"",i=e.html;function s(){o&&(r.title="string"==typeof o?o:n?o.on:o.off,r.setAttribute("aria-label",r.title))}function a(t){t instanceof HTMLElement?(r.innerHTML="",r.appendChild(t)):"string"==typeof t&&(r.innerHTML=t)}function u(){i&&("string"==typeof i||i instanceof HTMLElement?a(i):a(n?i.on:i.off),r.setAttribute("aria-label",r.title))}function c(t,e){t.split(" ").forEach((function(t){e?r.classList.add(t):r.classList.remove(t)}))}function p(){e.addClassOn&&c(e.addClassOn,n),e.addClassOff&&c(e.addClassOff,!n)}s(),u(),e.addClass&&c(e.addClass,!0),p();var l=function(t){void 0!==t&&(n=t),u(),s(),p()},h=function(t){if(n=void 0!==t?t:!n,e.onClick){var r=e.onClick(n);Promise.resolve(r).then((function(){return l()})).catch((function(){return n=!n}))}else l()},f=t({html:r,onClick:h});return f.onClick=h,f.changeStatus=l,f}var gt=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e._loadControlQueue={"top-right":[],"bottom-right":[],"top-left":[],"bottom-left":[]},e._isControlLoading={"top-right":!1,"bottom-right":!1,"top-left":!1,"bottom-left":!1},e}return e(r,t),r.prototype.addControl=function(t,e,r){return n(this,void 0,void 0,(function(){var i,s=this;return o(this,(function(a){return e=null!=e?e:"top-left",(i="string"==typeof t?this.getControl(t,r):t)?[2,new Promise((function(t){s._setControlQueue(e,(function(){return n(s,void 0,void 0,(function(){var r,n;return o(this,(function(o){switch(o.label){case 0:return[4,i];case 1:return r=o.sent(),n=this.mapAdapter.addControl(r,e),t(n),[2]}}))}))}))}))]:[2]}))}))},r.prototype.createControl=function(t,e){return n(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,this.onLoad("build-map")];case 1:return r.sent(),this.mapAdapter.createControl?[2,this.mapAdapter.createControl(t,e)]:[2]}}))}))},r.prototype.createButtonControl=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.onLoad("build-map")];case 1:return e.sent(),this.mapAdapter.createButtonControl?[2,this.mapAdapter.createButtonControl(t)]:[2]}}))}))},r.prototype.createToggleControl=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.onLoad("build-map")];case 1:return e.sent(),this.mapAdapter.createToggleControl?[2,this.mapAdapter.createToggleControl(t)]:this.mapAdapter.createButtonControl?[2,mt(this.mapAdapter.createButtonControl,t)]:[2]}}))}))},r.prototype.removeControl=function(t){var e=this;"remove"in t?t.remove():this.mapAdapter.removeControl&&Promise.resolve(t).then((function(t){e.mapAdapter.removeControl(t)}))},r.prototype.getControl=function(t,e){var n=this.mapAdapter.controlAdapters[t];if(n)return new n(e);var o=r.controls[t];return o?o(this,e):void 0},r.prototype.getControlContainer=function(){if(this.mapAdapter.getControlContainer)return this.mapAdapter.getControlContainer()},r.prototype._setControlQueue=function(t,e){this._loadControlQueue[t].push(e),this._isControlLoading[t]||this._applyControls(t)},r.prototype._applyControls=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return this._loadControlQueue[t].length?(this._isControlLoading[t]=!0,[4,(0,this._loadControlQueue[t][0])()]):[3,2];case 1:return e.sent(),this._loadControlQueue[t].splice(0,1),this._applyControls(t),[3,3];case 2:this._isControlLoading[t]=!1,e.label=3;case 3:return[2]}}))}))},r.controls={CONTROL:function(t,e){return t.createControl(e.control,e.options)},BUTTON:function(t,e){return t.createButtonControl(e)},TOGGLE:function(t,e){return t.createToggleControl(e)}},r}(vt),_t={};function bt(t){return _t[t]}var wt=function(t){function r(e){var r=t.call(this,e)||this;return r._addControls(),_t[r.id]=r,r}return e(r,t),r.get=function(t){return bt(t)},r.prototype._addLayerProviders=function(){var t,e,r,i;return n(this,void 0,void 0,(function(){var n,s,u,c,p,l,h,f,d,y;return o(this,(function(o){switch(o.label){case 0:o.trys.push([0,18,19,24]),n=a(this._starterKits),o.label=1;case 1:return[4,n.next()];case 2:return(s=o.sent()).done?[3,17]:(u=s.value).getLayerAdapters?[4,u.getLayerAdapters.call(u)]:[3,16];case 3:if(!(c=o.sent()))return[3,16];o.label=4;case 4:o.trys.push([4,10,11,16]),r=void 0,p=a(c),o.label=5;case 5:return[4,p.next()];case 6:return(l=o.sent()).done?[3,9]:[4,(h=l.value).createAdapter(this)];case 7:(f=o.sent())&&(this.mapAdapter.layerAdapters[h.name]=f),o.label=8;case 8:return[3,5];case 9:return[3,16];case 10:return d=o.sent(),r={error:d},[3,16];case 11:return o.trys.push([11,,14,15]),l&&!l.done&&(i=p.return)?[4,i.call(p)]:[3,13];case 12:o.sent(),o.label=13;case 13:return[3,15];case 14:if(r)throw r.error;return[7];case 15:return[7];case 16:return[3,1];case 17:return[3,24];case 18:return y=o.sent(),t={error:y},[3,24];case 19:return o.trys.push([19,,22,23]),s&&!s.done&&(e=n.return)?[4,e.call(n)]:[3,21];case 20:o.sent(),o.label=21;case 21:return[3,23];case 22:if(t)throw t.error;return[7];case 23:return[7];case 24:return[2]}}))}))},r.prototype._onLoadSync=function(){var t,e;return n(this,void 0,void 0,(function(){var r,n,i,s,u;return o(this,(function(o){switch(o.label){case 0:o.trys.push([0,8,9,14]),r=a(this._starterKits),o.label=1;case 1:return[4,r.next()];case 2:if((n=o.sent()).done)return[3,7];if(!(i=n.value).onLoadSync)return[3,6];o.label=3;case 3:return o.trys.push([3,5,,6]),[4,i.onLoadSync.call(i,this)];case 4:return o.sent(),[3,6];case 5:return s=o.sent(),console.error(s),[3,6];case 6:return[3,1];case 7:return[3,14];case 8:return u=o.sent(),t={error:u},[3,14];case 9:return o.trys.push([9,,12,13]),n&&!n.done&&(e=r.return)?[4,e.call(r)]:[3,11];case 10:o.sent(),o.label=11;case 11:return[3,13];case 12:if(t)throw t.error;return[7];case 13:return[7];case 14:return[2]}}))}))},r.prototype._addControls=function(){var t=this;this.options.controls&&this.options.controls.forEach((function(e){var r=e,n={};"string"==typeof e&&t.options.controlsOptions&&t.options.controlsOptions[e]&&void 0!==(n=t.options.controlsOptions[e]).control&&(r=n.control);var o=n.position,i=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}(n,["position"]);t.addControl(r,o||"top-left",i)})),this._emitStatusEvent("controls:create")},r}(gt);function Lt(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new wt(t).onLoad()]}))}))}var Ot,Ct=function(){function t(e){var r;void 0===e&&(e={}),this.cache=[];var n=null!==(r=e.namespace)&&void 0!==r?r:"default";return t.instance[n]?t.instance[n]:(t.instance[n]=this,this)}return t.prototype.clean=function(){this.cache.length=0},t.prototype.all=function(){return this.cache},t.prototype.addFull=function(t,e,r){return this.add(t,e,r,!0)},t.prototype.add=function(t,e,r,n){var o=this,i=this._find(t,r);if(i)return i.value;var s=void 0;s=e instanceof Function?e():e;var a=r&&JSON.parse(JSON.stringify(U(r))),u={key:t,value:s,props:a,options:a};return n&&!N(s)?s:(this.cache.push(u),s instanceof Promise?(s.catch((function(e){throw o.delete(t,r),e})),n&&s.then((function(e){return N(e)||o.delete(t,r),e})),s):s)},t.prototype.match=function(t,e){var r=this._find(t,e);if(r)return r.value},t.prototype.matchAll=function(t,e){var r=this;return t?this.cache.filter((function(n){return r._filter(n,t,e)})).map((function(t){return t.value})):this.cache.map((function(t){return t.value}))},t.prototype.delete=function(t,e){var r=this,n=[];"string"==typeof t?n=this.cache.filter((function(n){return r._filter(n,t,e)})):n.push(t);for(var o=0,i=n;o<i.length;o++){var s=this.cache.indexOf(i[o]);this.cache.splice(s,1)}},t.prototype._find=function(t,e){var r=this;return this.cache.find((function(n){return r._filter(n,t,e)}))},t.prototype._filter=function(t,e,r){return t.key===e&&(!r||G(t.props||t.options||{},U(r)))},t.instance={},t}(),It=function(t){function r(e){var n=t.call(this)||this;return n.name="NgwError",Object.assign(n,e),Object.setPrototypeOf(n,r.prototype),n}return e(r,t),r}(Error),Et=function(t){function r(e){var n=t.call(this)||this;return n.name="NetworkError",Object.setPrototypeOf(n,r.prototype),n.message="Unable to request ".concat(e,".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin),n}return e(r,t),r}(Error);function Pt(t){return"[object Object]"===Object.prototype.toString.call(t)}Ot=function(t,e,r,n,o){void 0===r&&(r={}),r.method=r.method||"GET";var i=new XMLHttpRequest;i.open(r.method||"GET",t,!0),"blob"===r.responseType&&(i.responseType=r.responseType);var s=function(){try{return JSON.parse(i.responseText)}catch(t){return i.responseText}};i.onload=function(){-1!==[401,403,404,422,500].indexOf(i.status)&&n(new It(s())),function(t){void 0===t&&(t=!1);var o=t?n:e;"blob"===r.responseType?o(i.response):i.responseText?o(s()):n({message:""})}()},i.onerror=function(e){n(0===i.status?new Et(t):e)},i.upload.onprogress=function(t){t.lengthComputable&&(r.onProgress&&r.onProgress(t.loaded/t.total*100,t))};var a,u=r.headers;if(u)for(var c in u){var p=u[c];"string"==typeof p&&i.setRequestHeader(c,p)}if(void 0!==r.withCredentials&&(i.withCredentials=r.withCredentials),r.file){if((a=new FormData).append("file",r.file),r.data)for(var l in r.data)a.append(l,a[l])}else a=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;o&&o((function(){i.abort()})),i.send(a)};var At=/\{ *([\w_-]+) *\}/g;function Mt(t,e){return t.replace(At,(function(t,r){var n=e[r];if(void 0===n)throw new Error("No value provided for letiable "+t);return"function"==typeof n&&(n=n(e)),n}))}var xt=function(t){function r(e){var n=t.call(this,e)||this;return n.name="ResourceNotFoundError",n.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(n,r.prototype),n}return e(r,t),r}(It),kt=function(t){function r(e){var n=t.call(this,e)||this;return n.name="InsufficientPermissionsError",n.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(n,r.prototype),n}return e(r,t),r}(It),St=[];function Nt(t){St.push(t)}var Bt=["description"];function Tt(t,e){void 0===e&&(e=""),e=e?e+"__":"";for(var r={},n=0,o=Object.entries(t);n<o.length;n++){var i=o[n],s=i[0],a=i[1];if(-1===Bt.indexOf(s))if(Pt(a))if("owner_user"===s){var u=Tt(a,s);Object.assign(r,u)}else"parent"===s&&"id"in a&&(r.parent_id=a.id);else S(a)&&(r[e+s]=a)}return r}var Rt=function(){function t(t){this.connector=t,this.cache=new Ct}return t.prototype.getOne=function(t,e){var n=this,o=new Ct,i={},s=r(r({},e),{cache:!1});"string"==typeof t?i.keyname=t:"number"==typeof t?i.id=t:Pt(t)&&(i.id=t.id);return o.addFull("resource",(function(){return"string"==typeof t?n._fetchResourceBy({keyname:t},s):"number"==typeof t?n._fetchResourceById(t,s):Pt(t)?n._fetchResourceBy(t,s):x.resolve(void 0)}),i)},t.prototype.getOneOrFail=function(t,e){return this.getOne(t,e).then((function(t){if(t)return t;throw new xt}))},t.prototype.getId=function(t,e){return"number"==typeof t?x.resolve(t):"string"==typeof t||Pt(t)?this.getOne(t,e).then((function(t){if(t)return t.resource.id})):x.resolve(void 0)},t.prototype.getIdOrFail=function(t,e){return this.getId(t,e).then((function(t){if(void 0===t)throw new Error;return t}))},t.prototype.getMany=function(t,e){var n=this;return this._resourceCacheFilter(t).then((function(o){if(!o.length){var i={};return t.keyname?i.keyname=t.keyname:Object.assign(i,Tt(t)),n.connector.get("resource.search",e,r({serialization:"full"},i)).then((function(t){if(t)for(var e=0,r=t;e<r.length;e++){var o=r[e];n.cache.add("resource.item",x.resolve(o),{id:o.resource.id})}return t}))}return o}))},t.prototype.getParent=function(t,e){var r=this;return this.getOne(t,e).then((function(t){return t?r.getOne(t.resource.parent.id,e):x.resolve(void 0)}))},t.prototype.getChildrenOf=function(t,e){var n=this;return this.getId(t).then((function(t){return n.connector.get("resource.collection",r({cache:!0},e),{parent:t}).then((function(t){for(var e=0,r=t;e<r.length;e++){var o=r[e];n.cache.add("resource.item",x.resolve(o),{id:o.resource.id})}return t}))}))},t.prototype.update=function(t,e){var r=this;return this.getId(t).then((function(t){if(void 0!==t)return r.connector.put("resource.item",{data:e},{id:t})}))},t.prototype.delete=function(t){var e=this;return this.getId(t).then((function(t){if(void 0!==t)return e.connector.delete("resource.item",null,{id:t}).then((function(){e._cleanResourceItemCache(t)}))}))},t.prototype._cleanResourceItemCache=function(t){return n(this,void 0,void 0,(function(){var e,r,n,i,s,a,u,c;return o(this,(function(o){switch(o.label){case 0:e=this.cache.all(),r=[],n=0,i=e,o.label=1;case 1:return n<i.length?(a=(s=i[n]).options&&s.options.id,["resource.item","resource"].includes(s.key)&&void 0!==a?"number"!=typeof a?[3,2]:(a===t&&r.push(s),[3,4]):[3,4]):[3,5];case 2:return[4,this.getId(a)];case 3:o.sent()===t&&r.push(s),o.label=4;case 4:return n++,[3,1];case 5:for(u=0,c=r;u<c.length;u++)this.cache.delete(c[u]);return[2]}}))}))},t.prototype._fetchResourceById=function(t,e){var r=this;return this.cache.add("resource.item",(function(){return r.connector.get("resource.item",e,{id:t})}),{id:t}).catch((function(t){if(!(t instanceof xt))throw t}))},t.prototype._fetchResourceBy=function(t,e){return this.getMany(t,e).then((function(t){return t[0]}))},t.prototype._resourceCacheFilter=function(t){return x.all(this.cache.matchAll("resource.item")).then((function(e){return e.filter((function(e){if(e)return t.keyname&&e.resource.keyname?t.keyname===e.resource.keyname:S(t.id)&&S(e.resource.id)?t.id===e.resource.id:G(t,e.resource)})),[]}))},t}();var jt=0,Ft=function(){function t(t){this.options=t,this.id=jt++,this.emitter=new c.exports.EventEmitter,this.routeStr="/api/component/pyramid/route";var e=function(t){return St.find((function(e){if(e.options.baseUrl===t.baseUrl){if(!t.auth)return!0;if(e.options.auth)return G(e.options.auth,t.auth)}}))}(t);if(e)return e;this.options.route&&(this.routeStr=this.options.route),this.resources=new Rt(this),Nt(this)}return t.create=function(t){return new this(t)},t.prototype.setNgw=function(t){this.logout(),this.options.baseUrl=t,Nt(this)},t.prototype.connect=function(){var t=this,e=new Ct,r=this.options.auth;return e.add("route",(function(){return new x((function(e,n){var o=function(){return t.makeQuery(t.routeStr,{},{}).then((function(t){e(t)})).catch((function(t){n(t)}))};if(r){var i=r.login,s=r.password;if(i&&s)return t.getUserInfo({login:i,password:s}).then((function(){o()})).catch((function(t){return n(t)}))}return o()}))}),{id:this.id,auth:r,baseUrl:this.options.baseUrl})},t.prototype.login=function(t){return this.logout(),Nt(this),this.getUserInfo(t)},t.prototype.logout=function(){var t;-1!==(t=St.indexOf(this))&&St.splice(t,1),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()},t.prototype.getUserInfo=function(t){var e=this;if(this.user&&this.user.id)return x.resolve(this.user);t&&(this.options.auth=t);var r={headers:this.getAuthorizationHeaders(t)};return this.makeQuery("/api/component/auth/current_user",{},r).then((function(t){return e.user=t,e.emitter.emit("login",t),t})).catch((function(t){throw e.emitter.emit("login:error",t),t}))},t.prototype.getAuthorizationHeaders=function(t){var e=this.makeClientId(t);if(e)return{Authorization:"Basic "+e}},t.prototype.makeClientId=function(t){if(t=t||this.options.auth){var e=t.password,r=unescape(encodeURIComponent("".concat(t.login,":").concat(e)));return window.btoa(r)}},t.prototype.apiRequest=function(t,e,n){var o=this;void 0===e&&(e={}),void 0===n&&(n={});var i=n.method,a=n.headers,u=n.withCredentials,c=n.responseType,p=U(e),l=function(){return function(t){var e=t.params;return new x((function(r,n){t.connector.connect().then((function(o){var i=o&&o[t.name];if(i){var a=(i=s([],i,!0)).shift();if(i.length){for(var u={},c=0;c<i.length;c++){var p=i[c];if(u[c]="{"+p+"}",void 0===e[p])throw new Error("`"+p+"` url api argument is not specified")}a&&(a=Mt(a,u))}if(e){var l=[],h=e.paramList;for(var f in Array.isArray(h)&&(delete e.paramList,h.forEach((function(t){l.push("".concat(t[0],"=").concat(t[1]))}))),e)-1===i.indexOf(f)&&l.push("".concat(f,"=").concat(e[f]));l.length&&(a=a+"?"+l.join("&"))}a?r(t.connector.makeQuery(a,e,t.requestOptions)):n(new Error("request url is not set"))}else r(void 0)})).catch((function(t){n(t)}))}))}({name:t,params:p,requestOptions:n,connector:o})};return n.cache&&"GET"===i?(new Ct).add(t,l,r({params:p},U({headers:a,withCredentials:u,responseType:c,baseUrl:this.options.baseUrl,auth:this.options.auth}))):l()},t.prototype.post=function(t,e,r){return(e=e||{}).method="POST",this.apiRequest(t,r,e)},t.prototype.get=function(t,e,r){return(e=e||{}).method="GET",this.apiRequest(t,r,e)},t.prototype.patch=function(t,e,r){return(e=e||{}).method="PATCH",this.apiRequest(t,r,e)},t.prototype.put=function(t,e,r){return(e=e||{}).method="PUT",this.apiRequest(t,r,e)},t.prototype.delete=function(t,e,r){return(e=e||{}).method="DELETE",this.apiRequest(t,r,e)},t.prototype.makeQuery=function(t,e,r){if(void 0===r&&(r={}),t=(this.options.baseUrl?this.options.baseUrl:"")+t)return e&&(t=Mt(t,e)),t=q(t),this._loadData(encodeURI(t),r);throw new Error("Empty `url` not allowed")},t.prototype.getResource=function(t,e){return this.resources.getOne(t,e)},t.prototype.getResourceOrFail=function(t,e){return this.resources.getOneOrFail(t,e)},t.prototype.getResourceBy=function(t){return this.resources.getOne(t)},t.prototype.getResourceByKeyname=function(t){return this.resources.getOne(t)},t.prototype.getResourceById=function(t){return this.resources.getOne(t)},t.prototype.getResourceId=function(t,e){return this.resources.getId(t,e)},t.prototype.getResourceIdOrFail=function(t,e){return this.resources.getIdOrFail(t,e)},t.prototype.getResourcesBy=function(t,e){return this.resources.getMany(t,e)},t.prototype.getResourceParent=function(t,e){return this.resources.getParent(t,e)},t.prototype.getResourceChildren=function(t,e){return this.resources.getChildrenOf(t,e)},t.prototype.updateResource=function(t,e){return this.resources.update(t,e)},t.prototype.deleteResource=function(t){return this.resources.delete(t)},t.prototype._loadData=function(t,e){var n=this;return e.responseType=e.responseType||"json",new x((function(o,i,s){n.user&&((e=e||{}).headers=r(r({},n.getAuthorizationHeaders()),e.headers)),Ot(t,o,e,i,s)})).catch((function(t){if(t instanceof x.CancelError);else{var e=n._handleHttpError(t);if(e)throw e}}))},t.prototype._handleHttpError=function(t){if(t&&t instanceof It){if("nextgisweb.resource.exception.ResourceNotFound"===t.exception)throw new xt(t);if("nextgisweb.core.exception.InsufficientPermissions"===t.exception)throw new kt(t)}return t},t.errors={NgwError:It,ResourceNotFoundError:xt},t}();var Dt=["fields","intersects","limit","orderBy","strategy"];function zt(t){var e={};return Dt.forEach((function(r){var n=t[r];void 0!==n&&(e[r]=n)})),e}function Vt(t){var e=t.extent_bottom,r=t.extent_left,n=t.extent_top,o=t.extent_right;if(e&&r&&n&&o){var i=[r,e,o,n];return i[3]>82&&(i[3]=82),i[1]<-82&&(i[1]=-82),i}}function Gt(t){var e=t.cache;return t.connector.get("layer.extent",{cache:void 0===e||e},{id:t.resourceId}).then((function(t){if(t){var e=t.extent;return[e.minLon,e.minLat,e.maxLon,e.maxLat]}}))}function Ut(t){return t.connector.getResource(t.resourceId).then((function(e){if(e)return Zt(e,t.connector)}))}function Zt(t,e){if(t.webmap)return x.resolve(Vt(t.webmap));var r=t.resource;return r.cls&&-1!==r.cls.indexOf("style")?e.getResource(r.parent.id).then((function(t){if(t)return Gt({resourceId:t.resource.id,connector:e})})):Gt({resourceId:r.id,connector:e})}function qt(t,e){return n(this,void 0,void 0,(function(){var r,n,i,s,a;return o(this,(function(o){switch(o.label){case 0:return n=r=t.resource,i=t.keyname,s=t.resourceId,r?"string"!=typeof r?[3,1]:(i=r,[3,5]):[3,5];case 1:return"number"!=typeof r?[3,2]:(s=r,[3,5]);case 2:return n.resource&&void 0!==n.resource&&"resource"in n?(s=r.resource.id,[3,5]):[3,3];case 3:return[4,qt(r,e)];case 4:s=o.sent(),o.label=5;case 5:return s||!i?[3,7]:[4,e.getResource(i)];case 6:(a=o.sent())&&(s=a.resource.id),o.label=7;case 7:return[2,s]}}))}))}var Wt={srs:4326,geom_format:"geojson"};function Ht(t){return{geometry:t.geom,id:t.id,type:"Feature",properties:t.fields}}function Jt(t,e){var r=e.extensions,n=e.geom,o=e.fields,i=e.srs;t.extensions=r?r.join(","):"",void 0!==o&&(t.fields=Array.isArray(o)?o.join(","):""),void 0!==n&&(t.geom=n?"yes":"no",n||(delete t.srs,delete t.geom_format)),S(i)&&(t.srs=i)}function $t(t){var e=Kt(t);return x.all(e).then((function(e){for(var r=[],n=[],o=0,i=e;o<i.length;o++)for(var s=0,a=i[o];s<a.length;s++){var u=a[s];r.includes(u.id)||(n.push(u),r.push(u.id))}return t.offset||t.limit?n.splice(void 0!==t.offset?t.offset:0,void 0!==t.limit?t.limit:n.length):n}))}function Qt(t){var e=t[0],r=t[1],n=t[2],o="id"!==e?"fld_":"",i="",s="",a=String(e).trim().replace(/^(%?)(.+?)(%?)$/,(function(t,e,r,n){return i=e,s=n,r})),u=i+n+s;return["".concat(o).concat(a,"__").concat(r),u]}function Kt(t,e,n){void 0===e&&(e=[]),void 0===n&&(n=[]);var o=t.filters,i="string"==typeof o[0]?o[0]:"all",a=o.filter((function(t){return Array.isArray(t)}));if("any"===i)for(var u=0,c=a;u<c.length;u++){Y(d=c[u])?e.push(Xt(r(r({},t),{paramList:s(s([],n,!0),[Qt(d)],!1)}))):Kt(r(r({},t),{filters:d}),e,s([],n,!0))}else if("all"===i){for(var p=[],l=[],h=0,f=a;h<f.length;h++){var d;Y(d=f[h])?p.push(Qt(d)):l.push(d)}if(l.length)for(var y=0,v=l;y<v.length;y++){var m=v[y];Kt(r(r({},t),{filters:m}),e,s(s([],n,!0),p,!0))}else e.push(Xt(r(r({},t),{paramList:s(s([],n,!0),p,!0)})))}return e}function Xt(t){var e,n,o=r({},Wt),i=t.limit,s=t.offset,a=t.orderBy,u=t.paramList,c=t.connector,p=t.intersects,l=t.resourceId;if(i?i!==Number.POSITIVE_INFINITY&&(o.limit=i):o.limit=7e3,s&&(o.offset=s),Jt(o,t),a&&(o.order_by=a.join(",")),Array.isArray(p)){var h=(n=p,Array.isArray(n)&&4===n.length&&n.every((function(t){return"number"==typeof t}))?j(p):p);o.intersects=(e=h.map((function(t){var e=z(t[0],t[1]);return e[0]+" "+e[1]})),"POLYGON((".concat(e.join(", "),"))"))}else"string"==typeof p&&(o.intersects=p);u&&(o.paramList=u);var f=r({id:l},o);return c.get("feature_layer.feature.collection",{cache:t.cache},f)}function Yt(t){var e,r=function(){var r=t[e];if(Z(r)){var n=r;if(S(n.year)&&S(n.month)&&S(n.day)){var o=[n.year,n.month-1,n.day];"hour"in n&&[n.hour,n.minute,n.second].forEach((function(t){o.push(t)})),t[e]=(new(Date.bind.apply(Date,s([void 0],o,!1)))).toISOString()}}};for(e in t)r();return t}function te(t){var e=t.filters;return e?$t(r(r({},t),{filters:e})).then((function(n){var o;return(null===(o=t.clientFilterValidate)||void 0===o||o)&&(n=n.filter((function(t){return tt(Yt(r(r({},t.fields),{id:t.id})),e)}))),n})):Xt(t)}function ee(t){return function(t){return te(t).then((function(t){var e=[];return t.forEach((function(t){e.push(Ht(t))})),e}))}(t).then((function(t){return{type:"FeatureCollection",features:t}}))}function re(t){var i,s;return n(this,void 0,void 0,(function(){var a,u,p,l,h,f,d,y,v,m,g,_,b,w,L,O=this;return o(this,(function(C){switch(C.label){case 0:return a=t.item,u=t.webMap,h=null==(l=t.addLayerOptionsPriority)||l,d=t.Adapter||u.mapAdapter.layerAdapters.GEOJSON,y=[],v=!1,[4,qt(f=t.layerOptions,p=t.connector)];case 1:return _=C.sent(),(null===(s=null===(i=f.adapterOptions)||void 0===i?void 0:i.popupOptions)||void 0===s?void 0:s.fromProperties)&&(f.adapterOptions.popupOptions.createPopupContent=function(t){var e=t.feature;return e&&function(t,e){var r=document.createElement("div");if(e&&e.feature_layer)e.feature_layer.fields.forEach((function(e){if(e.grid_visibility){var n=t.properties&&t.properties[e.keyname];if(n){var o=document.createElement("div");r.appendChild(o),o.innerHTML="<span>".concat(e.display_name,"</span>: ").concat(n,"<span></span>")}}}));else if(t.properties)for(var n in t.properties){var o=document.createElement("div");r.appendChild(o),o.innerHTML="<span>".concat(n,"</span>: ").concat(t.properties[n],"<span></span>")}return r}(e,a)}),b=function(t,e){return n(O,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return L(),m={filters:t,options:e},[4,g=ee(r({resourceId:_,filters:t,connector:p,cache:!0},e))];case 1:return[2,n.sent()]}}))}))},w=!1,L=function(){g&&(g.cancel(),g=void 0)},[2,function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.emitter=new c.exports.EventEmitter,e}return e(i,t),i.prototype.addLayer=function(e){return n(this,void 0,void 0,(function(){var n,i,s,u,c;return o(this,(function(o){switch(o.label){case 0:return n=!e.data,i=void 0===e.waitFullLoad||e.waitFullLoad,void 0!==f.id&&(e.id=f.id),a&&a.vector_layer&&(e.type=Te[a.vector_layer.geometry_type]),f.adapterOptions&&(e=h?r(r({},f.adapterOptions),e):r(r({},e),f.adapterOptions)),e.data&&0===Object.keys(e.data).length&&(e.data=void 0,n=!1),this.options.strategy=s=e.strategy||void 0,u=t.prototype.addLayer.call(this,e),m={filters:e.propertiesFilter,options:zt(e)},n&&(c=this.updateLayer()),i&&c?[4,c]:[3,2];case 1:o.sent(),o.label=2;case 2:return s&&s.startsWith("BBOX")&&!v&&this._addBboxEventListener(),[2,u]}}))}))},i.prototype.getExtent=function(){return this.getBounds()},i.prototype.getBounds=function(){return n(this,void 0,void 0,(function(){var e,r;return o(this,(function(n){return e=this.getLayers&&this.getLayers().length,(null==(r=this.options.strategy)?void 0:r.startsWith("BBOX"))||e?[2,Ut({connector:p,resourceId:a.resource.id})]:t.prototype.getBounds?[2,t.prototype.getBounds.call(this)]:[2]}))}))},i.prototype.beforeRemove=function(){w=!0,this._removeMoveEventListener(),this._removeBboxEventListener(),this.__disableMapMoveListener=void 0,this.__enableMapMoveListener=void 0,this.__onMapMove=void 0,this.__onMapMoveStart=void 0,L()},i.prototype.getCount=function(){return function(t){var e=t.cache;return t.connector.get("feature_layer.feature.count",{cache:void 0===e||e},{id:t.resourceId}).then((function(t){return t.total_count}))}({connector:p,resourceId:_,cache:!0})},i.prototype.updateLayer=function(e){var i;return n(this,void 0,void 0,(function(){var n,s,a,c,p,l,h,d,g,_,L;return o(this,(function(o){switch(o.label){case 0:return e=e||m||{},(null===(i=this.options.strategy)||void 0===i?void 0:i.startsWith("BBOX"))?[4,u.onLoad("create")]:[3,2];case 1:if(o.sent(),e.options=e.options||{},e.options.intersects=u.getBounds(),s=(n=this.options).minZoom,a=n.maxZoom,void 0!==(c=u.getZoom())){if(void 0!==s&&c<s)return[2];if(void 0!==a&&c>a)return[2];if(v)return[2]}o.label=2;case 2:if(w)return[2];o.label=3;case 3:return o.trys.push([3,10,,11]),this.emitter.emit("preupdate",e),u._emitLayerEvent("layer:preupdate",f.id||"",e),[4,b(e.filters,r(r({},e.options),{srs:this.options.srs}))];case 4:return p=o.sent(),l=p,[4,this.getCount()];case 5:if(h=o.sent(),"BBOX+"!==this.options.strategy)return[3,7];for(l={type:"FeatureCollection",features:[]},d=0,g=p.features;d<g.length;d++)_=g[d],-1===y.indexOf(String(_.id))&&(y.push(String(_.id)),l.features.push(_));return v=void 0!==h&&y.length>=h,[4,u.addLayerData(this,l)];case 6:return o.sent(),[3,9];case 7:return v=void 0!==h&&p.features.length>=h,[4,u.setLayerData(this,p)];case 8:o.sent(),o.label=9;case 9:return this.emitter.emit("updated",p),u._emitLayerEvent("layer:updated",f.id||"",{data:p,newData:l,isFull:v}),[3,11];case 10:if((L=o.sent())instanceof Error&&"CancelError"!==L.name)throw L;return[3,11];case 11:return t.prototype.updateLayer&&t.prototype.updateLayer.call(this),[2]}}))}))},i.prototype.propertiesFilter=function(t,e){return n(this,void 0,void 0,(function(){var n;return o(this,(function(o){switch(o.label){case 0:return L(),this.filter&&v?(this.filter((function(e){var n=e.feature&&e.feature.properties&&Yt(r({},e.feature.properties));return!n||tt(n,t)})),[3,3]):[3,1];case 1:return this.setData?(this.clearLayer&&this.clearLayer(),[4,b(t,r(r({},e),{srs:this.options.srs}))]):[3,3];case 2:n=o.sent(),this.setData(n),o.label=3;case 3:return[2]}}))}))},i.prototype.removeFilter=function(){m=void 0,this.propertiesFilter([]),this.filter&&this.filter((function(){return!0}))},i.prototype._addBboxEventListener=function(){var t=this;this.__enableMapMoveListener=function(e){e===t&&(t._removeMoveEventListener(),t.updateLayer(),t._addMoveEventListener())},this.__disableMapMoveListener=function(e){e===t&&t._removeMoveEventListener()},u.emitter.on("layer:show",this.__enableMapMoveListener),u.emitter.on("layer:hide",this.__disableMapMoveListener),this.__enableMapMoveListener(this)},i.prototype._removeBboxEventListener=function(){this.__enableMapMoveListener&&u.emitter.on("layer:show",this.__enableMapMoveListener),this.__disableMapMoveListener&&u.emitter.on("layer:hide",this.__disableMapMoveListener)},i.prototype._addMoveEventListener=function(){var t=this;this.__onMapMove=function(t,e){var r;function n(){for(var o=this,i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];n.clear(),r=setTimeout((function(){r=null,t.apply(o,i)}),e)}return void 0===e&&(e=10),n.clear=function(){r&&(clearTimeout(r),r=null)},n}((function(){return t.updateLayer()})),this.__onMapMoveStart=L,u.emitter.on("movestart",this.__onMapMoveStart),u.emitter.on("moveend",this.__onMapMove)},i.prototype._removeMoveEventListener=function(){this.__onMapMove&&u.emitter.removeListener("moveend",this.__onMapMove),this.__onMapMoveStart&&u.emitter.removeListener("movestart",this.__onMapMoveStart)},i}(d)]}}))}))}function ne(t){var e,r=t.options,n=t.webMap,o=t.baseUrl,i=r.adapter||"IMAGE",s=n&&n.getLayerAdapters(),a=r.resource,u=r.tileNoData?r.tileNoData:200;if("number"==typeof a){if("IMAGE"===i){if(!s||s.IMAGE)return function(t){var e=t.resourceId,r=t.nd,n=t.headers,o=t.baseUrl+"/api/component/render/image",i={resource:e};return r&&(i.nd=r),{url:o,resourceId:e,headers:n,params:i,updateWmsParams:function(t){return r&&(t.nd=r),Ne(t,e)}}}({resourceId:a,headers:r.headers,nd:u,baseUrl:o});i="TILE"}if("WMS"===i){e="".concat(o,"/api/resource/").concat(a,"/wms");var c=r.adapterOptions;return{url:e,format:"image/png",version:"1.1.1",layers:c&&c.layers,headers:r.headers}}if("MVT"===i)return{url:e=o+"/api/component/feature_layer/mvt?x={x}&y={y}&z={z}&resource="+a+"&simplification="+(r.simplification||0)};if("TERRAIN"===i)return{url:e=o+"/api/resource/".concat(a,"/terrain_provider"),adapter:i};if("MODEL_3D"===i)return{url:e=o+"/api/component/model_3d/".concat(a,"/data.glb")};if("TILE"===i)return{url:e=o+"/api/component/render/tile?z={z}&x={x}&y={y}&resource="+a+"&nd="+u,adapter:i}}else{if(void 0!==a)throw new Error("Option `resource` must be number, not "+typeof a);console.log("Option `resource` not set")}}function oe(t){var i=t.layerOptions,s=t.webMap,a=t.connector,u=t.item;return n(this,void 0,void 0,(function(){var t,c,p,l,h,f;return o(this,(function(d){switch(d.label){case 0:return t=u.resource.cls,c={wmsserver_service:"WMS",tmsclient_layer:"IMAGE"},void 0!==(p=i.adapter||t&&c[t]||"IMAGE")&&(i.adapter=p),"IMAGE"===p&&(l=s.getLayerAdapters(),!l||l.IMAGE||(p="TILE")),(h=s.mapAdapter.layerAdapters[p])?[4,qt(i,a)]:[3,2];case 1:return f=d.sent(),[2,function(t){function c(e,n){var o,c=t.call(this,e,n)||this;c.map=e,c.item=u,c.resourceId=f;var p=ne({options:i,webMap:s,baseUrl:a.options.baseUrl||""});if(p){var l=r(r({},p),{setViewDelay:null===(o=i.adapterOptions)||void 0===o?void 0:o.setViewDelay,params:{resource:f},layers:String(f),resourceId:f});i.adapterOptions&&S(i.adapterOptions.setViewDelay)&&(l.setViewDelay=i.adapterOptions.setViewDelay),c.options=r(r({},c.options),l)}return c}return e(c,t),c.prototype.addLayer=function(e){return t.prototype.addLayer.call(this,r(r({},this.options),e))},c.prototype.getIdentificationIds=function(){return n(this,void 0,void 0,(function(){var t;return o(this,(function(e){return S(t=this.item&&this.item.resource.parent.id)?[2,[t]]:[2]}))}))},c}(h)];case 2:throw new Error(p+" not supported yet. Only TILE")}}))}))}function ie(t,e,r,n){return!!ue(t,e,r,ce,n)}function se(t,e,r,n){return ue(t,e,r,pe,n)}function ae(t,e){void 0===e&&(e="children");var r=[],n=("function"==typeof e?e:function(t){return t[e]})(t);return n&&(Array.isArray(n)?r=n:r.push(n)),n?r:void 0}function ue(t,e,r,n,o){void 0===e&&(e=function(t){return!!t}),void 0===r&&(r="children");var i="function"==typeof e?e:function(t){return tt(t,e)};return n(t,o?function(t){return i(o(t))}:i,r)}function ce(t,e,r,n){void 0===e&&(e=function(t){return!!t});var o=[];if(Array.isArray(t))o=t;else{if(e(t))return t;var i=ae(t,r);i&&(o=i)}for(var s=0;s<o.length;s++)if(o[s]){var a=ce(o[s],e,r);if(a)return a}}function pe(t,e,r,n){void 0===e&&(e=function(t){return!!t}),void 0===n&&(n=[]);var o=[];if(Array.isArray(t))o=t;else{e(t)&&n.push(t);var i=ae(t,r);i&&(o=i)}for(var s=0;s<o.length;s++)o[s]&&pe(o[s],e,r,n);return n}function le(t,e,r,n){void 0===e&&(e=function(t){return!!t});var o=[];if(Array.isArray(t))o=t;else{if(!e(t))return!1;var i=ae(t,r);i&&(o=i)}for(var s=0;s<o.length;s++){if(o[s])if(!le(o[s],e,r))return!1}return!0}var he=function(){function t(t){this._children=[],this.item=t}return t.prototype.setParent=function(t){this._parent=t},t.prototype.addChild=function(t){this._children.push(t)},t.prototype.getParent=function(){return this._parent},t.prototype.getParents=function(t){var e=this.getParent();return e?se(e,t,(function(t){return t.tree.getParent()})):[]},t.prototype.getRoot=function(){for(var t=this.getParent(),e=t;t;)(t=t.tree.getParent())&&(e=t);return e},t.prototype.find=function(t){return ue(this._children,t,(function(t){return t.tree.getChildren()}),ce,e);var e},t.prototype.every=function(t){return!!ue(this._children,t,(function(t){return t.tree.getChildren()}),le,e);var e},t.prototype.some=function(t){return ie(this._children,t,(function(t){return t.tree.getChildren()}))},t.prototype.all=function(t){return this.getDescendants(t)},t.prototype.getDescendants=function(t){return se(this._children,t,(function(t){return t.tree.getChildren()}))},t.prototype.getChildren=function(){return s([],this._children,!0)},t}(),fe=function(){function t(t,e,r){this.emitter=new c.exports.EventEmitter,this._blocked=!1,this.item=e,this.options=Object.assign({},r),this.name=t,this._value=this.getProperty()}return t.prototype.getProperty=function(){return"function"==typeof this.options.getProperty?this.options.getProperty.call(this,this.item):this.options.value},t.prototype.getParents=function(){return this.item.tree.getParents()||[]},t.prototype.getParent=function(){return this.item.tree.getParent()},t.prototype.getChildren=function(){return this.item.tree.getChildren()},t.prototype.isGroup=function(){return this.item.tree.getDescendants().length},t.prototype.isBlocked=function(){var t=this;if(void 0===this._blocked){var e=this.item.tree.getParents();if(e){var r=e.find((function(e){var r=e.properties&&e.properties.property(t.name);return!!r&&!r.get()}));this._blocked=!!r}else this._blocked=!1}return this._blocked},t.prototype.set=function(t,e){this._value=this._prepareValue(t),this.update(this._value,e),this._fireChangeEvent(this._value,e)},t.prototype.get=function(){return this.getValue()},t.prototype.update=function(t,e){this._callOnSet(t,e)},t.prototype.getContainer=function(){return this._container},t.prototype.destroy=function(){if(this._container){var t=this._container.parentNode;t&&t.removeChild(this._container)}this._removeEventsListener&&this._removeEventsListener()},t.prototype.getValue=function(){return void 0!==this._value?this._value:this.getProperty()},t.prototype._prepareValue=function(t){return t},t.prototype._callOnSet=function(t,e){this.options.onSet&&this.options.onSet.call(this,t,e,this.item)},t.prototype._fireChangeEvent=function(t,e){var r=this;this.emitter&&(t=void 0!==t?t:this.getValue(),this.emitter.emit("change",{value:t,options:e}),this.item.tree.getParents().forEach((function(n){var o=n.properties&&n.properties.property(r.name);o&&o.emitter.emit("change-tree",{value:t,options:e,item:r.item})})))},t}(),de=function(t){function n(e,o,i){var s=t.call(this,e,o,r(r({},n.options),i))||this;return s.set(s.get()),s}return e(n,t),n.prototype.update=function(t,e){if(t){if(e&&e.bubble||this.options.bubble){this.unBlock(e);var r=this.getParent(),n=r&&r.properties&&r.properties.property(this.name);n&&n.set(t,Object.assign({},e,{bubble:!0,propagation:!1}))}this.isBlocked()||this._turnOn(e)}else this._turnOff(e);(e&&e.propagation||this.options.propagation)&&this._propagation(t,e)},n.prototype.getHierarchyValue=function(){var t=this;return this.get()&&this.getParents().every((function(e){var r=e.properties&&e.properties.get(t.name);return r&&r.get()}))},n.prototype.block=function(t){this._blocked=!0,this._block(t)},n.prototype.unBlock=function(t){this._blocked=!1,this.getValue()&&this._unBlock(t)},n.prototype.blockChild=function(t){var e=this;this.item.tree.getDescendants().forEach((function(r){return e._blockChild(r,t)}))},n.prototype.unblockChild=function(t){var e=this;this.item.tree.getChildren().forEach((function(r){return e._unBlockChild(r,t)}))},n.prototype._prepareValue=function(t){return t},n.prototype._turnOff=function(t){this.options.turnOff&&this.options.turnOff.call(this,t),this._callOnSet(!1,t),this.options.hierarchy&&this.isGroup()&&this.blockChild(t)},n.prototype._turnOn=function(t){this.options.turnOn&&this.options.turnOn.call(this,t),this._callOnSet(!0,t),this.options.hierarchy&&this.isGroup()&&this.unblockChild(t)},n.prototype._block=function(t){this._turnOff(t)},n.prototype._unBlock=function(t){this._turnOn(t)},n.prototype._blockChild=function(t,e){var r=t.properties&&t.properties.property(this.name);r&&r.block&&r.block(e)},n.prototype._unBlockChild=function(t,e){var r=t.properties&&t.properties.property(this.name);r&&r.unBlock&&r.unBlock(e)},n.prototype._propagation=function(t,e){if(this.isGroup())for(var n=this.item.tree.getChildren(),o=0;o<n.length;o++){var i=n[o],s=i.properties&&i.properties.property(this.name);s&&s.set(t,r(r({},e),{propagation:!0,bubble:!1}))}},n.options={hierarchy:!0,bubble:!1,propagation:!1,label:"Toggle"},n}(fe),ye=function(){function t(t,e){this.item=t,this.options={},this._properties={},this._propertiesList=[],e&&e.forEach(this._setPropertyHandler.bind(this))}return t.prototype.add=function(t){this._setPropertyHandler(t)},t.prototype._setPropertyHandler=function(e){var n=t.handlers,o=e.handler;if(!o&&e.type)switch(e.type){case"boolean":o=n.CheckProperty;break;case"string":o=n.BaseProperty;break;default:o=n.BaseProperty}if(o&&e.name){var i=r({},e||{});this._properties[e.name]=new o(e.name,this.item,i),this._propertiesList.push(e.name)}},t.prototype.update=function(){this.list().forEach((function(t){t.update()}))},t.prototype.get=function(t){var e=this.property(t);if(e)return e.get()},t.prototype.set=function(t,e,r){var n=this.property(t);if(n)return n.set(e,r)},t.prototype.property=function(t){return this._properties[t]},t.prototype.list=function(){var t=this;return this._propertiesList.map((function(e){return t._properties[e]}))},t.prototype.destroy=function(){for(var t in this._properties){var e=this.property(t);e&&e.destroy&&e.destroy()}this._properties={},this._propertiesList=[]},t.handlers={CheckProperty:de},t}(),ve=0,me=function(){function t(t){this.options={},this.id=ve,ve+=1,this.options=r({},t),this.tree=new he(this)}return t.prototype.initProperties=function(){this.properties=new ye(this,this.options.properties)},t}(),ge=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return e(r,t),r.prototype.getProperty=function(){var t=this.item.layer;return t&&t&&t.options&&void 0!==t.options.opacity?t.options.opacity:1},r.prototype.update=function(t,e){var r=this;if(e=e||{},this.isGroup()){this._value=this._prepareValue(t,e);for(var n=0,o=this.getChildren();n<o.length;n++){var i=o[n].properties.property(this.name);i&&(e.propagation?i.set(t,e):i.update(i.get(),e))}}var s=this.item.layer;if(s){var a=this.getParents().reduce((function(t,e){var n=e.properties.property(r.name);return t*(n?n.getValue():1)}),1);this.item.webMap.setLayerOpacity(s,this._prepareValue(t*a))}},r.prototype._prepareValue=function(t,e){return e&&e.propagation&&this.isGroup()?1:Number(t)},r}(fe),_e=function(t){function i(e,n,o,s,a,u){var p=t.call(this,r(r({},i.options),o))||this;if(p.webMap=e,p.emitter=new c.exports.EventEmitter,p._rootDescendantsCount=0,s&&(p.connector=s),a&&p.tree.setParent(a),p.item=n,"root"===p.item.item_type)p._rootDescendantsCount=p._sumUp(p.item.children);else{var l=p.tree.getRoot();l&&(p._rootDescendantsCount=l._rootDescendantsCount)}return p.initProperties(),u||p._init(n),p}return e(i,t),i.create=function(t,e,r,s,a){return n(this,void 0,void 0,(function(){var n;return o(this,(function(o){switch(o.label){case 0:return[4,(n=new i(t,e,r,s,a,!0))._init(e)];case 1:return o.sent(),[2,n]}}))}))},i.prototype.initItem=function(t){var e=this,r=t,n=this.getItemOptions(t),o=function(t){r._layer=t,e.layer=t,e.properties.get("visibility")&&e.properties.set("visibility",!0),void 0!==n.opacity&&e.webMap.setLayerOpacity(t,n.opacity)};if("group"===t.item_type||"root"===t.item_type)return t.children&&t.children.length&&this.getChildren(t).forEach((function(t){var r=new i(e.webMap,t,e.options,e.connector,e);e.tree.addChild(r)})),Promise.resolve();var s=void 0;if("layer"===t.item_type)s=t.adapter||t.layer_adapter.toUpperCase();else if(i.GetAdapterFromLayerType[t.item_type]){s=(0,i.GetAdapterFromLayerType[t.item_type])(t,n,this.webMap,this.connector)}return s?this.webMap.addLayer(s,n).then((function(t){o(t)})):t._layer?Promise.resolve(o(t._layer)):Promise.reject("No layer added")},i.prototype.bringToFront=function(){},i.prototype.fit=function(){},i.prototype.getLayer=function(){return this.layer},i.prototype.getItemOptions=function(t){var e="layer"===t.item_type&&t.layer_transparency,r="number"==typeof e?(100-e)/100:void 0,n={visibility:!1,headers:this.options.headers,crossOrigin:this.options.crossOrigin,setViewDelay:this.options.setViewDelay,params:{resource:this.item.resourceId}};if(this.options.order){var o=String(this.options.drawOrderEnabled&&"draw_order_position"in t?this._rootDescendantsCount-t.draw_order_position:this.id).padStart(4,"0");n.order=Number((0|this.options.order)+"."+o)}if("layer"===t.item_type){var i=this._getZoomRange(t);!function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];for(var n=0,o=e;n<o.length;n++)for(var i=o[n],s=0,a=Object.getOwnPropertyNames(i);s<a.length;s++){var u=a[s];t[u]=i[u]}}(n,{updateWmsParams:t.updateWmsParams,url:t.url,headers:this.options.headers,ratio:this.options.ratio,maxZoom:i.maxZoom,minZoom:i.minZoom,minScale:t.layer_min_scale_denom,maxScale:t.layer_max_scale_denom})}return void 0!==r&&(n.opacity=r),n},i.prototype.getChildren=function(t){return s([],t.children,!0).reverse()},i.prototype._mapScaleToZoomLevel=function(t){return function(t,e){void 0===e&&(e=0);var r=e;return function(t){return Math.log(t/256)/Math.LN2}(function(){if(void 0===Be){var t=document.createElement("div");t.style.cssText="position: absolute; left: -100%; top: -100%; width: 100cm;",document.body.appendChild(t);var e=t.offsetWidth;document.body.removeChild(t),Be=e}return Be}()*function(t){return 12756274*Math.PI*Math.cos(t*Math.PI/180)}(r)/t)}(t)},i.prototype._getZoomRange=function(t){var e=this.options.minZoom,r=this.options.maxZoom,n=t.layer_min_scale_denom?this._mapScaleToZoomLevel(t.layer_min_scale_denom):void 0,o=t.layer_max_scale_denom?this._mapScaleToZoomLevel(t.layer_max_scale_denom):void 0,i=[e,n].filter(Boolean),s=[r,o].filter(Boolean);return{minZoom:i.length?Math.max.apply(Math,i):void 0,maxZoom:s.length?Math.min.apply(Math,s):void 0}},i.prototype._init=function(t){var e=this;this.initItem(t).then((function(){e.emitter.emit("init")}))},i.prototype._sumUp=function(t,e){void 0===e&&(e=0);for(var r=0,n=t;r<n.length;r++){var o=n[r];"layer"===o.item_type?(e+=1,o.draw_order_position=o.draw_order_position||e):"group"===o.item_type&&(e=this._sumUp(o.children,e))}return e},i.GetAdapterFromLayerType={},i.options={properties:[{type:"boolean",name:"visibility",getProperty:function(t){if(t){if("group"===t.item.item_type||"root"===t.item.item_type)return ie(t.item,(function(t){return"layer_enabled"in t&&t.layer_enabled}),(function(t){return t.children}));if("layer"===t.item.item_type)return t.item.layer_enabled}return!1},onSet:function(t,e,r){r&&"layer"===r.item.item_type&&(r.layer&&(t?r.webMap.showLayer(r.layer):r.webMap.hideLayer(r.layer)),r.item.layer_enabled=t)}},{name:"opacity",handler:ge}]},i}(me);function be(t){var e=t.webMap,i=t.connector,s=t.item,a=t.adapterOptions,u=void 0===a?{}:a,c=t.idPrefix,p=void 0===c?"first-show-adapter":c;return n(this,void 0,void 0,(function(){return o(this,(function(t){return[2,function(t){var e=t.webMap,i=t.adapterOptions,s=void 0===i?{}:i,a=t.onLayerAdded,u=t.createAdapter;return n(this,void 0,void 0,(function(){return o(this,(function(t){return[2,function(){function t(){this.options={},this.layer=[],this._removed=!1,this._creatingInProgress=!1}return t.prototype.addLayer=function(){return this.layer},t.prototype.removeLayer=function(){this._removed=!0;for(var t=0,r=this.layer;t<r.length;t++)e.removeLayer(r[t])},t.prototype.destroyed=function(){return this._removed},t.prototype.showLayer=function(){return n(this,void 0,void 0,(function(){var t,r;return o(this,(function(n){switch(n.label){case 0:if(this.options.visibility=!0,!this.layer.length)return[3,5];t=0,r=this.layer,n.label=1;case 1:return t<r.length?[4,e.showLayer(r[t])]:[3,4];case 2:n.sent(),n.label=3;case 3:return t++,[3,1];case 4:return[3,7];case 5:return[4,this.loadLayer()];case 6:n.sent(),n.label=7;case 7:return[2]}}))}))},t.prototype.hideLayer=function(){return n(this,void 0,void 0,(function(){var t,r;return o(this,(function(n){switch(n.label){case 0:if(this.options.visibility=!1,!this.layer)return[3,4];t=0,r=this.layer,n.label=1;case 1:return t<r.length?[4,e.hideLayer(r[t])]:[3,4];case 2:n.sent(),n.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},t.prototype.loadLayer=function(){return n(this,void 0,void 0,(function(){var t,n,i;return o(this,(function(o){switch(o.label){case 0:return this.layer.length||this._creatingInProgress?[3,5]:(this._creatingInProgress=!0,[4,u(this)]);case 1:return(t=o.sent())?[4,(n=new t(e.mapAdapter.map,r({},s))).addLayer({order:this.options.order,headers:this.options.headers,baselayer:this.options.baselayer})]:[3,5];case 2:return i=o.sent(),a&&a(n),Object.assign(n.options,s),n.layer=i,this._removed&&e.removeLayer(n),this.layer.push(n),this.options.visibility?[4,e.showLayer(n)]:[3,4];case 3:o.sent(),o.label=4;case 4:this._creatingInProgress=!1,o.label=5;case 5:return[2,this.layer]}}))}))},t}()]}))}))}({webMap:e,adapterOptions:u,onLayerAdded:function(t){t.options.baselayer=!1,t.id=p+"-"+s.resource_id},createAdapter:function(){return Se({resource:s.resource_id,adapterOptions:{name:s.display_name,opacity:s.opacity}},e,i)}})]}))}))}var we=function(){function t(t){this.options=t,this.resourceId=t.resourceId;var e=t.item;this.item=e,this.name=t.labelField&&e.fields?e.fields[t.labelField]:String(e.id)}return t.prototype.extent=function(){var t=this;return this._extent?x.resolve(this._extent):this.options.connector.get("feature_layer.feature.item_extent",null,{id:this.resourceId,fid:this.item.id}).then((function(e){var r=e.extent,n=[r.minLon,r.minLat,r.maxLon,r.maxLat];return t._extent=n,n}))},t.prototype.geoJson=function(){var t=this;return this.item.geom?x.resolve(Ht(this.item)):De({resourceId:this.resourceId,featureId:this.item.id,connector:this.options.connector,geom:!0,fields:null,extensions:null}).then((function(e){return t.item.geom=e.geom,Ht(t.item)}))},t}(),Le=function(){function t(t,e){this.map=t,this.options=e,this.NgwWebmapItem=_e,this.pixelRadius=10,this.webmapClassName="webmap",this.emitter=new c.exports.EventEmitter,this._webmapBaselayersIds=[];var r=e.resourceId;if(Array.isArray(r)?(this.resourceId=r[0],this.options.id=r[1]):this.resourceId=r,!this.resourceId)throw new Error("NGW `resourceId` is not defined")}return t.prototype.addLayer=function(t){var e,i;return n(this,void 0,void 0,(function(){var n,s;return o(this,(function(o){switch(o.label){case 0:return this.options=r(r({},this.options),t),n=this,[4,this._getWebMapLayerItem()];case 1:return n.layer=o.sent(),s=null===(i=null===(e=this.response)||void 0===e?void 0:e.webmap)||void 0===i?void 0:i.extent_constrained,this.options.useExtentConstrained&&this._extent&&s&&(this.options.webMap.setView({maxBounds:this._extent}),window.webmap=this.options.webMap),[2,this.layer]}}))}))},t.prototype.removeLayer=function(){var t=this.options.webMap.mapAdapter;if(this.getDependLayers().forEach((function(e){"layer"in e&&t.removeLayer(e.layer.layer)})),this._webmapBaselayersIds.length){for(var e=0,r=this._webmapBaselayersIds;e<r.length;e++){this.options.webMap.removeLayer(r[e])}this._lastActiveBaselayer&&this.options.webMap.showLayer(this._lastActiveBaselayer)}this.options.useExtentConstrained&&this._extent&&this.options.webMap.setView({maxBounds:null}),delete this.layer,delete this.response,delete this._webmapLayersIds},t.prototype.showLayer=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){return this.layer&&this.layer.properties?[2,this.layer.properties.property("visibility").set(!0)]:[2]}))}))},t.prototype.hideLayer=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){return this.layer&&this.layer.properties?[2,this.layer.properties.property("visibility").set(!1)]:[2]}))}))},t.prototype.setOpacity=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){return this.layer&&this.layer.properties?[2,this.layer.properties.property("opacity").set(t)]:[2]}))}))},t.prototype.getExtent=function(){return this.getBounds()},t.prototype.getBounds=function(){var t=this.response&&this.response.webmap;if(t)return Vt(t)},t.prototype.getDependLayers=function(){return this.layer&&this.layer.tree.getDescendants()||[]},t.prototype.getBookmarksResourceId=function(){var t=this.response&&this.response.webmap;if(t)return t.bookmark_resource.id},t.prototype.fetchBookmarks=function(){var t=this.getBookmarksResourceId(),e=this.options.connector;if(t)return e.getResourceOrFail(t).then((function(r){var n,o=null===(n=r.feature_layer)||void 0===n?void 0:n.fields.find((function(t){return t.label_field})),i=o&&o.keyname;return te({connector:e,resourceId:t,geom:!1,fields:i?[i]:void 0}).then((function(r){for(var n=[],o=0,s=r;o<s.length;o++){var a=new we({item:s[o],resourceId:t,labelField:i,connector:e});n.push(a)}return n}))}));throw new Error("Webmap was not loaded correctly, it is impossible to extract bookmarks")},t.prototype.getIdentificationIds=function(){return n(this,void 0,void 0,(function(){var t,e;return o(this,(function(r){switch(r.label){case 0:return t=[],(e=this._webmapLayersIds)?[3,2]:[4,this._getWebMapIds()];case 1:e=r.sent(),this._webmapLayersIds=e,r.label=2;case 2:return e&&e.length&&this.getDependLayers().sort((function(t,e){return e.id-t.id})).forEach((function(e){var r=e.item,n=r.parentId;if(void 0!==n&&"layer"===r.item_type){var o=e.properties.property("visibility");o.get()&&!o.isBlocked()&&t.push(n)}})),[2,t]}}))}))},t.prototype._getWebMapLayerItem=function(){return n(this,void 0,void 0,(function(){var t,e=this;return o(this,(function(r){switch(r.label){case 0:return this.resourceId?[4,this.getWebMapConfig(this.resourceId)]:[3,2];case 1:if((t=r.sent())&&t.root_item)return[2,new Promise((function(r){var n={};if(e.options.connector&&e.options.connector.options.auth){var o=e.options.connector.getAuthorizationHeaders();o&&(n.headers=o)}n.setViewDelay=e.options.setViewDelay,n.order=e.options.order,n.ratio=e.options.ratio,n.crossOrigin=e.options.crossOrigin,n.minZoom=e.options.minZoom,n.maxZoom=e.options.maxZoom,n.drawOrderEnabled=t.draw_order_enabled;var i=new e.NgwWebmapItem(e.options.webMap,t.root_item,n,e.options.connector);i.emitter.on("init",(function(){return r(i)}))}))];r.label=2;case 2:return[2]}}))}))},t.prototype.getWebMapConfig=function(t){return n(this,void 0,void 0,(function(){var e,r;return o(this,(function(n){switch(n.label){case 0:return[4,this.options.connector.getResource(t)];case 1:return(e=n.sent())&&(this.response=e,r=e[this.webmapClassName],this._setupBaselayers(e),r)?(this._extent=[r.extent_left,r.extent_bottom,r.extent_right,r.extent_top],this._updateItemsParams(r.root_item,this.options.webMap,e),[2,r]):[2]}}))}))},t.prototype._setupBaselayers=function(t){var e,r=this.options.webMap;if(null===(e=this.options.useBasemap)||void 0===e||e)if(t.basemap_webmap&&t.basemap_webmap.basemaps.length){var n=r.getActiveBaseLayer();this._lastActiveBaselayer=n?n.id:void 0,this._setBasemaps(t.basemap_webmap)}else this.options.defaultBasemap&&r.addBaseLayer("OSM",{id:"webmap-default-baselayer",name:"OpenStreetMap"})},t.prototype._setBasemaps=function(t){for(var e=this,r=this.options.webMap,n=!1,o=function(t){be({webMap:r,connector:i.options.connector,item:t,adapterOptions:{crossOrigin:i.options.crossOrigin}}).then((function(o){var i=!n&&t.enabled;return t.enabled&&(n=!0),r.addBaseLayer(o,{id:Fe+t.resource_id,name:t.display_name,opacity:t.opacity,visibility:i}).then((function(t){t.id&&e._webmapBaselayersIds.push(t.id)}))}))},i=this,s=0,a=t.basemaps;s<a.length;s++){o(a[s])}},t.prototype._updateItemsParams=function(t,e,n){var o=this;if(t)if("group"===t.item_type||"root"===t.item_type)t.children&&(t.children=t.children.map((function(t){return o._updateItemsParams(t,e,n)}))),"root"===t.item_type&&(t.display_name=n.resource.display_name);else if("layer"===t.item_type){var i=q(this.options.connector.options.baseUrl+"/api/component/render/image"),s=t.layer_style_id;t.url=i,t.resourceId=s,t.updateWmsParams=function(t){return Ne(t,s)};var a=ne({options:{adapter:t.layer_adapter.toUpperCase(),resource:s},webMap:e,baseUrl:this.options.connector.options.baseUrl||""});t=r(r({},t),a)}return t},t.prototype._getWebMapIds=function(){return n(this,void 0,void 0,(function(){var t,e,r,n=this;return o(this,(function(o){switch(o.label){case 0:return(t=this.layer)&&"root"===t.item.item_type?(e=t.tree.getDescendants(),r=[],e.forEach((function(t){var e=t.item;if("layer"===e.item_type){var o=n.options.connector.getResource(e.layer_style_id).then((function(t){if(t){var r=Number(t.resource.parent.id);return e.parentId=r,r}}));r.push(o)}})),[4,Promise.all(r)]):[3,2];case 1:return[2,o.sent().filter((function(t){return void 0!==t}))];case 2:return[2]}}))}))},t}();var Oe=function(){function t(){}return t.prototype.getExtent=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){return[2,this.getBounds()]}))}))},t.prototype.getBounds=function(){return n(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return this._extent?[2,this._extent]:this.item?(t=this,[4,Zt(this.item,this.connector)]):[3,2];case 1:return t._extent=e.sent(),[2,this._extent];case 2:return[2]}}))}))},t}(),Ce={tms:"TILE"};function Ie(t){return new Promise((function(e,r){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState&&200===n.status&&n.responseText)try{e(JSON.parse(n.responseText))}catch(t){r(t)}},n.open("GET",q(t),!0),n.send()}))}var Ee="https://qms.nextgis.com";function Pe(t,e,i){return void 0===e&&(e=Ee),void 0===i&&(i={}),e||(e=Ee),function(){function s(t,e){this.map=t;var n=r(r({},i),e);this.options=n,this.options.baselayer=!0,n.qms&&(this.qms=n.qms)}return s.prototype.addLayer=function(i){return n(this,void 0,void 0,(function(){var n,a,u,c,p,l,h,f;return o(this,(function(o){switch(o.label){case 0:if(this.qms||!i.qmsId)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),n=this,[4,Ie(e+"/api/v1/geoservices/"+i.qmsId)];case 2:return n.qms=o.sent(),[3,4];case 3:return a=o.sent(),console.error(a),[3,4];case 4:return(u=this.qms)&&(p=t.mapAdapter.layerAdapters[c=Ce[u.type||"tms"]])&&(y=s,v=p,["showLayer","hideLayer"].forEach((function(t){var e=Object.getOwnPropertyDescriptor(v.prototype,t);e&&Object.defineProperty(y.prototype,t,e)})),"TILE"===c)?(i=r(r({order:0,maxZoom:t.options.maxZoom,minZoom:t.options.minZoom},this.options),function(t){var e=("https:"===location.protocol?"https":"http")+"://",r=t.url.replace(/^(https?|ftp):\/\//,e);return t.y_origin_top||(r=r.replace("{y}","{-y}")),{url:r,name:t.name,attribution:t.copyright_text,maxZoom:t.z_max,minZoom:t.z_min}}(u)),u.origin_url&&(d=[],l=[u.origin_url.replace(/{switch:(.*?)}/,(function(t,e){return"string"==typeof e&&e.split(",").forEach((function(t){return d.push(t)})),"{s}"})),d],h=l[0],(f=l[1]).length&&(i.subdomains=f,i.url=h)),this.options=i,[2,new p(this.map,i).addLayer(i)]):[2]}var d,y,v}))}))},s}()}var Ae=function(){function t(t){this.options={url:"https://qms.nextgis.com"},this.options=r(r({},this.options),t),this.url=this.options.url}return t.prototype.getLayerAdapters=function(){var t=this;return Promise.resolve([{name:"QMS",createAdapter:function(e){return Promise.resolve(t._createAdapter(e))}}])},t.prototype._createAdapter=function(t){return Pe(t,this.url)},t.utils={createQmsAdapter:Pe},t}();var Me={},xe=["mapserver_style","qgis_vector_style","qgis_raster_style","wmsserver_service","raster_style","basemap_layer","vector_layer","raster_layer","webmap","tmsclient_layer"];function ke(t){var e=t.layerOptions,i=t.webMap,s=t.connector,a=t.item;return n(this,void 0,void 0,(function(){var t,n;return o(this,(function(o){switch(o.label){case 0:return[4,s.getResourceChildren(a.resource.id)];case 1:return t=o.sent(),(n=t&&t[0])?[2,Se(r(r({},e),{resource:n.resource.id}),i,s)]:[2]}}))}))}function Se(t,i,s){return n(this,void 0,void 0,(function(){var a,u,c,p,l,h,f,d,y,v,m,g;return o(this,(function(_){switch(_.label){case 0:return c=t.adapter,[4,qt(t,s)];case 1:return(p=_.sent())?(l=t.resource)&&l.resource&&void 0!==l.resource.id?(u=l,[3,4]):[3,2]:[3,15];case 2:return[4,s.getResource(p)];case 3:u=_.sent(),_.label=4;case 4:return u?(h=u.resource.cls,f=r(r({},t),{resource:p}),d={layerOptions:f,webMap:i,connector:s,item:u},-1===xe.indexOf(h)?[3,12]:"webmap"!==h?[3,5]:(a=function(t){var r=t.layerOptions,i=t.webMap,s=t.connector;return n(this,void 0,void 0,(function(){var t;return o(this,(function(n){switch(n.label){case 0:return[4,qt(r,s)];case 1:return t=n.sent(),[2,function(r){function n(e){return r.call(this,e,{url:"",webMap:i,resourceId:t,connector:s})||this}return e(n,r),n}(Le)]}}))}))}(d),[3,11])):[3,14];case 5:if("vector_layer"!==h)return[3,6];if(void 0!==c&&"GEOJSON"!==c){if("MVT"!==c)return[2,ke(d)];a=oe(d)}else a=re(d);return[3,11];case 6:return"raster_layer"!==h?[3,7]:[2,ke(d)];case 7:return"basemap_layer"!==h?[3,8]:(a=function(t){var i=t.webMap,s=t.item;return n(this,void 0,void 0,(function(){var t,a,u,c;return o(this,(function(p){if(s.basemap_layer){if(a=s.basemap_layer.url,t=s.basemap_layer.qms)return u=JSON.parse(t),[2,Promise.resolve(Ae.utils.createQmsAdapter(i,void 0,{qms:u,baselayer:!0}))];if(a&&(c=i.mapAdapter.layerAdapters.TILE))return[2,function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return e(i,t),i.prototype.addLayer=function(e){return n(this,void 0,void 0,(function(){return o(this,(function(n){return[2,t.prototype.addLayer.call(this,r(r({},e),{url:a}))]}))}))},i}(c)]}return[2]}))}))}(d),[3,11]);case 8:return"GEOJSON"!==c?[3,10]:[4,s.getResource(u.resource.parent.id)];case 9:return(y=_.sent())&&(v=r(r({},t),{resource:u.resource.parent.id}),a=re(r(r({},d),{item:y,layerOptions:v}))),[3,11];case 10:a=oe(d),_.label=11;case 11:return[3,13];case 12:if(!Me[h])throw"Resource class '".concat(h,"' not yet supported.");m=Me[h],g=void 0,(g=c&&"function"!=typeof g?m[c]:m)&&(a=g(d)),_.label=13;case 13:return[3,15];case 14:throw"Resource item is not found";case 15:return a?[2,a.then((function(t){if(t){var e=t;return u&&(e.prototype.item=u,e.prototype.resourceId=u.resource.id,e.prototype.connector=s),k(e,[Oe],{replace:!1}),e}}))]:[2]}}))}))}function Ne(t,e){var r=t.bbox,n=t.width,o=t.height,i=t.nd;return{resource:Array.isArray(e)?e.join(","):e,extent:r,size:n+","+o,timestamp:Date.now(),nd:i}}var Be,Te={POINT:"point",LINESTRING:"line",POLYGON:"polygon",MULTIPOINT:"point",MULTILINESTRING:"line",MULTIPOLYGON:"polygon",POINTZ:"point",LINESTRINGZ:"line",POLYGONZ:"polygon",MULTIPOINTZ:"point",MULTILINESTRINGZ:"line",MULTIPOLYGONZ:"polygon"};var Re=function(){function t(t){if(this.options=t,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 Ft({baseUrl:this.url,auth:this.options.auth})}}return t.addClassAdapters=function(t,e){Me[t]=e},t.prototype.onLoadSync=function(t){return n(this,void 0,void 0,(function(){var e,n,i;return o(this,(function(o){switch(o.label){case 0:if(!this.options.resourceId||!this.url)return[3,4];if(!(e=[this.options.resourceId]).length)return[3,4];n=0,i=e,o.label=1;case 1:return n<i.length?[4,t.addLayer(Le,r({visibility:!0,fit:!0,pixelRadius:this.options.pixelRadius},{resourceId:i[n],connector:this.connector,webMap:t}))]:[3,4];case 2:return[2,o.sent()];case 3:return n++,[3,1];case 4:return[2]}}))}))},t.prototype.getLayerAdapters=function(){return Promise.resolve([this._getLayerAdapter()])},t.prototype._getLayerAdapter=function(){var t=this;return{name:"WEBMAP",createAdapter:function(e){return Promise.resolve(t._createAdapter(e))}}},t.prototype._createAdapter=function(t){var n;return n={webMap:t,connector:this.connector,baseUrl:this.url},function(t){function o(e,o){return o=r(r({},n),o),t.call(this,e,o)||this}return e(o,t),o}(Le)},t}(),je=function(){function t(t){var e=t.feature;this.id=e.id,this.geom=e.geom,this.label=e.label,this.parent=e.parent,this.fields=e.fields,this.layerId=e.layerId,this.connector=t.connector}return t.prototype.identify=function(t){var e=this;return void 0===t&&(t={}),this._item?x.resolve(this._item):De(r({connector:this.connector,featureId:this.id,resourceId:this.layerId,fields:null,extensions:["attachment","description"]},t)).then((function(t){return e._item=t,e.geom=t.geom,e.extensions=t.extensions,t}))},t.prototype.resource=function(){var t=this;return this._resource?x.resolve(this._resource.feature_layer):this.connector.getResource(this.layerId).then((function(e){return t._resource=e,t._resource.feature_layer}))},t.prototype.getBounds=function(){return this._extent?x.resolve(this._extent):(t={connector:this.connector,featureId:this.id,resourceId:this.layerId}).connector.get("feature_layer.feature.item_extent",{cache:void 0===(e=t.cache)||e},{id:t.resourceId,fid:t.featureId}).then((function(t){if(t){var e=t.extent;return[e.minLon,e.minLat,e.maxLon,e.maxLat]}}));var t,e},t.prototype.geojson=function(){var t=this;return this._geojson?x.resolve(this._geojson):this.identify().then((function(e){return e.toGeojson().then((function(e){return t._geojson=e,e}))}))},t}(),Fe="webmap-baselayer";function De(t){var e=r({},Wt);Jt(e,t);var n=r({id:t.resourceId,fid:t.featureId},e);return t.connector.get("feature_layer.feature.item",{cache:t.cache||!0},n).then((function(e){return r(r({},e),{toGeojson:function(){return e.geom?x.resolve(Ht(e)):De(r(r({},t),{geom:!0,fields:null,extensions:null})).then((function(t){var n=t.geom;return Ht(r(r({},e),{geom:n}))}))}})}))}function ze(t){return De(t).then((function(t){return Ht(t)}))}function Ve(t,e){void 0===e&&(e=!1);var r=[],n=[];for(var o in t){var i=Number(o);isNaN(i)||r.push(i)}var s=t.resources;s&&r.sort((function(t,e){return s.indexOf(t)-s.indexOf(e)}));for(var a=0;a<r.length;a++){var u=t[o=r[a]];if("features"in u){var c=u.features,p=Number(o),l=c[0];if(l&&(n.push({featureId:l.id,resourceId:p,feature:l}),!e))break}}return n}function Ge(t,e){var n;T(t);var o=t.lngLat,i=null!==(n=e.geom)&&void 0!==n?n:function(t,e,r,n){void 0===r&&(r=10),void 0===n&&(n=6);for(var o=r/6371*D,i=o/Math.cos(e*F),s=[],a=0;a<n+1;a++){var u=Math.PI*(a/(n/2)),c=t+i*Math.cos(u),p=e+o*Math.sin(u);s.push([c,p])}return s}(o[0],o[1],e.radius);return function(t){var e=t.geom,r=[];if(Array.isArray(e))r=e;else{var n="Feature"===e.type?e.geometry:"Polygon"===e.type&&e;n&&(r=n.coordinates[0])}if(r){for(var o=[],i=0,s=r;i<s.length;i++){var a=s[i],u=z(a[0],a[1]);o.push(u[0]+" "+u[1])}var c="POLYGON((".concat(o.join(", "),"))");return t.connector.post("feature_layer.identify",{data:{geom:c,srs:3857,layers:t.layers}})}throw new Error("Not valid geometry format to make intersection")}(r(r({},e),{geom:i}))}function Ue(t,e){var r;return n(this,void 0,void 0,(function(){var n,i,s,a,u,c,p;return o(this,(function(o){switch(o.label){case 0:return[4,t.get("pyramid.settings",null,{component:"pyramid"})];case 1:if(!((n=o.sent())&&n.company_logo&&n.company_logo.enabled))return[3,6];(i=document.createElement("a")).style.position="absolute",i.style.bottom="0",i.style.right="0",i.style.padding=null!==(r=null==e?void 0:e.padding)&&void 0!==r?r:"10px",i.className="ngw-map-logo",e&&e.cssClass&&(i.className+=" "+e.cssClass),(s=new Image).style.maxHeight="100px",s.style.maxWidth="100px",s.src="",o.label=2;case 2:return o.trys.push([2,4,,5]),[4,t.get("pyramid.company_logo",{responseType:"blob"})];case 3:return a=o.sent(),u=window.URL||window.webkitURL,c=u.createObjectURL(a),s.src=c,[3,5];case 4:return p=o.sent(),console.warn(p),[3,5];case 5:return null!==n.company_logo.link&&""!==n.company_logo.link.trim()&&(i.href=n.company_logo.link,i.target="_blank",-1!==n.company_logo.link.search(/:\/\/nextgis/)&&(s.alt="Get your own Web GIS at nextgis.com")),i.appendChild(s),[2,i];case 6:return[2]}}))}))}var Ze={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 qe(t){void 0===t&&(t={});var e=t.color||"blue",r=t.strokeColor||"white",n=t.size||12,o=n/2,i="number"==typeof t.stroke?t.stroke:.8,s=n/12,a=Ze[t.shape||"circle"]||"circle",u=function(t,e,r,n){void 0===r&&(r=0);var o=r/2,i='<svg\n version="1.1"\n xmlns="http://www.w3.org/2000/svg"\n width="'.concat(t,'"\n height="').concat(e,'"\n viewBox="-').concat(o," -").concat(o," ").concat(t+r," ").concat(e+r,'"\n >').concat(n,"</svg>");return(new DOMParser).parseFromString(i,"image/svg+xml").documentElement}(n,n,i*s,"string"==typeof a?a:a(t)),c=u.firstChild,p="scale(".concat(s,")");return c.setAttribute("fill",e),i&&(c.setAttribute("stroke",r),c.setAttribute("stroke-width",String(i))),c.setAttribute("transform",p),{type:"icon",iconSize:[n,n],iconAnchor:[o,o],html:(new XMLSerializer).serializeToString(u),svg:u}}function We(t,e,n,o){if("number"==typeof e||"string"==typeof e)e=Number(e),t.push(r(r({},n),{resource:e}));else if(Array.isArray(e)){var i=e[0],s=e[1];t.push(r(r(r({},n),{resource:i,id:s}),o))}else"object"==typeof e&&t.push(r(r(r({},n),e),o))}var He={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};var Je=function(t){function i(e){var n=t.call(this,function(t){var e=[new Ae];return t.starterKits&&t.starterKits.forEach((function(t){e.push(t)})),t.connector?t.connector&&(t.baseUrl=t.connector.options.baseUrl):t.connector=new Ft({baseUrl:t.baseUrl||"",auth:t.auth}),(t=B(He,t)).center||t.bounds||(t.bounds=[-179,-90,180,90]),t.connector&&e.push(new Re({connector:t.connector,auth:t.auth})),r(r({},t),{starterKits:e,create:!1})}(e))||this;return n.emitter=new c.exports.EventEmitter,n._ngwLayers={},n._promises={select:[],identify:[]},e.connector&&(n.connector=e.connector),n._createWebMap().then((function(){var t=n.getContainer();t&&t.classList.add("ngw-map-container"),n.options.whitlabel&&n._whiteLabel()})),n}return e(i,t),i.prototype.addControl=function(e,r,i){return n(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,this.onLoad("controls:create")];case 1:return n.sent(),[2,t.prototype.addControl.call(this,e,r,i)]}}))}))},i.prototype.addNgwLayer=function(t){return n(this,void 0,void 0,(function(){var e,n,i,s,a,u,c,p,l;return o(this,(function(o){switch(o.label){case 0:return[4,this.onMapLoad()];case 1:if(o.sent(),n=t.resourceId,((e=t.keyname)||void 0!==n)&&console.warn("DEPRECATED WARN: ".concat("set `resource` options instead of `keyname` or `resourceId`")),i=t.resource,!e&&!n&&!i)throw new Error("resource, resourceId or keyname is required parameter to add NGW layer");if(!S(this.options.baseUrl))return[3,5];o.label=2;case 2:return o.trys.push([2,4,,5]),S(this.options.setViewDelay)&&(t.adapterOptions=t.adapterOptions||{},S(t.adapterOptions.setViewDelay)||(t.adapterOptions.setViewDelay=this.options.setViewDelay)),s=function(t,e,r){var n=r.getAuthorizationHeaders();return n&&(t.headers=n),Se(t,e,r)}(t,this,this.connector),a=r(r({visibility:!0},t),t.adapterOptions),[4,this.addLayer(s,a)];case 3:return u=o.sent(),c=u&&this.getLayerId(u),u&&c&&(this._ngwLayers[c]={layer:u,resourceId:u.resourceId},u.options.name=u.options.name||u.item&&u.item.resource.display_name,u.options.baselayer&&this.getActiveBaseLayer()),[2,u];case 4:return p=o.sent(),l=Z(i)&&"id"in i?i.id:e||n||i,console.error("Can't add NGW layer ".concat(l,"."),p),[3,5];case 5:return[2]}}))}))},i.prototype.fit=function(){var t=this.options,e=t.center,r=t.zoom,n=t.bounds;e?(this.setCenter(e),r&&this.setZoom(r)):n&&this.fitBounds(n)},i.prototype.fetchNgwLayerItem=function(t){return De(r({connector:this.connector},t))},i.prototype.fetchNgwLayerItems=function(t){return te(r({connector:this.connector},t))},i.prototype.fetchNgwLayerFeature=function(t){return ze(r({connector:this.connector},t))},i.prototype.fetchNgwLayerFeatures=function(t){return ee(r({connector:this.connector},t))},i.prototype.fetchIdentifyItem=function(t,e){var n,o,i,s=(o=(n={identify:t,connector:this.connector,requestOptions:e}).connector,(i=Ve(n.identify))&&i.length?De(r(r({connector:o},n.requestOptions),i[0])):x.resolve(void 0));return this._addPromise("identify",s),s},i.prototype.fetchIdentifyGeoJson=function(t,e){void 0===e&&(e=!1);var n=function(t){var e=t.connector,n=t.identify;for(var o in n){var i=Number(o);if(!isNaN(i)){var s=n[o];if("features"in s){var a=s.features.find((function(t){return t.geom}));if(a&&a.geom){var u=a.geom;return x.resolve(Ht(r(r({},a),{geom:u})))}}}}var c=Ve(n);return c&&c.length?ze(r({connector:e},c[0])):x.resolve(void 0)}({identify:t,connector:this.connector,multiple:e});return n&&"then"in n?(this._addPromise("identify",n),n):x.resolve(n)},i.prototype.getIdentifyGeoJson=function(t,e){return void 0===e&&(e=!1),this.fetchIdentifyGeoJson(t,e)},i.prototype.getNgwLayers=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.onLoad()];case 1:return t.sent(),[2,this._ngwLayers]}}))}))},i.prototype.getNgwLayerByResourceId=function(t){return n(this,void 0,void 0,(function(){var e,r,n,i,s,a,u;return o(this,(function(o){switch(o.label){case 0:for(r in e=[],this._ngwLayers)e.push(r);n=0,o.label=1;case 1:return n<e.length?(i=this._ngwLayers[e[n]]).resourceId!==t?[3,2]:[2,i&&i.layer]:[3,6];case 2:return i.layer.getIdentificationIds?[4,i.layer.getIdentificationIds()]:[3,4];case 3:if((s=o.sent())&&s.some((function(e){return e===t})))return[2,i.layer];o.label=4;case 4:if(i.layer.getDependLayers&&(a=i.layer.getDependLayers(),u=a.find((function(e){return e.item&&e.item.parentId===t}))))return[2,u.layer];o.label=5;case 5:return n++,[3,1];case 6:return[2]}}))}))},i.prototype.fitLayer=function(e,r){return n(this,void 0,void 0,(function(){var n,i,s,a,u=this;return o(this,(function(o){switch(o.label){case 0:return n="string"==typeof e||"number"==typeof e?String(n):e.id,(i=n&&this._ngwLayers[n])?i.layer.getBounds?[4,i.layer.getBounds()]:[3,2]:[3,7];case 1:return(s=o.sent())&&this.fitBounds(s,r),[3,6];case 2:return a=void 0,i.layer.item?(a=i.layer.item,[3,5]):[3,3];case 3:return[4,this.connector.getResource(i.resourceId)];case 4:a=o.sent(),o.label=5;case 5:a&&Zt(a,this.connector).then((function(t){t&&u.fitBounds(t,r)})),o.label=6;case 6:return[3,8];case 7:t.prototype.fitLayer.call(this,e,r),o.label=8;case 8:return[2]}}))}))},i.prototype.zoomToLayer=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){return[2,this.fitLayer(t)]}))}))},i.prototype.onLoad=function(e){return void 0===e&&(e="ngw-map:create"),t.prototype.onLoad.call(this,e)},i.prototype.removeLayer=function(e){var r=this.getLayer(e);if(r){var n=this.getLayerId(r);n&&delete this._ngwLayers[n],t.prototype.removeLayer.call(this,r)}},i.prototype.enableSelection=function(){var t=this;this.$$selectFromNgwRaster||(this.$$selectFromNgwRaster=function(e){t.emitter.listenerCount("ngw:select")&&t._selectFromNgwRaster(e)},this.$$selectFromNgwVector=function(e){t.emitter.listenerCount("ngw:select")&&t._selectFromNgwVector(e)},this.emitter.on("click",this.$$selectFromNgwRaster),this.emitter.on("layer:click",this.$$selectFromNgwVector))},i.prototype.disableSelection=function(){this.$$selectFromNgwRaster&&(this.emitter.removeListener("click",this.$$selectFromNgwRaster),this.emitter.removeListener("click",this._selectFromNgwVector),this.$$selectFromNgwRaster=void 0,this.$$selectFromNgwVector=void 0)},i.prototype.getNgwLayerItem=function(t){return this.fetchNgwLayerItem(t)},i.prototype.getNgwLayerItems=function(t){return this.fetchNgwLayerItems(t)},i.prototype.getNgwLayerFeature=function(t){return this.fetchNgwLayerFeature(t)},i.prototype.getNgwLayerFeatures=function(t){return this.fetchNgwLayerFeatures(t)},i.prototype.cancelPromise=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.cancelPromises.apply(this,t)},i.prototype.cancelPromises=function(){for(var t=this,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];e.length||(e=Object.keys(this._promises)),e.forEach((function(e){var r=t._promises[e];r&&(r.forEach((function(t){return t.cancel()})),t._promises[e]=[])}))},i.prototype._addPromise=function(t,e){var r=this._promises[t];if(r&&-1===r.indexOf(e)){var n=function(){var t=r.indexOf(e);-1!==t&&r.splice(t,1)};e.then(n),e.catch(n),r.push(e)}},i.prototype._isFitFromResource=function(){var t=this._initMapState;return!t.zoom||!t.center},i.prototype._createWebMap=function(){return n(this,void 0,void 0,(function(){var t,e,r,n,i,s,a,u,c,p;return o(this,(function(o){switch(o.label){case 0:return[4,this.create()];case 1:if(o.sent(),this.options.qmsId&&this._addQmsBaseLayer(),this.options.osm&&this._addOsmBaseLayer(),t=[],e=this._isFitFromResource(),this.options.webmapId&&We(t,this.options.webmapId,{fit:e}),this.options.resources&&Array.isArray(this.options.resources))for(r=0,n=this.options.resources;r<n.length;r++)i=n[r],s={},e||(s.fit=!1),We(t,i,{},s);a=0,u=t,o.label=2;case 2:if(!(a<u.length))return[3,7];c=u[a],o.label=3;case 3:return o.trys.push([3,5,,6]),[4,this.addNgwLayer(c)];case 4:return o.sent(),[3,6];case 5:return p=o.sent(),console.warn(p),[3,6];case 6:return a++,[3,2];case 7:return this._emitStatusEvent("ngw-map:create",this),this.enableSelection(),[2]}}))}))},i.prototype._addOsmBaseLayer=function(){this.addBaseLayer("OSM")},i.prototype._addQmsBaseLayer=function(){var t,e;Array.isArray(this.options.qmsId)?(t=this.options.qmsId[0],e=this.options.qmsId[1]):t=Number(this.options.qmsId);var r={qmsId:t};e&&(r.id=e),this.addBaseLayer("QMS",r)},i.prototype._selectFromNgwVector=function(t){var e,n=t.layer,o=n.item&&n.item.resource.id,i=t.feature;if(void 0!==o&&i){var s=i.id;if(s){var a={id:Number(s),fields:i.properties||{},label:"#".concat(o),layerId:Number(o),parent:"",geom:i.geometry},u=((e={featureCount:1})[o]={featureCount:1,features:[a]},e);return this._emitStatusEvent("ngw:select",this._prepareToIdentify(r(r({},u),{resources:[o],sourceType:"vector"}))),u}}},i.prototype._selectFromNgwRaster=function(t){return n(this,void 0,void 0,(function(){var e,n,i,s,a,u,c,p,l,h=this;return o(this,(function(o){switch(o.label){case 0:return this._emitStatusEvent("ngw:preselect"),e=[],(n=Object.values(this._ngwLayers)).sort((function(t,e){return t.layer.order&&e.layer.order?e.layer.order-t.layer.order:1})),n.forEach((function(t){var r=t.layer,n="function"==typeof r.getIdentificationIds&&r.getIdentificationIds;n&&r.options.selectable&&h.isLayerVisible(r)&&e.push(n.call(r))})),[4,Promise.all(e)];case 1:return i=o.sent(),s=[],i.forEach((function(t){t&&t.forEach((function(t){return s.push(t)}))})),s.length?(a=this.options.pixelRadius||10,u=this.getCenter(),c=void 0!==(c=this.getZoom())?c:20,u&&c?(p=function(t,e,r){return(r=null!=r?r:10)*(40075016.686*Math.abs(Math.cos(180*t[1]/Math.PI))/Math.pow(2,e+8))*5e-4}(u,c,a),l=Ge(t,{layers:s,connector:this.connector,radius:p}).then((function(e){return h._emitStatusEvent("ngw:select",h._prepareToIdentify(r(r({},e),{resources:s,sourceType:"raster",event:t}))),e})),this._addPromise("select",l),[2,l]):(this._emitStatusEvent("ngw:select",null),[2])):(this._emitStatusEvent("ngw:select",null),[2])}}))}))},i.prototype._prepareToIdentify=function(t){var e=this;return r(r({},t),{getIdentifyItems:function(){return Ve(t,!0).map((function(t){return new je({feature:t.feature,connector:e.connector})}))}})},i.prototype._whiteLabel=function(){return n(this,void 0,void 0,(function(){var t,e;return o(this,(function(r){switch(r.label){case 0:return(t=this.getContainer())?[4,Ue(this.connector,this.options.companyLogoOptions)]:[3,2];case 1:(e=r.sent())&&t.appendChild(e),r.label=2;case 2:return[2]}}))}))},i.getIcon=qe,i}(wt);function $e(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new Je(t).onLoad()]}))}))}export{Je as NgwMap,wt as WebMap,gt as WebMapControls,vt as WebMapLayers,yt as WebMapMain,$e as createNgwMap,mt as createToggleControl,Lt as createWebMap,ot as detectGeometryType,nt as findMostFrequentGeomType,bt as getWebMap,at as updateGeoJsonAdapterOptions};
2
16
  //# sourceMappingURL=ngw-map.esm-browser.prod.js.map