@nextgis/geocoder 3.0.0-alpha.2 → 3.0.0-alpha.3
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/geocoder.cjs.js +1 -1
- package/lib/geocoder.esm-browser.js +7 -8
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +1 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +1 -1
- package/lib/geocoder.global.js +7 -8
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e){return null!=e}function t(t){return"string"==typeof t?!!t:e(t)}function r(e,t,r,o){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===o:n(e,t));return e===t}function n(e,t){const n=Object.keys(e).sort(),o=Object.keys(t).sort();if(n.length!==o.length)return!1;if(n.join("")!==o.join(""))return!1;for(let s=0;s<n.length;s++){if(!r(e[n[s]],t[o[s]],e,t))return!1}return!0}function o(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]=o(e[r])})),t}function s(e){return e.replace(/([^:]\/)\/+/g,"$1")}class i{constructor(e){e&&function(e,...t){for(const r of t)for(const t of Object.getOwnPropertyNames(r))e[t]=r[t]}(this,e)}}var a=Object.defineProperty,c=Object.defineProperties,l=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,p=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),d=(e,t,r)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,y=(e,t)=>{for(var r in t||(t={}))h.call(t,r)&&d(e,r,t[r]);if(u)for(var r of u(t))f.call(t,r)&&d(e,r,t[r]);return e},m=(e,t)=>c(e,l(t)),v=function(e,t){this[0]=e,this[1]=t},b=(e,t,r)=>{var n=(e,t,o,s)=>{try{var i=r[e](t),a=(t=i.value)instanceof v,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?n("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,o,s):o({value:r,done:c}))).catch((e=>n("throw",e,o,s)))}catch(l){s(l)}},o=e=>s[e]=t=>new Promise(((r,o)=>n(e,t,r,o))),s={};return r=r.apply(e,t),s[p("asyncIterator")]=()=>s,o("next"),o("throw"),o("return"),s},g=(e,t,r)=>(t=e[p("asyncIterator")])?t.call(e):(e=e[p("iterator")](),t={},(r=(r,n)=>(n=e[r])&&(t[r]=t=>new Promise(((r,o,s)=>(t=n.call(e,t),s=t.done,Promise.resolve(t.value).then((e=>r({value:e,done:s})),o))))))("next"),r("return"),t);let w=0;class O extends i{constructor(e){super(e),d(this,"providers"+"",[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}search(e){return b(this,null,(function*(){this.abort();let t=!0;const r=[];for(const c of this.providers)try{const r=c.search(e);try{for(var n,o,s,i=g(r);n=!(o=yield new v(i.next())).done;n=!1){const e=o.value;t=!1,yield m(y({},e),{provider:c,_id:w++})}}catch(o){s=[o]}finally{try{n&&(o=i.return)&&(yield new v(o.call(i)))}finally{if(s)throw s[0]}}}catch(a){"CancelError"!==a.name&&r.push(a)}if(t&&r.length)throw new Error(`All providers failed: ${r.map((e=>e.message)).join("; ")}`)}))}result(e){return e.provider?e.provider.result(e):Promise.resolve(void 0)}reverse(e){return b(this,null,(function*(){for(const i of this.providers)if(i.reverse)try{const s=i.reverse(e);try{for(var t,r,n,o=g(s);t=!(r=yield new v(o.next())).done;t=!1){const e=r.value;yield m(y({},e),{provider:i,_id:w++})}}catch(r){n=[r]}finally{try{t&&(r=o.return)&&(yield new v(r.call(o)))}finally{if(n)throw n[0]}}}catch(s){}}))}reverseGeocodeFirstResult(e){return t=this,r=null,n=function*(){for(const i of this.providers)if("function"==typeof i.reverse)try{try{for(var t,r,n,o=g(i.reverse(e));t=!(r=yield o.next()).done;t=!1)return r.value}catch(r){n=[r]}finally{try{t&&(r=o.return)&&(yield r.call(o))}finally{if(n)throw n[0]}}}catch(s){console.error("Error in reverse geocoding:",s)}},new Promise(((e,o)=>{var s=e=>{try{a(n.next(e))}catch(t){o(t)}},i=e=>{try{a(n.throw(e))}catch(t){o(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((n=n.apply(t,r)).next())}));var t,r,n}}var _=Object.defineProperty,P=(e,t,r)=>((e,t,r)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class x extends i{constructor(){super(...arguments),P(this,"searchUrl"),P(this,"label")}}function j(){}function E(){E.init.call(this)}function I(e){return void 0===e._maxListeners?E.defaultMaxListeners:e._maxListeners}function R(e,t,r,n){var o,s,i,a;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]):(s=e._events=new j,e._eventsCount=0),i){if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),!i.warned&&(o=I(e))&&o>0&&i.length>o){i.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=i.length,a=c,"function"==typeof console.warn?console.warn(a):console.log(a)}}else i=s[t]=r,++e._eventsCount;return e}function L(e,t,r){var n=!1;function o(){e.removeListener(t,o),n||(n=!0,r.apply(e,arguments))}return o.listener=r,o}function C(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function k(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}j.prototype=Object.create(null),E.EventEmitter=E,E.usingDomains=!1,E.prototype.domain=void 0,E.prototype._events=void 0,E.prototype._maxListeners=void 0,E.defaultMaxListeners=10,E.init=function(){this.domain=null,E.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new j,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},E.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},E.prototype.getMaxListeners=function(){return I(this)},E.prototype.emit=function(e){var t,r,n,o,s,i,a,c="error"===e;if(i=this._events)c=c&&null==i.error;else if(!c)return!1;if(a=this.domain,c){if(t=arguments[1],!a){if(t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=i[e]))return!1;var u="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,o=k(e,n),s=0;s<n;++s)o[s].call(r)}(r,u,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var o=e.length,s=k(e,o),i=0;i<o;++i)s[i].call(r,n)}(r,u,this,arguments[1]);break;case 3:!function(e,t,r,n,o){if(t)e.call(r,n,o);else for(var s=e.length,i=k(e,s),a=0;a<s;++a)i[a].call(r,n,o)}(r,u,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,o,s){if(t)e.call(r,n,o,s);else for(var i=e.length,a=k(e,i),c=0;c<i;++c)a[c].call(r,n,o,s)}(r,u,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(n-1),s=1;s<n;s++)o[s-1]=arguments[s];!function(e,t,r,n){if(t)e.apply(r,n);else for(var o=e.length,s=k(e,o),i=0;i<o;++i)s[i].apply(r,n)}(r,u,this,o)}return!0},E.prototype.on=E.prototype.addListener=function(e,t){return R(this,e,t,!1)},E.prototype.prependListener=function(e,t){return R(this,e,t,!0)},E.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,L(this,e,t)),this},E.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,L(this,e,t)),this},E.prototype.removeListener=function(e,t){var r,n,o,s,i;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener&&r.listener===t)0==--this._eventsCount?this._events=new j:(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length;s-- >0;)if(r[s]===t||r[s].listener&&r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new j,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,o=e.length;n<o;r+=1,n+=1)e[r]=e[n];e.pop()}(r,o);n.removeListener&&this.emit("removeListener",e,i||t)}return this},E.prototype.off=function(e,t){return this.removeListener(e,t)},E.prototype.removeAllListeners=function(e){var t,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new j,this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=new j:delete r[e]),this;if(0===arguments.length){for(var n,o=Object.keys(r),s=0;s<o.length;++s)"removeListener"!==(n=o[s])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new j,this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},E.prototype.listeners=function(e){var t,r=this._events;return r&&(t=r[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(t):[]},E.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):C.call(e,t)},E.prototype.listenerCount=C,E.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var S=Object.defineProperty,A=(e,t,r)=>((e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);const T=class e{constructor(t={}){var r;A(this,"cache",[]);const n=null!=(r=t.namespace)?r:"default";return e.instance[n]?e.instance[n]:(e.instance[n]=this,this)}clean(){this.cache.length=0}all(){return this.cache}addFull(e,t,r){return this.add(e,t,r,!0)}add(e,r,n,s){const i=this._find(e,n);if(i)return i.value;{let i;i=r instanceof Function?r():r;const a=n&&JSON.parse(JSON.stringify(o(n))),c={key:e,value:i,props:a};return s&&!t(i)?i:(this.cache.push(c),i instanceof Promise?(i.catch((t=>{this.delete(e,n)})),s&&i.then((r=>(t(r)||this.delete(e,n),r))),i):i)}}match(e,t){const r=this._find(e,t);return null==r?void 0:r.value}matchAll(e,t){return e?this.cache.filter((r=>this._filter(r,e,t))).map((e=>e.value)):this.cache.map((e=>e.value))}delete(e,t){const r="string"==typeof e?this.cache.filter((r=>this._filter(r,e,t))):[e];for(const n of r){const e=this.cache.indexOf(n);-1!==e&&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)return!1;if(!r)return!0;return n(e.props||{},o(r))}};A(T,"instance",{});let q=T;var U="3.0.0-alpha.2",$=Object.defineProperty,N=(e,t,r)=>((e,t,r)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class F extends Error{constructor(e){super(),N(this,"name","NgwError"),N(this,"title"),N(this,"message"),N(this,"detail"),N(this,"exception"),N(this,"status_code"),N(this,"data"),N(this,"guru_meditation"),Object.assign(this,e),Object.setPrototypeOf(this,F.prototype)}}var M=Object.defineProperty,D=(e,t,r)=>((e,t,r)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class G extends F{constructor(e){super(e),D(this,"name","ResourceNotFoundError"),D(this,"exception","nextgisweb.resource.exception.ResourceNotFound"),Object.setPrototypeOf(this,G.prototype)}}function B(e){return"[object Object]"===Object.prototype.toString.call(e)}const H=["description"];function J(t,r=""){r=r?r+"__":"";const n={};for(const[o,s]of Object.entries(t))if(-1===H.indexOf(o))if(B(s))if("owner_user"===o){const e=J(s,o);Object.assign(n,e)}else"parent"===o&&"id"in s&&(n.parent_id=s.id);else e(s)&&(n[r+o]=s);return n}var z=Object.defineProperty,Q=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,K=(e,t,r)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,V=(e,t)=>{for(var r in t||(t={}))W.call(t,r)&&K(e,r,t[r]);if(Q)for(var r of Q(t))X.call(t,r)&&K(e,r,t[r]);return e},Y=(e,t,r)=>K(e,"symbol"!=typeof t?t+"":t,r);class Z{constructor({connector:e,cacheId:t}){Y(this,"cache"),Y(this,"connector"),this.connector=e,this.cache=new q({namespace:t})}getOne(e,t){const r=V({},t);return"string"==typeof e||"number"==typeof e||B(e),"string"==typeof e?this._fetchResourceBy({keyname:e},r):"number"==typeof e?this._fetchResourceById(e,r):B(e)?this._fetchResourceBy(e,r):Promise.resolve(void 0)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new G}))}getId(e,t){return"number"==typeof e?Promise.resolve(e):"string"==typeof e||B(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):Promise.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,J(e)),this.connector.get("resource.search",t,V({serialization:"full"},r)).then((e=>{if((null==t?void 0:t.cache)&&e)for(const t of e)this.cache.add("resource.item",Promise.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):Promise.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",t,{parent:e}).then((e=>{const n=[];for(const o of e)(null==t?void 0:t.cache)&&this.cache.add("resource.item",Promise.resolve(o),{id:o.resource.id}),r.push(o),(null==t?void 0:t.recursive)&&o.resource.children&&n.push(this._getChildrenOf(o.resource.id,t,r));return n.length?Promise.all(n).then((()=>r)):r}))}_cleanResourceItemCache(e){return t=this,r=null,n=function*(){var t;const r=this.cache.all(),n=[];for(const o of r){const r=null==(t=o.props)?void 0:t.id;["resource.item","resource"].includes(o.key)&&void 0!==r&&("number"==typeof r?r===e&&n.push(o):(yield this.getId(r))===e&&n.push(o))}for(const e of n)this.cache.delete(e)},new Promise(((e,o)=>{var s=e=>{try{a(n.next(e))}catch(t){o(t)}},i=e=>{try{a(n.throw(e))}catch(t){o(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((n=n.apply(t,r)).next())}));var t,r,n}_fetchResourceById(e,t){return this.connector.get("resource.item",t,{id:e})}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(t){return Promise.all(this.cache.matchAll("resource.item")).then((r=>(r.filter((r=>{if(r)return t.keyname&&r.resource.keyname?t.keyname===r.resource.keyname:e(t.id)&&e(r.resource.id)?t.id===r.resource.id:n(t,r.resource)})),[])))}}const ee=[];function te(e){ee.push(e)}class re extends Error{constructor(e="AbortError"){super(e),this.name="AbortError"}}var ne=Object.defineProperty,oe=(e,t,r)=>((e,t,r)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class se extends F{constructor(e){super(e),oe(this,"name","InsufficientPermissionsError"),oe(this,"exception","nextgisweb.core.exception.InsufficientPermissions"),Object.setPrototypeOf(this,se.prototype)}}const ie=/\{ *([\w_-]+) *\}/g;function ae(e,t){return e.replace(ie,((e,r)=>{let n=t[r];if(void 0===n)throw new Error("No value provided for letiable "+e);return"function"==typeof n&&(n=n(t)),n}))}var ce=Object.defineProperty,le=Object.getOwnPropertySymbols,ue=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,fe=(e,t,r)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;function pe(e){return t=this,r=null,n=function*(){const{params:t,name:r,connector:n,requestOptions:o}=e,s=yield n.connect();let i=s&&s[r];if(i){i=[...i];let e=i.shift();if(i.length){const r={};for(let e=0;e<i.length;e++){const n=i[e];if(r[e]=`{${n}}`,void 0===t[n])throw new Error(`\`${n}\` URL API argument is not specified`)}e&&(e=ae(e,r))}if(t){const r=[],n=t.paramList;Array.isArray(n)&&n.forEach((([e,t])=>{r.push(`${e}=${t}`)}));for(const e in t)-1===i.indexOf(e)&&r.push(`${e}=${t[e]}`);r.length&&(e=`${e}?${r.join("&")}`)}if(e)return n.makeQuery(e,t,((e,t)=>{for(var r in t||(t={}))ue.call(t,r)&&fe(e,r,t[r]);if(le)for(var r of le(t))he.call(t,r)&&fe(e,r,t[r]);return e})({cacheName:r},o));throw new Error("Request URL is not set")}},new Promise(((e,o)=>{var s=e=>{try{a(n.next(e))}catch(t){o(t)}},i=e=>{try{a(n.throw(e))}catch(t){o(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((n=n.apply(t,r)).next())}));var t,r,n}var de=Object.defineProperty,ye=(e,t,r)=>((e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,t+"",r);class me extends Error{constructor(e){super(),ye(this,"name","NetworkError"),Object.setPrototypeOf(this,me.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}let ve;ve=(e,t,r={},n,o)=>{r.method=r.method||"GET";const s=new XMLHttpRequest;s.open(r.method||"GET",e,!0),"blob"===r.responseType&&(s.responseType=r.responseType);const i=()=>{try{return JSON.parse(s.responseText)}catch(e){return s.responseText}};s.onload=()=>{-1!==[401,403,404,422,500].indexOf(s.status)&&n(new F(i())),((e=!1)=>{const o=e?n:t;"blob"===r.responseType?o(s.response):s.responseText?o(i()):n({message:""})})()},s.onerror=t=>{n(0===s.status?new me(e):t)},s.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&&s.setRequestHeader(l,e)}let c;if(void 0!==r.withCredentials&&(s.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;o&&o((()=>{s.abort()})),s.send(c)};var be=Object.defineProperty,ge=Object.defineProperties,we=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,xe=(e,t,r)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,je=(e,t)=>{for(var r in t||(t={}))_e.call(t,r)&&xe(e,r,t[r]);if(Oe)for(var r of Oe(t))Pe.call(t,r)&&xe(e,r,t[r]);return e},Ee=(e,t,r)=>xe(e,"symbol"!=typeof t?t+"":t,r),Ie=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(t){o(t)}},i=e=>{try{a(r.throw(e))}catch(t){o(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));let Re=0,Le=0;class Ce{constructor(e){this.options=e,Ee(this,"id",Re++),Ee(this,"emitter",new E),Ee(this,"user"),Ee(this,"resources"),Ee(this,"cache"),Ee(this,"withCredentials"),Ee(this,"client",`NextGIS-NGW-Connector/${U}`),Ee(this,"routeStr","/api/component/pyramid/route"),Ee(this,"activeRequests",{}),Ee(this,"requestTransform");const t=function(e){return ee.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return n(t.options.auth,e.auth)}}))}(e);if(this.cache=new q({namespace:e.cacheId}),t)return t;{const{route:t,requestTransform:r,withCredentials:n}=this.options;t&&(this.routeStr=t),r&&(this.requestTransform=r),void 0!==n&&(this.withCredentials=n),this.resources=new Z({connector:this,cacheId:e.cacheId}),te(this)}}static create(e){return new this(e)}clearCache(){this.cache.clean(),this.resources.cache.clean()}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,te(this)}connect(){return Ie(this,null,(function*(){const e=this.options.auth;if(e){const{login:t,password:r}=e;t&&r&&(yield this._login({login:t,password:r}))}const t=`${this.routeStr}?client=${this.client}`;return yield this.makeQuery(t,{},{cacheName:"route",cache:!0,cacheProps:{id:this.id,auth:e,baseUrl:this.options.baseUrl}})}))}login(e,t){return this.logout(),te(this),this._login(e,t)}logout(){this.abort(),function(e){const t=ee.indexOf(e);-1!==t&&ee.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.clearCache(),this.emitter.emit("logout")}getUserInfo(e,t){return Ie(this,null,(function*(){if(this.user&&this.user.id)return this.user;e&&(this.options.auth=e);const r=je({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,n=encodeURIComponent(`${t}:${r}`);return window.btoa(n)}}abort(){for(const e of Object.values(this.activeRequests))e.abort();this.activeRequests={}}getActiveApiRequests(){return je({},this.activeRequests)}apiRequest(e,t={},r={}){var n;return pe({name:e,params:o(t=null!=(n=r.params)?n:t),requestOptions:r,connector:this})}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){return Ie(this,arguments,(function*(e,t,r={}){var n;if(!(e=(this.options.baseUrl?this.options.baseUrl:"")+e))throw new Error("Empty `url` not allowed");if(t){const r=((e,t)=>{var r={};for(var n in e)_e.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&Oe)for(var n of Oe(e))t.indexOf(n)<0&&Pe.call(e,n)&&(r[n]=e[n]);return r})(t,["paramList"]);e=ae(e,r)}e=encodeURI(s(e)),r=je({withCredentials:this.withCredentials},r);const{cache:i,signal:a,method:c="GET",headers:l,cacheName:u,cacheProps:h,responseType:f,withCredentials:p}=r,d=new AbortController,y=d.signal;if(a){if(a.aborted)throw new re;a.addEventListener("abort",(()=>{d.abort()}))}r.signal=y;const m=()=>Ie(this,null,(function*(){const t=Le++;this.activeRequests[t]=d;try{return this._loadData(e,r)}finally{this._cleanActiveRequest(t)}}));if(i&&"GET"===c){const r=h||(v=je({},o({headers:l,withCredentials:p,responseType:f,baseUrl:this.options.baseUrl,userId:null==(n=this.user)?void 0:n.id})),ge(v,we({params:t})));return this.cache.add(u||e,m,r,!1)}var v;return m()}))}getResource(e,t){return this.resources.getOne(e,t)}getResourceOrFail(e,t){return this.resources.getOneOrFail(e,t)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e,t){return this.resources.getId(e,t)}getResourceIdOrFail(e,t){return this.resources.getIdOrFail(e,t)}getResourcesBy(e,t){return this.resources.getMany(e,t)}getResourceParent(e,t){return this.resources.getParent(e,t)}getResourceChildren(e,t){return this.resources.getChildrenOf(e,t)}updateResource(e,t){return this.resources.update(e,t)}deleteResource(e){return this.resources.delete(e)}_loadData(e,t){return t.responseType=t.responseType||"json",new Promise(((r,n)=>{var o;if(this.user&&((t=t||{}).headers=je(je({},this.getAuthorizationHeaders()),t.headers)),this.requestTransform){const[r,n]=this.requestTransform(e,t);e=r,t=n}let s;ve(e,r,t,n,(e=>{s=e})),null==(o=t.signal)||o.addEventListener("abort",(()=>{void 0!==s&&s(),n(new re)}))})).catch((e=>{if("AbortError"!==e.name){const t=this._handleHttpError(e);if(t)throw t}throw e}))}_login(e,t){return Ie(this,null,(function*(){try{const r=yield this.getUserInfo(e,t);return this.user=r,this.emitter.emit("login",r),r}catch(r){throw this.emitter.emit("login:error",r),r}}))}_cleanActiveRequest(e){delete this.activeRequests[e]}_handleHttpError(e){if(e&&e instanceof F){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new G(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new se(e)}return e}}function ke(e,t,r){if((t=String(t))===(e=String(e)))return!0;if(r&&t.toUpperCase()===e.toUpperCase())return!0;const n=`^${o=t,o.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}$`.replace(/%/g,".*").replace("_",".");var o;return null!==new RegExp(n,r?"i":"").exec(e)}Ee(Ce,"errors",{NgwError:F,ResourceNotFoundError:G});const Se={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)=>ke(e,t),ilike:(e,t)=>ke(e,t,!0)};function Ae(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function Te(e,t){const r="string"==typeof t[0]?t[0]:"all",n=t=>{if(Ae(t)){const[r,n,o]=t,s=Se[n];if(s){if(("like"===n||"ilike"===n)&&"string"==typeof r){let t="";const n=r.replace(/^%?(\w+)%?$/,((n,s)=>(t=e[s],r.replace(s,o))));return s(t,n)}return s(e[r],o)}return!1}return Te(e,t)},o=t.filter((e=>Array.isArray(e)));return"any"===r?o.some(n):o.every(n)}var qe=Object.defineProperty,Ue=Object.defineProperties,$e=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,De=(e,t,r)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ge=(e,t)=>{for(var r in t||(t={}))Fe.call(t,r)&&De(e,r,t[r]);if(Ne)for(var r of Ne(t))Me.call(t,r)&&De(e,r,t[r]);return e},Be=(e,t)=>Ue(e,$e(t)),He=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(t){o(t)}},i=e=>{try{a(r.throw(e))}catch(t){o(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));const Je={srs:4326,geom_format:"geojson"};function ze(e){return He(this,null,(function*(){const t=We(e),r=yield Promise.all(t),n=[],o=[];for(const e of r)for(const t of e)n.includes(t.id)||(o.push(t),n.push(t.id));return e.offset||e.limit?o.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:o.length):o}))}function Qe(e){const[t,r,n]=e;let o="",s="";return[`${"id"!==t?"fld_":""}${String(t).trim().replace(/^(%?)(.+?)(%?)$/,((e,t,r,n)=>(o=t,s=n,r)))}__${r}`,o+n+s]}function We(e,t=[],r=[]){var n;const{filters:o}=e,s=null!=(n=e.paramList)?n:[],i="string"==typeof o[0]?o[0]:"all",a=o.filter((e=>Array.isArray(e)));if("any"===i)for(const c of a)Ae(c)?t.push(Ke(Be(Ge({},e),{paramList:[...r,...s,Qe(c)]}))):We(Be(Ge({},e),{filters:c}),t,[...r]);else if("all"===i){const n=[],o=[];for(const e of a)Ae(e)?n.push(Qe(e)):o.push(e);if(o.length)for(const s of o)We(Be(Ge({},e),{filters:s}),t,[...r,...n]);else t.push(Ke(Be(Ge({},e),{paramList:[...r,...s,...n]})))}return t}function Xe(e){return`POLYGON((${e.map((([e,t])=>{const[r,n]=function(e,t){t=t>85.06?85.06:t<-85.06?-85.06:t;const r=20037508.34*e/180;let n=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return n=20037508.34*n/180,[r,n]}(e,t).map((e=>Math.round(1*(e+Number.EPSILON))/1));return r+" "+n})).join(", ")}))`}function Ke(t){const r=Ge({},Je),{limit:n,cache:o,signal:s,offset:i,orderBy:a,paramList:c,connector:l,geomFormat:u,intersects:h,resourceId:f}=t;if(n?n!==Number.POSITIVE_INFINITY&&(r.limit=n):r.limit=7e3,i&&(r.offset=i),u&&(r.geom_format=u),function(t,r){const{extensions:n,geom:o,fields:s,srs:i,ilike:a,like:c}=r,l=n?n.join(","):"";"*"!==l&&(t.extensions=l),null!=s&&(t.fields=Array.isArray(s)?s.join(","):""),void 0!==o&&(t.geom=o?"yes":"no",o||(delete t.srs,delete t.geom_format)),e(a)?t.ilike=a:e(c)&&(t.like=c),e(i)&&(t.srs=i)}(r,t),a&&(r.order_by=a.join(",")),Array.isArray(h)){const e=(p=h,Array.isArray(p)&&4===p.length&&p.every((e=>"number"==typeof e))?function(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}(h):h);r.intersects=Xe(e)}else"string"==typeof h&&(r.intersects=h);var p;c&&(r.paramList=c);const d=Ge({id:f},r);return l.get("feature_layer.feature.collection",{cache:o,signal:s},d)}var Ve=Object.defineProperty,Ye=Object.defineProperties,Ze=Object.getOwnPropertyDescriptors,et=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,nt=(e,t,r)=>t in e?Ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ot=(e,t)=>{for(var r in t||(t={}))tt.call(t,r)&&nt(e,r,t[r]);if(et)for(var r of et(t))rt.call(t,r)&&nt(e,r,t[r]);return e},st=(e,t)=>Ye(e,Ze(t));function it(t){return r=this,n=null,o=function*(){var r;const n=t.filters;if(n){let o=yield ze(st(ot({},t),{filters:n}));return(null!=(r=t.clientFilterValidate)?r:at(n))&&(o=o.filter((t=>Te(function(t){let r;for(r in t){const n=t[r];if("[object Object]"===Object.prototype.toString.call(n)){const o=n;if(e(o.year)&&e(o.month)&&e(o.day)){const e=[o.year,o.month-1,o.day];"hour"in o&&[o.hour,o.minute,o.second].forEach((t=>{e.push(t)})),t[r]=new Date(...e).toISOString()}}else"id"===r&&"string"==typeof n&&(t[r]=n.split(",").map(Number))}return t}(st(ot({},t.fields),{id:t.id})),n)))),o}return Ke(t)},new Promise(((e,t)=>{var s=e=>{try{a(o.next(e))}catch(r){t(r)}},i=e=>{try{a(o.throw(e))}catch(r){t(r)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((o=o.apply(r,n)).next())}));var r,n,o}function at(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(at(r))return!0}}return!1}var ct=Object.defineProperty,lt=Object.getOwnPropertySymbols,ut=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,ft=(e,t,r)=>t in e?ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,pt=(e,t,r)=>ft(e,"symbol"!=typeof t?t+"":t,r),dt=function(e,t){this[0]=e,this[1]=t},yt=(e,t,r)=>{var n,o,s=(e,t,n,o)=>{try{var i=r[e](t),a=(t=i.value)instanceof dt,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?s("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,o):n({value:r,done:c}))).catch((e=>s("throw",e,n,o)))}catch(l){o(l)}},i=e=>a[e]=t=>new Promise(((r,n)=>s(e,t,r,n))),a={};return r=r.apply(e,t),a[(n="asyncIterator",(o=Symbol[n])?o:Symbol.for("Symbol."+n))]=()=>a,i("next"),i("throw"),i("return"),a};const mt=class e extends x{constructor(e){var t;if(super(e),pt(this,"searchResources",[]),pt(this,"connector"),pt(this,"_abortControllers",[]),!e.searchUrl&&!(null==(t=e.connectorOptions)?void 0:t.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new Ce(((e,t)=>{for(var r in t||(t={}))ut.call(t,r)&&ft(e,r,t[r]);if(lt)for(var r of lt(t))ht.call(t,r)&&ft(e,r,t[r]);return e})({baseUrl:this.searchUrl},e.connectorOptions)),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}search(t){return yt(this,null,(function*(){var r,n;const o=this._makeSignal();for(const i of this.searchResources){if(o.aborted)break;const{searchMethod:a}=i,c=null!=(r=i.limit)?r:e.limit,l=null!=(n=i.id)?n:i.resourceId;try{const e=yield new dt(this.connector.getResourceOrFail(l,{cache:!0})),r={connector:this.connector,resourceId:l,signal:o,limit:c};"like"===a?r.like=t:r.ilike=t;const n=it(r),s=yield new dt(n);for(const o of this._items({entries:s,query:t,config:i,resourceItem:e}))o.result=()=>this.result(o),yield o}catch(s){s&&"name"in s&&"CancelError"!==s.name&&console.warn(s)}}}))}result(e){const t=this._makeSignal();return this.connector.get("feature_layer.feature.item_extent",{signal:t},{id:e.resourceId,fid:e.featureId}).then((t=>{const r=t.extent;return{text:e.text,extent:[r.minLon,r.minLat,r.maxLon,r.maxLat]}}))}reverse(e){return yt(this,null,(function*(){throw new Error("Not implemented")}))}_makeSignal(){const e=new AbortController;return this._abortControllers.push(e),e.signal}_items({entries:e,query:t,config:r,resourceItem:n}){var o;const s=[];let i;n.feature_layer&&(i=null==(o=n.feature_layer.fields.find((e=>e.label_field)))?void 0:o.keyname);return this.searchResources.find((e=>{var t;return null!=(t=e.id)?t:e.resourceId===n.resource.id}))&&e.forEach((e=>{let o=i?e.fields[i]:e.id;r.renderSearch?o=r.renderSearch({item:e,resourceItem:n}):i&&(o=e.fields[i]),s.push({query:t,text:o,featureId:e.id,resourceId:n.resource.id,item:e,resourceItem:n})})),s}};pt(mt,"limit",300);let vt=mt;var bt=Object.defineProperty,gt=(e,t,r)=>((e,t,r)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r),wt=function(e,t){this[0]=e,this[1]=t},Ot=(e,t,r)=>{var n,o,s=(e,t,n,o)=>{try{var i=r[e](t),a=(t=i.value)instanceof wt,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?s("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,o):n({value:r,done:c}))).catch((e=>s("throw",e,n,o)))}catch(l){o(l)}},i=e=>a[e]=t=>new Promise(((r,n)=>s(e,t,r,n))),a={};return r=r.apply(e,t),a[(n="asyncIterator",(o=Symbol[n])?o:Symbol.for("Symbol."+n))]=()=>a,i("next"),i("throw"),i("return"),a};class _t extends x{constructor(e){super(e),gt(this,"searchUrl","https://nominatim.openstreetmap.org"),gt(this,"_abort",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._abort.forEach((e=>e())),this._abort=[]}search(e){return Ot(this,null,(function*(){const t=s(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new Promise(((r,n)=>{const o=new XMLHttpRequest;o.open("GET",t,!0),o.onload=()=>{try{const t=JSON.parse(o.responseText).features.map((t=>({geom:t,extent:t.bbox,text:t.properties&&t.properties.display_name,query:e})));r(t)}catch(t){n(t)}},o.onerror=e=>{n(e)},this._abort.push(o.abort),o.send()})).catch((e=>{throw e})),n=yield new wt(r);if(n)for(const e of n)e.result=()=>this.result(e),yield e}))}result(e){return Promise.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}reverse(e){return Ot(this,null,(function*(){const[t,r]=e,n=s(`${this.searchUrl}/reverse?format=geojson&lat=${r}&lon=${t}`),o=new Promise(((e,o)=>{const s=new XMLHttpRequest;s.open("GET",n,!0),s.onload=()=>{try{const n=JSON.parse(s.responseText).features[0];e({geom:n,extent:n.bbox,text:n.properties&&n.properties.display_name,query:`${r}, ${t}`})}catch(n){o(n)}},s.onerror=e=>{o(e)},this._abort.push(s.abort),s.send()})).catch((e=>{throw e})),i=yield new wt(o);i&&(i.result=()=>this.result(i),yield i)}))}}function Pt(e){return new O(e)}export{x as BaseProvider,O as Geocoder,vt as NgwProvider,_t as NominatimProvider,Pt as create};
|
|
1
|
+
function e(e){return null!=e}function t(t){return"string"==typeof t?!!t:e(t)}function r(e,t,r,o){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===o:n(e,t));return e===t}function n(e,t){const n=Object.keys(e).sort(),o=Object.keys(t).sort();if(n.length!==o.length)return!1;if(n.join("")!==o.join(""))return!1;for(let s=0;s<n.length;s++){if(!r(e[n[s]],t[o[s]],e,t))return!1}return!0}function o(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]=o(e[r])})),t}function s(e){return e.replace(/([^:]\/)\/+/g,"$1")}class i{constructor(e){e&&function(e,...t){for(const r of t)for(const t of Object.getOwnPropertyNames(r))e[t]=r[t]}(this,e)}}var a=Object.defineProperty,c=Object.defineProperties,l=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,p=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),d=(e,t,r)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,y=(e,t)=>{for(var r in t||(t={}))h.call(t,r)&&d(e,r,t[r]);if(u)for(var r of u(t))f.call(t,r)&&d(e,r,t[r]);return e},m=(e,t)=>c(e,l(t)),v=function(e,t){this[0]=e,this[1]=t},b=(e,t,r)=>{var n=(e,t,o,s)=>{try{var i=r[e](t),a=(t=i.value)instanceof v,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?n("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,o,s):o({value:r,done:c}))).catch((e=>n("throw",e,o,s)))}catch(l){s(l)}},o=e=>s[e]=t=>new Promise(((r,o)=>n(e,t,r,o))),s={};return r=r.apply(e,t),s[p("asyncIterator")]=()=>s,o("next"),o("throw"),o("return"),s},g=(e,t,r)=>(t=e[p("asyncIterator")])?t.call(e):(e=e[p("iterator")](),t={},(r=(r,n)=>(n=e[r])&&(t[r]=t=>new Promise(((r,o,s)=>(t=n.call(e,t),s=t.done,Promise.resolve(t.value).then((e=>r({value:e,done:s})),o))))))("next"),r("return"),t);let w=0;class O extends i{constructor(e){super(e),d(this,"providers"+"",[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}search(e){return b(this,null,(function*(){this.abort();let t=!0;const r=[];for(const c of this.providers)try{const r=c.search(e);try{for(var n,o,s,i=g(r);n=!(o=yield new v(i.next())).done;n=!1){const e=o.value;t=!1,yield m(y({},e),{provider:c,_id:w++})}}catch(o){s=[o]}finally{try{n&&(o=i.return)&&(yield new v(o.call(i)))}finally{if(s)throw s[0]}}}catch(a){"CancelError"!==a.name&&r.push(a)}if(t&&r.length)throw new Error(`All providers failed: ${r.map((e=>e.message)).join("; ")}`)}))}result(e){return e.provider?e.provider.result(e):Promise.resolve(void 0)}reverse(e){return b(this,null,(function*(){for(const i of this.providers)if(i.reverse)try{const s=i.reverse(e);try{for(var t,r,n,o=g(s);t=!(r=yield new v(o.next())).done;t=!1){const e=r.value;yield m(y({},e),{provider:i,_id:w++})}}catch(r){n=[r]}finally{try{t&&(r=o.return)&&(yield new v(r.call(o)))}finally{if(n)throw n[0]}}}catch(s){}}))}reverseGeocodeFirstResult(e){return t=this,r=null,n=function*(){for(const i of this.providers)if("function"==typeof i.reverse)try{try{for(var t,r,n,o=g(i.reverse(e));t=!(r=yield o.next()).done;t=!1)return r.value}catch(r){n=[r]}finally{try{t&&(r=o.return)&&(yield r.call(o))}finally{if(n)throw n[0]}}}catch(s){console.error("Error in reverse geocoding:",s)}},new Promise(((e,o)=>{var s=e=>{try{a(n.next(e))}catch(t){o(t)}},i=e=>{try{a(n.throw(e))}catch(t){o(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((n=n.apply(t,r)).next())}));var t,r,n}}var _=Object.defineProperty,P=(e,t,r)=>((e,t,r)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class x extends i{constructor(){super(...arguments),P(this,"searchUrl"),P(this,"label")}}function j(){}function E(){E.init.call(this)}function I(e){return void 0===e._maxListeners?E.defaultMaxListeners:e._maxListeners}function R(e,t,r,n){var o,s,i,a;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]):(s=e._events=new j,e._eventsCount=0),i){if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),!i.warned&&(o=I(e))&&o>0&&i.length>o){i.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=i.length,a=c,"function"==typeof console.warn?console.warn(a):console.log(a)}}else i=s[t]=r,++e._eventsCount;return e}function L(e,t,r){var n=!1;function o(){e.removeListener(t,o),n||(n=!0,r.apply(e,arguments))}return o.listener=r,o}function C(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function k(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}j.prototype=Object.create(null),E.EventEmitter=E,E.usingDomains=!1,E.prototype.domain=void 0,E.prototype._events=void 0,E.prototype._maxListeners=void 0,E.defaultMaxListeners=10,E.init=function(){this.domain=null,E.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new j,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},E.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},E.prototype.getMaxListeners=function(){return I(this)},E.prototype.emit=function(e){var t,r,n,o,s,i,a,c="error"===e;if(i=this._events)c=c&&null==i.error;else if(!c)return!1;if(a=this.domain,c){if(t=arguments[1],!a){if(t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=i[e]))return!1;var u="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,o=k(e,n),s=0;s<n;++s)o[s].call(r)}(r,u,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var o=e.length,s=k(e,o),i=0;i<o;++i)s[i].call(r,n)}(r,u,this,arguments[1]);break;case 3:!function(e,t,r,n,o){if(t)e.call(r,n,o);else for(var s=e.length,i=k(e,s),a=0;a<s;++a)i[a].call(r,n,o)}(r,u,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,o,s){if(t)e.call(r,n,o,s);else for(var i=e.length,a=k(e,i),c=0;c<i;++c)a[c].call(r,n,o,s)}(r,u,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(n-1),s=1;s<n;s++)o[s-1]=arguments[s];!function(e,t,r,n){if(t)e.apply(r,n);else for(var o=e.length,s=k(e,o),i=0;i<o;++i)s[i].apply(r,n)}(r,u,this,o)}return!0},E.prototype.on=E.prototype.addListener=function(e,t){return R(this,e,t,!1)},E.prototype.prependListener=function(e,t){return R(this,e,t,!0)},E.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,L(this,e,t)),this},E.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,L(this,e,t)),this},E.prototype.removeListener=function(e,t){var r,n,o,s,i;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener&&r.listener===t)0==--this._eventsCount?this._events=new j:(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length;s-- >0;)if(r[s]===t||r[s].listener&&r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new j,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,o=e.length;n<o;r+=1,n+=1)e[r]=e[n];e.pop()}(r,o);n.removeListener&&this.emit("removeListener",e,i||t)}return this},E.prototype.off=function(e,t){return this.removeListener(e,t)},E.prototype.removeAllListeners=function(e){var t,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new j,this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=new j:delete r[e]),this;if(0===arguments.length){for(var n,o=Object.keys(r),s=0;s<o.length;++s)"removeListener"!==(n=o[s])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new j,this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},E.prototype.listeners=function(e){var t,r=this._events;return r&&(t=r[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(t):[]},E.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):C.call(e,t)},E.prototype.listenerCount=C,E.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var S=Object.defineProperty,A=(e,t,r)=>((e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);const T=class e{constructor(t={}){var r;A(this,"cache",[]);const n=null!=(r=t.namespace)?r:"default";return e.instance[n]?e.instance[n]:(e.instance[n]=this,this)}clean(){this.cache.length=0}all(){return this.cache}addFull(e,t,r){return this.add(e,t,r,!0)}add(e,r,n,s){const i=this._find(e,n);if(i)return i.value;{let i;i=r instanceof Function?r():r;const a=n&&JSON.parse(JSON.stringify(o(n))),c={key:e,value:i,props:a};return s&&!t(i)?i:(this.cache.push(c),i instanceof Promise?(i.catch((t=>{this.delete(e,n)})),s&&i.then((r=>(t(r)||this.delete(e,n),r))),i):i)}}match(e,t){const r=this._find(e,t);return null==r?void 0:r.value}matchAll(e,t){return e?this.cache.filter((r=>this._filter(r,e,t))).map((e=>e.value)):this.cache.map((e=>e.value))}delete(e,t){const r="string"==typeof e?this.cache.filter((r=>this._filter(r,e,t))):[e];for(const n of r){const e=this.cache.indexOf(n);-1!==e&&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)return!1;if(!r)return!0;return n(e.props||{},o(r))}};A(T,"instance",{});let q=T;var U="3.0.0-alpha.3",N=Object.defineProperty,$=(e,t,r)=>((e,t,r)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class F extends Error{constructor(e){super(),$(this,"name","NgwError"),$(this,"title"),$(this,"message"),$(this,"detail"),$(this,"exception"),$(this,"status_code"),$(this,"data"),$(this,"guru_meditation"),Object.assign(this,e),Object.setPrototypeOf(this,F.prototype)}}var M=Object.defineProperty,D=(e,t,r)=>((e,t,r)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class G extends F{constructor(e){super(e),D(this,"name","ResourceNotFoundError"),D(this,"exception","nextgisweb.resource.exception.ResourceNotFound"),Object.setPrototypeOf(this,G.prototype)}}function B(e){return"[object Object]"===Object.prototype.toString.call(e)}const H=["description"];function J(t,r=""){r=r?r+"__":"";const n={};for(const[o,s]of Object.entries(t))if(-1===H.indexOf(o))if(B(s))if("owner_user"===o){const e=J(s,o);Object.assign(n,e)}else"parent"===o&&"id"in s&&(n.parent_id=s.id);else e(s)&&(n[r+o]=s);return n}var z=Object.defineProperty,Q=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,K=(e,t,r)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,V=(e,t)=>{for(var r in t||(t={}))W.call(t,r)&&K(e,r,t[r]);if(Q)for(var r of Q(t))X.call(t,r)&&K(e,r,t[r]);return e},Y=(e,t,r)=>K(e,"symbol"!=typeof t?t+"":t,r);class Z{constructor({connector:e,cacheId:t}){Y(this,"cache"),Y(this,"connector"),this.connector=e,this.cache=new q({namespace:t})}getOne(e,t){const r=V({},t);return"string"==typeof e||"number"==typeof e||B(e),"string"==typeof e?this._fetchResourceBy({keyname:e},r):"number"==typeof e?this._fetchResourceById(e,r):B(e)?this._fetchResourceBy(e,r):Promise.resolve(void 0)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new G}))}getId(e,t){return"number"==typeof e?Promise.resolve(e):"string"==typeof e||B(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):Promise.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,J(e)),this.connector.get("resource.search",t,V({serialization:"full"},r)).then((e=>{if((null==t?void 0:t.cache)&&e)for(const t of e)this.cache.add("resource.item",Promise.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):Promise.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",t,{parent:e}).then((e=>{const n=[];for(const o of e)(null==t?void 0:t.cache)&&this.cache.add("resource.item",Promise.resolve(o),{id:o.resource.id}),r.push(o),(null==t?void 0:t.recursive)&&o.resource.children&&n.push(this._getChildrenOf(o.resource.id,t,r));return n.length?Promise.all(n).then((()=>r)):r}))}_cleanResourceItemCache(e){return t=this,r=null,n=function*(){var t;const r=this.cache.all(),n=[];for(const o of r){const r=null==(t=o.props)?void 0:t.id;["resource.item","resource"].includes(o.key)&&void 0!==r&&("number"==typeof r?r===e&&n.push(o):(yield this.getId(r))===e&&n.push(o))}for(const e of n)this.cache.delete(e)},new Promise(((e,o)=>{var s=e=>{try{a(n.next(e))}catch(t){o(t)}},i=e=>{try{a(n.throw(e))}catch(t){o(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((n=n.apply(t,r)).next())}));var t,r,n}_fetchResourceById(e,t){return this.connector.get("resource.item",t,{id:e})}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(t){return Promise.all(this.cache.matchAll("resource.item")).then((r=>(r.filter((r=>{if(r)return t.keyname&&r.resource.keyname?t.keyname===r.resource.keyname:e(t.id)&&e(r.resource.id)?t.id===r.resource.id:n(t,r.resource)})),[])))}}const ee=[];function te(e){ee.push(e)}class re extends Error{constructor(e="AbortError"){super(e),this.name="AbortError"}}var ne=Object.defineProperty,oe=(e,t,r)=>((e,t,r)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class se extends F{constructor(e){super(e),oe(this,"name","InsufficientPermissionsError"),oe(this,"exception","nextgisweb.core.exception.InsufficientPermissions"),Object.setPrototypeOf(this,se.prototype)}}const ie=/\{ *([\w_-]+) *\}/g;function ae(e,t){return e.replace(ie,((e,r)=>{let n=t[r];if(void 0===n)throw new Error("No value provided for letiable "+e);return"function"==typeof n&&(n=n(t)),n}))}var ce=Object.defineProperty,le=Object.getOwnPropertySymbols,ue=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,fe=(e,t,r)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;function pe(e){return t=this,r=null,n=function*(){const{params:t,name:r,connector:n,requestOptions:o}=e,s=yield n.connect();let i=s&&s[r];if(i){i=[...i];let e=i.shift();if(i.length){const r={};for(let e=0;e<i.length;e++){const n=i[e];if(r[e]=`{${n}}`,void 0===t[n])throw new Error(`\`${n}\` URL API argument is not specified`)}e&&(e=ae(e,r))}if(t){const r=[],n=t.paramList;Array.isArray(n)&&n.forEach((([e,t])=>{r.push(`${e}=${t}`)}));for(const e in t)-1===i.indexOf(e)&&r.push(`${e}=${t[e]}`);r.length&&(e=`${e}?${r.join("&")}`)}if(e)return n.makeQuery(e,t,((e,t)=>{for(var r in t||(t={}))ue.call(t,r)&&fe(e,r,t[r]);if(le)for(var r of le(t))he.call(t,r)&&fe(e,r,t[r]);return e})({cacheName:r},o));throw new Error("Request URL is not set")}},new Promise(((e,o)=>{var s=e=>{try{a(n.next(e))}catch(t){o(t)}},i=e=>{try{a(n.throw(e))}catch(t){o(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((n=n.apply(t,r)).next())}));var t,r,n}var de=Object.defineProperty,ye=(e,t,r)=>((e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,t+"",r);class me extends Error{constructor(e){super(),ye(this,"name","NetworkError"),Object.setPrototypeOf(this,me.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}let ve;ve=(e,t,r={},n,o)=>{r.method=r.method||"GET";const s=new XMLHttpRequest;s.open(r.method||"GET",e,!0),"blob"===r.responseType&&(s.responseType=r.responseType);const i=()=>{try{return JSON.parse(s.responseText)}catch(e){return s.responseText}};s.onload=()=>{-1!==[401,403,404,422,500].indexOf(s.status)&&n(new F(i())),((e=!1)=>{const o=e?n:t;"blob"===r.responseType?o(s.response):s.responseText?o(i()):n({message:""})})()},s.onerror=t=>{n(0===s.status?new me(e):t)},s.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&&s.setRequestHeader(l,e)}let c;if(void 0!==r.withCredentials&&(s.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;o&&o((()=>{s.abort()})),s.send(c)};var be=Object.defineProperty,ge=Object.defineProperties,we=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,xe=(e,t,r)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,je=(e,t)=>{for(var r in t||(t={}))_e.call(t,r)&&xe(e,r,t[r]);if(Oe)for(var r of Oe(t))Pe.call(t,r)&&xe(e,r,t[r]);return e},Ee=(e,t,r)=>xe(e,"symbol"!=typeof t?t+"":t,r),Ie=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(t){o(t)}},i=e=>{try{a(r.throw(e))}catch(t){o(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));let Re=0,Le=0;class Ce{constructor(e){this.options=e,Ee(this,"id",Re++),Ee(this,"emitter",new E),Ee(this,"user"),Ee(this,"resources"),Ee(this,"cache"),Ee(this,"withCredentials"),Ee(this,"client",`NextGIS-NGW-Connector/${U}`),Ee(this,"routeStr","/api/component/pyramid/route"),Ee(this,"activeRequests",{}),Ee(this,"requestTransform");const t=function(e){return ee.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return n(t.options.auth,e.auth)}}))}(e);if(this.cache=new q({namespace:e.cacheId}),t)return t;{const{route:t,requestTransform:r,withCredentials:n}=this.options;t&&(this.routeStr=t),r&&(this.requestTransform=r),void 0!==n&&(this.withCredentials=n),this.resources=new Z({connector:this,cacheId:e.cacheId}),te(this)}}static create(e){return new this(e)}clearCache(){this.cache.clean(),this.resources.cache.clean()}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,te(this)}connect(){return Ie(this,null,(function*(){const e=this.options.auth;if(e){const{login:t,password:r}=e;t&&r&&(yield this._login({login:t,password:r}))}const t=`${this.routeStr}?client=${this.client}`;return yield this.makeQuery(t,{},{cacheName:"route",cache:!0,cacheProps:{id:this.id,auth:e,baseUrl:this.options.baseUrl}})}))}login(e,t){return this.logout(),te(this),this._login(e,t)}logout(){this.abort(),function(e){const t=ee.indexOf(e);-1!==t&&ee.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.clearCache(),this.emitter.emit("logout")}getUserInfo(e,t){return Ie(this,null,(function*(){if(this.user&&this.user.id)return this.user;e&&(this.options.auth=e);const r=je({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,n=[t,r].map(encodeURIComponent).join(":");return window.btoa(n)}}abort(){for(const e of Object.values(this.activeRequests))e.abort();this.activeRequests={}}getActiveApiRequests(){return je({},this.activeRequests)}apiRequest(e,t={},r={}){var n;return pe({name:e,params:o(t=null!=(n=r.params)?n:t),requestOptions:r,connector:this})}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){return Ie(this,arguments,(function*(e,t,r={}){var n;if(!(e=(this.options.baseUrl?this.options.baseUrl:"")+e))throw new Error("Empty `url` not allowed");if(t){const r=((e,t)=>{var r={};for(var n in e)_e.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&Oe)for(var n of Oe(e))t.indexOf(n)<0&&Pe.call(e,n)&&(r[n]=e[n]);return r})(t,["paramList"]);e=ae(e,r)}e=encodeURI(s(e)),r=je({withCredentials:this.withCredentials},r);const{cache:i,signal:a,method:c="GET",headers:l,cacheName:u,cacheProps:h,responseType:f,withCredentials:p}=r,d=new AbortController,y=d.signal;if(a){if(a.aborted)throw new re;a.addEventListener("abort",(()=>{d.abort()}))}r.signal=y;const m=()=>Ie(this,null,(function*(){const t=Le++;this.activeRequests[t]=d;try{return this._loadData(e,r)}finally{this._cleanActiveRequest(t)}}));if(i&&"GET"===c){const r=h||(v=je({},o({headers:l,withCredentials:p,responseType:f,baseUrl:this.options.baseUrl,userId:null==(n=this.user)?void 0:n.id})),ge(v,we({params:t})));return this.cache.add(u||e,m,r,!1)}var v;return m()}))}getResource(e,t){return this.resources.getOne(e,t)}getResourceOrFail(e,t){return this.resources.getOneOrFail(e,t)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e,t){return this.resources.getId(e,t)}getResourceIdOrFail(e,t){return this.resources.getIdOrFail(e,t)}getResourcesBy(e,t){return this.resources.getMany(e,t)}getResourceParent(e,t){return this.resources.getParent(e,t)}getResourceChildren(e,t){return this.resources.getChildrenOf(e,t)}updateResource(e,t){return this.resources.update(e,t)}deleteResource(e){return this.resources.delete(e)}_loadData(e,t){return t.responseType=t.responseType||"json",new Promise(((r,n)=>{var o;if(this.user&&((t=t||{}).headers=je(je({},this.getAuthorizationHeaders()),t.headers)),this.requestTransform){const[r,n]=this.requestTransform(e,t);e=r,t=n}let s;ve(e,r,t,n,(e=>{s=e})),null==(o=t.signal)||o.addEventListener("abort",(()=>{void 0!==s&&s(),n(new re)}))})).catch((e=>{if("AbortError"!==e.name){const t=this._handleHttpError(e);if(t)throw t}throw e}))}_login(e,t){return Ie(this,null,(function*(){try{const r=yield this.getUserInfo(e,t);return this.user=r,this.emitter.emit("login",r),r}catch(r){throw this.emitter.emit("login:error",r),r}}))}_cleanActiveRequest(e){delete this.activeRequests[e]}_handleHttpError(e){if(e&&e instanceof F){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new G(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new se(e)}return e}}function ke(e,t,r){if((t=String(t))===(e=String(e)))return!0;if(r&&t.toUpperCase()===e.toUpperCase())return!0;const n=`^${o=t,o.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}$`.replace(/%/g,".*").replace("_",".");var o;return null!==new RegExp(n,r?"i":"").exec(e)}Ee(Ce,"errors",{NgwError:F,ResourceNotFoundError:G});const Se={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)=>ke(e,t),ilike:(e,t)=>ke(e,t,!0)};function Ae(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function Te(e,t){const r="string"==typeof t[0]?t[0]:"all",n=t=>{if(Ae(t)){const[r,n,o]=t,s=Se[n];if(s){if(("like"===n||"ilike"===n)&&"string"==typeof r){let t="";const n=r.replace(/^%?(\w+)%?$/,((n,s)=>(t=e[s],r.replace(s,o))));return s(t,n)}return s(e[r],o)}return!1}return Te(e,t)},o=t.filter((e=>Array.isArray(e)));return"any"===r?o.some(n):o.every(n)}var qe=Object.defineProperty,Ue=Object.defineProperties,Ne=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,De=(e,t,r)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ge=(e,t)=>{for(var r in t||(t={}))Fe.call(t,r)&&De(e,r,t[r]);if($e)for(var r of $e(t))Me.call(t,r)&&De(e,r,t[r]);return e},Be=(e,t)=>Ue(e,Ne(t)),He=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(t){o(t)}},i=e=>{try{a(r.throw(e))}catch(t){o(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));const Je={srs:4326,geom_format:"geojson"};function ze(e){return He(this,null,(function*(){const t=We(e),r=yield Promise.all(t),n=[],o=[];for(const e of r)for(const t of e)n.includes(t.id)||(o.push(t),n.push(t.id));return e.offset||e.limit?o.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:o.length):o}))}function Qe(e){const[t,r,n]=e;let o="",s="";return[`${"id"!==t?"fld_":""}${String(t).trim().replace(/^(%?)(.+?)(%?)$/,((e,t,r,n)=>(o=t,s=n,r)))}__${r}`,o+n+s]}function We(e,t=[],r=[]){var n;const{filters:o}=e,s=null!=(n=e.paramList)?n:[],i="string"==typeof o[0]?o[0]:"all",a=o.filter((e=>Array.isArray(e)));if("any"===i)for(const c of a)Ae(c)?t.push(Ke(Be(Ge({},e),{paramList:[...r,...s,Qe(c)]}))):We(Be(Ge({},e),{filters:c}),t,[...r]);else if("all"===i){const n=[],o=[];for(const e of a)Ae(e)?n.push(Qe(e)):o.push(e);if(o.length)for(const s of o)We(Be(Ge({},e),{filters:s}),t,[...r,...n]);else t.push(Ke(Be(Ge({},e),{paramList:[...r,...s,...n]})))}return t}function Xe(e){return`POLYGON((${e.map((([e,t])=>{const[r,n]=function(e,t){t=t>85.06?85.06:t<-85.06?-85.06:t;const r=20037508.34*e/180;let n=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return n=20037508.34*n/180,[r,n]}(e,t).map((e=>Math.round(1*(e+Number.EPSILON))/1));return r+" "+n})).join(", ")}))`}function Ke(t){const r=Ge({},Je),{limit:n,cache:o,signal:s,offset:i,orderBy:a,paramList:c,connector:l,geomFormat:u,intersects:h,resourceId:f}=t;if(n?n!==Number.POSITIVE_INFINITY&&(r.limit=n):r.limit=7e3,i&&(r.offset=i),u&&(r.geom_format=u),function(t,r){const{extensions:n,geom:o,fields:s,srs:i,ilike:a,like:c}=r,l=n?n.join(","):"";"*"!==l&&(t.extensions=l),null!=s&&(t.fields=Array.isArray(s)?s.join(","):""),void 0!==o&&(t.geom=o?"yes":"no",o||(delete t.srs,delete t.geom_format)),e(a)?t.ilike=a:e(c)&&(t.like=c),e(i)&&(t.srs=i)}(r,t),a&&(r.order_by=a.join(",")),Array.isArray(h)){const e=(p=h,Array.isArray(p)&&4===p.length&&p.every((e=>"number"==typeof e))?function(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}(h):h);r.intersects=Xe(e)}else"string"==typeof h&&(r.intersects=h);var p;c&&(r.paramList=c);const d=Ge({id:f},r);return l.get("feature_layer.feature.collection",{cache:o,signal:s},d)}var Ve=Object.defineProperty,Ye=Object.defineProperties,Ze=Object.getOwnPropertyDescriptors,et=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,nt=(e,t,r)=>t in e?Ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ot=(e,t)=>{for(var r in t||(t={}))tt.call(t,r)&&nt(e,r,t[r]);if(et)for(var r of et(t))rt.call(t,r)&&nt(e,r,t[r]);return e},st=(e,t)=>Ye(e,Ze(t));function it(t){return r=this,n=null,o=function*(){var r;const n=t.filters;if(n){let o=yield ze(st(ot({},t),{filters:n}));return(null!=(r=t.clientFilterValidate)?r:at(n))&&(o=o.filter((t=>Te(function(t){let r;for(r in t){const n=t[r];if("[object Object]"===Object.prototype.toString.call(n)){const o=n;if(e(o.year)&&e(o.month)&&e(o.day)){const e=[o.year,o.month-1,o.day];"hour"in o&&[o.hour,o.minute,o.second].forEach((t=>{e.push(t)})),t[r]=new Date(...e).toISOString()}}else"id"===r&&"string"==typeof n&&(t[r]=n.split(",").map(Number))}return t}(st(ot({},t.fields),{id:t.id})),n)))),o}return Ke(t)},new Promise(((e,t)=>{var s=e=>{try{a(o.next(e))}catch(r){t(r)}},i=e=>{try{a(o.throw(e))}catch(r){t(r)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,i);a((o=o.apply(r,n)).next())}));var r,n,o}function at(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(at(r))return!0}}return!1}var ct=Object.defineProperty,lt=Object.getOwnPropertySymbols,ut=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,ft=(e,t,r)=>t in e?ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,pt=(e,t,r)=>ft(e,"symbol"!=typeof t?t+"":t,r),dt=function(e,t){this[0]=e,this[1]=t},yt=(e,t,r)=>{var n,o,s=(e,t,n,o)=>{try{var i=r[e](t),a=(t=i.value)instanceof dt,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?s("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,o):n({value:r,done:c}))).catch((e=>s("throw",e,n,o)))}catch(l){o(l)}},i=e=>a[e]=t=>new Promise(((r,n)=>s(e,t,r,n))),a={};return r=r.apply(e,t),a[(n="asyncIterator",(o=Symbol[n])?o:Symbol.for("Symbol."+n))]=()=>a,i("next"),i("throw"),i("return"),a};const mt=class e extends x{constructor(e){var t;if(super(e),pt(this,"searchResources",[]),pt(this,"connector"),pt(this,"_abortControllers",[]),!e.searchUrl&&!(null==(t=e.connectorOptions)?void 0:t.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new Ce(((e,t)=>{for(var r in t||(t={}))ut.call(t,r)&&ft(e,r,t[r]);if(lt)for(var r of lt(t))ht.call(t,r)&&ft(e,r,t[r]);return e})({baseUrl:this.searchUrl},e.connectorOptions)),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}search(t){return yt(this,null,(function*(){var r,n;const o=this._makeSignal();for(const i of this.searchResources){if(o.aborted)break;const{searchMethod:a}=i,c=null!=(r=i.limit)?r:e.limit,l=null!=(n=i.id)?n:i.resourceId;try{const e=yield new dt(this.connector.getResourceOrFail(l,{cache:!0})),r={connector:this.connector,resourceId:l,signal:o,limit:c};"like"===a?r.like=t:r.ilike=t;const n=it(r),s=yield new dt(n);for(const o of this._items({entries:s,query:t,config:i,resourceItem:e}))o.result=()=>this.result(o),yield o}catch(s){s&&"name"in s&&"CancelError"!==s.name&&console.warn(s)}}}))}result(e){const t=this._makeSignal();return this.connector.get("feature_layer.feature.item_extent",{signal:t},{id:e.resourceId,fid:e.featureId}).then((t=>{const r=t.extent;return{text:e.text,extent:[r.minLon,r.minLat,r.maxLon,r.maxLat]}}))}reverse(e){return yt(this,null,(function*(){throw new Error("Not implemented")}))}_makeSignal(){const e=new AbortController;return this._abortControllers.push(e),e.signal}_items({entries:e,query:t,config:r,resourceItem:n}){var o;const s=[];let i;n.feature_layer&&(i=null==(o=n.feature_layer.fields.find((e=>e.label_field)))?void 0:o.keyname);return this.searchResources.find((e=>{var t;return null!=(t=e.id)?t:e.resourceId===n.resource.id}))&&e.forEach((e=>{let o=i?e.fields[i]:e.id;r.renderSearch?o=r.renderSearch({item:e,resourceItem:n}):i&&(o=e.fields[i]),s.push({query:t,text:o,featureId:e.id,resourceId:n.resource.id,item:e,resourceItem:n})})),s}};pt(mt,"limit",300);let vt=mt;var bt=Object.defineProperty,gt=(e,t,r)=>((e,t,r)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r),wt=function(e,t){this[0]=e,this[1]=t},Ot=(e,t,r)=>{var n,o,s=(e,t,n,o)=>{try{var i=r[e](t),a=(t=i.value)instanceof wt,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?s("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,o):n({value:r,done:c}))).catch((e=>s("throw",e,n,o)))}catch(l){o(l)}},i=e=>a[e]=t=>new Promise(((r,n)=>s(e,t,r,n))),a={};return r=r.apply(e,t),a[(n="asyncIterator",(o=Symbol[n])?o:Symbol.for("Symbol."+n))]=()=>a,i("next"),i("throw"),i("return"),a};class _t extends x{constructor(e){super(e),gt(this,"searchUrl","https://nominatim.openstreetmap.org"),gt(this,"_abort",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._abort.forEach((e=>e())),this._abort=[]}search(e){return Ot(this,null,(function*(){const t=s(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new Promise(((r,n)=>{const o=new XMLHttpRequest;o.open("GET",t,!0),o.onload=()=>{try{const t=JSON.parse(o.responseText).features.map((t=>({geom:t,extent:t.bbox,text:t.properties&&t.properties.display_name,query:e})));r(t)}catch(t){n(t)}},o.onerror=e=>{n(e)},this._abort.push(o.abort),o.send()})).catch((e=>{throw e})),n=yield new wt(r);if(n)for(const e of n)e.result=()=>this.result(e),yield e}))}result(e){return Promise.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}reverse(e){return Ot(this,null,(function*(){const[t,r]=e,n=s(`${this.searchUrl}/reverse?format=geojson&lat=${r}&lon=${t}`),o=new Promise(((e,o)=>{const s=new XMLHttpRequest;s.open("GET",n,!0),s.onload=()=>{try{const n=JSON.parse(s.responseText).features[0];e({geom:n,extent:n.bbox,text:n.properties&&n.properties.display_name,query:`${r}, ${t}`})}catch(n){o(n)}},s.onerror=e=>{o(e)},this._abort.push(s.abort),s.send()})).catch((e=>{throw e})),i=yield new wt(o);i&&(i.result=()=>this.result(i),yield i)}))}}function Pt(e){return new O(e)}export{x as BaseProvider,O as Geocoder,vt as NgwProvider,_t as NominatimProvider,Pt as create};
|
|
2
2
|
//# sourceMappingURL=geocoder.esm-browser.prod.js.map
|