@nextgis/ngw-map 3.0.1 → 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.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 3.1.0; author: NextGIS */
2
2
  const svgPath = {
3
3
  brill: '<path d="m6 0-5 6 5 6 5-6z"/>',
4
4
  circle: '<circle cx="6" cy="6" r="6"/>',
@@ -351,6 +351,20 @@ function isArray(val) {
351
351
  function fixUrlStr(url) {
352
352
  return url.replace(/([^:]\/)\/+/g, "$1");
353
353
  }
354
+ function updateUrlParams(urlStr, params) {
355
+ const url = new URL(urlStr);
356
+ const searchParams = new URLSearchParams(url.search);
357
+ Object.entries(params).forEach(([key, value]) => {
358
+ if (value === void 0) {
359
+ searchParams.delete(key);
360
+ } else {
361
+ searchParams.set(key, value);
362
+ }
363
+ });
364
+ searchParams.set("timestamp", String((/* @__PURE__ */ new Date()).getTime()));
365
+ const newSearch = [...searchParams.entries()].map(([key, value]) => `${key}=${value}`).join("&");
366
+ return `${url.origin}${url.pathname}?${newSearch}`;
367
+ }
354
368
 
355
369
  const templateRe = /\{ *([\w_-]+) *\}/g;
356
370
  function template(str, data) {
@@ -1322,7 +1336,7 @@ var __spreadValues$x = (a, b) => {
1322
1336
  }
1323
1337
  return a;
1324
1338
  };
1325
- var __objRest$5 = (source, exclude) => {
1339
+ var __objRest$6 = (source, exclude) => {
1326
1340
  var target = {};
1327
1341
  for (var prop in source)
1328
1342
  if (__hasOwnProp$y.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -1476,7 +1490,7 @@ function request(path, options, cacheEngine) {
1476
1490
  cache,
1477
1491
  query,
1478
1492
  json
1479
- } = _a, opt = __objRest$5(_a, [
1493
+ } = _a, opt = __objRest$6(_a, [
1480
1494
  "withCredentials",
1481
1495
  "responseType",
1482
1496
  "cacheProps",
@@ -1586,7 +1600,7 @@ var __spreadValues$w = (a, b) => {
1586
1600
  return a;
1587
1601
  };
1588
1602
  var __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
1589
- var __objRest$4 = (source, exclude) => {
1603
+ var __objRest$5 = (source, exclude) => {
1590
1604
  var target = {};
1591
1605
  for (var prop in source)
1592
1606
  if (__hasOwnProp$x.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -1665,7 +1679,7 @@ function route(name, connector, ...rest) {
1665
1679
  for (const method of methods) {
1666
1680
  const methodResp = (requestOptions) => {
1667
1681
  var _b;
1668
- const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$4(_a, ["headers"]);
1682
+ const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$5(_a, ["headers"]);
1669
1683
  if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
1670
1684
  throw new AbortError();
1671
1685
  }
@@ -1823,7 +1837,7 @@ var __spreadValues$v = (a, b) => {
1823
1837
  return a;
1824
1838
  };
1825
1839
  var __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b));
1826
- var __objRest$3 = (source, exclude) => {
1840
+ var __objRest$4 = (source, exclude) => {
1827
1841
  var target = {};
1828
1842
  for (var prop in source)
1829
1843
  if (__hasOwnProp$w.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -2031,7 +2045,7 @@ class NgwConnector {
2031
2045
  throw new Error("Empty `url` not allowed");
2032
2046
  }
2033
2047
  if (params) {
2034
- const _a = params, restParams = __objRest$3(_a, ["paramList"]);
2048
+ const _a = params, restParams = __objRest$4(_a, ["paramList"]);
2035
2049
  url = template(url, restParams);
2036
2050
  }
2037
2051
  url = encodeURI(fixUrlStr(url));
@@ -3101,7 +3115,7 @@ const operationsAliases = {
3101
3115
  return like(a, b, true);
3102
3116
  }
3103
3117
  };
3104
- function isPropertyFilter(filter) {
3118
+ function isPropertyFilter$1(filter) {
3105
3119
  const pf = filter;
3106
3120
  if (pf.length === 3 && typeof pf[0] === "string" && typeof pf[1] === "string") {
3107
3121
  return true;
@@ -3119,7 +3133,7 @@ function featureFilter(feature, filters) {
3119
3133
  function propertiesFilter(properties, filters) {
3120
3134
  const logic = typeof filters[0] === "string" ? filters[0] : "all";
3121
3135
  const filterFunction = (p) => {
3122
- if (isPropertyFilter(p)) {
3136
+ if (isPropertyFilter$1(p)) {
3123
3137
  const [field, operation, value] = p;
3124
3138
  const operationExec = operationsAliases[operation];
3125
3139
  if (operationExec) {
@@ -3272,7 +3286,7 @@ function getQueries(opt, _queries = [], _parentAllParams = []) {
3272
3286
  const filters_ = filters.filter((x) => Array.isArray(x));
3273
3287
  if (logic === "any") {
3274
3288
  for (const f of filters_) {
3275
- if (isPropertyFilter(f)) {
3289
+ if (isPropertyFilter$1(f)) {
3276
3290
  _queries.push(
3277
3291
  fetchNgwLayerItemsRequest(__spreadProps$f(__spreadValues$q({}, opt), {
3278
3292
  paramList: [..._parentAllParams, ...paramList, createParam(f)]
@@ -3286,7 +3300,7 @@ function getQueries(opt, _queries = [], _parentAllParams = []) {
3286
3300
  const filters2 = [];
3287
3301
  const propertiesFilterList = [];
3288
3302
  for (const f of filters_) {
3289
- if (isPropertyFilter(f)) {
3303
+ if (isPropertyFilter$1(f)) {
3290
3304
  filters2.push(createParam(f));
3291
3305
  } else {
3292
3306
  propertiesFilterList.push(f);
@@ -5103,7 +5117,7 @@ var __spreadValues$g = (a, b) => {
5103
5117
  return a;
5104
5118
  };
5105
5119
  var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
5106
- var __objRest$2 = (source, exclude) => {
5120
+ var __objRest$3 = (source, exclude) => {
5107
5121
  var target = {};
5108
5122
  for (var prop in source)
5109
5123
  if (__hasOwnProp$h.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -5116,7 +5130,7 @@ var __objRest$2 = (source, exclude) => {
5116
5130
  return target;
5117
5131
  };
5118
5132
  function updateImageParams(params, resourceId) {
5119
- const _a = params, { bbox, width, height, nd } = _a, rest = __objRest$2(_a, ["bbox", "width", "height", "nd"]);
5133
+ const _a = params, { bbox, width, height, nd } = _a, rest = __objRest$3(_a, ["bbox", "width", "height", "nd"]);
5120
5134
  return __spreadProps$9(__spreadValues$g({}, rest), {
5121
5135
  resource: Array.isArray(resourceId) ? resourceId.join(",") : resourceId,
5122
5136
  extent: bbox,
@@ -5247,7 +5261,7 @@ var __spreadValues$f = (a, b) => {
5247
5261
  }
5248
5262
  return a;
5249
5263
  };
5250
- var __objRest$1 = (source, exclude) => {
5264
+ var __objRest$2 = (source, exclude) => {
5251
5265
  var target = {};
5252
5266
  for (var prop in source)
5253
5267
  if (__hasOwnProp$g.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -5280,11 +5294,11 @@ var __async$h = (__this, __arguments, generator) => {
5280
5294
  step((generator = generator.apply(__this, __arguments)).next());
5281
5295
  });
5282
5296
  };
5283
- const URL = "https://qms.nextgis.com";
5284
- function createQmsAdapter(webMapOrOptions, url = URL, createOpt = {}) {
5297
+ const URL$1 = "https://qms.nextgis.com";
5298
+ function createQmsAdapter(webMapOrOptions, url = URL$1, createOpt = {}) {
5285
5299
  let webMap;
5286
5300
  if ("webMap" in webMapOrOptions) {
5287
- const _a = webMapOrOptions, { webMap: webMap_, url: url_ } = _a, adapterOptions = __objRest$1(_a, ["webMap", "url"]);
5301
+ const _a = webMapOrOptions, { webMap: webMap_, url: url_ } = _a, adapterOptions = __objRest$2(_a, ["webMap", "url"]);
5288
5302
  webMap = webMap_;
5289
5303
  if (url_) {
5290
5304
  url = url_;
@@ -5296,7 +5310,7 @@ function createQmsAdapter(webMapOrOptions, url = URL, createOpt = {}) {
5296
5310
  webMap = webMapOrOptions;
5297
5311
  }
5298
5312
  if (!url) {
5299
- url = URL;
5313
+ url = URL$1;
5300
5314
  }
5301
5315
  class QmsAdapter {
5302
5316
  constructor(map, options) {
@@ -5925,6 +5939,134 @@ function createWebMapAdapter(_0) {
5925
5939
  });
5926
5940
  }
5927
5941
 
5942
+ function isPropertyFilter(value) {
5943
+ return Array.isArray(value) && value.length === 3 && typeof value[0] === "string" && typeof value[1] === "string";
5944
+ }
5945
+ function isPropertiesFilterGroup(value) {
5946
+ return Array.isArray(value) && !isPropertyFilter(value);
5947
+ }
5948
+ function toGetExpr(field) {
5949
+ return ["get", field];
5950
+ }
5951
+ function toConditionExpr(filter) {
5952
+ const [fieldRaw, op, value] = filter;
5953
+ const field = String(fieldRaw);
5954
+ const getExpr = toGetExpr(field);
5955
+ switch (op) {
5956
+ case "eq":
5957
+ if (value === null) {
5958
+ return ["is_null", getExpr];
5959
+ }
5960
+ return ["==", getExpr, value];
5961
+ case "ne":
5962
+ if (value === null) {
5963
+ return ["!is_null", getExpr];
5964
+ }
5965
+ return ["!=", getExpr, value];
5966
+ case "gt":
5967
+ if (typeof value !== "number" && typeof value !== "string") {
5968
+ throw new Error(
5969
+ `Operator "gt" requires number or string for "${field}"`
5970
+ );
5971
+ }
5972
+ return [">", getExpr, value];
5973
+ case "lt":
5974
+ if (typeof value !== "number" && typeof value !== "string") {
5975
+ throw new Error(
5976
+ `Operator "lt" requires number or string for "${field}"`
5977
+ );
5978
+ }
5979
+ return ["<", getExpr, value];
5980
+ case "ge":
5981
+ if (typeof value !== "number" && typeof value !== "string") {
5982
+ throw new Error(
5983
+ `Operator "ge" requires number or string for "${field}"`
5984
+ );
5985
+ }
5986
+ return [">=", getExpr, value];
5987
+ case "le":
5988
+ if (typeof value !== "number" && typeof value !== "string") {
5989
+ throw new Error(
5990
+ `Operator "le" requires number or string for "${field}"`
5991
+ );
5992
+ }
5993
+ return ["<=", getExpr, value];
5994
+ case "in":
5995
+ if (!Array.isArray(value) || !value.every((x) => typeof x === "string" || typeof x === "number")) {
5996
+ throw new Error(
5997
+ `Operator "in" requires (string | number)[] for "${field}"`
5998
+ );
5999
+ }
6000
+ if (!value.length) {
6001
+ throw new Error(
6002
+ `Operator "in" requires non-empty array for "${field}"`
6003
+ );
6004
+ }
6005
+ return ["in", getExpr, ...value];
6006
+ case "notin":
6007
+ if (!Array.isArray(value) || !value.every((x) => typeof x === "string" || typeof x === "number")) {
6008
+ throw new Error(
6009
+ `Operator "notin" requires (string | number)[] for "${field}"`
6010
+ );
6011
+ }
6012
+ if (!value.length) {
6013
+ throw new Error(
6014
+ `Operator "notin" requires non-empty array for "${field}"`
6015
+ );
6016
+ }
6017
+ return ["!in", getExpr, ...value];
6018
+ case "like":
6019
+ case "ilike":
6020
+ throw new Error(
6021
+ `Operator "${op}" is not supported by server FilterExpression`
6022
+ );
6023
+ default: {
6024
+ const exhaustive = op;
6025
+ throw new Error(`Unsupported operator: ${exhaustive}`);
6026
+ }
6027
+ }
6028
+ }
6029
+ function toGroupExpr(filters) {
6030
+ let logicalOp = "all";
6031
+ const children = [];
6032
+ for (const item of filters) {
6033
+ if (item === "all" || item === "any") {
6034
+ logicalOp = item;
6035
+ continue;
6036
+ }
6037
+ if (isPropertyFilter(item)) {
6038
+ children.push(toConditionExpr(item));
6039
+ continue;
6040
+ }
6041
+ if (isPropertiesFilterGroup(item)) {
6042
+ children.push(toGroupExpr(item));
6043
+ continue;
6044
+ }
6045
+ throw new Error("Invalid PropertiesFilter node");
6046
+ }
6047
+ return [logicalOp, ...children];
6048
+ }
6049
+ function propertiesFilterToExpression(filters) {
6050
+ if (!(filters == null ? void 0 : filters.length)) {
6051
+ return [];
6052
+ }
6053
+ return toGroupExpr(filters);
6054
+ }
6055
+ function propertiesFilterToExpressionString(filters) {
6056
+ if (!(filters == null ? void 0 : filters.length)) {
6057
+ return void 0;
6058
+ }
6059
+ return JSON.stringify(
6060
+ propertiesFilterToExpression(filters)
6061
+ );
6062
+ }
6063
+
6064
+ function createLayerFilterParam(resourceId, filter) {
6065
+ return {
6066
+ [`filter[${resourceId}]`]: propertiesFilterToExpressionString(filter)
6067
+ };
6068
+ }
6069
+
5928
6070
  var __defProp$j = Object.defineProperty;
5929
6071
  var __defProps$6 = Object.defineProperties;
5930
6072
  var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
@@ -5944,6 +6086,18 @@ var __spreadValues$b = (a, b) => {
5944
6086
  return a;
5945
6087
  };
5946
6088
  var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
6089
+ var __objRest$1 = (source, exclude) => {
6090
+ var target = {};
6091
+ for (var prop in source)
6092
+ if (__hasOwnProp$c.call(source, prop) && exclude.indexOf(prop) < 0)
6093
+ target[prop] = source[prop];
6094
+ if (source != null && __getOwnPropSymbols$c)
6095
+ for (var prop of __getOwnPropSymbols$c(source)) {
6096
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$c.call(source, prop))
6097
+ target[prop] = source[prop];
6098
+ }
6099
+ return target;
6100
+ };
5947
6101
  var __publicField$c = (obj, key, value) => __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
5948
6102
  var __async$c = (__this, __arguments, generator) => {
5949
6103
  return new Promise((resolve, reject) => {
@@ -6008,8 +6162,18 @@ function createRasterAdapter(_0) {
6008
6162
  baseUrl: connector.options.baseUrl || ""
6009
6163
  });
6010
6164
  if (opt) {
6011
- const layerAdapterOptions = __spreadProps$6(__spreadValues$b(__spreadValues$b({}, opt), layerOptions.adapterOptions), {
6012
- params: { resource: resourceId },
6165
+ const _a = layerOptions.adapterOptions || {}, { propertiesFilter } = _a, restAdapterOptions = __objRest$1(_a, ["propertiesFilter"]);
6166
+ const filterParams = createLayerFilterParam(
6167
+ resourceId,
6168
+ propertiesFilter
6169
+ );
6170
+ const layerAdapterOptions = __spreadProps$6(__spreadValues$b(__spreadValues$b({}, opt), restAdapterOptions), {
6171
+ params: __spreadValues$b({
6172
+ resource: resourceId
6173
+ }, filterParams),
6174
+ url: adapter === "TILE" && opt.url ? updateUrlParams(opt.url, __spreadValues$b({
6175
+ resource: String(resourceId)
6176
+ }, filterParams)) : opt.url,
6013
6177
  layers: opt.layers || String(resourceId),
6014
6178
  resourceId
6015
6179
  });
@@ -6022,6 +6186,15 @@ function createRasterAdapter(_0) {
6022
6186
  addLayer(addOptions) {
6023
6187
  return super.addLayer(__spreadValues$b(__spreadValues$b({}, this.options), addOptions));
6024
6188
  }
6189
+ propertiesFilter(filters) {
6190
+ return __async$c(this, null, function* () {
6191
+ var _a;
6192
+ const opt = this.options;
6193
+ const params = __spreadValues$b(__spreadValues$b({}, opt.params || {}), createLayerFilterParam(this.resourceId, filters));
6194
+ opt.params = params;
6195
+ (_a = this.updateLayer) == null ? void 0 : _a.call(this, { params });
6196
+ });
6197
+ }
6025
6198
  getIdentificationIds() {
6026
6199
  return __async$c(this, null, function* () {
6027
6200
  if (this.item) {
@@ -6517,7 +6690,8 @@ function getCompanyLogo(connector, options) {
6517
6690
  component: "pyramid"
6518
6691
  }
6519
6692
  });
6520
- if (settings && settings.company_logo && settings.company_logo.enabled) {
6693
+ const company_logo = settings && "company_logo" in settings ? settings.company_logo : void 0;
6694
+ if (company_logo && company_logo.enabled) {
6521
6695
  const anchor = document.createElement("a");
6522
6696
  anchor.style.position = "absolute";
6523
6697
  anchor.style.bottom = "0";
@@ -6552,10 +6726,10 @@ function getCompanyLogo(connector, options) {
6552
6726
  } else {
6553
6727
  return;
6554
6728
  }
6555
- if (settings.company_logo.link !== null && settings.company_logo.link.trim() !== "") {
6556
- anchor.href = settings.company_logo.link;
6729
+ if (company_logo.link !== null && company_logo.link.trim() !== "") {
6730
+ anchor.href = company_logo.link;
6557
6731
  anchor.target = "_blank";
6558
- if (settings.company_logo.link.search(/:\/\/nextgis/) !== -1) {
6732
+ if (company_logo.link.search(/:\/\/nextgis/) !== -1) {
6559
6733
  img.alt = "Get your own Web GIS at nextgis.com";
6560
6734
  }
6561
6735
  }
@@ -9983,7 +10157,7 @@ const _NgwMap = class _NgwMap extends WebMap {
9983
10157
  addNgwLayer(options) {
9984
10158
  return __async$1(this, null, function* () {
9985
10159
  yield this.onMapLoad();
9986
- const { keyname, resourceId } = options;
10160
+ const { keyname, resourceId, filters } = options;
9987
10161
  if (keyname || resourceId !== void 0) {
9988
10162
  deprecatedWarn(
9989
10163
  "set `resource` options instead of `keyname` or `resourceId`"
@@ -9997,12 +10171,15 @@ const _NgwMap = class _NgwMap extends WebMap {
9997
10171
  }
9998
10172
  if (defined(this.options.baseUrl)) {
9999
10173
  try {
10174
+ options.adapterOptions = options.adapterOptions || {};
10000
10175
  if (defined(this.options.setViewDelay)) {
10001
- options.adapterOptions = options.adapterOptions || {};
10002
10176
  if (!defined(options.adapterOptions.setViewDelay)) {
10003
10177
  options.adapterOptions.setViewDelay = this.options.setViewDelay;
10004
10178
  }
10005
10179
  }
10180
+ if (defined(filters)) {
10181
+ options.adapterOptions.propertiesFilter = filters;
10182
+ }
10006
10183
  const adapter = createNgwLayerAdapter(options, this, this.connector);
10007
10184
  const adapterOpts = __spreadValues(__spreadValues({
10008
10185
  visibility: true