ol-wfst 4.0.0 → 4.0.2

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +224 -130
  3. package/dist/@types.d.ts +32 -0
  4. package/dist/@types.d.ts.map +1 -1
  5. package/dist/WfsLayer.d.ts +15 -2
  6. package/dist/WfsLayer.d.ts.map +1 -1
  7. package/dist/WmsLayer.d.ts +16 -3
  8. package/dist/WmsLayer.d.ts.map +1 -1
  9. package/dist/modules/{Modes/baseLayer.d.ts → base/BaseLayer.d.ts} +1 -1
  10. package/dist/modules/base/BaseLayer.d.ts.map +1 -0
  11. package/dist/modules/base/WfsSource.d.ts +48 -0
  12. package/dist/modules/base/WfsSource.d.ts.map +1 -0
  13. package/dist/modules/base/WmsSource.d.ts +47 -0
  14. package/dist/modules/base/WmsSource.d.ts.map +1 -0
  15. package/dist/modules/errors.d.ts.map +1 -1
  16. package/dist/ol-wfst.js +83 -321
  17. package/dist/ol-wfst.js.map +1 -1
  18. package/dist/ol-wfst.min.js +1 -1
  19. package/dist/ol-wfst.min.js.map +1 -1
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/lib/@types.d.ts +32 -0
  22. package/lib/@types.d.ts.map +1 -1
  23. package/lib/WfsLayer.d.ts +15 -2
  24. package/lib/WfsLayer.d.ts.map +1 -1
  25. package/lib/WmsLayer.d.ts +16 -3
  26. package/lib/WmsLayer.d.ts.map +1 -1
  27. package/lib/index-es.js +79 -317
  28. package/lib/index-es.js.map +1 -1
  29. package/lib/modules/{Modes/baseLayer.d.ts → base/BaseLayer.d.ts} +1 -1
  30. package/lib/modules/base/BaseLayer.d.ts.map +1 -0
  31. package/lib/modules/base/WfsSource.d.ts +48 -0
  32. package/lib/modules/base/WfsSource.d.ts.map +1 -0
  33. package/lib/modules/base/WmsSource.d.ts +47 -0
  34. package/lib/modules/base/WmsSource.d.ts.map +1 -0
  35. package/lib/modules/errors.d.ts.map +1 -1
  36. package/lib/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +1 -1
  38. package/dist/modules/Modes/WfsSource.d.ts +0 -60
  39. package/dist/modules/Modes/WfsSource.d.ts.map +0 -1
  40. package/dist/modules/Modes/WmsSource.d.ts +0 -82
  41. package/dist/modules/Modes/WmsSource.d.ts.map +0 -1
  42. package/dist/modules/Modes/baseLayer.d.ts.map +0 -1
  43. package/dist/modules/Modes/baseSource.d.ts +0 -103
  44. package/dist/modules/Modes/baseSource.d.ts.map +0 -1
  45. package/lib/modules/Modes/WfsSource.d.ts +0 -60
  46. package/lib/modules/Modes/WfsSource.d.ts.map +0 -1
  47. package/lib/modules/Modes/WmsSource.d.ts +0 -82
  48. package/lib/modules/Modes/WmsSource.d.ts.map +0 -1
  49. package/lib/modules/Modes/baseLayer.d.ts.map +0 -1
  50. package/lib/modules/Modes/baseSource.d.ts +0 -103
  51. package/lib/modules/Modes/baseSource.d.ts.map +0 -1
package/lib/index-es.js CHANGED
@@ -13,12 +13,12 @@ import GeoJSON from 'ol/format/GeoJSON';
13
13
  import VectorSource, { VectorSourceEvent } from 'ol/source/Vector';
14
14
  import { transformExtent } from 'ol/proj';
15
15
  import { bbox } from 'ol/loadingstrategy';
16
- import BaseObject from 'ol/Object';
17
16
  import TileLayer from 'ol/layer/Tile';
18
17
  import { GeoJSON as GeoJSON$1, WFS, KML } from 'ol/format';
19
18
  import TileWMS from 'ol/source/TileWMS';
20
19
  import TileState from 'ol/TileState';
21
20
  import { MultiPolygon, MultiLineString, MultiPoint, GeometryCollection, Polygon, Circle as Circle$1 } from 'ol/geom';
21
+ import BaseObject from 'ol/Object';
22
22
  import { fromCircle } from 'ol/geom/Polygon';
23
23
  import { getCenter } from 'ol/extent';
24
24
 
@@ -51,8 +51,7 @@ const showError = (msg, originalError = null, layerName = '') => {
51
51
  isError.add(layerName);
52
52
  let err_msg = `<b>Error: ${msg}</b>`;
53
53
  if (originalError) {
54
- console.log(originalError);
55
- //err_msg += `. ${originalError.message}`;
54
+ err_msg += `. ${originalError.message}`;
56
55
  }
57
56
  const al = Modal.alert(err_msg, options);
58
57
  al.show();
@@ -404,153 +403,15 @@ var BaseLayerProperty;
404
403
  BaseLayerProperty["GEOSERVER"] = "geoserver";
405
404
  })(BaseLayerProperty || (BaseLayerProperty = {}));
406
405
 
407
- class BaseSource extends BaseObject {
408
- /**
409
- * @public
410
- * @param value
411
- * @param opt_silent
412
- */
413
- setCqlFilter(value, opt_silent) {
414
- this.set(BaseSourceProperty.CQLFILTER, value, opt_silent);
415
- }
416
- /**
417
- * @public
418
- * @returns
419
- */
420
- getCqlFilter() {
421
- return this.get(BaseSourceProperty.CQLFILTER);
422
- }
423
- /**
424
- * @public
425
- * @param value
426
- * @param opt_silent
427
- */
428
- setSortBy(value, opt_silent) {
429
- this.set(BaseSourceProperty.SORTBY, value, opt_silent);
430
- }
431
- /**
432
- * @public
433
- * @returns
434
- */
435
- getSortBy() {
436
- return this.get(BaseSourceProperty.SORTBY);
437
- }
438
- /**
439
- * @public
440
- * @param value
441
- * @param opt_silent
442
- */
443
- setFeatureId(value, opt_silent) {
444
- this.set(BaseSourceProperty.FEATUREID, value, opt_silent);
445
- }
446
- /**
447
- * @public
448
- * @returns
449
- */
450
- getFeatureId() {
451
- return this.get(BaseSourceProperty.FEATUREID);
452
- }
453
- /**
454
- * @public
455
- * @param value
456
- * @param opt_silent
457
- */
458
- setFilter(value, opt_silent) {
459
- this.set(BaseSourceProperty.FILTER, value, opt_silent);
460
- }
461
- /**
462
- * @public
463
- * @returns
464
- */
465
- getFilter() {
466
- return this.get(BaseSourceProperty.FILTER);
467
- }
468
- /**
469
- * @public
470
- * @param value
471
- * @param opt_silent
472
- */
473
- setFormatOptions(value, opt_silent) {
474
- this.set(BaseSourceProperty.FORMATOPTIONS, value, opt_silent);
475
- }
476
- /**
477
- * @public
478
- * @returns
479
- */
480
- getFormatOptions() {
481
- return this.get(BaseSourceProperty.FORMATOPTIONS);
482
- }
483
- /**
484
- * @public
485
- * @param value
486
- * @param opt_silent
487
- */
488
- setMaxFeatures(value, opt_silent) {
489
- this.set(BaseSourceProperty.MAXFEATURES, value, opt_silent);
490
- }
491
- /**
492
- * @public
493
- * @returns
494
- */
495
- getMaxFeatures() {
496
- return this.get(BaseSourceProperty.MAXFEATURES);
497
- }
498
- /**
499
- * @public
500
- * @param value
501
- * @param opt_silent
502
- */
503
- setStartIndex(value, opt_silent) {
504
- this.set(BaseSourceProperty.STARTINDEX, value, opt_silent);
505
- }
506
- /**
507
- * @public
508
- * @returns
509
- */
510
- getStartIndex() {
511
- return this.get(BaseSourceProperty.STARTINDEX);
512
- }
513
- /**
514
- * @public
515
- * @param value
516
- * @param opt_silent
517
- */
518
- setPropertyName(value, opt_silent) {
519
- this.set(BaseSourceProperty.PROPERTYNAME, value, opt_silent);
520
- }
521
- /**
522
- * @public
523
- * @returns
524
- */
525
- getPropertyName() {
526
- return this.get(BaseSourceProperty.PROPERTYNAME);
527
- }
528
- }
529
- var BaseSourceProperty;
530
- (function (BaseSourceProperty) {
531
- BaseSourceProperty["CQLFILTER"] = "cql_filter";
532
- BaseSourceProperty["SORTBY"] = "sortBy";
533
- BaseSourceProperty["FEATUREID"] = "featureid";
534
- BaseSourceProperty["FILTER"] = "filter";
535
- BaseSourceProperty["FORMATOPTIONS"] = "format_options";
536
- BaseSourceProperty["MAXFEATURES"] = "maxFeatures";
537
- BaseSourceProperty["STARTINDEX"] = "startIndex";
538
- BaseSourceProperty["PROPERTYNAME"] = "propertyname";
539
- })(BaseSourceProperty || (BaseSourceProperty = {}));
540
-
541
- class WfsSource extends Mixin(VectorSource, BaseSource) {
542
- geoserverProps_ = [
543
- 'cql_filter',
544
- 'filter',
545
- 'orderBy',
546
- 'maxFeatures',
547
- 'startIndex',
548
- 'featureid',
549
- 'format_options',
550
- 'propertyname',
551
- 'strict'
552
- ];
553
- urlParams_ = new URLSearchParams({
406
+ /**
407
+ * Layer source to retrieve WFS features from geoservers
408
+ * https://docs.geoserver.org/stable/en/user/services/wfs/reference.html
409
+ *
410
+ * @extends {ol/source/Vector~VectorSource}
411
+ * @param options
412
+ */
413
+ class WfsSource extends VectorSource {
414
+ urlParams = new URLSearchParams({
554
415
  SERVICE: 'wfs',
555
416
  REQUEST: 'GetFeature',
556
417
  OUTPUTFORMAT: 'application/json',
@@ -567,46 +428,10 @@ class WfsSource extends Mixin(VectorSource, BaseSource) {
567
428
  const extentGeoServer = transformExtent(extent, projection.getCode(), options.geoServerAdvanced.projection);
568
429
  // https://docs.geoserver.org/stable/en/user/services/wfs/reference.html
569
430
  // request features using a bounding box with CRS maybe different from featureTypes native CRS
570
- this.urlParams_.set('bbox', extentGeoServer.toString() +
431
+ this.urlParams.set('bbox', extentGeoServer.toString() +
571
432
  `,${options.geoServerAdvanced.projection}`);
572
433
  }
573
- const cqlFilter = this.getCqlFilter();
574
- if (cqlFilter) {
575
- this.urlParams_.set('cql_filter', cqlFilter);
576
- }
577
- const sortBy = this.getSortBy();
578
- if (sortBy) {
579
- this.urlParams_.set('sortBy', sortBy);
580
- }
581
- const filter = this.getFilter();
582
- if (filter) {
583
- this.urlParams_.set('filter', filter);
584
- }
585
- const featureId = this.getFeatureId();
586
- if (featureId) {
587
- this.urlParams_.set('featureid', featureId);
588
- }
589
- const formatOptions = this.getFormatOptions();
590
- if (formatOptions) {
591
- this.urlParams_.set('formatOptions', formatOptions);
592
- }
593
- const maxFeatures = this.getMaxFeatures();
594
- if (maxFeatures) {
595
- this.urlParams_.set('maxFeatures', String(maxFeatures));
596
- }
597
- const startIndex = this.getStartIndex();
598
- if (startIndex) {
599
- this.urlParams_.set('startIndex', String(startIndex));
600
- }
601
- const propertyName = this.getPropertyName();
602
- if (propertyName) {
603
- this.urlParams_.set('propertyname', propertyName);
604
- }
605
- const strict = this.getStrict();
606
- if (strict !== undefined) {
607
- this.urlParams_.set('strict', String(strict));
608
- }
609
- const url_fetch = options.geoserverUrl + '?' + this.urlParams_.toString();
434
+ const url_fetch = options.geoserverUrl + '?' + this.urlParams.toString();
610
435
  const response = await fetch(url_fetch, {
611
436
  headers: options.headers,
612
437
  credentials: options.credentials
@@ -636,52 +461,11 @@ class WfsSource extends Mixin(VectorSource, BaseSource) {
636
461
  }
637
462
  }
638
463
  });
639
- this.urlParams_.set('version', options.geoServerAdvanced.getFeatureVersion);
640
- this.urlParams_.set('typename', options.name);
641
- this.urlParams_.set('srsName', options.geoServerAdvanced.projection.toString());
642
- const geoserverOptions = options.geoserverVendor;
643
- this.setCqlFilter(geoserverOptions.cql_filter, true);
644
- this.setSortBy(geoserverOptions.sortBy, true);
645
- this.setFeatureId(geoserverOptions.featureid, true);
646
- this.setFilter(geoserverOptions.filter, true);
647
- this.setFormatOptions(geoserverOptions.format_options, true);
648
- this.setMaxFeatures(geoserverOptions.maxFeatures, true);
649
- this.setStartIndex(geoserverOptions.startIndex, true);
650
- this.setPropertyName(geoserverOptions.propertyname, true);
651
- this.setStrict(geoserverOptions.strict, true);
652
- this.addEvents_();
464
+ this.urlParams.set('version', options.geoServerAdvanced.getFeatureVersion);
465
+ this.urlParams.set('typename', options.name);
466
+ this.urlParams.set('srsName', options.geoServerAdvanced.projection.toString());
653
467
  }
654
- /**
655
- * @public
656
- * @param value
657
- * @param opt_silent
658
- */
659
- setStrict(value, opt_silent) {
660
- this.set(WfsSourceProperty.STRICT, value, opt_silent);
661
- }
662
- /**
663
- * @public
664
- * @returns
665
- */
666
- getStrict() {
667
- return this.get(WfsSourceProperty.STRICT);
668
- }
669
- /**
670
- * @private
671
- */
672
- addEvents_() {
673
- this.on(['propertychange'], (evt) => {
674
- // If a geoserver property was modified, refresh the source
675
- if (this.geoserverProps_.includes(evt.key)) {
676
- this.refresh();
677
- }
678
- });
679
- }
680
- }
681
- var WfsSourceProperty;
682
- (function (WfsSourceProperty) {
683
- WfsSourceProperty["STRICT"] = "strict";
684
- })(WfsSourceProperty || (WfsSourceProperty = {}));
468
+ }
685
469
 
686
470
  /**
687
471
  * Layer to retrieve WFS features from geoservers
@@ -732,6 +516,10 @@ class WfsLayer extends Mixin(BaseLayer, (VectorLayer)) {
732
516
  }
733
517
  });
734
518
  this.setSource(source);
519
+ const geoserverOptions = options.geoserverVendor;
520
+ Object.keys(geoserverOptions).forEach((param) => {
521
+ source.urlParams.set(param, geoserverOptions[param]);
522
+ });
735
523
  }
736
524
  /**
737
525
  * @public
@@ -741,22 +529,41 @@ class WfsLayer extends Mixin(BaseLayer, (VectorLayer)) {
741
529
  // Refrescamos el wms
742
530
  source.refresh();
743
531
  }
532
+ /**
533
+ * Use this to update Geoserver Wms Vendors (https://docs.geoserver.org/latest/en/user/services/wms/vendor.html)
534
+ * and other arguements (https://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap)
535
+ * in all the getMap requests.
536
+ *
537
+ * Example: you can use this to change the style of the WMS, add a custom sld, set a cql_filter, etc.
538
+ *
539
+ * @public
540
+ * @param paramName
541
+ * @param value Use `undefined` or `null` to remove the param
542
+ * @param refresh
543
+ */
544
+ setCustomParam(paramName, value = null, refresh = true) {
545
+ const source = this.getSource();
546
+ if (value === undefined || value === null) {
547
+ source.urlParams.delete(paramName);
548
+ }
549
+ else {
550
+ source.urlParams.set(paramName, value);
551
+ }
552
+ if (refresh) {
553
+ this.refresh();
554
+ }
555
+ return source.urlParams;
556
+ }
744
557
  }
745
558
 
746
- class WmsSource extends Mixin(TileWMS, BaseSource) {
747
- geoserverProps_ = [
748
- 'cql_filter',
749
- 'filter',
750
- 'orderBy',
751
- 'maxFeatures',
752
- 'startIndex',
753
- 'featureid',
754
- 'format_options',
755
- 'propertyname',
756
- 'buffer',
757
- 'clip',
758
- 'env'
759
- ];
559
+ /**
560
+ * Layer source to retrieve WMS information from geoservers
561
+ * https://docs.geoserver.org/stable/en/user/services/wms/reference.html
562
+ *
563
+ * @extends {ol/source/TieWMS~TileWMS}
564
+ * @param options
565
+ */
566
+ class WmsSource extends TileWMS {
760
567
  constructor(options) {
761
568
  super({
762
569
  url: options.geoserverUrl,
@@ -801,75 +608,8 @@ class WmsSource extends Mixin(TileWMS, BaseSource) {
801
608
  },
802
609
  ...options
803
610
  });
804
- this.addEvents_();
805
- }
806
- /**
807
- * @public
808
- * @param value
809
- * @param opt_silent
810
- */
811
- setBuffer(value, opt_silent) {
812
- this.set(WmsSourceProperty.BUFFER, value, opt_silent);
813
- }
814
- /**
815
- * @public
816
- * @returns
817
- */
818
- getBuffer() {
819
- return this.get(WmsSourceProperty.BUFFER);
820
- }
821
- /**
822
- * @public
823
- * @param value
824
- * @param opt_silent
825
- */
826
- setEnv(value, opt_silent) {
827
- this.set(WmsSourceProperty.ENV, value, opt_silent);
828
- }
829
- /**
830
- * @public
831
- * @returns
832
- */
833
- getEnv() {
834
- return this.get(WmsSourceProperty.ENV);
835
- }
836
- /**
837
- * @public
838
- * @param value
839
- * @param opt_silent
840
- */
841
- setClip(value, opt_silent) {
842
- this.set(WmsSourceProperty.CLIP, value, opt_silent);
843
- }
844
- /**
845
- * @public
846
- * @returns
847
- */
848
- getClip() {
849
- return this.get(WmsSourceProperty.CLIP);
850
- }
851
- /**
852
- * @private
853
- */
854
- addEvents_() {
855
- this.on(['propertychange'], (evt) => {
856
- console.log(evt.key);
857
- // If a geoserver property was modified, refresh the source
858
- if (this.geoserverProps_.includes(evt.key)) {
859
- this.updateParams({
860
- [evt.key]: evt.target.get(evt.key)
861
- });
862
- this.refresh();
863
- }
864
- });
865
611
  }
866
- }
867
- var WmsSourceProperty;
868
- (function (WmsSourceProperty) {
869
- WmsSourceProperty["BUFFER"] = "buffer";
870
- WmsSourceProperty["ENV"] = "env";
871
- WmsSourceProperty["CLIP"] = "clip";
872
- })(WmsSourceProperty || (WmsSourceProperty = {}));
612
+ }
873
613
 
874
614
  /**
875
615
  * Layer to retrieve WMS information from geoservers
@@ -929,7 +669,7 @@ class WmsLayer extends Mixin(BaseLayer, (TileLayer)) {
929
669
  * @returns
930
670
  * @private
931
671
  */
932
- async getFeaturesByClickEvent(evt) {
672
+ async _getFeaturesByClickEvent(evt) {
933
673
  const coordinate = evt.coordinate;
934
674
  const view = getMap().getView();
935
675
  // Si la vista es lejana, disminumos el buffer
@@ -977,6 +717,28 @@ class WmsLayer extends Mixin(BaseLayer, (TileLayer)) {
977
717
  params.t = new Date().getMilliseconds();
978
718
  source.updateParams(params);
979
719
  }
720
+ /**
721
+ * Use this to update Geoserver Wfs Vendors (https://docs.geoserver.org/latest/en/user/services/wfs/vendor.html)
722
+ * and other arguements (https://docs.geoserver.org/stable/en/user/services/wfs/reference.html)
723
+ * in all the getFeature requests.
724
+ *
725
+ * Example: you can use this to set a cql_filter, limit the numbers of features, etc.
726
+ *
727
+ * @public
728
+ * @param paramName
729
+ * @param value
730
+ * @param refresh
731
+ */
732
+ setCustomParam(paramName, value = null, refresh = true) {
733
+ const source = this.getSource();
734
+ source.updateParams({
735
+ [paramName]: value
736
+ });
737
+ if (refresh) {
738
+ this.refresh();
739
+ }
740
+ return source.getParams();
741
+ }
980
742
  }
981
743
 
982
744
  function createElement(tagName, attrs = {}, ...children) {
@@ -2558,7 +2320,7 @@ class Wfst extends Control {
2558
2320
  layer instanceof WfsLayer) {
2559
2321
  return;
2560
2322
  }
2561
- const features = await layer.getFeaturesByClickEvent(evt);
2323
+ const features = await layer._getFeaturesByClickEvent(evt);
2562
2324
  if (!features.length) {
2563
2325
  return;
2564
2326
  }