@nextgis/geocoder 1.17.0 → 1.18.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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.17.0; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.18.3; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -536,6 +536,47 @@ var Geocoder = (function (exports) {
536
536
  return typeof val === 'string' ? !!val : defined(val);
537
537
  }
538
538
 
539
+ function getBoundsCoordinates(b) {
540
+ var westNorth = [b[0], b[1]];
541
+ var eastNorth = [b[2], b[1]];
542
+ var eastSouth = [b[2], b[3]];
543
+ var westSouth = [b[0], b[3]];
544
+ return [westNorth, eastNorth, eastSouth, westSouth, westNorth];
545
+ }
546
+
547
+ function degrees2meters(lng, lat) {
548
+ lat = lat > 85.06 ? 85.06 : lat < -85.06 ? -85.06 : lat;
549
+ var x = (lng * 20037508.34) / 180;
550
+ var y = Math.log(Math.tan(((90 + lat) * Math.PI) / 360)) / (Math.PI / 180);
551
+ y = (y * 20037508.34) / 180;
552
+ return [x, y];
553
+ }
554
+ // export function degrees2meters2(lon: number, lat: number): [number, number] {
555
+ // const radius = 6378137.0;
556
+ // const x = (radius * lon * Math.PI) / 180.0;
557
+ // const y =
558
+ // radius * Math.log(Math.tan(Math.PI / 4.0 + (lat * Math.PI) / 360.0));
559
+ // return [x, y];
560
+ // }
561
+ // export function meters2degress2(x: number, y: number): LngLatArray {
562
+ // const radius = 6378137.0;
563
+ // const lon = (180 / Math.PI) * (x / radius);
564
+ // const lat = (360 / Math.PI) * (Math.atan(Math.exp(y / radius)) - Math.PI / 4);
565
+ // return [lon, lat];
566
+ // }
567
+ // const lon = -77.035974;
568
+ // const lat = 38.898717;
569
+ // console.log(degrees2meters(lon, lat), degrees2meters2(lon, lat));
570
+ // const x = -8575605.398443861;
571
+ // const y = 4707174.018280405;
572
+ // console.log(meters2degress(x, y), meters2degress2(x, y));
573
+
574
+ function isLngLatBoundsArray(array) {
575
+ return (Array.isArray(array) &&
576
+ array.length === 4 &&
577
+ array.every(function (x) { return typeof x === 'number'; }));
578
+ }
579
+
539
580
  /**
540
581
  * Copy the values of all of the enumerable own properties from one or more source objects to a
541
582
  * target object. Returns the target object.
@@ -617,11 +658,29 @@ var Geocoder = (function (exports) {
617
658
  return newObj;
618
659
  }
619
660
 
661
+ function round(val, toFixed) {
662
+ var n = toFixed ? Number('1e+' + toFixed) : 1;
663
+ return Math.round((val + Number.EPSILON) * n) / n;
664
+ }
665
+
666
+ function isObject$1(val) {
667
+ return Object.prototype.toString.call(val) === '[object Object]';
668
+ }
669
+ function isArray(val) {
670
+ return Object.prototype.toString.call(val) === '[object Array]';
671
+ }
672
+
620
673
  function fixUrlStr(url) {
621
674
  // remove double slash
622
675
  return url.replace(/([^:]\/)\/+/g, '$1');
623
676
  }
624
677
 
678
+ /**
679
+ * Represents the base class for a geocoder.
680
+ * This abstract class provides the basic methods that every geocoder should implement.
681
+ *
682
+ * @template O - The type of options that can be passed to the geocoder.
683
+ */
625
684
  var BaseGeocoder = /** @class */ (function () {
626
685
  function BaseGeocoder(options) {
627
686
  if (options) {
@@ -722,6 +781,11 @@ var Geocoder = (function (exports) {
722
781
  return Geocoder;
723
782
  }(BaseGeocoder));
724
783
 
784
+ /**
785
+ * Abstract base class representing a search provider.
786
+ * It builds upon the BaseGeocoder functionalities with provider-specific properties.
787
+ * @template O - Options type which extends BaseProviderOptions.
788
+ */
725
789
  var BaseProvider = /** @class */ (function (_super) {
726
790
  __extends(BaseProvider, _super);
727
791
  function BaseProvider() {
@@ -2419,110 +2483,426 @@ var Geocoder = (function (exports) {
2419
2483
  */
2420
2484
  var NgwConnector = NgwConnector$1;
2421
2485
 
2486
+ function reEscape(s) {
2487
+ return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
2488
+ }
2489
+ function like(b, a, iLike) {
2490
+ a = String(a);
2491
+ b = String(b);
2492
+ if (a === b)
2493
+ return true;
2494
+ if (iLike && a.toUpperCase() === b.toUpperCase())
2495
+ return true;
2496
+ var re = "^".concat(reEscape(a), "$").replace(/%/g, '.*').replace('_', '.');
2497
+ return new RegExp(re, iLike ? 'i' : '').exec(b) !== null;
2498
+ }
2499
+ var operationsAliases = {
2500
+ // greater(>)
2501
+ gt: function (a, b) { return a > b; },
2502
+ // lower(<)
2503
+ lt: function (a, b) { return a < b; },
2504
+ // greater or equal(>=)
2505
+ ge: function (a, b) { return a >= b; },
2506
+ // lower or equal(<=)
2507
+ le: function (a, b) { return a <= b; },
2508
+ // equal(=)
2509
+ eq: function (a, b) { return a === b; },
2510
+ // not equal(!=)
2511
+ ne: function (a, b) { return a !== b; },
2512
+ in: function (a, b) { return b.indexOf(a) !== -1; },
2513
+ notin: function (a, b) { return b.indexOf(a) === -1; },
2514
+ // LIKE SQL statement(for strings compare)
2515
+ like: function (a, b) {
2516
+ return like(a, b);
2517
+ },
2518
+ // ILIKE SQL statement(for strings compare)
2519
+ ilike: function (a, b) {
2520
+ return like(a, b, true);
2521
+ },
2522
+ };
2523
+ function isPropertyFilter(filter) {
2524
+ var pf = filter;
2525
+ if (pf.length === 3 &&
2526
+ typeof pf[0] === 'string' &&
2527
+ typeof pf[1] === 'string') {
2528
+ return true;
2529
+ }
2530
+ return false;
2531
+ }
2532
+ function propertiesFilter(properties, filters) {
2533
+ var logic = typeof filters[0] === 'string' ? filters[0] : 'all';
2534
+ var filterFunction = function (p) {
2535
+ if (isPropertyFilter(p)) {
2536
+ var field_1 = p[0], operation = p[1], value_1 = p[2];
2537
+ var operationExec = operationsAliases[operation];
2538
+ if (operationExec) {
2539
+ if (operation === 'like' || operation === 'ilike') {
2540
+ if (typeof field_1 === 'string') {
2541
+ var prop_1 = '';
2542
+ var value_ = field_1.replace(/^%?(\w+)%?$/, function (match, cleanField) {
2543
+ prop_1 = properties[cleanField];
2544
+ return field_1.replace(cleanField, value_1);
2545
+ });
2546
+ return operationExec(prop_1, value_);
2547
+ }
2548
+ }
2549
+ return operationExec(properties[field_1], value_1);
2550
+ }
2551
+ return false;
2552
+ }
2553
+ else {
2554
+ return propertiesFilter(properties, p);
2555
+ }
2556
+ };
2557
+ var filters_ = filters.filter(function (x) { return Array.isArray(x); });
2558
+ return logic === 'any'
2559
+ ? filters_.some(filterFunction)
2560
+ : filters_.every(filterFunction);
2561
+ }
2562
+
2563
+ var FEATURE_REQUEST_PARAMS = {
2564
+ srs: 4326,
2565
+ geom_format: 'geojson',
2566
+ };
2567
+ function updateItemRequestParam(params, options) {
2568
+ var extensions = options.extensions, geom = options.geom, fields = options.fields, srs = options.srs, ilike = options.ilike, like = options.like;
2569
+ if (extensions) {
2570
+ params.extensions = extensions.join(',');
2571
+ }
2572
+ if (fields !== undefined) {
2573
+ params.fields = Array.isArray(fields) ? fields.join(',') : '';
2574
+ }
2575
+ if (geom !== undefined) {
2576
+ params.geom = geom ? 'yes' : 'no';
2577
+ if (!geom) {
2578
+ delete params.srs;
2579
+ delete params.geom_format;
2580
+ }
2581
+ }
2582
+ if (defined(ilike)) {
2583
+ params.ilike = ilike;
2584
+ }
2585
+ else if (defined(like)) {
2586
+ params.like = like;
2587
+ }
2588
+ if (defined(srs)) {
2589
+ params.srs = srs;
2590
+ }
2591
+ }
2592
+ // NGW REST API is not able to filtering by combined queries
2593
+ // therefore the filter is divided into several requests
2594
+ function createFeatureFieldFilterQueries(opt) {
2595
+ var queries = getQueries(opt);
2596
+ return CancelablePromise.all(queries).then(function (itemsParts) {
2597
+ // this list of ids used for optimization
2598
+ var ids = [];
2599
+ var items = [];
2600
+ for (var _i = 0, itemsParts_1 = itemsParts; _i < itemsParts_1.length; _i++) {
2601
+ var part = itemsParts_1[_i];
2602
+ for (var _a = 0, part_1 = part; _a < part_1.length; _a++) {
2603
+ var item = part_1[_a];
2604
+ if (!ids.includes(item.id)) {
2605
+ items.push(item);
2606
+ ids.push(item.id);
2607
+ }
2608
+ }
2609
+ }
2610
+ var offset = opt.offset !== undefined ? opt.offset : 0;
2611
+ var limit = opt.limit !== undefined ? opt.limit : items.length;
2612
+ if (opt.offset || opt.limit) {
2613
+ return items.splice(offset, limit);
2614
+ }
2615
+ return items;
2616
+ });
2617
+ }
2618
+ function createParam(pf) {
2619
+ var field = pf[0], operation = pf[1], value = pf[2];
2620
+ var isFldStr = field !== 'id' ? 'fld_' : '';
2621
+ var vStart = '';
2622
+ var vEnd = '';
2623
+ var field_ = String(field)
2624
+ .trim()
2625
+ .replace(/^(%?)(.+?)(%?)$/, function (m, a, b, c) {
2626
+ vStart = a;
2627
+ vEnd = c;
2628
+ return b;
2629
+ });
2630
+ var v = vStart + value + vEnd;
2631
+ return ["".concat(isFldStr).concat(field_, "__").concat(operation), v];
2632
+ }
2633
+ function getQueries(opt, _queries, _parentAllParams) {
2634
+ if (_queries === void 0) { _queries = []; }
2635
+ if (_parentAllParams === void 0) { _parentAllParams = []; }
2636
+ var filters = opt.filters;
2637
+ var logic = typeof filters[0] === 'string' ? filters[0] : 'all';
2638
+ var filters_ = filters.filter(function (x) { return Array.isArray(x); });
2639
+ if (logic === 'any') {
2640
+ for (var _i = 0, filters_1 = filters_; _i < filters_1.length; _i++) {
2641
+ var f = filters_1[_i];
2642
+ if (isPropertyFilter(f)) {
2643
+ _queries.push(fetchNgwLayerItemsRequest(__assign(__assign({}, opt), { paramList: __spreadArray(__spreadArray([], _parentAllParams, true), [createParam(f)], false) })));
2644
+ }
2645
+ else {
2646
+ getQueries(__assign(__assign({}, opt), { filters: f }), _queries, __spreadArray([], _parentAllParams, true));
2647
+ }
2648
+ }
2649
+ }
2650
+ else if (logic === 'all') {
2651
+ var filters_3 = [];
2652
+ var propertiesFilterList = [];
2653
+ for (var _a = 0, filters_2 = filters_; _a < filters_2.length; _a++) {
2654
+ var f = filters_2[_a];
2655
+ if (isPropertyFilter(f)) {
2656
+ filters_3.push(createParam(f));
2657
+ }
2658
+ else {
2659
+ propertiesFilterList.push(f);
2660
+ }
2661
+ }
2662
+ if (propertiesFilterList.length) {
2663
+ for (var _b = 0, propertiesFilterList_1 = propertiesFilterList; _b < propertiesFilterList_1.length; _b++) {
2664
+ var x = propertiesFilterList_1[_b];
2665
+ getQueries(__assign(__assign({}, opt), { filters: x }), _queries, __spreadArray(__spreadArray([], _parentAllParams, true), filters_3, true));
2666
+ }
2667
+ }
2668
+ else {
2669
+ _queries.push(fetchNgwLayerItemsRequest(__assign(__assign({}, opt), { paramList: __spreadArray(__spreadArray([], _parentAllParams, true), filters_3, true) })));
2670
+ }
2671
+ }
2672
+ return _queries;
2673
+ }
2674
+ function createWktFromCoordArray(coord) {
2675
+ var polygon = coord.map(function (_a) {
2676
+ var lng = _a[0], lat = _a[1];
2677
+ var _b = degrees2meters(lng, lat).map(function (c) { return round(c); }), x = _b[0], y = _b[1];
2678
+ return x + ' ' + y;
2679
+ });
2680
+ return "POLYGON((".concat(polygon.join(', '), "))");
2681
+ }
2682
+ function fetchNgwLayerItemsRequest(options) {
2683
+ var params = __assign({}, FEATURE_REQUEST_PARAMS);
2684
+ var limit = options.limit, cache = options.cache, signal = options.signal, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, geomFormat = options.geomFormat, intersects = options.intersects, resourceId = options.resourceId;
2685
+ if (limit) {
2686
+ if (limit !== Number.POSITIVE_INFINITY) {
2687
+ params.limit = limit;
2688
+ }
2689
+ }
2690
+ else {
2691
+ // Strict restriction on loading data from large layers
2692
+ params.limit = 7000;
2693
+ }
2694
+ if (offset) {
2695
+ params.offset = offset;
2696
+ }
2697
+ if (geomFormat) {
2698
+ params.geom_format = geomFormat;
2699
+ }
2700
+ updateItemRequestParam(params, options);
2701
+ if (orderBy) {
2702
+ params.order_by = orderBy.join(',');
2703
+ }
2704
+ if (Array.isArray(intersects)) {
2705
+ var coordinates = isLngLatBoundsArray(intersects)
2706
+ ? getBoundsCoordinates(intersects)
2707
+ : intersects;
2708
+ params.intersects = createWktFromCoordArray(coordinates);
2709
+ }
2710
+ else if (typeof intersects === 'string') {
2711
+ params.intersects = intersects;
2712
+ }
2713
+ if (paramList) {
2714
+ params.paramList = paramList;
2715
+ }
2716
+ var reqParams = __assign({ id: resourceId }, params);
2717
+ return connector.get('feature_layer.feature.collection', { cache: cache, signal: signal }, reqParams);
2718
+ }
2719
+
2720
+ function prepareNgwFieldsToPropertiesFilter(fields) {
2721
+ var f;
2722
+ var _loop_1 = function () {
2723
+ var field = fields[f];
2724
+ if (isObject$1(field)) {
2725
+ var date = field;
2726
+ if (defined(date.year) && defined(date.month) && defined(date.day)) {
2727
+ var dt_1 = [
2728
+ date.year,
2729
+ date.month - 1,
2730
+ date.day,
2731
+ ];
2732
+ if ('hour' in date) {
2733
+ [date.hour, date.minute, date.second].forEach(function (x) {
2734
+ dt_1.push(x);
2735
+ });
2736
+ }
2737
+ fields[f] = new (Date.bind.apply(Date, __spreadArray([void 0], dt_1, false)))().toISOString();
2738
+ }
2739
+ }
2740
+ else if (f === 'id' && typeof field === 'string') {
2741
+ fields[f] = field.split(',').map(Number);
2742
+ }
2743
+ };
2744
+ for (f in fields) {
2745
+ _loop_1();
2746
+ }
2747
+ return fields;
2748
+ }
2749
+
2750
+ function fetchNgwLayerItems(options) {
2751
+ var filters = options.filters;
2752
+ if (filters) {
2753
+ return createFeatureFieldFilterQueries(__assign(__assign({}, options), { filters: filters })).then(function (data) {
2754
+ var _a;
2755
+ var clientFilterValidate = (_a = options.clientFilterValidate) !== null && _a !== void 0 ? _a : isFilterWithAnyCase(filters);
2756
+ // Additional client-side filter check
2757
+ if (clientFilterValidate) {
2758
+ data = data.filter(function (y) {
2759
+ var fields = prepareNgwFieldsToPropertiesFilter(__assign(__assign({}, y.fields), { id: y.id }));
2760
+ var result = propertiesFilter(fields, filters);
2761
+ return result;
2762
+ });
2763
+ }
2764
+ return data;
2765
+ });
2766
+ }
2767
+ else {
2768
+ return fetchNgwLayerItemsRequest(options);
2769
+ }
2770
+ }
2771
+ function isFilterWithAnyCase(filters) {
2772
+ if (filters[0] === 'any') {
2773
+ return true;
2774
+ }
2775
+ for (var i = 1; i < filters.length; i++) {
2776
+ var p = filters[i];
2777
+ if (isArray(p)) {
2778
+ var deep = isFilterWithAnyCase(p);
2779
+ if (deep) {
2780
+ return true;
2781
+ }
2782
+ }
2783
+ }
2784
+ return false;
2785
+ }
2786
+
2422
2787
  var NgwProvider = /** @class */ (function (_super) {
2423
2788
  __extends(NgwProvider, _super);
2424
2789
  function NgwProvider(options) {
2425
- var _this = _super.call(this, options) || this;
2790
+ var _this = this;
2791
+ var _a;
2792
+ _this = _super.call(this, options) || this;
2426
2793
  _this.caseInsensitive = true;
2427
- _this.searchUrl = 'https://maxim.nextgis.com';
2428
2794
  _this.searchResources = [];
2429
- _this.requests = [];
2795
+ _this._abortControllers = [];
2796
+ if (!options.searchUrl && !((_a = options.connectorOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
2797
+ throw new Error('The `searchUrl` of `connectorOptions.baseUrl` are required');
2798
+ }
2430
2799
  _this.connector =
2431
2800
  options.connector ||
2432
- new NgwConnector({
2433
- baseUrl: _this.searchUrl,
2434
- });
2801
+ new NgwConnector(__assign({ baseUrl: _this.searchUrl }, options.connectorOptions));
2435
2802
  _this.searchResources = options.searchResources;
2436
2803
  return _this;
2437
2804
  }
2438
2805
  NgwProvider.prototype.abort = function () {
2439
- this.requests.forEach(function (x) {
2440
- x.cancel();
2806
+ this._abortControllers.forEach(function (a) {
2807
+ a.abort();
2441
2808
  });
2442
- this.requests = [];
2809
+ this._abortControllers.length = 0;
2443
2810
  };
2444
- NgwProvider.prototype.search = function (like) {
2811
+ NgwProvider.prototype.search = function (query) {
2812
+ var _a, _b;
2445
2813
  return __asyncGenerator(this, arguments, function search_1() {
2446
- var _loop_1, this_1, _i, _a, resource;
2814
+ var signal, _i, _c, config, searchMethod, limit, resourceId, resource, options, request, entries, _loop_1, _d, _e, item, er_1;
2447
2815
  var _this = this;
2448
- return __generator(this, function (_b) {
2449
- switch (_b.label) {
2816
+ return __generator(this, function (_f) {
2817
+ switch (_f.label) {
2450
2818
  case 0:
2451
- _loop_1 = function (resource) {
2452
- var limit, request, resp, entries, _loop_2, _c, _d, item;
2453
- return __generator(this, function (_e) {
2454
- switch (_e.label) {
2819
+ signal = this._makeSignal();
2820
+ _i = 0, _c = this.searchResources;
2821
+ _f.label = 1;
2822
+ case 1:
2823
+ if (!(_i < _c.length)) return [3 /*break*/, 11];
2824
+ config = _c[_i];
2825
+ if (signal.aborted) {
2826
+ return [3 /*break*/, 11];
2827
+ }
2828
+ searchMethod = config.searchMethod;
2829
+ limit = (_a = config.limit) !== null && _a !== void 0 ? _a : NgwProvider.limit;
2830
+ resourceId = (_b = config.id) !== null && _b !== void 0 ? _b : config.resourceId;
2831
+ _f.label = 2;
2832
+ case 2:
2833
+ _f.trys.push([2, 9, , 10]);
2834
+ return [4 /*yield*/, __await(this.connector.getResourceOrFail(resourceId, {
2835
+ cache: true,
2836
+ }))];
2837
+ case 3:
2838
+ resource = _f.sent();
2839
+ options = {
2840
+ connector: this.connector,
2841
+ resourceId: resourceId,
2842
+ signal: signal,
2843
+ limit: limit,
2844
+ };
2845
+ if (searchMethod === 'like') {
2846
+ options.like = query;
2847
+ }
2848
+ else {
2849
+ options.ilike = query;
2850
+ }
2851
+ request = fetchNgwLayerItems(options);
2852
+ return [4 /*yield*/, __await(request)];
2853
+ case 4:
2854
+ entries = _f.sent();
2855
+ _loop_1 = function (item) {
2856
+ return __generator(this, function (_g) {
2857
+ switch (_g.label) {
2455
2858
  case 0:
2456
- limit = resource.limit || 300;
2457
- request = this_1.connector.get('feature_layer.store', {
2458
- headers: { RANGE: "items=0-".concat(limit) },
2459
- }, {
2460
- id: resource.id,
2461
- like: like,
2462
- });
2463
- this_1.requests.push(request);
2464
- request.catch(function (er) {
2465
- console.warn(er);
2466
- });
2467
- return [4 /*yield*/, __await(request)];
2468
- case 1:
2469
- resp = _e.sent();
2470
- entries = [];
2471
- if (resp) {
2472
- resp.forEach(function (x) {
2473
- entries.push(__assign({ query: like, resourceId: resource.id }, x));
2474
- });
2475
- }
2476
- _loop_2 = function (item) {
2477
- return __generator(this, function (_f) {
2478
- switch (_f.label) {
2479
- case 0:
2480
- item.result = function () { return _this.result(item); };
2481
- return [4 /*yield*/, __await(item)];
2482
- case 1: return [4 /*yield*/, _f.sent()];
2483
- case 2:
2484
- _f.sent();
2485
- return [2 /*return*/];
2486
- }
2487
- });
2488
- };
2489
- _c = 0, _d = this_1._items(entries);
2490
- _e.label = 2;
2859
+ item.result = function () { return _this.result(item); };
2860
+ return [4 /*yield*/, __await(item)];
2861
+ case 1: return [4 /*yield*/, _g.sent()];
2491
2862
  case 2:
2492
- if (!(_c < _d.length)) return [3 /*break*/, 5];
2493
- item = _d[_c];
2494
- return [5 /*yield**/, _loop_2(item)];
2495
- case 3:
2496
- _e.sent();
2497
- _e.label = 4;
2498
- case 4:
2499
- _c++;
2500
- return [3 /*break*/, 2];
2501
- case 5: return [2 /*return*/];
2863
+ _g.sent();
2864
+ return [2 /*return*/];
2502
2865
  }
2503
2866
  });
2504
2867
  };
2505
- this_1 = this;
2506
- _i = 0, _a = this.searchResources;
2507
- _b.label = 1;
2508
- case 1:
2509
- if (!(_i < _a.length)) return [3 /*break*/, 4];
2510
- resource = _a[_i];
2511
- return [5 /*yield**/, _loop_1(resource)];
2512
- case 2:
2513
- _b.sent();
2514
- _b.label = 3;
2515
- case 3:
2868
+ _d = 0, _e = this._items({
2869
+ entries: entries,
2870
+ query: query,
2871
+ config: config,
2872
+ resourceItem: resource,
2873
+ });
2874
+ _f.label = 5;
2875
+ case 5:
2876
+ if (!(_d < _e.length)) return [3 /*break*/, 8];
2877
+ item = _e[_d];
2878
+ return [5 /*yield**/, _loop_1(item)];
2879
+ case 6:
2880
+ _f.sent();
2881
+ _f.label = 7;
2882
+ case 7:
2883
+ _d++;
2884
+ return [3 /*break*/, 5];
2885
+ case 8: return [3 /*break*/, 10];
2886
+ case 9:
2887
+ er_1 = _f.sent();
2888
+ if (er_1 &&
2889
+ 'name' in er_1 &&
2890
+ er_1.name !== 'CancelError') {
2891
+ console.warn(er_1);
2892
+ }
2893
+ return [3 /*break*/, 10];
2894
+ case 10:
2516
2895
  _i++;
2517
2896
  return [3 /*break*/, 1];
2518
- case 4: return [2 /*return*/];
2897
+ case 11: return [2 /*return*/];
2519
2898
  }
2520
2899
  });
2521
2900
  });
2522
2901
  };
2523
2902
  NgwProvider.prototype.result = function (item) {
2903
+ var signal = this._makeSignal();
2524
2904
  var req = this.connector
2525
- .get('feature_layer.feature.item_extent', null, {
2905
+ .get('feature_layer.feature.item_extent', { signal: signal }, {
2526
2906
  id: item.resourceId,
2527
2907
  fid: item.featureId,
2528
2908
  })
@@ -2533,25 +2913,47 @@ var Geocoder = (function (exports) {
2533
2913
  extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],
2534
2914
  };
2535
2915
  });
2536
- this.requests.push(req);
2537
2916
  return req;
2538
2917
  };
2539
- NgwProvider.prototype._items = function (entries) {
2540
- var _this = this;
2918
+ NgwProvider.prototype._makeSignal = function () {
2919
+ var abortController = new AbortController();
2920
+ this._abortControllers.push(abortController);
2921
+ return abortController.signal;
2922
+ };
2923
+ NgwProvider.prototype._items = function (_a) {
2924
+ var _b;
2925
+ var entries = _a.entries, query = _a.query, config = _a.config, resourceItem = _a.resourceItem;
2541
2926
  var items = [];
2542
- entries.forEach(function (entry) {
2543
- var meta = _this.searchResources.find(function (x) { return x.id === entry.resourceId; });
2544
- if (meta) {
2927
+ var labelField = undefined;
2928
+ if (resourceItem.feature_layer) {
2929
+ labelField = (_b = resourceItem.feature_layer.fields.find(function (f) { return f.label_field; })) === null || _b === void 0 ? void 0 : _b.keyname;
2930
+ }
2931
+ var meta = this.searchResources.find(function (x) { var _a; return (_a = x.id) !== null && _a !== void 0 ? _a : x.resourceId === resourceItem.resource.id; });
2932
+ if (meta) {
2933
+ entries.forEach(function (entry) {
2934
+ var text = labelField ? entry.fields[labelField] : entry.id;
2935
+ if (config.renderSearch) {
2936
+ text = config.renderSearch({
2937
+ item: entry,
2938
+ resourceItem: resourceItem,
2939
+ });
2940
+ }
2941
+ else if (labelField) {
2942
+ text = entry.fields[labelField];
2943
+ }
2545
2944
  items.push({
2546
- query: entry.query,
2547
- text: entry.label,
2945
+ query: query,
2946
+ text: text,
2548
2947
  featureId: entry.id,
2549
- resourceId: entry.resourceId,
2948
+ resourceId: resourceItem.resource.id,
2949
+ item: entry,
2950
+ resourceItem: resourceItem,
2550
2951
  });
2551
- }
2552
- });
2952
+ });
2953
+ }
2553
2954
  return items;
2554
2955
  };
2956
+ NgwProvider.limit = 300;
2555
2957
  return NgwProvider;
2556
2958
  }(BaseProvider));
2557
2959
 
@@ -2653,6 +3055,12 @@ var Geocoder = (function (exports) {
2653
3055
  return NominatimProvider;
2654
3056
  }(BaseProvider));
2655
3057
 
3058
+ /**
3059
+ * Modern geocoder on async generators. May use different data providers.
3060
+ *
3061
+ * @packageDocumentation
3062
+ * @module geocoder
3063
+ */
2656
3064
  function create(options) {
2657
3065
  return new Geocoder(options);
2658
3066
  }