@nextgis/ngw-map 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-map; version: 3.0.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 3.1.0; author: NextGIS */
2
2
  var NgwMap = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -354,6 +354,20 @@ var NgwMap = (function (exports) {
354
354
  function fixUrlStr(url) {
355
355
  return url.replace(/([^:]\/)\/+/g, "$1");
356
356
  }
357
+ function updateUrlParams(urlStr, params) {
358
+ const url = new URL(urlStr);
359
+ const searchParams = new URLSearchParams(url.search);
360
+ Object.entries(params).forEach(([key, value]) => {
361
+ if (value === void 0) {
362
+ searchParams.delete(key);
363
+ } else {
364
+ searchParams.set(key, value);
365
+ }
366
+ });
367
+ searchParams.set("timestamp", String((/* @__PURE__ */ new Date()).getTime()));
368
+ const newSearch = [...searchParams.entries()].map(([key, value]) => `${key}=${value}`).join("&");
369
+ return `${url.origin}${url.pathname}?${newSearch}`;
370
+ }
357
371
 
358
372
  const templateRe = /\{ *([\w_-]+) *\}/g;
359
373
  function template(str, data) {
@@ -1068,7 +1082,7 @@ var NgwMap = (function (exports) {
1068
1082
 
1069
1083
  var pkg = {
1070
1084
  name: "@nextgis/ngw-connector",
1071
- version: "3.0.0",
1085
+ version: "3.0.1",
1072
1086
  _priority: 12,
1073
1087
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
1074
1088
  main: "index.js",
@@ -1325,7 +1339,7 @@ var NgwMap = (function (exports) {
1325
1339
  }
1326
1340
  return a;
1327
1341
  };
1328
- var __objRest$5 = (source, exclude) => {
1342
+ var __objRest$6 = (source, exclude) => {
1329
1343
  var target = {};
1330
1344
  for (var prop in source)
1331
1345
  if (__hasOwnProp$y.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -1479,7 +1493,7 @@ var NgwMap = (function (exports) {
1479
1493
  cache,
1480
1494
  query,
1481
1495
  json
1482
- } = _a, opt = __objRest$5(_a, [
1496
+ } = _a, opt = __objRest$6(_a, [
1483
1497
  "withCredentials",
1484
1498
  "responseType",
1485
1499
  "cacheProps",
@@ -1589,7 +1603,7 @@ var NgwMap = (function (exports) {
1589
1603
  return a;
1590
1604
  };
1591
1605
  var __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
1592
- var __objRest$4 = (source, exclude) => {
1606
+ var __objRest$5 = (source, exclude) => {
1593
1607
  var target = {};
1594
1608
  for (var prop in source)
1595
1609
  if (__hasOwnProp$x.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -1668,7 +1682,7 @@ var NgwMap = (function (exports) {
1668
1682
  for (const method of methods) {
1669
1683
  const methodResp = (requestOptions) => {
1670
1684
  var _b;
1671
- const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$4(_a, ["headers"]);
1685
+ const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$5(_a, ["headers"]);
1672
1686
  if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
1673
1687
  throw new AbortError();
1674
1688
  }
@@ -1826,7 +1840,7 @@ var NgwMap = (function (exports) {
1826
1840
  return a;
1827
1841
  };
1828
1842
  var __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b));
1829
- var __objRest$3 = (source, exclude) => {
1843
+ var __objRest$4 = (source, exclude) => {
1830
1844
  var target = {};
1831
1845
  for (var prop in source)
1832
1846
  if (__hasOwnProp$w.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -2001,7 +2015,7 @@ var NgwMap = (function (exports) {
2001
2015
  credentials = credentials || this.options.auth;
2002
2016
  if (credentials) {
2003
2017
  const { login, password } = credentials;
2004
- const encodedStr = [login, password].map(encodeURIComponent).join(":");
2018
+ const encodedStr = `${login}:${password}`;
2005
2019
  {
2006
2020
  return window.btoa(encodedStr);
2007
2021
  }
@@ -2034,7 +2048,7 @@ var NgwMap = (function (exports) {
2034
2048
  throw new Error("Empty `url` not allowed");
2035
2049
  }
2036
2050
  if (params) {
2037
- const _a = params, restParams = __objRest$3(_a, ["paramList"]);
2051
+ const _a = params, restParams = __objRest$4(_a, ["paramList"]);
2038
2052
  url = template(url, restParams);
2039
2053
  }
2040
2054
  url = encodeURI(fixUrlStr(url));
@@ -3104,7 +3118,7 @@ var NgwMap = (function (exports) {
3104
3118
  return like(a, b, true);
3105
3119
  }
3106
3120
  };
3107
- function isPropertyFilter(filter) {
3121
+ function isPropertyFilter$1(filter) {
3108
3122
  const pf = filter;
3109
3123
  if (pf.length === 3 && typeof pf[0] === "string" && typeof pf[1] === "string") {
3110
3124
  return true;
@@ -3122,7 +3136,7 @@ var NgwMap = (function (exports) {
3122
3136
  function propertiesFilter(properties, filters) {
3123
3137
  const logic = typeof filters[0] === "string" ? filters[0] : "all";
3124
3138
  const filterFunction = (p) => {
3125
- if (isPropertyFilter(p)) {
3139
+ if (isPropertyFilter$1(p)) {
3126
3140
  const [field, operation, value] = p;
3127
3141
  const operationExec = operationsAliases[operation];
3128
3142
  if (operationExec) {
@@ -3275,7 +3289,7 @@ var NgwMap = (function (exports) {
3275
3289
  const filters_ = filters.filter((x) => Array.isArray(x));
3276
3290
  if (logic === "any") {
3277
3291
  for (const f of filters_) {
3278
- if (isPropertyFilter(f)) {
3292
+ if (isPropertyFilter$1(f)) {
3279
3293
  _queries.push(
3280
3294
  fetchNgwLayerItemsRequest(__spreadProps$f(__spreadValues$q({}, opt), {
3281
3295
  paramList: [..._parentAllParams, ...paramList, createParam(f)]
@@ -3289,7 +3303,7 @@ var NgwMap = (function (exports) {
3289
3303
  const filters2 = [];
3290
3304
  const propertiesFilterList = [];
3291
3305
  for (const f of filters_) {
3292
- if (isPropertyFilter(f)) {
3306
+ if (isPropertyFilter$1(f)) {
3293
3307
  filters2.push(createParam(f));
3294
3308
  } else {
3295
3309
  propertiesFilterList.push(f);
@@ -5106,7 +5120,7 @@ var NgwMap = (function (exports) {
5106
5120
  return a;
5107
5121
  };
5108
5122
  var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
5109
- var __objRest$2 = (source, exclude) => {
5123
+ var __objRest$3 = (source, exclude) => {
5110
5124
  var target = {};
5111
5125
  for (var prop in source)
5112
5126
  if (__hasOwnProp$h.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -5119,7 +5133,7 @@ var NgwMap = (function (exports) {
5119
5133
  return target;
5120
5134
  };
5121
5135
  function updateImageParams(params, resourceId) {
5122
- const _a = params, { bbox, width, height, nd } = _a, rest = __objRest$2(_a, ["bbox", "width", "height", "nd"]);
5136
+ const _a = params, { bbox, width, height, nd } = _a, rest = __objRest$3(_a, ["bbox", "width", "height", "nd"]);
5123
5137
  return __spreadProps$9(__spreadValues$g({}, rest), {
5124
5138
  resource: Array.isArray(resourceId) ? resourceId.join(",") : resourceId,
5125
5139
  extent: bbox,
@@ -5250,7 +5264,7 @@ var NgwMap = (function (exports) {
5250
5264
  }
5251
5265
  return a;
5252
5266
  };
5253
- var __objRest$1 = (source, exclude) => {
5267
+ var __objRest$2 = (source, exclude) => {
5254
5268
  var target = {};
5255
5269
  for (var prop in source)
5256
5270
  if (__hasOwnProp$g.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -5283,11 +5297,11 @@ var NgwMap = (function (exports) {
5283
5297
  step((generator = generator.apply(__this, __arguments)).next());
5284
5298
  });
5285
5299
  };
5286
- const URL = "https://qms.nextgis.com";
5287
- function createQmsAdapter(webMapOrOptions, url = URL, createOpt = {}) {
5300
+ const URL$1 = "https://qms.nextgis.com";
5301
+ function createQmsAdapter(webMapOrOptions, url = URL$1, createOpt = {}) {
5288
5302
  let webMap;
5289
5303
  if ("webMap" in webMapOrOptions) {
5290
- const _a = webMapOrOptions, { webMap: webMap_, url: url_ } = _a, adapterOptions = __objRest$1(_a, ["webMap", "url"]);
5304
+ const _a = webMapOrOptions, { webMap: webMap_, url: url_ } = _a, adapterOptions = __objRest$2(_a, ["webMap", "url"]);
5291
5305
  webMap = webMap_;
5292
5306
  if (url_) {
5293
5307
  url = url_;
@@ -5299,7 +5313,7 @@ var NgwMap = (function (exports) {
5299
5313
  webMap = webMapOrOptions;
5300
5314
  }
5301
5315
  if (!url) {
5302
- url = URL;
5316
+ url = URL$1;
5303
5317
  }
5304
5318
  class QmsAdapter {
5305
5319
  constructor(map, options) {
@@ -5928,6 +5942,134 @@ var NgwMap = (function (exports) {
5928
5942
  });
5929
5943
  }
5930
5944
 
5945
+ function isPropertyFilter(value) {
5946
+ return Array.isArray(value) && value.length === 3 && typeof value[0] === "string" && typeof value[1] === "string";
5947
+ }
5948
+ function isPropertiesFilterGroup(value) {
5949
+ return Array.isArray(value) && !isPropertyFilter(value);
5950
+ }
5951
+ function toGetExpr(field) {
5952
+ return ["get", field];
5953
+ }
5954
+ function toConditionExpr(filter) {
5955
+ const [fieldRaw, op, value] = filter;
5956
+ const field = String(fieldRaw);
5957
+ const getExpr = toGetExpr(field);
5958
+ switch (op) {
5959
+ case "eq":
5960
+ if (value === null) {
5961
+ return ["is_null", getExpr];
5962
+ }
5963
+ return ["==", getExpr, value];
5964
+ case "ne":
5965
+ if (value === null) {
5966
+ return ["!is_null", getExpr];
5967
+ }
5968
+ return ["!=", getExpr, value];
5969
+ case "gt":
5970
+ if (typeof value !== "number" && typeof value !== "string") {
5971
+ throw new Error(
5972
+ `Operator "gt" requires number or string for "${field}"`
5973
+ );
5974
+ }
5975
+ return [">", getExpr, value];
5976
+ case "lt":
5977
+ if (typeof value !== "number" && typeof value !== "string") {
5978
+ throw new Error(
5979
+ `Operator "lt" requires number or string for "${field}"`
5980
+ );
5981
+ }
5982
+ return ["<", getExpr, value];
5983
+ case "ge":
5984
+ if (typeof value !== "number" && typeof value !== "string") {
5985
+ throw new Error(
5986
+ `Operator "ge" requires number or string for "${field}"`
5987
+ );
5988
+ }
5989
+ return [">=", getExpr, value];
5990
+ case "le":
5991
+ if (typeof value !== "number" && typeof value !== "string") {
5992
+ throw new Error(
5993
+ `Operator "le" requires number or string for "${field}"`
5994
+ );
5995
+ }
5996
+ return ["<=", getExpr, value];
5997
+ case "in":
5998
+ if (!Array.isArray(value) || !value.every((x) => typeof x === "string" || typeof x === "number")) {
5999
+ throw new Error(
6000
+ `Operator "in" requires (string | number)[] for "${field}"`
6001
+ );
6002
+ }
6003
+ if (!value.length) {
6004
+ throw new Error(
6005
+ `Operator "in" requires non-empty array for "${field}"`
6006
+ );
6007
+ }
6008
+ return ["in", getExpr, ...value];
6009
+ case "notin":
6010
+ if (!Array.isArray(value) || !value.every((x) => typeof x === "string" || typeof x === "number")) {
6011
+ throw new Error(
6012
+ `Operator "notin" requires (string | number)[] for "${field}"`
6013
+ );
6014
+ }
6015
+ if (!value.length) {
6016
+ throw new Error(
6017
+ `Operator "notin" requires non-empty array for "${field}"`
6018
+ );
6019
+ }
6020
+ return ["!in", getExpr, ...value];
6021
+ case "like":
6022
+ case "ilike":
6023
+ throw new Error(
6024
+ `Operator "${op}" is not supported by server FilterExpression`
6025
+ );
6026
+ default: {
6027
+ const exhaustive = op;
6028
+ throw new Error(`Unsupported operator: ${exhaustive}`);
6029
+ }
6030
+ }
6031
+ }
6032
+ function toGroupExpr(filters) {
6033
+ let logicalOp = "all";
6034
+ const children = [];
6035
+ for (const item of filters) {
6036
+ if (item === "all" || item === "any") {
6037
+ logicalOp = item;
6038
+ continue;
6039
+ }
6040
+ if (isPropertyFilter(item)) {
6041
+ children.push(toConditionExpr(item));
6042
+ continue;
6043
+ }
6044
+ if (isPropertiesFilterGroup(item)) {
6045
+ children.push(toGroupExpr(item));
6046
+ continue;
6047
+ }
6048
+ throw new Error("Invalid PropertiesFilter node");
6049
+ }
6050
+ return [logicalOp, ...children];
6051
+ }
6052
+ function propertiesFilterToExpression(filters) {
6053
+ if (!(filters == null ? void 0 : filters.length)) {
6054
+ return [];
6055
+ }
6056
+ return toGroupExpr(filters);
6057
+ }
6058
+ function propertiesFilterToExpressionString(filters) {
6059
+ if (!(filters == null ? void 0 : filters.length)) {
6060
+ return void 0;
6061
+ }
6062
+ return JSON.stringify(
6063
+ propertiesFilterToExpression(filters)
6064
+ );
6065
+ }
6066
+
6067
+ function createLayerFilterParam(resourceId, filter) {
6068
+ return {
6069
+ [`filter[${resourceId}]`]: propertiesFilterToExpressionString(filter)
6070
+ };
6071
+ }
6072
+
5931
6073
  var __defProp$j = Object.defineProperty;
5932
6074
  var __defProps$6 = Object.defineProperties;
5933
6075
  var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
@@ -5947,6 +6089,18 @@ var NgwMap = (function (exports) {
5947
6089
  return a;
5948
6090
  };
5949
6091
  var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
6092
+ var __objRest$1 = (source, exclude) => {
6093
+ var target = {};
6094
+ for (var prop in source)
6095
+ if (__hasOwnProp$c.call(source, prop) && exclude.indexOf(prop) < 0)
6096
+ target[prop] = source[prop];
6097
+ if (source != null && __getOwnPropSymbols$c)
6098
+ for (var prop of __getOwnPropSymbols$c(source)) {
6099
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$c.call(source, prop))
6100
+ target[prop] = source[prop];
6101
+ }
6102
+ return target;
6103
+ };
5950
6104
  var __publicField$c = (obj, key, value) => __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
5951
6105
  var __async$c = (__this, __arguments, generator) => {
5952
6106
  return new Promise((resolve, reject) => {
@@ -6011,8 +6165,18 @@ var NgwMap = (function (exports) {
6011
6165
  baseUrl: connector.options.baseUrl || ""
6012
6166
  });
6013
6167
  if (opt) {
6014
- const layerAdapterOptions = __spreadProps$6(__spreadValues$b(__spreadValues$b({}, opt), layerOptions.adapterOptions), {
6015
- params: { resource: resourceId },
6168
+ const _a = layerOptions.adapterOptions || {}, { propertiesFilter } = _a, restAdapterOptions = __objRest$1(_a, ["propertiesFilter"]);
6169
+ const filterParams = createLayerFilterParam(
6170
+ resourceId,
6171
+ propertiesFilter
6172
+ );
6173
+ const layerAdapterOptions = __spreadProps$6(__spreadValues$b(__spreadValues$b({}, opt), restAdapterOptions), {
6174
+ params: __spreadValues$b({
6175
+ resource: resourceId
6176
+ }, filterParams),
6177
+ url: adapter === "TILE" && opt.url ? updateUrlParams(opt.url, __spreadValues$b({
6178
+ resource: String(resourceId)
6179
+ }, filterParams)) : opt.url,
6016
6180
  layers: opt.layers || String(resourceId),
6017
6181
  resourceId
6018
6182
  });
@@ -6025,6 +6189,15 @@ var NgwMap = (function (exports) {
6025
6189
  addLayer(addOptions) {
6026
6190
  return super.addLayer(__spreadValues$b(__spreadValues$b({}, this.options), addOptions));
6027
6191
  }
6192
+ propertiesFilter(filters) {
6193
+ return __async$c(this, null, function* () {
6194
+ var _a;
6195
+ const opt = this.options;
6196
+ const params = __spreadValues$b(__spreadValues$b({}, opt.params || {}), createLayerFilterParam(this.resourceId, filters));
6197
+ opt.params = params;
6198
+ (_a = this.updateLayer) == null ? void 0 : _a.call(this, { params });
6199
+ });
6200
+ }
6028
6201
  getIdentificationIds() {
6029
6202
  return __async$c(this, null, function* () {
6030
6203
  if (this.item) {
@@ -6520,7 +6693,8 @@ var NgwMap = (function (exports) {
6520
6693
  component: "pyramid"
6521
6694
  }
6522
6695
  });
6523
- if (settings && settings.company_logo && settings.company_logo.enabled) {
6696
+ const company_logo = settings && "company_logo" in settings ? settings.company_logo : void 0;
6697
+ if (company_logo && company_logo.enabled) {
6524
6698
  const anchor = document.createElement("a");
6525
6699
  anchor.style.position = "absolute";
6526
6700
  anchor.style.bottom = "0";
@@ -6555,10 +6729,10 @@ var NgwMap = (function (exports) {
6555
6729
  } else {
6556
6730
  return;
6557
6731
  }
6558
- if (settings.company_logo.link !== null && settings.company_logo.link.trim() !== "") {
6559
- anchor.href = settings.company_logo.link;
6732
+ if (company_logo.link !== null && company_logo.link.trim() !== "") {
6733
+ anchor.href = company_logo.link;
6560
6734
  anchor.target = "_blank";
6561
- if (settings.company_logo.link.search(/:\/\/nextgis/) !== -1) {
6735
+ if (company_logo.link.search(/:\/\/nextgis/) !== -1) {
6562
6736
  img.alt = "Get your own Web GIS at nextgis.com";
6563
6737
  }
6564
6738
  }
@@ -9986,7 +10160,7 @@ var NgwMap = (function (exports) {
9986
10160
  addNgwLayer(options) {
9987
10161
  return __async$1(this, null, function* () {
9988
10162
  yield this.onMapLoad();
9989
- const { keyname, resourceId } = options;
10163
+ const { keyname, resourceId, filters } = options;
9990
10164
  if (keyname || resourceId !== void 0) {
9991
10165
  deprecatedWarn(
9992
10166
  "set `resource` options instead of `keyname` or `resourceId`"
@@ -10000,12 +10174,15 @@ var NgwMap = (function (exports) {
10000
10174
  }
10001
10175
  if (defined(this.options.baseUrl)) {
10002
10176
  try {
10177
+ options.adapterOptions = options.adapterOptions || {};
10003
10178
  if (defined(this.options.setViewDelay)) {
10004
- options.adapterOptions = options.adapterOptions || {};
10005
10179
  if (!defined(options.adapterOptions.setViewDelay)) {
10006
10180
  options.adapterOptions.setViewDelay = this.options.setViewDelay;
10007
10181
  }
10008
10182
  }
10183
+ if (defined(filters)) {
10184
+ options.adapterOptions.propertiesFilter = filters;
10185
+ }
10009
10186
  const adapter = createNgwLayerAdapter(options, this, this.connector);
10010
10187
  const adapterOpts = __spreadValues(__spreadValues({
10011
10188
  visibility: true