@nextgis/ngw-map 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ngw-map.cjs.js +1 -1
- package/lib/ngw-map.cjs.prod.js +1 -1
- package/lib/ngw-map.esm-browser.js +21 -9
- 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.esm-bundler.prod.js +1 -1
- package/lib/ngw-map.global.js +62 -46
- 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 +9 -9
package/lib/ngw-map.cjs.js
CHANGED
package/lib/ngw-map.cjs.prod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("events"),t=require("@nextgis/cancelable-promise"),s=require("@nextgis/utils"),r=require("@nextgis/webmap"),i=require("@nextgis/ngw-kit"),o=require("@nextgis/icons"),n=require("@nextgis/ngw-connector"),a=require("@nextgis/qms-kit");function c(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var h=c(t),d=c(n);function u(e,t,s,r){if("number"==typeof t||"string"==typeof t)t=Number(t),e.push({...s,resource:t});else if(Array.isArray(t)){const[i,o]=t;e.push({...s,resource:i,id:o,...r})}else"object"==typeof t&&e.push({...s,...t,...r})}const l={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 y extends r.WebMap{constructor(t){super(function(e){const t=[new a.QmsKit];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new d({baseUrl:e.baseUrl||"",auth:e.auth}),(e=s.deepmerge(l,e)).center||e.bounds||(e.bounds=[-179,-90,180,90]),e.connector&&t.push(new i.NgwKit({connector:e.connector,auth:e.auth})),{...e,starterKits:t,create:!1}}(t)),this.emitter=new e.EventEmitter,this._ngwLayers={},this._promises={select:[],identify:[]},t.connector&&(this.connector=t.connector),this._createWebMap().then((()=>{const e=this.getContainer();e&&e.classList.add("ngw-map-container"),this.options.whitlabel&&this._whiteLabel()}))}async addControl(e,t,s){return await this.onLoad("controls:create"),super.addControl(e,t,s)}async addNgwLayer(e){await this.onMapLoad();const{keyname:t,resourceId:r}=e;(t||void 0!==r)&&s.deprecatedWarn("set `resource` options instead of `keyname` or `resourceId`");const o=e.resource;if(!t&&!r&&!o)throw new Error("resource, resourceId or keyname is required parameter to add NGW layer");if(s.defined(this.options.baseUrl))try{s.defined(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},s.defined(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=i.createNgwLayerAdapter(e,this,this.connector),r={visibility:!0,...e,...e.adapterOptions},o=await this.addLayer(t,r),n=o&&this.getLayerId(o);if(o&&n&&(this._ngwLayers[n]={layer:o,resourceId:o.resourceId},o.options.name=o.options.name||o.item&&o.item.resource.display_name,o.options.baselayer)){if(this.getActiveBaseLayer())return o}return o}catch(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("events"),t=require("@nextgis/cancelable-promise"),s=require("@nextgis/utils"),r=require("@nextgis/webmap"),i=require("@nextgis/ngw-kit"),o=require("@nextgis/icons"),n=require("@nextgis/ngw-connector"),a=require("@nextgis/qms-kit");function c(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var h=c(t),d=c(n);function u(e,t,s,r){if("number"==typeof t||"string"==typeof t)t=Number(t),e.push({...s,resource:t});else if(Array.isArray(t)){const[i,o]=t;e.push({...s,resource:i,id:o,...r})}else"object"==typeof t&&e.push({...s,...t,...r})}const l={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 y extends r.WebMap{constructor(t){super(function(e){const t=[new a.QmsKit];return e.starterKits&&e.starterKits.forEach((e=>{t.push(e)})),e.connector?e.connector&&(e.baseUrl=e.connector.options.baseUrl):e.connector=new d({baseUrl:e.baseUrl||"",auth:e.auth}),(e=s.deepmerge(l,e)).center||e.bounds||(e.bounds=[-179,-90,180,90]),e.connector&&t.push(new i.NgwKit({connector:e.connector,auth:e.auth})),{...e,starterKits:t,create:!1}}(t)),this.emitter=new e.EventEmitter,this._ngwLayers={},this._promises={select:[],identify:[]},t.connector&&(this.connector=t.connector),this._createWebMap().then((()=>{const e=this.getContainer();e&&e.classList.add("ngw-map-container"),this.options.whitlabel&&this._whiteLabel()}))}async addControl(e,t,s){return await this.onLoad("controls:create"),super.addControl(e,t,s)}async addNgwLayer(e){await this.onMapLoad();const{keyname:t,resourceId:r}=e;(t||void 0!==r)&&s.deprecatedWarn("set `resource` options instead of `keyname` or `resourceId`");const o=e.resource;if(!t&&!r&&!o)throw new Error("resource, resourceId or keyname is required parameter to add NGW layer");if(s.defined(this.options.baseUrl))try{s.defined(this.options.setViewDelay)&&(e.adapterOptions=e.adapterOptions||{},s.defined(e.adapterOptions.setViewDelay)||(e.adapterOptions.setViewDelay=this.options.setViewDelay));const t=i.createNgwLayerAdapter(e,this,this.connector),r={visibility:!0,...e,...e.adapterOptions},o=await this.addLayer(t,r),n=o&&this.getLayerId(o);if(o&&n&&(this._ngwLayers[n]={layer:o,resourceId:o.resourceId},o.options.name=o.options.name||o.item&&o.item.resource.display_name,o.options.baselayer)){if(this.getActiveBaseLayer())return o}return o}catch(n){const e=s.isObject(o)&&"id"in o?o.id:t||r||o;console.error(`Can't add NGW layer ${e}.`,n)}}fit(){const{center:e,zoom:t,bounds:s}=this.options;e?(this.setCenter(e),t&&this.setZoom(t)):s&&this.fitBounds(s)}fetchNgwLayerItem(e){return i.fetchNgwLayerItem({connector:this.connector,...e})}fetchNgwLayerItems(e){return i.fetchNgwLayerItems({connector:this.connector,...e})}fetchNgwLayerFeature(e){return i.fetchNgwLayerFeature({connector:this.connector,...e})}fetchNgwLayerFeatures(e){return i.fetchNgwLayerFeatureCollection({connector:this.connector,...e})}fetchIdentifyItem(e,t){const s=i.fetchIdentifyItem({identify:e,connector:this.connector,requestOptions:t});return this._addPromise("identify",s),s}fetchIdentifyGeoJson(e,t=!1){const s=i.fetchIdentifyGeoJson({identify:e,connector:this.connector,multiple:t});return s&&"then"in s?(this._addPromise("identify",s),s):h.resolve(s)}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 s=this._ngwLayers[t];if(s.resourceId===e)return s&&s.layer;if(s.layer.getIdentificationIds){const t=await s.layer.getIdentificationIds();if(t&&t.some((t=>t===e)))return s.layer}if(s.layer.getDependLayers){const t=s.layer.getDependLayers().find((t=>t.item&&t.item.parentId===e));if(t)return t.layer}}}async fitLayer(e,t){let s;s="string"==typeof e||"number"==typeof e?String(s):e.id;const r=s&&this._ngwLayers[s];if(r)if(r.layer.getBounds){const e=await r.layer.getBounds();e&&this.fitBounds(e,t)}else{let e;if(r.layer.item)e=r.layer.item;else{const t=r.resourceId;e=await this.connector.getResource(t)}e&&i.fetchNgwResourceExtent(e,this.connector).then((e=>{e&&this.fitBounds(e,t)}))}else super.fitLayer(e,t)}async zoomToLayer(e){return this.fitLayer(e)}onLoad(e="ngw-map:create"){return super.onLoad(e)}removeLayer(e){const t=this.getLayer(e);if(t){const e=this.getLayerId(t);e&&delete this._ngwLayers[e],super.removeLayer(t)}}enableSelection(){this.$$selectFromNgwRaster||(this.$$selectFromNgwRaster=e=>{this.emitter.listenerCount("ngw:select")&&this._selectFromNgwRaster(e)},this.$$selectFromNgwVector=e=>{this.emitter.listenerCount("ngw:select")&&this._selectFromNgwVector(e)},this.emitter.on("click",this.$$selectFromNgwRaster),this.emitter.on("layer:click",this.$$selectFromNgwVector))}disableSelection(){this.$$selectFromNgwRaster&&(this.emitter.removeListener("click",this.$$selectFromNgwRaster),this.emitter.removeListener("click",this._selectFromNgwVector),this.$$selectFromNgwRaster=void 0,this.$$selectFromNgwVector=void 0)}getNgwLayerItem(e){return this.fetchNgwLayerItem(e)}getNgwLayerItems(e){return this.fetchNgwLayerItems(e)}getNgwLayerFeature(e){return this.fetchNgwLayerFeature(e)}getNgwLayerFeatures(e){return this.fetchNgwLayerFeatures(e)}cancelPromise(...e){this.cancelPromises(...e)}cancelPromises(...e){e.length||(e=Object.keys(this._promises)),e.forEach((e=>{const t=this._promises[e];t&&(t.forEach((e=>e.cancel())),this._promises[e]=[])}))}_addPromise(e,t){const s=this._promises[e];if(s&&-1===s.indexOf(t)){const e=()=>{const e=s.indexOf(t);-1!==e&&s.splice(e,1)};t.then(e),t.catch(e),s.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&&u(e,this.options.webmapId,{fit:t}),this.options.resources&&Array.isArray(this.options.resources))for(const r of this.options.resources){const s={};t||(s.fit=!1),u(e,r,{},s)}for(const r of e)try{await this.addNgwLayer(r)}catch(s){console.warn(s)}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 s={qmsId:e};t&&(s.id=t),this.addBaseLayer("QMS",s)}_selectFromNgwVector(e){const t=e.layer,s=t.item&&t.item.resource.id,r=e.feature;if(void 0!==s&&r){const e=r.id;if(e){const t={featureCount:1,[s]:{featureCount:1,features:[{id:Number(e),fields:r.properties||{},label:`#${s}`,layerId:Number(s),parent:"",geom:r.geometry}]}};return this._emitStatusEvent("ngw:select",this._prepareToIdentify({...t,resources:[s],sourceType:"vector"})),t}}}async _selectFromNgwRaster(e){this._emitStatusEvent("ngw:preselect");const t=[],s=Object.values(this._ngwLayers);s.sort(((e,t)=>e.layer.order&&t.layer.order?t.layer.order-e.layer.order:1)),s.forEach((e=>{const s=e.layer,r="function"==typeof s.getIdentificationIds&&s.getIdentificationIds;r&&s.options.selectable&&this.isLayerVisible(s)&&t.push(r.call(s))}));const r=Promise.all(t),o=await r,n=[];if(o.forEach((e=>{e&&e.forEach((e=>n.push(e)))})),!n.length)return void this._emitStatusEvent("ngw:select",null);const a=this.options.pixelRadius||10,c=this.getCenter();let h=this.getZoom();if(h=void 0!==h?h:20,!c||!h)return void this._emitStatusEvent("ngw:select",null);const d=function(e,t,s){return(s=null!=s?s:10)*(40075016.686*Math.abs(Math.cos(180*e[1]/Math.PI))/Math.pow(2,t+8))*5e-4}(c,h,a),u=i.sendIdentifyRequest(e,{layers:n,connector:this.connector,radius:d}).then((t=>(this._emitStatusEvent("ngw:select",this._prepareToIdentify({...t,resources:n,sourceType:"raster",event:e})),t)));return this._addPromise("select",u),u}_prepareToIdentify(e){return{...e,getIdentifyItems:()=>i.getIdentifyItems(e,!0).map((e=>i.createIdentifyItem({feature:e.feature,connector:this.connector})))}}async _whiteLabel(){const e=this.getContainer();if(e){const t=await i.getCompanyLogo(this.connector,this.options.companyLogoOptions);t&&e.appendChild(t)}}}for(var m in y.getIcon=o.getIcon,exports.NgwMap=y,exports.createNgwMap=async function(e){return new y(e).onLoad()},r)"default"===m||exports.hasOwnProperty(m)||(exports[m]=r[m]);
|
|
2
2
|
//# sourceMappingURL=ngw-map.cjs.prod.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-map; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/ngw-map; version: 1.11.0; author: NextGIS */
|
|
2
2
|
var events = {exports: {}};
|
|
3
3
|
|
|
4
4
|
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
@@ -3611,6 +3611,10 @@ class NetworkError extends Error {
|
|
|
3611
3611
|
}
|
|
3612
3612
|
}
|
|
3613
3613
|
|
|
3614
|
+
function isObject(val) {
|
|
3615
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3614
3618
|
let loadData;
|
|
3615
3619
|
// @ts-ignore
|
|
3616
3620
|
{
|
|
@@ -3644,7 +3648,7 @@ let loadData;
|
|
|
3644
3648
|
}
|
|
3645
3649
|
};
|
|
3646
3650
|
xhr.onload = () => {
|
|
3647
|
-
if ([401, 403, 404, 500].indexOf(xhr.status) !== -1) {
|
|
3651
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
3648
3652
|
error(new NgwError(getResponseText()));
|
|
3649
3653
|
}
|
|
3650
3654
|
processingResponse();
|
|
@@ -3699,7 +3703,7 @@ let loadData;
|
|
|
3699
3703
|
data = new FormData();
|
|
3700
3704
|
data.append('file', options.file);
|
|
3701
3705
|
if (options.data) {
|
|
3702
|
-
for (const d in data) {
|
|
3706
|
+
for (const d in options.data) {
|
|
3703
3707
|
data.append(d, data[d]);
|
|
3704
3708
|
}
|
|
3705
3709
|
}
|
|
@@ -3785,10 +3789,6 @@ function removeConnector(connector) {
|
|
|
3785
3789
|
}
|
|
3786
3790
|
}
|
|
3787
3791
|
|
|
3788
|
-
function isObject(val) {
|
|
3789
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
3790
|
-
}
|
|
3791
|
-
|
|
3792
3792
|
const exclude = ['description'];
|
|
3793
3793
|
/**
|
|
3794
3794
|
* @remarks
|
|
@@ -4013,7 +4013,7 @@ class ResourcesControl {
|
|
|
4013
4013
|
}
|
|
4014
4014
|
}
|
|
4015
4015
|
_fetchResourceById(id, requestOptions) {
|
|
4016
|
-
const promise = () => this.connector.get('resource.item', requestOptions, { id })
|
|
4016
|
+
const promise = () => this.connector.get('resource.item', requestOptions, { id });
|
|
4017
4017
|
return this.cache
|
|
4018
4018
|
.add('resource.item', promise, {
|
|
4019
4019
|
id,
|
|
@@ -4215,7 +4215,7 @@ class NgwConnector$1 {
|
|
|
4215
4215
|
headers: this.getAuthorizationHeaders(credentials),
|
|
4216
4216
|
// withCredentials: true
|
|
4217
4217
|
};
|
|
4218
|
-
// Do not use
|
|
4218
|
+
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
4219
4219
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
4220
4220
|
.then((data) => {
|
|
4221
4221
|
this.user = data;
|
|
@@ -6203,8 +6203,17 @@ class NgwWebmapLayerAdapter {
|
|
|
6203
6203
|
}
|
|
6204
6204
|
}
|
|
6205
6205
|
async addLayer(options) {
|
|
6206
|
+
var _a, _b;
|
|
6206
6207
|
this.options = { ...this.options, ...options };
|
|
6207
6208
|
this.layer = await this._getWebMapLayerItem();
|
|
6209
|
+
const extentConstrained = (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.webmap) === null || _b === void 0 ? void 0 : _b.extent_constrained;
|
|
6210
|
+
if (this.options.useExtentConstrained &&
|
|
6211
|
+
this._extent &&
|
|
6212
|
+
extentConstrained) {
|
|
6213
|
+
this.options.webMap.setView({ maxBounds: this._extent });
|
|
6214
|
+
// @ts-ignore
|
|
6215
|
+
window.webmap = this.options.webMap;
|
|
6216
|
+
}
|
|
6208
6217
|
return this.layer;
|
|
6209
6218
|
}
|
|
6210
6219
|
removeLayer() {
|
|
@@ -6223,6 +6232,9 @@ class NgwWebmapLayerAdapter {
|
|
|
6223
6232
|
this.options.webMap.showLayer(this._lastActiveBaselayer);
|
|
6224
6233
|
}
|
|
6225
6234
|
}
|
|
6235
|
+
if (this.options.useExtentConstrained && this._extent) {
|
|
6236
|
+
this.options.webMap.setView({ maxBounds: null });
|
|
6237
|
+
}
|
|
6226
6238
|
delete this.layer;
|
|
6227
6239
|
delete this.response;
|
|
6228
6240
|
delete this._webmapLayersIds;
|