@nextgis/ngw-map 1.10.0 → 1.11.7
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 -12
- 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 -49
- 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.7; author: NextGIS */
|
|
2
2
|
var events = {exports: {}};
|
|
3
3
|
|
|
4
4
|
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
@@ -1464,9 +1464,6 @@ const paintTypeAlias = {
|
|
|
1464
1464
|
line: 'path',
|
|
1465
1465
|
point: 'circle',
|
|
1466
1466
|
};
|
|
1467
|
-
/**
|
|
1468
|
-
* @internal
|
|
1469
|
-
*/
|
|
1470
1467
|
const typeAlias = {
|
|
1471
1468
|
Point: 'point',
|
|
1472
1469
|
LineString: 'line',
|
|
@@ -3611,6 +3608,10 @@ class NetworkError extends Error {
|
|
|
3611
3608
|
}
|
|
3612
3609
|
}
|
|
3613
3610
|
|
|
3611
|
+
function isObject(val) {
|
|
3612
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3614
3615
|
let loadData;
|
|
3615
3616
|
// @ts-ignore
|
|
3616
3617
|
{
|
|
@@ -3644,7 +3645,7 @@ let loadData;
|
|
|
3644
3645
|
}
|
|
3645
3646
|
};
|
|
3646
3647
|
xhr.onload = () => {
|
|
3647
|
-
if ([401, 403, 404, 500].indexOf(xhr.status) !== -1) {
|
|
3648
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
3648
3649
|
error(new NgwError(getResponseText()));
|
|
3649
3650
|
}
|
|
3650
3651
|
processingResponse();
|
|
@@ -3699,7 +3700,7 @@ let loadData;
|
|
|
3699
3700
|
data = new FormData();
|
|
3700
3701
|
data.append('file', options.file);
|
|
3701
3702
|
if (options.data) {
|
|
3702
|
-
for (const d in data) {
|
|
3703
|
+
for (const d in options.data) {
|
|
3703
3704
|
data.append(d, data[d]);
|
|
3704
3705
|
}
|
|
3705
3706
|
}
|
|
@@ -3785,10 +3786,6 @@ function removeConnector(connector) {
|
|
|
3785
3786
|
}
|
|
3786
3787
|
}
|
|
3787
3788
|
|
|
3788
|
-
function isObject(val) {
|
|
3789
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
3790
|
-
}
|
|
3791
|
-
|
|
3792
3789
|
const exclude = ['description'];
|
|
3793
3790
|
/**
|
|
3794
3791
|
* @remarks
|
|
@@ -4013,7 +4010,7 @@ class ResourcesControl {
|
|
|
4013
4010
|
}
|
|
4014
4011
|
}
|
|
4015
4012
|
_fetchResourceById(id, requestOptions) {
|
|
4016
|
-
const promise = () => this.connector.get('resource.item', requestOptions, { id })
|
|
4013
|
+
const promise = () => this.connector.get('resource.item', requestOptions, { id });
|
|
4017
4014
|
return this.cache
|
|
4018
4015
|
.add('resource.item', promise, {
|
|
4019
4016
|
id,
|
|
@@ -4215,7 +4212,7 @@ class NgwConnector$1 {
|
|
|
4215
4212
|
headers: this.getAuthorizationHeaders(credentials),
|
|
4216
4213
|
// withCredentials: true
|
|
4217
4214
|
};
|
|
4218
|
-
// Do not use
|
|
4215
|
+
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
4219
4216
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
4220
4217
|
.then((data) => {
|
|
4221
4218
|
this.user = data;
|
|
@@ -6203,8 +6200,17 @@ class NgwWebmapLayerAdapter {
|
|
|
6203
6200
|
}
|
|
6204
6201
|
}
|
|
6205
6202
|
async addLayer(options) {
|
|
6203
|
+
var _a, _b;
|
|
6206
6204
|
this.options = { ...this.options, ...options };
|
|
6207
6205
|
this.layer = await this._getWebMapLayerItem();
|
|
6206
|
+
const extentConstrained = (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.webmap) === null || _b === void 0 ? void 0 : _b.extent_constrained;
|
|
6207
|
+
if (this.options.useExtentConstrained &&
|
|
6208
|
+
this._extent &&
|
|
6209
|
+
extentConstrained) {
|
|
6210
|
+
this.options.webMap.setView({ maxBounds: this._extent });
|
|
6211
|
+
// @ts-ignore
|
|
6212
|
+
window.webmap = this.options.webMap;
|
|
6213
|
+
}
|
|
6208
6214
|
return this.layer;
|
|
6209
6215
|
}
|
|
6210
6216
|
removeLayer() {
|
|
@@ -6223,6 +6229,9 @@ class NgwWebmapLayerAdapter {
|
|
|
6223
6229
|
this.options.webMap.showLayer(this._lastActiveBaselayer);
|
|
6224
6230
|
}
|
|
6225
6231
|
}
|
|
6232
|
+
if (this.options.useExtentConstrained && this._extent) {
|
|
6233
|
+
this.options.webMap.setView({ maxBounds: null });
|
|
6234
|
+
}
|
|
6226
6235
|
delete this.layer;
|
|
6227
6236
|
delete this.response;
|
|
6228
6237
|
delete this._webmapLayersIds;
|