@nextgis/ngw-map 1.18.0 → 1.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ngw-map.cjs.js +1 -1
- package/lib/ngw-map.esm-browser.js +44 -15
- package/lib/ngw-map.esm-browser.js.map +1 -1
- package/lib/ngw-map.esm-browser.prod.js +1 -1
- package/lib/ngw-map.esm-browser.prod.js.map +1 -1
- package/lib/ngw-map.esm-bundler.js +1 -1
- package/lib/ngw-map.global.js +47 -15
- package/lib/ngw-map.global.js.map +1 -1
- package/lib/ngw-map.global.prod.js +1 -1
- package/lib/ngw-map.global.prod.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e,t={exports:{}},r="object"==typeof Reflect?Reflect:null,s=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}t.exports=o,t.exports.once=function(e,t){return new Promise((function(r,s){function i(r){e.removeListener(t,o),s(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}y(e,t,o,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&y(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 l(e,t,r,s){var i,o,n,l;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 h=new Error("Possible EventEmitter memory leak detected. "+n.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=n.length,l=h,console&&console.warn&&console.warn(l)}return e}function h(){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 u(e,t,r){var s={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=h.bind(s);return i.listener=r,s.wrapFn=i,i}function p(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):f(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 f(e,t){for(var r=new Array(t),s=0;s<t;++s)r[s]=e[s];return r}function y(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 l=c.length,h=f(c,l);for(r=0;r<l;++r)s(h[r],this,t)}return!0},o.prototype.on=o.prototype.addListener=function(e,t){return l(this,e,t,!1)},o.prototype.prependListener=function(e,t){return l(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,u(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,u(this,e,t)),this},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.off=o.prototype.removeListener,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 p(this,e,!0)},o.prototype.rawListeners=function(e){return p(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 m extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,m.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 b=0;class w{constructor(e,t){this.id=b++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise(((e,t)=>{this._setCanceledCallback=t=>e(t||new m)}));const r=[this._cancelPromise,new Promise(((t,r)=>e((e=>{e instanceof w?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 w((t=>t(e)))}static reject(e){return new w(((t,r)=>r(e)))}static all(e){return new w(((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 w(((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 m),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new m: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}}w.CancelError=m,w.TimeoutError=_,w.PromiseControl=g,Object.setPrototypeOf(w.prototype,Promise.prototype);var L=w;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 I(e){return null!=e}function E(e){return"string"==typeof e?!!e:I(e)}function A(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]=A(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]?A(s[e],i[e],r):i[e]}))),n}function C(e){if(!e.lngLat&&e.latLng){e.lngLat=[e.latLng.lng,e.latLng.lat]}return e}const M=6371;function k(e){return{type:"Polygon",coordinates:[P(e)]}}function P(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}const x=Math.PI/180,S=180/Math.PI;function N(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 T(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:F(e,t));return e===t}function F(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(!T(e[r[i]],t[s[i]],e,t))return!1}return!0}function B(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]=B(e[r])})),t}function R(e){return"[object Object]"===Object.prototype.toString.call(e)}function j(e){return e.replace(/([^:]\/)\/+/g,"$1")}function $(e){return"function"==typeof e}const q=(e,t,r)=>{try{const s=e(t,r);if(void 0!==s)return s}catch{}};function V(e){return(t,r)=>{for(const s of t){const t=q(e,s,r);if(void 0!==t)return t}throw new Error("Received a mismatched type")}}const D={array:e=>{const[t,r,s]=e;let i,o,n;if("string"==typeof t&&["string","number","boolean"].includes(t)?(i=t,"number"==typeof r?(o=r,n=s):n=r):Array.isArray(t)&&(n=t),!Array.isArray(n))throw new Error("Expected an array");if(i&&!n.every((e=>typeof e===i)))throw new Error(`Expected all items in array to be of type ${i}`);if(o&&n.length!==o)throw new Error(`Expected array of length ${o}`);return n},boolean:V((e=>"boolean"==typeof e?e:void 0)),literal:([e])=>e,number:V((e=>"number"==typeof e?e:void 0)),object:V((e=>null===e||"object"!=typeof e||Array.isArray(e)?void 0:e)),string:V((e=>"string"==typeof e?e:void 0)),"to-boolean":V(Boolean),"to-number":V(Number),"to-string":V(String),typeof:([e])=>typeof e};const U={get:function([e,t],r){const s=t||r;return s&&"object"==typeof s&&e in s?s[e]:null},length:([e])=>{if("string"==typeof e||Array.isArray(e))return e.length},at:function([e,t]){return t[e]},has:function([e,t],r){const s=t||r;return!(!s||"object"!=typeof s||!(e in s))},in:function([e,t]){if("string"==typeof t)return t.includes(String(e));if(Array.isArray(t))return t.includes(e);throw new Error(`Invalid input type for 'in'. Expected string or array, got ${typeof t}.`)},"index-of":function([e,t,r]){if("string"==typeof t)return t.indexOf(String(e),r);if(Array.isArray(t))return t.indexOf(e,r);throw new Error(`Invalid input type for 'index-of'. Expected string or array, got ${typeof t}.`)},slice:function(e){const[t,r,s]=e;if("string"==typeof t)return t.slice(r,s);if(Array.isArray(t))return t.slice(r,s);throw new Error(`Invalid input type for 'slice'. Expected string or array, got ${typeof t}.`)}};const z=([e,t])=>{if(typeof e!=typeof t)throw new Error("Values have different types.")};const G={"!":function([e]){return!e},"!=":function([e,t]){return z([e,t]),e!==t},"<":function([e,t]){return z([e,t]),e<t},"<=":function([e,t]){return z([e,t]),e<=t},"==":function([e,t]){return z([e,t]),e===t},">":function([e,t]){return z([e,t]),e>t},">=":function([e,t]){return z([e,t]),e>=t},all:function(e){for(let t=0;t<e.length;t++){if(!e[t])return!1}return!0},any:function(e){for(let t=0;t<e.length;t++){if(e[t])return!0}return!1},case:function(e){if(e.length<2)throw new Error('The "case" function requires at least a condition and a corresponding output.');const t=e[e.length-1];if(e.length%2==0)throw new Error("Missing a fallback value or unmatched condition-output pair.");for(let r=0;r<e.length-1;r+=2){if(e[r])return e[r+1]}return t},match:function(e){const[t,...r]=e,s=r.splice(-1,r.length%2)[0];for(let i=0;i<r.length-1;i+=2){if(r[i]===t)return r[i+1]}return s}};const Z={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function W(e){if("string"==typeof(r=e)&&/^#([A-Fa-f0-9]{3}){1,2}$/.test(r))return H(e);if("string"==typeof(t=e)&&t in Z)return function(e){return H(Z[e])}(e);if(function(e){return"string"==typeof e&&/^rgb(a?)\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)(?:\s*,\s*([01](?:\.\d+)?))?\s*\)$/.test(e)}(e))return function(e){const t=/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)$/;let r;if(r=e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/))return[parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3],10)];if(r=e.match(t))return[parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3],10),parseFloat(r[4])];throw new Error(`The '${e}' Is not valid rgb`)}(e);if(function(e){if("object"==typeof e&&null!==e)return"r"in e&&"g"in e&&"b"in e&&(!("a"in e)||"number"==typeof e.a&&e.a>=0&&e.a<=1);return!1}(e))return function({r:e,g:t,b:r,a:s}){return[e,t,r,...void 0!==s?[s]:[]]}(e);var t,r;throw new Error(`The '${e}' cannot be converted to color`)}function H(e){let t;if(t=/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/.exec(e))return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16)];if(t=/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/.exec(e))return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16),parseInt(t[4]+t[4],16)/255];if(t=/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/.exec(e))return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)];if(t=/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/.exec(e))return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16)/255];throw new Error(`The '${e}' Is not valid hex`)}function J(e,t,r,s,i){if("number"==typeof r&&"number"==typeof i)return r+(e-t)/(s-t)*(i-r);try{const o=W(r),n=W(i);return function(e){return`rgb(${e.join(",")})`}(o.map(((r,i)=>Math.ceil(J(e,t,r,s,n[i])))))}catch(o){console.log(o)}throw new Error("Unsupported output type for linear interpolation.")}function Q(e){if(Array.isArray(e)){const[t,...r]=e;return"string"==typeof t&&"literal"!==t&&t in K&&r.length>0}return!1}const K={...{"+":e=>e.reduce(((e,t)=>e+t),0),"-":e=>e.reduce(((e,t)=>e-t)),"*":e=>e.reduce(((e,t)=>e*t),1),"/":e=>e.reduce(((e,t)=>e/t)),"%":e=>e[0]%e[1],"^":e=>Math.pow(e[0],e[1]),abs:e=>Math.abs(e[0]),acos:e=>Math.acos(e[0]),asin:e=>Math.asin(e[0]),atan:e=>Math.atan(e[0]),ceil:e=>Math.ceil(e[0]),cos:e=>Math.cos(e[0]),e:()=>Math.E,floor:e=>Math.floor(e[0]),ln:e=>Math.log(e[0]),ln2:()=>Math.LN2,log10:e=>Math.log10(e[0]),log2:e=>Math.log2(e[0]),max:e=>Math.max(...e),min:e=>Math.min(...e),pi:()=>Math.PI,round:e=>Math.round(e[0]),sin:e=>Math.sin(e[0]),sqrt:e=>Math.sqrt(e[0]),tan:e=>Math.tan(e[0])},...D,...{concat:e=>e.reduce(((e,t)=>String(e)+String(t)),""),downcase:e=>String(e[0]).toLowerCase(),upcase:e=>String(e[0]).toUpperCase()},...U,...G,...{step:function(e){const[t,r,...s]=e;if("number"!=typeof t)return r;for(let i=0;i<s.length-2;i+=2){if(t>=s[i]&&t<s[i+2])return s[i+1]}return t>=s[s.length-2]?s[s.length-1]:r},interpolate:function([e,t,...r]){if(r.length<2)throw new Error("At least two stops are required");if("number"!=typeof t)throw new Error("Input must be a number.");if(r.length<2||r.length%2!=0)throw new Error("Invalid stops provided.");for(let s=0;s<r.length-2;s+=2){const i=r[s],o=r[s+2];if(t>=i&&t<=o&&"linear"===e[0])return J(t,i,r[s+1],o,r[s+3])}throw new Error("Invalid interpolation type.")}}};function X(e,t={}){const[r,...s]=e,i=K[r];if(i)return i(s.map((e=>Q(e)?X(e,t):e)),t);throw new Error(`Expression "${r}" is not supported.`)}function Y(e){return t=>{const r=t.properties;return!!r&&X(e,r)}}const ee=["iconSize","iconAnchor"];function te(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 re={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)=>te(e,t),ilike:(e,t)=>te(e,t,!0)};function se(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function ie(e,t){const r="string"==typeof t[0]?t[0]:"all",s=t=>{if(se(t)){const[r,s,i]=t,o=re[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 ie(e,t)},i=t.filter((e=>Array.isArray(e)));return"any"===r?i.some(s):i.every(s)}function oe(e){let t={};const r=[];for(const s of e)s&&(Array.isArray(s)?r.push(s):t=s);return e=>{const s=r.find((t=>function(e,t){const r={...e.properties};return!!r&&(r.$id=e.id,ie(r,t))}(e,t[0])));return s?{...t,...s[1]}:t}}function ne(e,t,r){const s=function(e){let t=!1;const r={};for(const s in e)if(-1===ee.indexOf(s)){const i=s,o=e[i];Q(o)&&(t=!0,r[i]=Y(o))}if(t)return t=>{const s={};for(const e in r)s[e]=r[e](t);return{...e,...s}}}(e);if(s){const i=e=>ae(s(e),t,r);return i.paint=e,i}let i={...t};return i={...i,...e},i.fill=void 0===i.fill||i.fill,i.stroke=void 0!==i.stroke?i.stroke:!i.fill||!(!i.strokeColor&&!i.strokeOpacity),i}function ae(e,t,r){if(!e)throw new Error("paint is empty");let s={...t};if($(e)){const s=s=>{const i=ae(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=>ae(oe(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=ae(i,t,r))}else{if("icon"===e.type)return e;s=ne(e,t,r)}return $(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 ce(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 le(e){let t;if("FeatureCollection"===e.type){t=ce(e.features.map((e=>e.geometry.type)))}else if("GeometryCollection"===e.type){t=ce(e.geometries.map((e=>e.type)))}else t="Feature"===e.type?e.geometry.type:e.type;return t}const he={polygon:"path",line:"path",point:"circle"},ue={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon"};function pe(e){if(e.data){const t=ue[le(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":he[t]),e.type=e.type||t}return e}class de{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 fe{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 ye extends fe{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 me extends fe{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 ge=0;const _e={minZoom:0,maxZoom:22,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 ve{constructor(e){this.options=_e,this.emitter=new t.exports.EventEmitter,this.keys=ve.keys,this.runtimeParams=[],this.getPaintFunctions=ve.getPaintFunctions,this.mapState=[ye,me],this.id=ge++,this._initMapState={},this._mapState=[],this._eventsStatus={},this._mapEvents={},this.mapAdapter=e.mapAdapter,this._starterKits=e.starterKits||[],e&&(this.options=A(_e||{},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:k(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&&I(t)?this.mapAdapter.setView(r,t):(r&&this.mapAdapter.setCenter(r),I(t)&&this.mapAdapter.setZoom(t))}else{this.mapAdapter.setView&&this.mapAdapter.setView(e)}}fitBounds(e,t){return e.every((e=>I(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(),C(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),I(e.maxzoom)&&(this.options.zoom=e.maxzoom),I(e.minzoom)&&(this.options.zoom=e.minzoom),I(e.maxzoom)&&I(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","mousemove","mouseout","mouseover"];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)}))}}ve.keys=new class{constructor(){this.keyCodeAlias=new de,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 be extends ve{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=I(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 l=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),l&&await this.showLayer(r));const h=t.opacity;void 0!==h&&h<=1&&this.setLayerOpacity(e,h);const u=s&&(e.getBounds||e.getExtent);if(t.fit&&u){const t=await u.call(e);t&&await this.fitBounds(t)}return t.onAdded&&t.onAdded(e),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=pe(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){let r;return"string"==typeof e?r=e:(r=e.url,t=e),this.addLayer("IMAGE",{...t,url:r})}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?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))}isLayerLabelVisible(e){var t;const r=this.getLayer(e);return r.isLabelVisible?r.isLabelVisible():null===(t=r.options.labelVisibility)||void 0===t||t}showLayerLabel(e){this.toggleLayerLabel(e,!0)}hideLayerLabel(e){this.toggleLayerLabel(e,!1)}toggleLayerLabel(e,t){const r=this.getLayer(e);return t=null!=t?t:!this.isLayerLabelVisible(e),r&&(t?r.showLabel&&(r.options.labelVisibility=!0,r.showLabel()):r.hideLabel&&(r.options.labelVisibility=!1,r.hideLabel()),r.id&&this._emitLayerEvent("layer:label:toggle",r.id,r)),t}selectLayer(e,t){const r=this.getLayer(e);if(r){r&&r.select&&r.select(t);const e=this.getLayerId(r);e&&this._selectedLayers.push(e)}}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){const e=s;if(e.propertiesFilter)return e.propertiesFilter(t,r);e.filter&&this.filterLayer(e,(e=>!e.feature||!e.feature.properties||ie(e.feature.properties,t)))}return Promise.resolve()}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(I(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),I(t)&&this._emitLayerEvent("layer:mouseout",t,e)},e.onMouseOver=e=>{const t=e.layer.id;n&&n(e),I(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=ae(e.paint||{},this.options.paint,this.getPaintFunctions)),e.selectedPaint&&this.options.selectedPaint&&(e.selectedPaint=ae(e.selectedPaint,this.options.selectedPaint,this.getPaintFunctions)))}}function we(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 l(e,t){e.split(" ").forEach((e=>{t?r.classList.add(e):r.classList.remove(e)}))}function h(){t.addClassOn&&l(t.addClassOn,s),t.addClassOff&&l(t.addClassOff,!s)}n(),c(),t.addClass&&l(t.addClass,!0),h();const u=e=>{void 0!==e&&(s=e),c(),n(),h()},p=e=>{if(s=void 0!==e?e:!s,t.onClick){const e=t.onClick(s);Promise.resolve(e).then((()=>u())).catch((()=>s=!s))}else u()},d=e({html:r,onClick:p});return d.onClick=p,d.changeStatus=u,d}class Le extends be{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?we(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=Le.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}}Le.controls={CONTROL:(e,t)=>e.createControl(t.control,t.options),BUTTON:(e,t)=>e.createButtonControl(t),TOGGLE:(e,t)=>e.createToggleControl(t)};const Oe={};function Ie(e){return Oe[e]}class Ee extends Le{constructor(e){super(e),this._addControls(),Oe[this.id]=this}static get(e){return Ie(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")}}function Ae(){return["ZOOM","ATTRIBUTION"]}async function Ce(e){return new Ee(e).onLoad()}class Me{constructor(e={}){var t;this.cache=[];const r=null!==(t=e.namespace)&&void 0!==t?t:"default";return Me.instance[r]?Me.instance[r]:(Me.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(B(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 F(e.props||e.options||{},B(r))}return!0}return!1}}Me.instance={};var ke=Me;class Pe extends Error{constructor(e){super(),this.name="NetworkError",Object.setPrototypeOf(this,Pe.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}class xe extends Error{constructor(e){super(),this.name="NgwError",Object.assign(this,e),Object.setPrototypeOf(this,xe.prototype)}}function Se(e){return"[object Object]"===Object.prototype.toString.call(e)}let Ne;Ne=(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 xe(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 Pe(e):t)},o.upload.onprogress=function(e){if(e.lengthComputable){r.onProgress&&r.onProgress(e.loaded/e.total*100,e)}};const a=r.headers;if(a)for(const l in a){const e=a[l];"string"==typeof e&&o.setRequestHeader(l,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 l in r.data)c.append(l,c[l])}else c=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;i&&i((()=>{o.abort()})),o.send(c)};const Te=/\{ *([\w_-]+) *\}/g;function Fe(e,t){return e.replace(Te,((e,r)=>{let s=t[r];if(void 0===s)throw new Error("No value provided for letiable "+e);return"function"==typeof s&&(s=s(t)),s}))}class Be extends xe{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,Be.prototype)}}class Re extends xe{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,Re.prototype)}}const je=[];function $e(e){je.push(e)}const qe=["description"];function Ve(e,t=""){t=t?t+"__":"";const r={};for(const[s,i]of Object.entries(e))if(-1===qe.indexOf(s))if(Se(i))if("owner_user"===s){const e=Ve(i,s);Object.assign(r,e)}else"parent"===s&&"id"in i&&(r.parent_id=i.id);else I(i)&&(r[t+s]=i);return r}class De{constructor(e){this.connector=e,this.cache=new ke}getOne(e,t){const r=new ke,s={},i={...t,cache:!1};"string"==typeof e?s.keyname=e:"number"==typeof e?s.id=e:Se(e)&&(void 0!==e.id?s.id=e.id:e.keyname&&(s.keyname=e.keyname));return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},i):"number"==typeof e?this._fetchResourceById(e,i):Se(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 Be}))}getId(e,t){return"number"==typeof e?L.resolve(e):"string"==typeof e||Se(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,Ve(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.getIdOrFail(e).then((e=>this._getChildrenOf(e,t)))}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)}))}))}_getChildrenOf(e,t,r=[]){return this.connector.get("resource.collection",{cache:!0,...t},{parent:e}).then((e=>{const s=[];for(const i of e)this.cache.add("resource.item",L.resolve(i),{id:i.resource.id}),r.push(i),(null==t?void 0:t.recursive)&&i.resource.children&&s.push(this._getChildrenOf(i.resource.id,t,r));return s.length?L.all(s).then((()=>r)):r}))}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 Be))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return L.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:I(e.id)&&I(t.resource.id)?e.id===t.resource.id:F(e,t.resource)})),[])))}}let Ue=0;class ze{constructor(e){this.options=e,this.id=Ue++,this.emitter=new t.exports.EventEmitter,this.routeStr="/api/component/pyramid/route",this.activeRequests=[];const r=function(e){return je.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return F(t.options.auth,e.auth)}}))}(e);if(r)return r;this.options.route&&(this.routeStr=this.options.route),this.options.requestTransform&&(this.requestTransform=this.options.requestTransform),this.resources=new De(this),$e(this)}static create(e){return new this(e)}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,$e(this)}connect(){const e=new ke,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._login({login:e,password:i}).then((()=>s())).catch((e=>r(e)))}return s()}))),{id:this.id,auth:t,baseUrl:this.options.baseUrl})}login(e,t){return this.logout(),$e(this),this._login(e,t)}logout(){this.abort(),function(e){const t=je.indexOf(e);-1!==t&&je.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()}getUserInfo(e,t){if(this.user&&this.user.id)return L.resolve(this.user);e&&(this.options.auth=e);const r={headers:this.getAuthorizationHeaders(e),...t};return this.makeQuery("/api/component/auth/current_user",{},r)}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)}}abort(){for(const e of this.activeRequests)e.cancel();this.activeRequests=[]}getActiveApiRequests(){return[...this.activeRequests]}apiRequest(e,t={},r={}){var s;const{method:i,headers:o,withCredentials:n,responseType:a}=r,c=B(t),l=()=>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=Fe(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:c,requestOptions:r,connector:this});if(r.cache&&"GET"===i){return(new ke).add(e,l,{params:c,...B({headers:o,withCredentials:n,responseType:a,baseUrl:this.options.baseUrl,userId:null===(s=this.user)||void 0===s?void 0:s.id})})}return l()}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=Fe(e,t)),e=encodeURI(j(e)),this._loadData(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){t.responseType=t.responseType||"json";const r=new L(((r,s,i)=>{if(this.user&&((t=t||{}).headers={...this.getAuthorizationHeaders(),...t.headers}),this.requestTransform){const[r,s]=this.requestTransform(e,t);e=r,t=s}Ne(e,r,t,s,i)})).then((e=>(this._cleanActiveRequests(r),e))).catch((e=>{if(this._cleanActiveRequests(r),e instanceof L.CancelError);else{const t=this._handleHttpError(e);if(t)throw t}}));return t.signal&&"function"==typeof t.signal.addEventListener&&t.signal.addEventListener("abort",(()=>{r.cancel(),this._cleanActiveRequests(r)})),this.activeRequests.push(r),r}_login(e,t){return this.getUserInfo(e,t).then((e=>(this.user=e,this.emitter.emit("login",e),e))).catch((e=>{throw this.emitter.emit("login:error",e),e}))}_cleanActiveRequests(e){const t=this.activeRequests.indexOf(e);-1!==t&&this.activeRequests.splice(t,1)}_handleHttpError(e){if(e&&e instanceof xe){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new Be(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new Re(e)}return e}}ze.errors={NgwError:xe,ResourceNotFoundError:Be};var Ge=ze;function Ze(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 We({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 He(e){return e.connector.getResource(e.resourceId).then((t=>{if(t)return Je(t,e.connector,e)}))}function Je(e,t,r){if(e.webmap)return L.resolve(Ze(e.webmap));{const s=e.resource;return s.cls&&-1!==s.cls.indexOf("style")?t.getResource(s.parent.id).then((e=>{if(e)return We({...r,resourceId:e.resource.id,connector:t})})):We({...r,resourceId:s.id,connector:t})}}class Qe{async getExtent(){return this.getBounds()}async getBounds(e){return this._extent?this._extent:this.item?(this._extent=await Je(this.item,this.connector,e),this._extent):void 0}}const Ke=["fields","intersects","limit","orderBy","strategy"];function Xe(e){const t={};return Ke.forEach((r=>{const s=e[r];void 0!==s&&(t[r]=s)})),t}async function Ye(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 Ye(r,t)),!o&&i){const e=await t.getResource(i);e&&(o=e.resource.id)}return o}const et={srs:4326,geom_format:"geojson"};function tt(e){return{geometry:e.geom,id:e.id,type:"Feature",properties:e.fields}}function rt(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)),I(o)&&(e.srs=o)}function st(e){const t=ot(e);return L.all(t).then((t=>{const r=[],s=[];for(const e of t)for(const t of e)r.includes(t.id)||(s.push(t),r.push(t.id));return e.offset||e.limit?s.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:s.length):s}))}function it(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]}function ot(e,t=[],r=[]){const{filters:s}=e,i="string"==typeof s[0]?s[0]:"all",o=s.filter((e=>Array.isArray(e)));if("any"===i)for(const n of o)se(n)?t.push(at({...e,paramList:[...r,it(n)]})):ot({...e,filters:n},t,[...r]);else if("all"===i){const s=[],i=[];for(const e of o)se(e)?s.push(it(e)):i.push(e);if(i.length)for(const o of i)ot({...e,filters:o},t,[...r,...s]);else t.push(at({...e,paramList:[...r,...s]}))}return t}function nt(e){return`POLYGON((${e.map((([e,t])=>{const[r,s]=N(e,t).map((e=>function(e,t){const r=t?Number("1e+"+t):1;return Math.round((e+Number.EPSILON)*r)/r}(e)));return r+" "+s})).join(", ")}))`}function at(e){const t={...et},{limit:r,cache:s,signal:i,offset:o,orderBy:n,paramList:a,connector:c,geomFormat:l,intersects:h,resourceId:u}=e;if(r?r!==Number.POSITIVE_INFINITY&&(t.limit=r):t.limit=7e3,o&&(t.offset=o),l&&(t.geom_format=l),rt(t,e),n&&(t.order_by=n.join(",")),Array.isArray(h)){const e=function(e){return Array.isArray(e)&&4===e.length&&e.every((e=>"number"==typeof e))}(h)?P(h):h;t.intersects=nt(e)}else"string"==typeof h&&(t.intersects=h);a&&(t.paramList=a);const p={id:u,...t};return c.get("feature_layer.feature.collection",{cache:s,signal:i},p)}function ct(e){let t;for(t in e){const r=e[t];if(R(r)){const s=r;if(I(s.year)&&I(s.month)&&I(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()}}else"id"===t&&"string"==typeof r&&(e[t]=r.split(",").map(Number))}return e}function lt(e){const t=e.filters;return t?st({...e,filters:t}).then((r=>{var s;return(null!==(s=e.clientFilterValidate)&&void 0!==s?s:ht(t))&&(r=r.filter((e=>ie(ct({...e.fields,id:e.id}),t)))),r})):at(e)}function ht(e){if("any"===e[0])return!0;for(let t=1;t<e.length;t++){const r=e[t];if("[object Array]"===Object.prototype.toString.call(r)){if(ht(r))return!0}}return!1}function ut(e){return function(e){return lt(e).then((e=>{const t=[];return e.forEach((e=>{t.push(tt(e))})),t}))}(e).then((e=>({type:"FeatureCollection",features:e})))}async function pt(e){var r,s;const{item:i,webMap:o,Adapter:n,connector:a,layerOptions:c,addLayerOptionsPriority:l}=e,h=null==l||l,u=c,p=n||o.mapAdapter.layerAdapters.GEOJSON,d=[];let f,y,m=!1;const g=await Ye(u,a);(null===(s=null===(r=u.adapterOptions)||void 0===r?void 0:r.popupOptions)||void 0===s?void 0:s.fromProperties)&&(u.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)=>(b(),f={filters:e,options:t},y=ut({resourceId:g,filters:e,connector:a,cache:!0,...t}),await y);let v=!1;const b=()=>{y&&(y.cancel(),y=void 0)};return class extends p{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!==u.id&&(e.id=u.id),i&&i.vector_layer&&(e.type=Dt[i.vector_layer.geometry_type]),u.adapterOptions&&(e=h?{...u.adapterOptions,...e}:{...e,...u.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 f={filters:e.propertiesFilter,options:Xe(e)},t&&(n=this.updateLayer()),r&&n&&await n,s&&s.startsWith("BBOX")&&!m&&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?He({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,b()}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||f||{},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(m)return}}if(!v){try{this.emitter.emit("preupdate",e),o._emitLayerEvent("layer:preupdate",u.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));m=void 0!==s&&d.length>=s,await o.addLayerData(this,r)}else m=void 0!==s&&t.features.length>=s,await o.setLayerData(this,t);this.emitter.emit("updated",t),o._emitLayerEvent("layer:updated",u.id||"",{data:t,newData:r,isFull:m})}catch(r){if(r instanceof Error&&"CancelError"!==r.name)throw r}super.updateLayer&&super.updateLayer()}}async propertiesFilter(e,t){if(b(),this.filter&&m)this.filter((t=>{const r=t.feature&&t.feature.properties&&ct({...t.feature.properties});return!r||ie(r,e)}));else if(this.setData){this.clearLayer&&this.clearLayer();const r=await _(e,{...t,srs:this.options.srs});this.setData(r)}}removeFilter(){f=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=b,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 dt({options:e,webMap:t,baseUrl:r}){var s;let i,o=e.adapter||"IMAGE";const n=t&&t.getLayerAdapters(),a=e.resource,c=e.tileNoData?e.tileNoData:200;if("number"==typeof a){if("IMAGE"===o){if(!n||n.IMAGE)return function({resourceId:e,baseUrl:t,nd:r,headers:s}){const i=t+"/api/component/render/image",o={resource:e};return r&&(o.nd=r),{url:i,resourceId:e,headers:s,params:o,updateWmsParams:t=>(r&&(t.nd=r),Vt(t,e))}}({resourceId:a,headers:e.headers,nd:c,baseUrl:r});o="TILE"}if("WMS"===o){i=`${r}/api/resource/${a}/wms`;const t=e.adapterOptions;return{url:i,format:"image/png",version:"1.1.1",layers:t&&t.layers,headers:e.headers}}if("MVT"===o)return i=r+"/api/component/feature_layer/mvt?x={x}&y={y}&z={z}&resource="+a+"&simplification="+(null!==(s=e.simplification)&&void 0!==s?s:6),{url:i,sourceLayer:"ngw:"+a,featureIdName:"$id"};if("TERRAIN"===o)return i=r+`/api/resource/${a}/terrain_provider`,{url:i,adapter:o};if("MODEL_3D"===o)return i=r+`/api/component/model_3d/${a}/data.glb`,{url:i};if("TILE"===o)return i=r+"/api/component/render/tile?z={z}&x={x}&y={y}&resource="+a+"&nd="+c,{url:i,adapter:o}}else{if(void 0!==a)throw new Error("Option `resource` must be number, not "+typeof a);console.log("Option `resource` not set")}}async function ft({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 Ye(e,r);return class extends n{constructor(o,n){super(o,n),this.map=o,this.item=s,this.resourceId=i;const a=dt({options:e,webMap:t,baseUrl:r.options.baseUrl||""});if(a){const t={...a,...e.adapterOptions,params:{resource:i},layers:a.layers||String(i),resourceId:i};e.adapterOptions&&I(e.adapterOptions.setViewDelay)&&(t.setViewDelay=e.adapterOptions.setViewDelay),this.options={...this.options,...t}}}addLayer(e){return super.addLayer({...this.options,...e})}async getIdentificationIds(){if(this.item){if("MVT"===o)return[this.item.resource.id];const e=this.item.resource.parent.id;if(I(e))return[e]}return[]}}}throw new Error(o+" not supported yet. Only TILE")}function yt(e,t,r,s){return!!_t(e,t,r,vt,s)}function mt(e,t,r,s){return _t(e,t,r,bt,s)}function gt(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 _t(e,t=(e=>!!e),r="children",s,i){const o="function"==typeof t?t:e=>ie(e,t);return s(e,i?e=>o(i(e)):o,r)}function vt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(t(e))return e;const s=gt(e,r);s&&(i=s)}for(let o=0;o<i.length;o++)if(i[o]){const e=vt(i[o],t,r,s);if(e)return e}}function bt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{t(e)&&s.push(e);const o=gt(e,r);o&&(i=o)}for(let o=0;o<i.length;o++)i[o]&&bt(i[o],t,r,s);return s}function wt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(!t(e))return!1;const s=gt(e,r);s&&(i=s)}for(let o=0;o<i.length;o++)if(i[o]){if(!wt(i[o],t,r,s))return!1}return!0}class Lt{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?mt(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 _t(this._children,e,(e=>e.tree.getChildren()),vt,t);var t}every(e){return!!_t(this._children,e,(e=>e.tree.getChildren()),wt,t);var t}some(e){return yt(this._children,e,(e=>e.tree.getChildren()))}all(e){return this.getDescendants(e)}getDescendants(e){return mt(this._children,e,(e=>e.tree.getChildren()))}getChildren(){return[...this._children]}}class Ot{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)return this._blocked;const e=this.item.tree.getParents();return this._blocked=this._calculateBlockedStatus(e),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})}))}}_calculateBlockedStatus(e){return e.some((e=>{var t;const r=null===(t=e.properties)||void 0===t?void 0:t.property(this.name);return!!r&&!r.get()}))}}class It extends Ot{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 Et{constructor(e,t){this.item=e,this.options={},this._properties={},this._propertiesList=[],t&&t.forEach(this._setPropertyHandler.bind(this))}add(e){this._setPropertyHandler(e)}update(){this.list().forEach((e=>e.update()))}get(e){const t=this.property(e);return t?t.get():void 0}set(e,t,r){const s=this.property(e);s&&s.getValue()!==t&&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=[]}_setPropertyHandler(e){const t=this._getHandler(e);if(t&&e.name){const r={...e};this._properties[e.name]=new t(e.name,this.item,r),this._propertiesList.push(e.name)}}_getHandler(e){const t=e.handler;return!t&&e.type?"boolean"===e.type?Et.handlers.CheckProperty:Et.handlers.BaseProperty:t}}Et.handlers={CheckProperty:It};let At=0;class Ct{constructor(e){this.options={},this.id=At,At+=1,this.options={...e},this.tree=new Lt(this)}initProperties(){this.properties=new Et(this,this.options.properties)}}class Mt extends Ct{constructor(e,r,s,i,o,n){if(super({...Mt.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 Mt(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){if(e.children&&e.children.length){const t=this.getChildren(e);for(const e of t){const t=new this.constructor(this.webMap,e,this.options,this.connector,this);this.tree.addChild(t)}}return Promise.resolve()}{let t;if("layer"===e.item_type)t=e.adapter||e.layer_adapter.toUpperCase();else if(Mt.GetAdapterFromLayerType[e.item_type]){t=(0,Mt.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,item:this.item}};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(this.options.popupOptions&&(s.popupOptions=this.options.popupOptions),"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===Ut){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),Ut=t}return Ut}()*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 kt({webMap:e,connector:t,item:r,adapterOptions:s={},idPrefix:i="first-show-adapter"}){const o=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:()=>qt({resource:r.resource_id,adapterOptions:{name:r.display_name,opacity:r.opacity}},e,t)});return o}Mt.GetAdapterFromLayerType={},Mt.options={properties:[{type:"boolean",name:"visibility",getProperty(e){if(e){if("group"===e.item.item_type||"root"===e.item.item_type)return yt(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 Ot{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 Pt{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(tt(this.item)):Wt({resourceId:this.resourceId,featureId:this.item.id,connector:this.options.connector,geom:!0,fields:null,extensions:null}).then((e=>(this.item.geom=e.geom,tt(this.item))))}}class xt{constructor(e,r){this.map=e,this.options=r,this.NgwWebmapItem=Mt,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}),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 Ze(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 lt({connector:t,resourceId:e,geom:!1,fields:o?[o]:void 0}).then((r=>{const s=[];for(const i of r){const r=new Pt({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,r.popupOptions=this.options.popupOptions;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)kt({webMap:t,connector:this.options.connector,item:s,adapterOptions:{crossOrigin:this.options.crossOrigin}}).then((e=>{const i=!r&&s.enabled;return s.enabled&&(r=!0),t.addBaseLayer(e,{id:Zt+s.resource_id,name:s.display_name,opacity:s.opacity,visibility:i}).then((e=>{e.id&&this._webmapBaselayersIds.push(e.id)}))}))}_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=j(this.options.connector.options.baseUrl+"/api/component/render/image"),s=e.layer_style_id;e.url=r,e.resourceId=s,e.updateWmsParams=e=>Vt(e,s);const i=dt({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=[];for(const e of t){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))}}}const St={tms:"TILE"};function Nt(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 Tt="https://qms.nextgis.com";function Ft(e,t=Tt,r={}){let s;if("webMap"in e){const{webMap:i,url:o,...n}=e;s=i,o&&(t=o),n&&(r=n)}else s=e;t||(t=Tt);class i{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(e){if(!this.qms&&e.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",j(e),!0),s.send()}))}(t+"/api/v1/geoservices/"+e.qmsId)}catch(a){console.error(a)}const r=this.qms;if(r){const t=St[r.type||"tms"],a=s.mapAdapter.layerAdapters[t];if(a&&(o=i,n=a,["showLayer","hideLayer"].forEach((e=>{const t=Object.getOwnPropertyDescriptor(n.prototype,e);t&&Object.defineProperty(o.prototype,e,t)})),"TILE"===t)){if(e={order:0,maxZoom:s.options.maxZoom,minZoom:s.options.minZoom,...this.options,...Nt(r)},r.origin_url){const[t,s]=function(e){const t=[];return[e=e.replace(/{switch:(.*?)}/,((e,r)=>("string"==typeof r&&r.split(",").forEach((e=>t.push(e))),"{s}"))),t]}(r.origin_url);s.length&&(e.subdomains=s,e.url=t)}this.options=e;return new a(this.map,e).addLayer(e)}}var o,n}}return i}class Bt{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 Ft({webMap:e,url:this.url})}}Bt.utils={createQmsAdapter:Ft};const Rt={},jt=["mapserver_style","qgis_vector_style","qgis_raster_style","wmsserver_service","raster_style","basemap_layer","vector_layer","raster_layer","postgis_layer","webmap","tmsclient_layer"];async function $t({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.id,o=await r.getResourceChildren(i),n=o&&o[0];if(n)return qt({...e,resource:n.resource.id},t,r)}async function qt(e,t,r){let s,i;const o=e.adapter,n=await Ye(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!==jt.indexOf(a))if("webmap"===a)s=async function({layerOptions:e,webMap:t,connector:r}){const s=await Ye(e,r);return class extends xt{constructor(e){super(e,{url:"",webMap:t,resourceId:s,connector:r})}}}(c);else if("vector_layer"===a||"postgis_layer"===a){const t=c.layerOptions.adapterOptions||{};if(t.type=t.type||i.vector_layer&&Dt[i.vector_layer.geometry_type],c.layerOptions.adapterOptions=t,e.adapterOptions=c,void 0!==o&&"GEOJSON"!==o){if("MVT"!==o)return $t(c);s=ft(c)}else s=pt(c)}else{if("raster_layer"===a)return $t(c);if("basemap_layer"===a)s=async function({webMap:e,item:t}){if(t.basemap_layer){const r=t.basemap_layer.qms,s=t.basemap_layer.url;if(r){const t=JSON.parse(r);return Promise.resolve(Bt.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=pt({...c,item:t,layerOptions:r})}}else s=ft(c)}else{if(!Rt[a])throw`Resource class '${a}' not yet supported.`;{const e=Rt[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,[Qe],{replace:!1}),t}}))}function Vt(e,t){const{bbox:r,width:s,height:i,nd:o}=e;return{resource:Array.isArray(t)?t.join(","):t,extent:r,size:s+","+i,timestamp:Date.now(),nd:null!=o?o:200}}const Dt={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 Ut;class zt{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 Ge({baseUrl:this.url,auth:this.options.auth})}}static addClassAdapters(e,t){Rt[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(xt,{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 xt{constructor(e,r){super(e,r={...t,...r})}};var t}}class Gt{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):Wt({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 Zt="webmap-baselayer";function Wt(e){const t={...et};rt(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(tt(t)):Wt({...e,geom:!0,fields:null,extensions:null}).then((e=>{const r=e.geom;return tt({...t,geom:r})}))})))}function Ht(e){return Wt(e).then((e=>tt(e)))}function Jt(e,t=!1){const r=[],s=[];for(const o in e){const e=Number(o);isNaN(e)||r.push(e)}const i=e.resources;i&&r.sort(((e,t)=>i.indexOf(e)-i.indexOf(t)));for(let o=0;o<r.length;o++){const i=r[o],n=e[i];if("features"in n){const e=Qt(n.features,Number(i),t);if(e.length&&(s.push(...e),!t))break}}return s}function Qt(e,t,r){const s=[];for(const i of e){if(s.push({featureId:i.id,resourceId:t,feature:i}),!r)break}return s}function Kt(e,t){C(e);const[r,s]=e.lngLat,{geom:i,radius:o,signal:n,cache:a}=t,c=null!=i?i:function(e,t,r=10,s=6){const i=r/M*S,o=i/Math.cos(t*x),n=[];for(let a=0;a<s+1;a++){const r=Math.PI*(a/(s/2)),c=e+o*Math.cos(r),l=t+i*Math.sin(r);n.push([c,l])}return n}(r,s,o);return function(e){const{geom:t,signal:r,cache:s}=e;let i=[];if(Array.isArray(t))i=t;else{const e="Feature"===t.type?t.geometry:"Polygon"===t.type&&t;e&&(i=e.coordinates[0])}if(i){const t=[];for(const[e,r]of i){const[s,i]=N(e,r);t.push(s+" "+i)}const o=`POLYGON((${t.join(", ")}))`;return e.connector.post("feature_layer.identify",{data:{geom:o,srs:3857,layers:e.layers},signal:r,cache:s})}throw new Error("Not valid geometry format to make intersection")}({...t,geom:c,signal:n,cache:a})}const Xt={brill:'<path d="m6 0-5 6 5 6 5-6z"/>',circle:'<circle cx="6" cy="6" r="6"/>',rect:'<rect width="12" height="12"/>',marker:'<path d="m6 0c-1.85 0-4 1.19-4 4.22 0 2.05 3.08 6.59 4 7.78 0.821-1.19 4-5.62 4-7.78 0-3.03-2.15-4.22-4-4.22z"/>',cross:'<path d="M 2.4,12 6,8.4 9.6,12 12,9.6 8.4,6 12,2.4 9.6,0 6,3.6 2.4,0 0,2.4 3.6,6 0,9.6 Z"/>',star:'<path d="m6 0.25 1.71 4.18 4.29-1.04e-4 -3.43 3.14 0.857 4.18-3.43-3.14-3.43 3.14 0.857-4.18-3.43-3.14 4.29-0.209z"/>',triangle:'<path d="m12 11.7h-12l6-11.2z"/>',plus:'<path d="m7.5 12v-4.5h4.5v-3h-4.5v-4.5h-3v4.5h-4.5v3h4.5v4.5z"/>',minus:'<path d="m12 7.5v-3h-12v3z"/>',asterisk:'<path d="m7.59 12v-3.27l2.83 1.64 1.58-2.74-2.85-1.64 2.83-1.64-1.56-2.74-2.83 1.64v-3.24h-3.17v3.24l-2.85-1.64-1.57 2.74 2.84 1.64-2.84 1.64 1.57 2.74 2.85-1.64v3.27z"/>'};function Yt(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 er={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 tr extends Ee{constructor(e){super(function(e){const t=[new Bt];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new Ge({baseUrl:e.baseUrl||"",auth:e.auth}),(e=A(er,e)).center||e.bounds||(e.bounds=[-179,-90,180,90]),e.connector&&t.push(new zt({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(I(this.options.baseUrl))try{I(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},I(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=function(e,t,r){const s=r.getAuthorizationHeaders();return s&&(e.headers=s),qt(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 Wt({connector:this.connector,...e})}fetchNgwLayerItems(e){return lt({connector:this.connector,...e})}fetchNgwLayerFeature(e){return Ht({connector:this.connector,...e})}fetchNgwLayerFeatures(e){return ut({connector:this.connector,...e})}fetchIdentifyItem(e,t){const r=function(e){const{connector:t,identify:r}=e,s=Jt(r);return s&&s.length?Wt({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,requestOptions:s}=e;for(const o in r){const e=Number(o);if(!isNaN(e)){const e=r[o];if("features"in e){const t=e.features.find((e=>e.geom));if(t&&t.geom){const e=t.geom;return L.resolve(tt({...t,geom:e}))}}}}const i=Jt(r);return i&&i.length?Ht({...s,connector:t,...i[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&&He({resourceId:e.resource.id,connector:this.connector}).then((e=>{e&&this.fitBounds(e,t)}))}else super.fitLayer("number"==typeof e?String(e):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._getSelectListenersCount()&&this.selectFromNgwRaster(e)},this.$$selectFromNgwVector=e=>{this._getSelectListenersCount()&&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.$$selectFromNgwRaster=void 0),this.$$selectFromNgwVector&&(this.emitter.removeListener("layer:click",this.$$selectFromNgwVector),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]=[])}))}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));for(const u of r){const e=u.layer,r="function"==typeof e.getIdentificationIds&&e.getIdentificationIds;r&&e.options.selectable&&this.isLayerVisible(e)&&t.push(r.call(e))}const s=Promise.all(t),i=await s,o=[];for(const u of i)u&&o.push(...u);if(!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 l=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),h=Kt(e,{layers:o,connector:this.connector,radius:l}).then((t=>{const r={...t,resources:o,sourceType:"raster",event:e},s=this._prepareToIdentify(r);return this._emitStatusEvent("ngw:select",s),s}));return this._addPromise("select",h),h}_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&&Yt(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),Yt(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;if(!(t.options.selectable&&this.isLayerVisible(t)))return;const 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}}}_prepareToIdentify(e){return{...e,getIdentifyItems:()=>Jt(e,!0).map((e=>new Gt({feature:e.feature,connector:this.connector})))}}_getSelectListenersCount(){return this.emitter.listenerCount("ngw:select")}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 rr(e){return new tr(e).onLoad()}tr.getIcon=function(e={}){var t,r,s,i;const o=null!==(t=e.shape)&&void 0!==t?t:"circle",n=null!==(r=e.color)&&void 0!==r?r:"blue",a=null!==(s=e.strokeColor)&&void 0!==s?s:"white",c=null!==(i=e.size)&&void 0!==i?i:12,l=c/2,h="number"==typeof e.stroke?e.stroke:.8,u=c/12,p=e.p||Xt[o]||"circle",d="string"==typeof p?p:p(e),f=function(e){return(new DOMParser).parseFromString(e,"image/svg+xml").documentElement}(e.svg||function(e,t,r=0,s){const i=r/2;return`<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>`}(c,c,h*u,d)),y=f.firstChild,m=`scale(${u})`;return y.setAttribute("fill",n),h&&(y.setAttribute("stroke",a),y.setAttribute("stroke-width",String(h))),y.setAttribute("transform",m),{type:"icon",iconSize:[c,c],iconAnchor:[l,l],html:(new XMLSerializer).serializeToString(f),svg:f}};export{tr as NgwMap,Ee as WebMap,Le as WebMapControls,be as WebMapLayers,ve as WebMapMain,rr as createNgwMap,we as createToggleControl,Ce as createWebMap,le as detectGeometryType,ce as findMostFrequentGeomType,Ae as getDefaultControls,Ie as getWebMap,pe as updateGeoJsonAdapterOptions};
|
|
1
|
+
var e,t={exports:{}},r="object"==typeof Reflect?Reflect:null,s=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function n(){n.init.call(this)}t.exports=n,t.exports.once=function(e,t){return new Promise((function(r,s){function i(r){e.removeListener(t,n),s(r)}function n(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}y(e,t,n,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&y(e,"error",t,r)}(e,i,{once:!0})}))},n.EventEmitter=n,n.prototype._events=void 0,n.prototype._eventsCount=0,n.prototype._maxListeners=void 0;var o=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?n.defaultMaxListeners:e._maxListeners}function l(e,t,r,s){var i,n,o,l;if(a(r),void 0===(n=e._events)?(n=e._events=Object.create(null),e._eventsCount=0):(void 0!==n.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),n=e._events),o=n[t]),void 0===o)o=n[t]=r,++e._eventsCount;else if("function"==typeof o?o=n[t]=s?[r,o]:[o,r]:s?o.unshift(r):o.push(r),(i=c(e))>0&&o.length>i&&!o.warned){o.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=o.length,l=h,console&&console.warn&&console.warn(l)}return e}function h(){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 u(e,t,r){var s={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=h.bind(s);return i.listener=r,s.wrapFn=i,i}function p(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):f(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 f(e,t){for(var r=new Array(t),s=0;s<t;++s)r[s]=e[s];return r}function y(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(n){s.once&&e.removeEventListener(t,i),r(n)}))}}Object.defineProperty(n,"defaultMaxListeners",{enumerable:!0,get:function(){return o},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+".");o=e}}),n.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},n.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},n.prototype.getMaxListeners=function(){return c(this)},n.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,n=this._events;if(void 0!==n)i=i&&void 0===n.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=n[e];if(void 0===c)return!1;if("function"==typeof c)s(c,this,t);else{var l=c.length,h=f(c,l);for(r=0;r<l;++r)s(h[r],this,t)}return!0},n.prototype.on=n.prototype.addListener=function(e,t){return l(this,e,t,!1)},n.prototype.prependListener=function(e,t){return l(this,e,t,!0)},n.prototype.once=function(e,t){return a(t),this.on(e,u(this,e,t)),this},n.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,u(this,e,t)),this},n.prototype.removeListener=function(e,t){var r,s,i,n,o;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,n=r.length-1;n>=0;n--)if(r[n]===t||r[n].listener===t){o=r[n].listener,i=n;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,o||t)}return this},n.prototype.off=n.prototype.removeListener,n.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,n=Object.keys(r);for(s=0;s<n.length;++s)"removeListener"!==(i=n[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},n.prototype.listeners=function(e){return p(this,e,!0)},n.prototype.rawListeners=function(e){return p(this,e,!1)},n.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},n.prototype.listenerCount=d,n.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]};class m extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,m.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,n){const o=n.value;return e=e||i,n.value=function(...s){const i=t(e);if(i)return i;return r(o.apply(this,s),e)},n}}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 b=0;class w{constructor(e,t){this.id=b++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise(((e,t)=>{this._setCanceledCallback=t=>e(t||new m)}));const r=[this._cancelPromise,new Promise(((t,r)=>e((e=>{e instanceof w?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 w((t=>t(e)))}static reject(e){return new w(((t,r)=>r(e)))}static all(e){return new w(((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 w(((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 m),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new m: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}}w.CancelError=m,w.TimeoutError=_,w.PromiseControl=g,Object.setPrototypeOf(w.prototype,Promise.prototype);var L=w;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 n=-1!==s.indexOf(r);if(!i&&!n||i){const s=Object.getOwnPropertyDescriptor(t.prototype,r);s&&Object.defineProperty(e.prototype,r,s)}}))}))}function I(e){return null!=e}function E(e){return"string"==typeof e?!!e:I(e)}function A(e,t,r=!1){let s=e;const i=t,n=Array.isArray(i);let o=n&&[]||{};return n&&Array.isArray(i)?r?(s=s||[],o=o.concat(s),i.forEach(((e,t)=>{void 0===o[t]?o[t]=e:"object"==typeof e?o[t]=A(s[t],e,r):-1===s.indexOf(e)&&o.push(e)}))):o=i:(s&&"object"==typeof s&&Object.keys(s).forEach((function(e){o[e]=s[e]})),Object.keys(i).forEach((function(e){o[e]="object"==typeof i[e]&&i[e]&&"object"==typeof s[e]&&"object"==typeof i[e]?A(s[e],i[e],r):i[e]}))),o}function C(e){if(!e.lngLat&&e.latLng){e.lngLat=[e.latLng.lng,e.latLng.lat]}return e}const P=6371;function M(e){return{type:"Polygon",coordinates:[k(e)]}}function k(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}const x=Math.PI/180,S=180/Math.PI;function N(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 F(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:T(e,t));return e===t}function T(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(!F(e[r[i]],t[s[i]],e,t))return!1}return!0}function B(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]=B(e[r])})),t}function R(e){return"[object Object]"===Object.prototype.toString.call(e)}function j(e){return e.replace(/([^:]\/)\/+/g,"$1")}function $(e){return"function"==typeof e}const q=(e,t,r)=>{try{const s=e(t,r);if(void 0!==s)return s}catch{}};function V(e){return(t,r)=>{for(const s of t){const t=q(e,s,r);if(void 0!==t)return t}throw new Error("Received a mismatched type")}}const D={array:e=>{const[t,r,s]=e;let i,n,o;if("string"==typeof t&&["string","number","boolean"].includes(t)?(i=t,"number"==typeof r?(n=r,o=s):o=r):Array.isArray(t)&&(o=t),!Array.isArray(o))throw new Error("Expected an array");if(i&&!o.every((e=>typeof e===i)))throw new Error(`Expected all items in array to be of type ${i}`);if(n&&o.length!==n)throw new Error(`Expected array of length ${n}`);return o},boolean:V((e=>"boolean"==typeof e?e:void 0)),literal:([e])=>e,number:V((e=>"number"==typeof e?e:void 0)),object:V((e=>null===e||"object"!=typeof e||Array.isArray(e)?void 0:e)),string:V((e=>"string"==typeof e?e:void 0)),"to-boolean":V(Boolean),"to-number":V(Number),"to-string":V(String),typeof:([e])=>typeof e};const U={get:function([e,t],r){const s=t||r;return s&&"object"==typeof s&&e in s?s[e]:null},length:([e])=>{if("string"==typeof e||Array.isArray(e))return e.length},at:function([e,t]){return t[e]},has:function([e,t],r){const s=t||r;return!(!s||"object"!=typeof s||!(e in s))},in:function([e,t]){if("string"==typeof t)return t.includes(String(e));if(Array.isArray(t))return t.includes(e);throw new Error(`Invalid input type for 'in'. Expected string or array, got ${typeof t}.`)},"index-of":function([e,t,r]){if("string"==typeof t)return t.indexOf(String(e),r);if(Array.isArray(t))return t.indexOf(e,r);throw new Error(`Invalid input type for 'index-of'. Expected string or array, got ${typeof t}.`)},slice:function(e){const[t,r,s]=e;if("string"==typeof t)return t.slice(r,s);if(Array.isArray(t))return t.slice(r,s);throw new Error(`Invalid input type for 'slice'. Expected string or array, got ${typeof t}.`)}};const z=([e,t])=>{if(typeof e!=typeof t)throw new Error("Values have different types.")};const G={"!":function([e]){return!e},"!=":function([e,t]){return z([e,t]),e!==t},"<":function([e,t]){return z([e,t]),e<t},"<=":function([e,t]){return z([e,t]),e<=t},"==":function([e,t]){return z([e,t]),e===t},">":function([e,t]){return z([e,t]),e>t},">=":function([e,t]){return z([e,t]),e>=t},all:function(e){for(let t=0;t<e.length;t++){if(!e[t])return!1}return!0},any:function(e){for(let t=0;t<e.length;t++){if(e[t])return!0}return!1},case:function(e){if(e.length<2)throw new Error('The "case" function requires at least a condition and a corresponding output.');const t=e[e.length-1];if(e.length%2==0)throw new Error("Missing a fallback value or unmatched condition-output pair.");for(let r=0;r<e.length-1;r+=2){if(e[r])return e[r+1]}return t},match:function(e){const[t,...r]=e,s=r.splice(-1,r.length%2)[0];for(let i=0;i<r.length-1;i+=2){if(r[i]===t)return r[i+1]}return s}};const Z={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function W(e){if("string"==typeof(r=e)&&/^#([A-Fa-f0-9]{3}){1,2}$/.test(r))return H(e);if("string"==typeof(t=e)&&t in Z)return function(e){return H(Z[e])}(e);if(function(e){return"string"==typeof e&&/^rgb(a?)\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)(?:\s*,\s*([01](?:\.\d+)?))?\s*\)$/.test(e)}(e))return function(e){const t=/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)$/;let r;if(r=e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/))return[parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3],10)];if(r=e.match(t))return[parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3],10),parseFloat(r[4])];throw new Error(`The '${e}' Is not valid rgb`)}(e);if(function(e){if("object"==typeof e&&null!==e)return"r"in e&&"g"in e&&"b"in e&&(!("a"in e)||"number"==typeof e.a&&e.a>=0&&e.a<=1);return!1}(e))return function({r:e,g:t,b:r,a:s}){return[e,t,r,...void 0!==s?[s]:[]]}(e);var t,r;throw new Error(`The '${e}' cannot be converted to color`)}function H(e){let t;if(t=/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/.exec(e))return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16)];if(t=/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/.exec(e))return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16),parseInt(t[4]+t[4],16)/255];if(t=/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/.exec(e))return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)];if(t=/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/.exec(e))return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16)/255];throw new Error(`The '${e}' Is not valid hex`)}function J(e,t,r,s,i){if("number"==typeof r&&"number"==typeof i)return r+(e-t)/(s-t)*(i-r);try{const n=W(r),o=W(i);return function(e){return`rgb(${e.join(",")})`}(n.map(((r,i)=>Math.ceil(J(e,t,r,s,o[i])))))}catch(n){console.log(n)}throw new Error("Unsupported output type for linear interpolation.")}function Q(e){if(Array.isArray(e)){const[t,...r]=e;return"string"==typeof t&&"literal"!==t&&t in K&&r.length>0}return!1}const K={...{"+":e=>e.reduce(((e,t)=>e+t),0),"-":e=>e.reduce(((e,t)=>e-t)),"*":e=>e.reduce(((e,t)=>e*t),1),"/":e=>e.reduce(((e,t)=>e/t)),"%":e=>e[0]%e[1],"^":e=>Math.pow(e[0],e[1]),abs:e=>Math.abs(e[0]),acos:e=>Math.acos(e[0]),asin:e=>Math.asin(e[0]),atan:e=>Math.atan(e[0]),ceil:e=>Math.ceil(e[0]),cos:e=>Math.cos(e[0]),e:()=>Math.E,floor:e=>Math.floor(e[0]),ln:e=>Math.log(e[0]),ln2:()=>Math.LN2,log10:e=>Math.log10(e[0]),log2:e=>Math.log2(e[0]),max:e=>Math.max(...e),min:e=>Math.min(...e),pi:()=>Math.PI,round:e=>Math.round(e[0]),sin:e=>Math.sin(e[0]),sqrt:e=>Math.sqrt(e[0]),tan:e=>Math.tan(e[0])},...D,...{concat:e=>e.reduce(((e,t)=>String(e)+String(t)),""),downcase:e=>String(e[0]).toLowerCase(),upcase:e=>String(e[0]).toUpperCase()},...U,...G,...{step:function(e){const[t,r,...s]=e;if("number"!=typeof t)return r;for(let i=0;i<s.length-2;i+=2){if(t>=s[i]&&t<s[i+2])return s[i+1]}return t>=s[s.length-2]?s[s.length-1]:r},interpolate:function([e,t,...r]){if(r.length<2)throw new Error("At least two stops are required");if("number"!=typeof t)throw new Error("Input must be a number.");if(r.length<2||r.length%2!=0)throw new Error("Invalid stops provided.");for(let s=0;s<r.length-2;s+=2){const i=r[s],n=r[s+2];if(t>=i&&t<=n&&"linear"===e[0])return J(t,i,r[s+1],n,r[s+3])}throw new Error("Invalid interpolation type.")}}};function X(e,t={}){const[r,...s]=e,i=K[r];if(i)return i(s.map((e=>Q(e)?X(e,t):e)),t);throw new Error(`Expression "${r}" is not supported.`)}function Y(e){return t=>{const r=t.properties;return!!r&&X(e,r)}}const ee=["iconSize","iconAnchor"];function te(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 re={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)=>te(e,t),ilike:(e,t)=>te(e,t,!0)};function se(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function ie(e,t){const r="string"==typeof t[0]?t[0]:"all",s=t=>{if(se(t)){const[r,s,i]=t,n=re[s];if(n){if(("like"===s||"ilike"===s)&&"string"==typeof r){let t="";const s=r.replace(/^%?(\w+)%?$/,((s,n)=>(t=e[n],r.replace(n,i))));return n(t,s)}return n(e[r],i)}return!1}return ie(e,t)},i=t.filter((e=>Array.isArray(e)));return"any"===r?i.some(s):i.every(s)}function ne(e){let t={};const r=[];for(const s of e)s&&(Array.isArray(s)?r.push(s):t=s);return e=>{const s=r.find((t=>function(e,t){const r={...e.properties};return!!r&&(r.$id=e.id,ie(r,t))}(e,t[0])));return s?{...t,...s[1]}:t}}function oe({paint:e,defaultPaint:t}){const r=function(e){let t=!1;const r={};for(const s in e)if(-1===ee.indexOf(s)){const i=s,n=e[i];Q(n)&&(t=!0,r[i]=Y(n))}if(t)return t=>{const s={};for(const e in r)s[e]=r[e](t);return{...e,...s}}}(e);if(r){const s=e=>ce({paint:r(e),defaultPaint:t});return s.paint=ae({paint:e,defaultPaint:t}),s}return ae({paint:e,defaultPaint:t})}function ae({paint:e,defaultPaint:t}){var r;let s={...t};return s={...s,...e},s.fill=null===(r=s.fill)||void 0===r||r,s.stroke=void 0!==s.stroke?s.stroke:!s.fill||!(!s.strokeColor&&!s.strokeOpacity),s}function ce({paint:e,defaultPaint:t,getPaintFunctions:r}){if(!e)throw new Error("paint is empty");let s={...t};if($(e)){const s=s=>{const i=ce({paint:e(s),defaultPaint:t,getPaintFunctions:r});return i.type=e.type,i};return s.type=e.type,s}if(function(e){return!!Array.isArray(e)}(e))return s=>ce({paint:ne(e)(s),defaultPaint:t,getPaintFunctions: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=ce({paint:i,defaultPaint:t,getPaintFunctions:r}))}else{if("icon"===e.type)return e;s=oe({paint:e,defaultPaint:t})}return $(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 le(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 he(e){let t;if("FeatureCollection"===e.type){t=le(e.features.map((e=>e.geometry.type)))}else if("GeometryCollection"===e.type){t=le(e.geometries.map((e=>e.type)))}else t="Feature"===e.type?e.geometry.type:e.type;return t}const ue={polygon:"path",line:"path",point:"circle"},pe={Point:"point",LineString:"line",MultiPoint:"point",Polygon:"polygon",MultiLineString:"line",MultiPolygon:"polygon"};function de(e){if(e.data){const t=pe[he(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":ue[t]),e.type=e.type||t}return e}class fe{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 ye{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 me extends ye{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 ge extends ye{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 _e=0;const ve={minZoom:0,maxZoom:22,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 be{constructor(e){this.options=ve,this.emitter=new t.exports.EventEmitter,this.keys=be.keys,this.runtimeParams=[],this.getPaintFunctions=be.getPaintFunctions,this.mapState=[me,ge],this.id=_e++,this._initMapState={},this._mapState=[],this._eventsStatus={},this._mapEvents={},this.mapAdapter=e.mapAdapter,this._starterKits=e.starterKits||[],e&&(this.options=A(ve||{},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:M(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&&I(t)?this.mapAdapter.setView(r,t):(r&&this.mapAdapter.setCenter(r),I(t)&&this.mapAdapter.setZoom(t))}else{this.mapAdapter.setView&&this.mapAdapter.setView(e)}}fitBounds(e,t){return e.every((e=>I(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",n),this._coordFromMapClickPromise=void 0},n=t=>{i(),C(t),e(t.lngLat)};this.mapAdapter.emitter.once("click",n),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),I(e.maxzoom)&&(this.options.zoom=e.maxzoom),I(e.minzoom)&&(this.options.zoom=e.minzoom),I(e.maxzoom)&&I(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","mousemove","mouseout","mouseover"];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)}))}}be.keys=new class{constructor(){this.keyCodeAlias=new fe,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 we extends be{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 n=this._layersIdCounter++,o=I(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 l=null===(s=(t={id:String(n),order:o,...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(n),e.options.id=e.id,t.baselayer&&(e.options.order=0),e.order=null!==(i=e.options.order)&&void 0!==i?i:o,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),l&&await this.showLayer(r));const h=t.opacity;void 0!==h&&h<=1&&this.setLayerOpacity(e,h);const u=s&&(e.getBounds||e.getExtent);if(t.fit&&u){const t=await u.call(e);t&&await this.fitBounds(t)}return t.onAdded&&t.onAdded(e),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(),n=await i;return n?this.addLayer(n,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=de(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){let r;return"string"==typeof e?r=e:(r=e.url,t=e),this.addLayer("IMAGE",{...t,url:r})}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),n=void 0!==r.silent&&r.silent,o=async e=>{const t=String(e.id),r=i?"layer:show":"layer:hide";if(n||(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,n||(this._emitLayerEvent(r,t,e),this._emitLayerEvent("layer:toggle",t,e))};return s?this.onMapLoad().then((()=>o(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))}isLayerLabelVisible(e){var t;const r=this.getLayer(e);return r.isLabelVisible?r.isLabelVisible():null===(t=r.options.labelVisibility)||void 0===t||t}showLayerLabel(e){this.toggleLayerLabel(e,!0)}hideLayerLabel(e){this.toggleLayerLabel(e,!1)}toggleLayerLabel(e,t){const r=this.getLayer(e);return t=null!=t?t:!this.isLayerLabelVisible(e),r&&(t?r.showLabel&&(r.options.labelVisibility=!0,r.showLabel()):r.hideLabel&&(r.options.labelVisibility=!1,r.hideLabel()),r.id&&this._emitLayerEvent("layer:label:toggle",r.id,r)),t}selectLayer(e,t){const r=this.getLayer(e);if(r){r&&r.select&&r.select(t);const e=this.getLayerId(r);e&&this._selectedLayers.push(e)}}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){const e=s;if(e.propertiesFilter)return e.propertiesFilter(t,r);e.filter&&this.filterLayer(e,(e=>!e.feature||!e.feature.properties||ie(e.feature.properties,t)))}return Promise.resolve()}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(I(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:n,onMouseOver:o}=e,a=s||i;e.onClick=e=>(a&&a(e),this._onLayerClick(e)),e.onMouseOut=e=>{const t=e.layer.id;n&&n(e),I(t)&&this._emitLayerEvent("layer:mouseout",t,e)},e.onMouseOver=e=>{const t=e.layer.id;o&&o(e),I(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=ce({paint:e.paint||{},defaultPaint:this.options.paint,getPaintFunctions:this.getPaintFunctions})),e.selectedPaint&&this.options.selectedPaint&&(e.selectedPaint=ce({paint:e.selectedPaint,defaultPaint:this.options.selectedPaint,getPaintFunctions:this.getPaintFunctions})))}}function Le(e,t){const r=document.createElement("div");let s=!1;t.getStatus?s=t.getStatus():t.status&&(s=t.status);const i=t.title||"",n=t.html;function o(){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(){n&&("string"==typeof n||n instanceof HTMLElement?a(n):a(s?n.on:n.off),r.setAttribute("aria-label",r.title))}function l(e,t){e.split(" ").forEach((e=>{t?r.classList.add(e):r.classList.remove(e)}))}function h(){t.addClassOn&&l(t.addClassOn,s),t.addClassOff&&l(t.addClassOff,!s)}o(),c(),t.addClass&&l(t.addClass,!0),h();const u=e=>{void 0!==e&&(s=e),c(),o(),h()},p=e=>{if(s=void 0!==e?e:!s,t.onClick){const e=t.onClick(s);Promise.resolve(e).then((()=>u())).catch((()=>s=!s))}else u()},d=e({html:r,onClick:p});return d.onClick=p,d.changeStatus=u,d}class Oe extends we{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?Le(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=Oe.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}}Oe.controls={CONTROL:(e,t)=>e.createControl(t.control,t.options),BUTTON:(e,t)=>e.createButtonControl(t),TOGGLE:(e,t)=>e.createToggleControl(t)};const Ie={};function Ee(e){return Ie[e]}class Ae extends Oe{constructor(e){super(e),this._addControls(),Ie[this.id]=this}static get(e){return Ee(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")}}function Ce(){return["ZOOM","ATTRIBUTION"]}async function Pe(e){return new Ae(e).onLoad()}class Me{constructor(e={}){var t;this.cache=[];const r=null!==(t=e.namespace)&&void 0!==t?t:"default";return Me.instance[r]?Me.instance[r]:(Me.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 n=r&&JSON.parse(JSON.stringify(B(r))),o={key:e,value:i,props:n,options:n};return s&&!E(i)?i:(this.cache.push(o),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 T(e.props||e.options||{},B(r))}return!0}return!1}}Me.instance={};var ke=Me;class xe extends Error{constructor(e){super(),this.name="NetworkError",Object.setPrototypeOf(this,xe.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}class Se extends Error{constructor(e){super(),this.name="NgwError",Object.assign(this,e),Object.setPrototypeOf(this,Se.prototype)}}function Ne(e){return"[object Object]"===Object.prototype.toString.call(e)}let Fe;Fe=(e,t,r={},s,i)=>{r.method=r.method||"GET";const n=new XMLHttpRequest;n.open(r.method||"GET",e,!0),"blob"===r.responseType&&(n.responseType=r.responseType);const o=()=>{try{return JSON.parse(n.responseText)}catch(e){return n.responseText}};n.onload=()=>{-1!==[401,403,404,422,500].indexOf(n.status)&&s(new Se(o())),((e=!1)=>{const i=e?s:t;"blob"===r.responseType?i(n.response):n.responseText?i(o()):s({message:""})})()},n.onerror=t=>{s(0===n.status?new xe(e):t)},n.upload.onprogress=function(e){if(e.lengthComputable){r.onProgress&&r.onProgress(e.loaded/e.total*100,e)}};const a=r.headers;if(a)for(const l in a){const e=a[l];"string"==typeof e&&n.setRequestHeader(l,e)}let c;if(void 0!==r.withCredentials&&(n.withCredentials=r.withCredentials),r.file){if(c=new FormData,c.append("file",r.file),r.data)for(const l in r.data)c.append(l,c[l])}else c=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;i&&i((()=>{n.abort()})),n.send(c)};const Te=/\{ *([\w_-]+) *\}/g;function Be(e,t){return e.replace(Te,((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 Re extends Se{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,Re.prototype)}}class je extends Se{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,je.prototype)}}const $e=[];function qe(e){$e.push(e)}const Ve=["description"];function De(e,t=""){t=t?t+"__":"";const r={};for(const[s,i]of Object.entries(e))if(-1===Ve.indexOf(s))if(Ne(i))if("owner_user"===s){const e=De(i,s);Object.assign(r,e)}else"parent"===s&&"id"in i&&(r.parent_id=i.id);else I(i)&&(r[t+s]=i);return r}class Ue{constructor(e){this.connector=e,this.cache=new ke}getOne(e,t){const r=new ke,s={},i={...t,cache:!1};"string"==typeof e?s.keyname=e:"number"==typeof e?s.id=e:Ne(e)&&(void 0!==e.id?s.id=e.id:e.keyname&&(s.keyname=e.keyname));return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},i):"number"==typeof e?this._fetchResourceById(e,i):Ne(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 Re}))}getId(e,t){return"number"==typeof e?L.resolve(e):"string"==typeof e||Ne(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,De(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.getIdOrFail(e).then((e=>this._getChildrenOf(e,t)))}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)}))}))}_getChildrenOf(e,t,r=[]){return this.connector.get("resource.collection",{cache:!0,...t},{parent:e}).then((e=>{const s=[];for(const i of e)this.cache.add("resource.item",L.resolve(i),{id:i.resource.id}),r.push(i),(null==t?void 0:t.recursive)&&i.resource.children&&s.push(this._getChildrenOf(i.resource.id,t,r));return s.length?L.all(s).then((()=>r)):r}))}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 Re))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:I(e.id)&&I(t.resource.id)?e.id===t.resource.id:T(e,t.resource)})),[])))}}let ze=0;class Ge{constructor(e){this.options=e,this.id=ze++,this.emitter=new t.exports.EventEmitter,this.routeStr="/api/component/pyramid/route",this.activeRequests=[];const r=function(e){return $e.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return T(t.options.auth,e.auth)}}))}(e);if(r)return r;this.options.route&&(this.routeStr=this.options.route),this.options.requestTransform&&(this.requestTransform=this.options.requestTransform),this.resources=new Ue(this),qe(this)}static create(e){return new this(e)}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,qe(this)}connect(){const e=new ke,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._login({login:e,password:i}).then((()=>s())).catch((e=>r(e)))}return s()}))),{id:this.id,auth:t,baseUrl:this.options.baseUrl})}login(e,t){return this.logout(),qe(this),this._login(e,t)}logout(){this.abort(),function(e){const t=$e.indexOf(e);-1!==t&&$e.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()}getUserInfo(e,t){if(this.user&&this.user.id)return L.resolve(this.user);e&&(this.options.auth=e);const r={headers:this.getAuthorizationHeaders(e),...t};return this.makeQuery("/api/component/auth/current_user",{},r)}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)}}abort(){for(const e of this.activeRequests)e.cancel();this.activeRequests=[]}getActiveApiRequests(){return[...this.activeRequests]}apiRequest(e,t={},r={}){var s;const{method:i,headers:n,withCredentials:o,responseType:a}=r,c=B(t),l=()=>function(e){const t=e.params;return new L(((r,s)=>{e.connector.connect().then((i=>{let n=i&&i[e.name];if(n){n=[...n];let i=n.shift();if(n.length){const e={};for(let r=0;r<n.length;r++){const s=n[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===n.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:c,requestOptions:r,connector:this});if(r.cache&&"GET"===i){return(new ke).add(e,l,{params:c,...B({headers:n,withCredentials:o,responseType:a,baseUrl:this.options.baseUrl,userId:null===(s=this.user)||void 0===s?void 0:s.id})})}return l()}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=encodeURI(j(e)),this._loadData(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){t.responseType=t.responseType||"json";const r=new L(((r,s,i)=>{if(this.user&&((t=t||{}).headers={...this.getAuthorizationHeaders(),...t.headers}),this.requestTransform){const[r,s]=this.requestTransform(e,t);e=r,t=s}Fe(e,r,t,s,i)})).then((e=>(this._cleanActiveRequests(r),e))).catch((e=>{if(this._cleanActiveRequests(r),e instanceof L.CancelError);else{const t=this._handleHttpError(e);if(t)throw t}}));return t.signal&&"function"==typeof t.signal.addEventListener&&t.signal.addEventListener("abort",(()=>{r.cancel(),this._cleanActiveRequests(r)})),this.activeRequests.push(r),r}_login(e,t){return this.getUserInfo(e,t).then((e=>(this.user=e,this.emitter.emit("login",e),e))).catch((e=>{throw this.emitter.emit("login:error",e),e}))}_cleanActiveRequests(e){const t=this.activeRequests.indexOf(e);-1!==t&&this.activeRequests.splice(t,1)}_handleHttpError(e){if(e&&e instanceof Se){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new Re(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new je(e)}return e}}Ge.errors={NgwError:Se,ResourceNotFoundError:Re};var Ze=Ge;function We(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 He({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 Je(e){return e.connector.getResource(e.resourceId).then((t=>{if(t)return Qe(t,e.connector,e)}))}function Qe(e,t,r){if(e.webmap)return L.resolve(We(e.webmap));{const s=e.resource;return s.cls&&-1!==s.cls.indexOf("style")?t.getResource(s.parent.id).then((e=>{if(e)return He({...r,resourceId:e.resource.id,connector:t})})):He({...r,resourceId:s.id,connector:t})}}class Ke{async getExtent(){return this.getBounds()}async getBounds(e){return this._extent?this._extent:this.item?(this._extent=await Qe(this.item,this.connector,e),this._extent):void 0}}const Xe=["fields","intersects","limit","orderBy","strategy"];function Ye(e){const t={};return Xe.forEach((r=>{const s=e[r];void 0!==s&&(t[r]=s)})),t}async function et(e,t){const r=e.resource,s=r;let{keyname:i,resourceId:n}=e;if(r&&("string"==typeof r?i=r:n="number"==typeof r?r:s.resource&&void 0!==s.resource&&"resource"in s?r.resource.id:await et(r,t)),!n&&i){const e=await t.getResource(i);e&&(n=e.resource.id)}return n}const tt={srs:4326,geom_format:"geojson"};function rt(e){return{geometry:e.geom,id:e.id,type:"Feature",properties:e.fields}}function st(e,t){const{extensions:r,geom:s,fields:i,srs:n}=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)),I(n)&&(e.srs=n)}function it(e){const t=ot(e);return L.all(t).then((t=>{const r=[],s=[];for(const e of t)for(const t of e)r.includes(t.id)||(s.push(t),r.push(t.id));return e.offset||e.limit?s.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:s.length):s}))}function nt(e){const[t,r,s]=e;let i="",n="";return[`${"id"!==t?"fld_":""}${String(t).trim().replace(/^(%?)(.+?)(%?)$/,((e,t,r,s)=>(i=t,n=s,r)))}__${r}`,i+s+n]}function ot(e,t=[],r=[]){const{filters:s}=e,i="string"==typeof s[0]?s[0]:"all",n=s.filter((e=>Array.isArray(e)));if("any"===i)for(const o of n)se(o)?t.push(ct({...e,paramList:[...r,nt(o)]})):ot({...e,filters:o},t,[...r]);else if("all"===i){const s=[],i=[];for(const e of n)se(e)?s.push(nt(e)):i.push(e);if(i.length)for(const n of i)ot({...e,filters:n},t,[...r,...s]);else t.push(ct({...e,paramList:[...r,...s]}))}return t}function at(e){return`POLYGON((${e.map((([e,t])=>{const[r,s]=N(e,t).map((e=>function(e,t){const r=t?Number("1e+"+t):1;return Math.round((e+Number.EPSILON)*r)/r}(e)));return r+" "+s})).join(", ")}))`}function ct(e){const t={...tt},{limit:r,cache:s,signal:i,offset:n,orderBy:o,paramList:a,connector:c,geomFormat:l,intersects:h,resourceId:u}=e;if(r?r!==Number.POSITIVE_INFINITY&&(t.limit=r):t.limit=7e3,n&&(t.offset=n),l&&(t.geom_format=l),st(t,e),o&&(t.order_by=o.join(",")),Array.isArray(h)){const e=function(e){return Array.isArray(e)&&4===e.length&&e.every((e=>"number"==typeof e))}(h)?k(h):h;t.intersects=at(e)}else"string"==typeof h&&(t.intersects=h);a&&(t.paramList=a);const p={id:u,...t};return c.get("feature_layer.feature.collection",{cache:s,signal:i},p)}function lt(e){let t;for(t in e){const r=e[t];if(R(r)){const s=r;if(I(s.year)&&I(s.month)&&I(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()}}else"id"===t&&"string"==typeof r&&(e[t]=r.split(",").map(Number))}return e}function ht(e){const t=e.filters;return t?it({...e,filters:t}).then((r=>{var s;return(null!==(s=e.clientFilterValidate)&&void 0!==s?s:ut(t))&&(r=r.filter((e=>ie(lt({...e.fields,id:e.id}),t)))),r})):ct(e)}function ut(e){if("any"===e[0])return!0;for(let t=1;t<e.length;t++){const r=e[t];if("[object Array]"===Object.prototype.toString.call(r)){if(ut(r))return!0}}return!1}function pt(e){return function(e){return ht(e).then((e=>{const t=[];return e.forEach((e=>{t.push(rt(e))})),t}))}(e).then((e=>({type:"FeatureCollection",features:e})))}async function dt(e){var r,s;const{item:i,webMap:n,Adapter:o,connector:a,layerOptions:c,addLayerOptionsPriority:l}=e,h=null==l||l,u=c,p=o||n.mapAdapter.layerAdapters.GEOJSON,d=[];let f,y,m=!1;const g=await et(u,a);(null===(s=null===(r=u.adapterOptions)||void 0===r?void 0:r.popupOptions)||void 0===s?void 0:s.fromProperties)&&(u.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)=>(b(),f={filters:e,options:t},y=pt({resourceId:g,filters:e,connector:a,cache:!0,...t}),await y);let v=!1;const b=()=>{y&&(y.cancel(),y=void 0)};return class extends p{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!==u.id&&(e.id=u.id),i&&i.vector_layer&&(e.type=Ut[i.vector_layer.geometry_type]),u.adapterOptions&&(e=h?{...u.adapterOptions,...e}:{...e,...u.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 n=super.addLayer(e);let o;return f={filters:e.propertiesFilter,options:Ye(e)},t&&(o=this.updateLayer()),r&&o&&await o,s&&s.startsWith("BBOX")&&!m&&this._addBboxEventListener(),n}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?Je({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,b()}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||f||{},null===(t=this.options.strategy)||void 0===t?void 0:t.startsWith("BBOX")){await n.onLoad("create"),e.options=e.options||{},e.options.intersects=n.getBounds();const{minZoom:t,maxZoom:r}=this.options,s=n.getZoom();if(void 0!==s){if(void 0!==t&&s<t)return;if(void 0!==r&&s>r)return;if(m)return}}if(!v){try{this.emitter.emit("preupdate",e),n._emitLayerEvent("layer:preupdate",u.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));m=void 0!==s&&d.length>=s,await n.addLayerData(this,r)}else m=void 0!==s&&t.features.length>=s,await n.setLayerData(this,t);this.emitter.emit("updated",t),n._emitLayerEvent("layer:updated",u.id||"",{data:t,newData:r,isFull:m})}catch(r){if(r instanceof Error&&"CancelError"!==r.name)throw r}super.updateLayer&&super.updateLayer()}}async propertiesFilter(e,t){if(b(),this.filter&&m)this.filter((t=>{const r=t.feature&&t.feature.properties&<({...t.feature.properties});return!r||ie(r,e)}));else if(this.setData){this.clearLayer&&this.clearLayer();const r=await _(e,{...t,srs:this.options.srs});this.setData(r)}}removeFilter(){f=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()},n.emitter.on("layer:show",this.__enableMapMoveListener),n.emitter.on("layer:hide",this.__disableMapMoveListener),this.__enableMapMoveListener(this)}_removeBboxEventListener(){this.__enableMapMoveListener&&n.emitter.on("layer:show",this.__enableMapMoveListener),this.__disableMapMoveListener&&n.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=b,n.emitter.on("movestart",this.__onMapMoveStart),n.emitter.on("moveend",this.__onMapMove)}_removeMoveEventListener(){this.__onMapMove&&n.emitter.removeListener("moveend",this.__onMapMove),this.__onMapMoveStart&&n.emitter.removeListener("movestart",this.__onMapMoveStart)}}}function ft({options:e,webMap:t,baseUrl:r}){var s;let i,n=e.adapter||"IMAGE";const o=t&&t.getLayerAdapters(),a=e.resource,c=e.tileNoData?e.tileNoData:200;if("number"==typeof a){if("IMAGE"===n){if(!o||o.IMAGE)return function({resourceId:e,baseUrl:t,nd:r,headers:s}){const i=t+"/api/component/render/image",n={resource:e};return r&&(n.nd=r),{url:i,resourceId:e,headers:s,params:n,updateWmsParams:t=>(r&&(t.nd=r),Dt(t,e))}}({resourceId:a,headers:e.headers,nd:c,baseUrl:r});n="TILE"}if("WMS"===n){i=`${r}/api/resource/${a}/wms`;const t=e.adapterOptions;return{url:i,format:"image/png",version:"1.1.1",layers:t&&t.layers,headers:e.headers}}if("MVT"===n)return i=r+"/api/component/feature_layer/mvt?x={x}&y={y}&z={z}&resource="+a+"&simplification="+(null!==(s=e.simplification)&&void 0!==s?s:6),{url:i,sourceLayer:"ngw:"+a,featureIdName:"$id"};if("TERRAIN"===n)return i=r+`/api/resource/${a}/terrain_provider`,{url:i,adapter:n};if("MODEL_3D"===n)return i=r+`/api/component/model_3d/${a}/data.glb`,{url:i};if("TILE"===n)return i=r+"/api/component/render/tile?z={z}&x={x}&y={y}&resource="+a+"&nd="+c,{url:i,adapter:n}}else{if(void 0!==a)throw new Error("Option `resource` must be number, not "+typeof a);console.log("Option `resource` not set")}}async function yt({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.cls;let n=e.adapter||i&&{wmsserver_service:"WMS",tmsclient_layer:"IMAGE"}[i]||"IMAGE";if(void 0!==n&&(e.adapter=n),"IMAGE"===n){const e=t.getLayerAdapters();!e||e.IMAGE||(n="TILE")}const o=t.mapAdapter.layerAdapters[n];if(o){const i=await et(e,r);return class extends o{constructor(n,o){super(n,o),this.map=n,this.item=s,this.resourceId=i;const a=ft({options:e,webMap:t,baseUrl:r.options.baseUrl||""});if(a){const t={...a,...e.adapterOptions,params:{resource:i},layers:a.layers||String(i),resourceId:i};e.adapterOptions&&I(e.adapterOptions.setViewDelay)&&(t.setViewDelay=e.adapterOptions.setViewDelay),this.options={...this.options,...t}}}addLayer(e){return super.addLayer({...this.options,...e})}async getIdentificationIds(){if(this.item){if("MVT"===n)return[this.item.resource.id];const e=this.item.resource.parent.id;if(I(e))return[e]}return[]}}}throw new Error(n+" not supported yet. Only TILE")}function mt(e,t,r,s){return!!vt(e,t,r,bt,s)}function gt(e,t,r,s){return vt(e,t,r,wt,s)}function _t(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 vt(e,t=(e=>!!e),r="children",s,i){const n="function"==typeof t?t:e=>ie(e,t);return s(e,i?e=>n(i(e)):n,r)}function bt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(t(e))return e;const s=_t(e,r);s&&(i=s)}for(let n=0;n<i.length;n++)if(i[n]){const e=bt(i[n],t,r,s);if(e)return e}}function wt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{t(e)&&s.push(e);const n=_t(e,r);n&&(i=n)}for(let n=0;n<i.length;n++)i[n]&&wt(i[n],t,r,s);return s}function Lt(e,t=(e=>!!e),r,s=[]){let i=[];if(Array.isArray(e))i=e;else{if(!t(e))return!1;const s=_t(e,r);s&&(i=s)}for(let n=0;n<i.length;n++)if(i[n]){if(!Lt(i[n],t,r,s))return!1}return!0}class Ot{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?gt(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 vt(this._children,e,(e=>e.tree.getChildren()),bt,t);var t}every(e){return!!vt(this._children,e,(e=>e.tree.getChildren()),Lt,t);var t}some(e){return mt(this._children,e,(e=>e.tree.getChildren()))}all(e){return this.getDescendants(e)}getDescendants(e){return gt(this._children,e,(e=>e.tree.getChildren()))}getChildren(){return[...this._children]}}class It{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)return this._blocked;const e=this.item.tree.getParents();return this._blocked=this._calculateBlockedStatus(e),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})}))}}_calculateBlockedStatus(e){return e.some((e=>{var t;const r=null===(t=e.properties)||void 0===t?void 0:t.property(this.name);return!!r&&!r.get()}))}}class Et extends It{constructor(e,t,r){super(e,t,{...Et.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],n=i.properties&&i.properties.property(this.name);n&&n.set(e,{...t,propagation:!0,bubble:!1})}}}}Et.options={hierarchy:!0,bubble:!1,propagation:!1,label:"Toggle"};class At{constructor(e,t){this.item=e,this.options={},this._properties={},this._propertiesList=[],t&&t.forEach(this._setPropertyHandler.bind(this))}add(e){this._setPropertyHandler(e)}update(){this.list().forEach((e=>e.update()))}get(e){const t=this.property(e);return t?t.get():void 0}set(e,t,r){const s=this.property(e);s&&s.getValue()!==t&&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=[]}_setPropertyHandler(e){const t=this._getHandler(e);if(t&&e.name){const r={...e};this._properties[e.name]=new t(e.name,this.item,r),this._propertiesList.push(e.name)}}_getHandler(e){const t=e.handler;return!t&&e.type?"boolean"===e.type?At.handlers.CheckProperty:At.handlers.BaseProperty:t}}At.handlers={CheckProperty:Et};let Ct=0;class Pt{constructor(e){this.options={},this.id=Ct,Ct+=1,this.options={...e},this.tree=new Ot(this)}initProperties(){this.properties=new At(this,this.options.properties)}}class Mt extends Pt{constructor(e,r,s,i,n,o){if(super({...Mt.options,...s}),this.webMap=e,this.emitter=new t.exports.EventEmitter,this._rootDescendantsCount=0,i&&(this.connector=i),n&&this.tree.setParent(n),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(),o||this._init(r)}static async create(e,t,r,s,i){const n=new Mt(e,t,r,s,i,!0);return await n._init(t),n}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){if(e.children&&e.children.length){const t=this.getChildren(e);for(const e of t){const t=new this.constructor(this.webMap,e,this.options,this.connector,this);this.tree.addChild(t)}}return Promise.resolve()}{let t;if("layer"===e.item_type)t=e.adapter||e.layer_adapter.toUpperCase();else if(Mt.GetAdapterFromLayerType[e.item_type]){t=(0,Mt.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,item:this.item}};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(this.options.popupOptions&&(s.popupOptions=this.options.popupOptions),"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===zt){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),zt=t}return zt}()*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,n=[t,s].filter(Boolean),o=[r,i].filter(Boolean);return{minZoom:n.length?Math.max(...n):void 0,maxZoom:o.length?Math.min(...o):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 kt({webMap:e,connector:t,item:r,adapterOptions:s={},idPrefix:i="first-show-adapter"}){const n=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}),n=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=n,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:()=>Vt({resource:r.resource_id,adapterOptions:{name:r.display_name,opacity:r.opacity}},e,t)});return n}Mt.GetAdapterFromLayerType={},Mt.options={properties:[{type:"boolean",name:"visibility",getProperty(e){if(e){if("group"===e.item.item_type||"root"===e.item.item_type)return mt(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 It{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 xt{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,n=[r,t,i,s];return this._extent=n,n}))}geoJson(){return this.item.geom?L.resolve(rt(this.item)):Ht({resourceId:this.resourceId,featureId:this.item.id,connector:this.options.connector,geom:!0,fields:null,extensions:null}).then((e=>(this.item.geom=e.geom,rt(this.item))))}}class St{constructor(e,r){this.map=e,this.options=r,this.NgwWebmapItem=Mt,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}),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 We(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)),n=i&&i.keyname;return ht({connector:t,resourceId:e,geom:!1,fields:n?[n]:void 0}).then((r=>{const s=[];for(const i of r){const r=new xt({item:i,resourceId:e,labelField:n,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,r.popupOptions=this.options.popupOptions;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)kt({webMap:t,connector:this.options.connector,item:s,adapterOptions:{crossOrigin:this.options.crossOrigin}}).then((e=>{const i=!r&&s.enabled;return s.enabled&&(r=!0),t.addBaseLayer(e,{id:Wt+s.resource_id,name:s.display_name,opacity:s.opacity,visibility:i}).then((e=>{e.id&&this._webmapBaselayersIds.push(e.id)}))}))}_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=j(this.options.connector.options.baseUrl+"/api/component/render/image"),s=e.layer_style_id;e.url=r,e.resourceId=s,e.updateWmsParams=e=>Dt(e,s);const i=ft({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=[];for(const e of t){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))}}}const Nt={tms:"TILE"};function Ft(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 Tt="https://qms.nextgis.com";function Bt(e,t=Tt,r={}){let s;if("webMap"in e){const{webMap:i,url:n,...o}=e;s=i,n&&(t=n),o&&(r=o)}else s=e;t||(t=Tt);class i{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(e){if(!this.qms&&e.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",j(e),!0),s.send()}))}(t+"/api/v1/geoservices/"+e.qmsId)}catch(a){console.error(a)}const r=this.qms;if(r){const t=Nt[r.type||"tms"],a=s.mapAdapter.layerAdapters[t];if(a&&(n=i,o=a,["showLayer","hideLayer"].forEach((e=>{const t=Object.getOwnPropertyDescriptor(o.prototype,e);t&&Object.defineProperty(n.prototype,e,t)})),"TILE"===t)){if(e={order:0,maxZoom:s.options.maxZoom,minZoom:s.options.minZoom,...this.options,...Ft(r)},r.origin_url){const[t,s]=function(e){const t=[];return[e=e.replace(/{switch:(.*?)}/,((e,r)=>("string"==typeof r&&r.split(",").forEach((e=>t.push(e))),"{s}"))),t]}(r.origin_url);s.length&&(e.subdomains=s,e.url=t)}this.options=e;return new a(this.map,e).addLayer(e)}}var n,o}}return i}class Rt{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 Bt({webMap:e,url:this.url})}}Rt.utils={createQmsAdapter:Bt};const jt={},$t=["mapserver_style","qgis_vector_style","qgis_raster_style","wmsserver_service","raster_style","basemap_layer","vector_layer","raster_layer","postgis_layer","webmap","tmsclient_layer"];async function qt({layerOptions:e,webMap:t,connector:r,item:s}){const i=s.resource.id,n=await r.getResourceChildren(i),o=n&&n[0];if(o)return Vt({...e,resource:o.resource.id},t,r)}async function Vt(e,t,r){let s,i;const n=e.adapter,o=await et(e,r);if(o){const a=e.resource;if(i=a&&a.resource&&void 0!==a.resource.id?a:await r.getResource(o),!i)throw"Resource item is not found";{const a=i.resource.cls,c={layerOptions:{...e,resource:o},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 et(e,r);return class extends St{constructor(e){super(e,{url:"",webMap:t,resourceId:s,connector:r})}}}(c);else if("vector_layer"===a||"postgis_layer"===a){const t=c.layerOptions.adapterOptions||{};if(t.type=t.type||i.vector_layer&&Ut[i.vector_layer.geometry_type],c.layerOptions.adapterOptions=t,e.adapterOptions=c,void 0!==n&&"GEOJSON"!==n){if("MVT"!==n)return qt(c);s=yt(c)}else s=dt(c)}else{if("raster_layer"===a)return qt(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(Rt.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"===n){const t=await r.getResource(i.resource.parent.id);if(t){const r={...e,resource:i.resource.parent.id};s=dt({...c,item:t,layerOptions:r})}}else s=yt(c)}else{if(!jt[a])throw`Resource class '${a}' not yet supported.`;{const e=jt[a];let t;t=n&&"function"!=typeof t?e[n]: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,[Ke],{replace:!1}),t}}))}function Dt(e,t){const{bbox:r,width:s,height:i,nd:n}=e;return{resource:Array.isArray(t)?t.join(","):t,extent:r,size:s+","+i,timestamp:Date.now(),nd:null!=n?n:200}}const Ut={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 zt;class Gt{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 Ze({baseUrl:this.url,auth:this.options.auth})}}static addClassAdapters(e,t){jt[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(St,{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 St{constructor(e,r){super(e,r={...t,...r})}};var t}}class Zt{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):Ht({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 Wt="webmap-baselayer";function Ht(e){const t={...tt};st(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(rt(t)):Ht({...e,geom:!0,fields:null,extensions:null}).then((e=>{const r=e.geom;return rt({...t,geom:r})}))})))}function Jt(e){return Ht(e).then((e=>rt(e)))}function Qt(e,t=!1){const r=[],s=[];for(const n in e){const e=Number(n);isNaN(e)||r.push(e)}const i=e.resources;i&&r.sort(((e,t)=>i.indexOf(e)-i.indexOf(t)));for(let n=0;n<r.length;n++){const i=r[n],o=e[i];if("features"in o){const e=Kt(o.features,Number(i),t);if(e.length&&(s.push(...e),!t))break}}return s}function Kt(e,t,r){const s=[];for(const i of e){if(s.push({featureId:i.id,resourceId:t,feature:i}),!r)break}return s}function Xt(e,t){C(e);const[r,s]=e.lngLat,{geom:i,radius:n,signal:o,cache:a}=t,c=null!=i?i:function(e,t,r=10,s=6){const i=r/P*S,n=i/Math.cos(t*x),o=[];for(let a=0;a<s+1;a++){const r=Math.PI*(a/(s/2)),c=e+n*Math.cos(r),l=t+i*Math.sin(r);o.push([c,l])}return o}(r,s,n);return function(e){const{geom:t,signal:r,cache:s}=e;let i=[];if(Array.isArray(t))i=t;else{const e="Feature"===t.type?t.geometry:"Polygon"===t.type&&t;e&&(i=e.coordinates[0])}if(i){const t=[];for(const[e,r]of i){const[s,i]=N(e,r);t.push(s+" "+i)}const n=`POLYGON((${t.join(", ")}))`;return e.connector.post("feature_layer.identify",{data:{geom:n,srs:3857,layers:e.layers},signal:r,cache:s})}throw new Error("Not valid geometry format to make intersection")}({...t,geom:c,signal:o,cache:a})}const Yt={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 er(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,n]=t;e.push({...r,resource:i,id:n,...s})}else"object"==typeof t&&e.push({...r,...t,...s})}const tr={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 rr extends Ae{constructor(e){super(function(e){const t=[new Rt];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new Ze({baseUrl:e.baseUrl||"",auth:e.auth}),(e=A(tr,e)).center||e.bounds||(e.bounds=[-179,-90,180,90]),e.connector&&t.push(new Gt({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(I(this.options.baseUrl))try{I(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},I(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=function(e,t,r){const s=r.getAuthorizationHeaders();return s&&(e.headers=s),Vt(e,t,r)}(e,this,this.connector),r={visibility:!0,...e,...e.adapterOptions},s=await this.addLayer(t,r),i=s&&this.getLayerId(s);if(s&&i&&(this._ngwLayers[i]={layer:s,resourceId:s.resourceId},s.options.name=s.options.name||s.item&&s.item.resource.display_name,s.options.baselayer)){if(this.getActiveBaseLayer())return s}return s}catch(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 Ht({connector:this.connector,...e})}fetchNgwLayerItems(e){return ht({connector:this.connector,...e})}fetchNgwLayerFeature(e){return Jt({connector:this.connector,...e})}fetchNgwLayerFeatures(e){return pt({connector:this.connector,...e})}fetchIdentifyItem(e,t){const r=function(e){const{connector:t,identify:r}=e,s=Qt(r);return s&&s.length?Ht({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,requestOptions:s}=e;for(const n in r){const e=Number(n);if(!isNaN(e)){const e=r[n];if("features"in e){const t=e.features.find((e=>e.geom));if(t&&t.geom){const e=t.geom;return L.resolve(rt({...t,geom:e}))}}}}const i=Qt(r);return i&&i.length?Jt({...s,connector:t,...i[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&&Je({resourceId:e.resource.id,connector:this.connector}).then((e=>{e&&this.fitBounds(e,t)}))}else super.fitLayer("number"==typeof e?String(e):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._getSelectListenersCount()&&this.selectFromNgwRaster(e)},this.$$selectFromNgwVector=e=>{this._getSelectListenersCount()&&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.$$selectFromNgwRaster=void 0),this.$$selectFromNgwVector&&(this.emitter.removeListener("layer:click",this.$$selectFromNgwVector),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]=[])}))}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));for(const u of r){const e=u.layer,r="function"==typeof e.getIdentificationIds&&e.getIdentificationIds;r&&e.options.selectable&&this.isLayerVisible(e)&&t.push(r.call(e))}const s=Promise.all(t),i=await s,n=[];for(const u of i)u&&n.push(...u);if(!n.length)return void this._emitStatusEvent("ngw:select",null);const o=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 l=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,o),h=Xt(e,{layers:n,connector:this.connector,radius:l}).then((t=>{const r={...t,resources:n,sourceType:"raster",event:e},s=this._prepareToIdentify(r);return this._emitStatusEvent("ngw:select",s),s}));return this._addPromise("select",h),h}_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&&er(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),er(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;if(!(t.options.selectable&&this.isLayerVisible(t)))return;const 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}}}_prepareToIdentify(e){return{...e,getIdentifyItems:()=>Qt(e,!0).map((e=>new Zt({feature:e.feature,connector:this.connector})))}}_getSelectListenersCount(){return this.emitter.listenerCount("ngw:select")}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 n=document.createElement("a");n.style.position="absolute",n.style.bottom="0",n.style.right="0",n.style.padding=null!==(r=null==t?void 0:t.padding)&&void 0!==r?r:"10px",n.className="ngw-map-logo",t&&t.cssClass&&(n.className+=" "+t.cssClass);const o=new Image;o.style.maxHeight="100px",o.style.maxWidth="100px",o.src="";try{const t=await e.get("pyramid.company_logo",{responseType:"blob"}),r=(window.URL||window.webkitURL).createObjectURL(t);o.src=r}catch(i){console.warn(i)}return null!==s.company_logo.link&&""!==s.company_logo.link.trim()&&(n.href=s.company_logo.link,n.target="_blank",-1!==s.company_logo.link.search(/:\/\/nextgis/)&&(o.alt="Get your own Web GIS at nextgis.com")),n.appendChild(o),n}}(this.connector,this.options.companyLogoOptions);t&&e.appendChild(t)}}}async function sr(e){return new rr(e).onLoad()}rr.getIcon=function(e={}){var t,r,s,i,n;const o=null!==(t=e.shape)&&void 0!==t?t:"circle",a=null!==(r=e.color)&&void 0!==r?r:"blue",c=null!==(s=e.strokeColor)&&void 0!==s?s:"white",l=null!==(i=e.size)&&void 0!==i?i:12,h=null!==(n=e.rotate)&&void 0!==n?n:0,u=l/2,p=void 0!==e.stroke?Number(e.stroke):.8,d=l/12,f=e.p||Yt[o]||"circle",y="string"==typeof f?f:f(e),m=function(e){return(new DOMParser).parseFromString(e,"image/svg+xml").documentElement}(e.svg||function(e,t,r=0,s){const i=r/2;return`<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>`}(l,l,p*d,y)),g=m.firstChild,_=`scale(${d}) rotate(${h}, 6, 6)`;return g.setAttribute("fill",a),p&&(g.setAttribute("stroke",c),g.setAttribute("stroke-width",String(p))),g.setAttribute("transform",_),{type:"icon",iconSize:[l,l],iconAnchor:[u,u],html:(new XMLSerializer).serializeToString(m),svg:m}};export{rr as NgwMap,Ae as WebMap,Oe as WebMapControls,we as WebMapLayers,be as WebMapMain,sr as createNgwMap,Le as createToggleControl,Pe as createWebMap,he as detectGeometryType,le as findMostFrequentGeomType,Ce as getDefaultControls,Ee as getWebMap,de as updateGeoJsonAdapterOptions};
|
|
2
2
|
//# sourceMappingURL=ngw-map.esm-browser.prod.js.map
|