adb-shared 22.0.0-beta.0 → 22.0.0-beta.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.
@@ -2,7 +2,7 @@ import * as i1$2 from "@angular/common";
2
2
  import { CommonModule } from "@angular/common";
3
3
  import * as i0 from "@angular/core";
4
4
  import { ChangeDetectionStrategy, Component, ElementRef, Inject, Injectable, InjectionToken, Input, NgModule, afterRenderEffect, computed, effect, forwardRef, inject, input, output, signal } from "@angular/core";
5
- import * as i4 from "@angular/forms";
5
+ import * as i3 from "@angular/forms";
6
6
  import { FormArray, FormControl, FormGroup, FormsModule, NG_VALUE_ACCESSOR, ReactiveFormsModule, Validators } from "@angular/forms";
7
7
  import GeoJSON from "ol/format/GeoJSON.js";
8
8
  import Draw from "ol/interaction/Draw.js";
@@ -30,13 +30,14 @@ import Feature from "ol/Feature.js";
30
30
  import { extend, getCenter, getForViewAndSize, isEmpty } from "ol/extent.js";
31
31
  import { finalize } from "rxjs/operators";
32
32
  import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
33
- import * as i3 from "@angular/common/http";
33
+ import * as i2 from "@angular/common/http";
34
+ import { HttpClient } from "@angular/common/http";
35
+ import { Subscription, combineLatest, debounceTime, map } from "rxjs";
34
36
  import LineString from "ol/geom/LineString.js";
35
37
  import MultiPolygon from "ol/geom/MultiPolygon.js";
36
38
  import * as i1$1 from "adb-shared";
37
39
  import { AdbButtonsModule, AdbDatePickerModule, AdbDirectivesModule, AdbFilterSectionModule, AdbPickerModule, AdbPipesModule } from "adb-shared";
38
40
  import { addYears, endOfDay, endOfYear, parseISO, startOfDay, startOfYear } from "date-fns";
39
- import { Subscription, combineLatest, debounceTime, map } from "rxjs";
40
41
  const DateTypes = {
41
42
  THIS_YEAR: "1",
42
43
  LAST_YEAR: "2",
@@ -548,17 +549,15 @@ var AdbMapConfigService = class AdbMapConfigService {
548
549
  observationFeatures;
549
550
  taxaListsApi;
550
551
  dynamic;
551
- gridOnly;
552
552
  enableClusterSelection;
553
553
  dataProviderIds;
554
554
  constructor(config) {
555
555
  this.dynamic = config.dynamic ?? false;
556
- this.gridOnly = config.gridOnly ?? false;
557
556
  this.dataProviderIds = config.dataProviderIds === void 0 ? void 0 : Object.freeze([...config.dataProviderIds]);
558
557
  this.enableClusterSelection = config.enableClusterSelection ?? false;
559
558
  this.artfaktaTaxonLists = config.artfaktaTaxonLists ?? "https://artfakta.se/metadata/listor";
560
559
  this.taxaListsApi = config.api + "/taxalists";
561
- this.observationFeatures = "https://sos-search-st.wt.artdata.slu.se/observations/internal/adaptivesearchlocations";
560
+ this.observationFeatures = config.api + "/observation-features";
562
561
  }
563
562
  static ɵfac = i0.ɵɵngDeclareFactory({
564
563
  minVersion: "12.0.0",
@@ -686,86 +685,73 @@ i0.ɵɵngDeclareClassMetadata({
686
685
  }],
687
686
  propDecorators: { nodes: [{ type: Input }] }
688
687
  });
689
- var TempUtils = class {
690
- static euRegulation = 5;
691
- static createQParams(qParams, mpp) {
688
+ var AdbBffMapDataSource = class AdbBffMapDataSource {
689
+ http = inject(HttpClient);
690
+ load(request) {
692
691
  const params = {
693
- returnInputBBox: true,
694
- cluster: true,
695
- createPolygons: "WhenNeeded",
696
- useCache: true,
697
- maxGridCells: 1e3,
698
- maxZoom: 19,
699
- clusterRadiusPx: 20,
700
- minLocationCountBeforeClustering: 0,
701
- disablePixelClusteringAtMetersPerPixel: 2,
702
- detailClusterRadiusPx: 10,
703
- metersPerPixel: mpp,
704
- adaptiveSearchStrategy: "Auto",
705
- locationAggregationLimit: 1e3,
706
- observationsLimit: 5e3,
707
- includeFilterAreasInResult: true
708
- };
709
- if (qParams.cutoff) params.cutoffYear = qParams.cutoff;
710
- if (qParams.bbox) params.bbox = qParams.bbox;
711
- return params;
712
- }
713
- static createObservationsBody(queryParams) {
714
- const params = queryParams;
715
- const body = { geographics: {} };
716
- const startDate = params.startAt ?? params.startDate;
717
- const endDate = params.endAt ?? params.endDate;
718
- if (startDate) body.date = {
719
- startDate,
720
- ...endDate && { endDate }
692
+ ...request.params,
693
+ mpp: request.metersPerPixel
721
694
  };
722
- if (params.taxonId) body.taxon = {
723
- Ids: [+params.taxonId],
724
- includeUnderlyingTaxa: true
725
- };
726
- const taxonListIds = this.getTaxonListIds(params);
727
- if (taxonListIds.length) {
728
- body.taxon ??= {};
729
- body.taxon.taxonListIds = taxonListIds;
730
- body.taxon.taxonListOperator = "Filter";
731
- }
732
- if (params.area) body.geographics = { areas: (Array.isArray(params.area) ? params.area : [params.area]).map((area) => {
733
- const [areaType, featureId] = area.split("-");
695
+ const array = (value) => value == null ? [] : Array.isArray(value) ? value : [value];
696
+ const sources = request.dataProviderIds?.length ? [...request.dataProviderIds] : params["ds"] ?? params["source"];
697
+ if (sources != null) params["source"] = sources;
698
+ const lists = [
699
+ ...array(params["list"]),
700
+ ...array(params["rc"]),
701
+ ...array(params["rlc"]),
702
+ ...params["eu"] ? [5] : []
703
+ ];
704
+ if (lists.length) params["list"] = lists;
705
+ for (const key of [
706
+ "ds",
707
+ "rc",
708
+ "rlc",
709
+ "eu",
710
+ "presentationMode"
711
+ ]) delete params[key];
712
+ for (const key of Object.keys(params)) if (params[key] == null) delete params[key];
713
+ return this.http.get(request.url, { params }).pipe(map((response) => {
714
+ const geoJson = response?.geoJson;
715
+ if (!geoJson || geoJson.type !== "FeatureCollection") throw new Error("Invalid BFF GeoJSON response");
734
716
  return {
735
- areaType,
736
- featureId
717
+ ...geoJson,
718
+ properties: {
719
+ ...geoJson.properties,
720
+ count: response.observationsTotalCount ?? geoJson.properties?.count
721
+ }
737
722
  };
738
- }) };
739
- if (params.geo) body.geographics.geometries = [{
740
- type: "Polygon",
741
- coordinates: [JSON.parse(params.geo)]
742
- }];
743
- if (params.locationId) body.geographics.locationIds = Array.isArray(params.locationId) ? params.locationId : [params.locationId];
744
- if (params.ds) body.dataProvider = { ids: this.toNumberArray(params.ds) };
745
- return {
746
- occurrenceStatus: params.noted === "true" ? "Present" : "BothPresentAndAbsent",
747
- notRecoveredFilter: "NoFilter",
748
- determinationFilter: "NotUnsureDetermination",
749
- extendedFilter: {
750
- notPresentFilter: "DontIncludeNotPresent",
751
- ...params.activities && { activityIds: JSON.parse(params.activities).map(Number) }
752
- },
753
- ...body
754
- };
755
- }
756
- static getTaxonListIds(params) {
757
- return [
758
- ...this.toNumberArray(params.rc),
759
- ...this.toNumberArray(params.rlc),
760
- ...this.toNumberArray(params.list),
761
- ...params.eu ? [this.euRegulation] : []
762
- ];
763
- }
764
- static toNumberArray(value) {
765
- if (!value) return [];
766
- return (Array.isArray(value) ? value : [value]).map(Number);
723
+ }));
767
724
  }
725
+ static ɵfac = i0.ɵɵngDeclareFactory({
726
+ minVersion: "12.0.0",
727
+ version: "22.2.4",
728
+ ngImport: i0,
729
+ type: AdbBffMapDataSource,
730
+ deps: [],
731
+ target: i0.ɵɵFactoryTarget.Injectable
732
+ });
733
+ static ɵprov = i0.ɵɵngDeclareInjectable({
734
+ minVersion: "12.0.0",
735
+ version: "22.2.4",
736
+ ngImport: i0,
737
+ type: AdbBffMapDataSource,
738
+ providedIn: "root"
739
+ });
768
740
  };
741
+ i0.ɵɵngDeclareClassMetadata({
742
+ minVersion: "12.0.0",
743
+ version: "22.2.4",
744
+ ngImport: i0,
745
+ type: AdbBffMapDataSource,
746
+ decorators: [{
747
+ type: Injectable,
748
+ args: [{ providedIn: "root" }]
749
+ }]
750
+ });
751
+ const ADB_MAP_DATA_SOURCE = new InjectionToken("ADB_MAP_DATA_SOURCE", {
752
+ providedIn: "root",
753
+ factory: () => inject(AdbBffMapDataSource)
754
+ });
769
755
  var MapFeaturePickerComponent = class MapFeaturePickerComponent {
770
756
  locationOptions = input.required(...ngDevMode ? [{ debugName: "locationOptions" }] : /* istanbul ignore next */ []);
771
757
  featureChosen = output();
@@ -1060,7 +1046,6 @@ var AdbMapComponent = class AdbMapComponent {
1060
1046
  activatedRoute;
1061
1047
  config;
1062
1048
  router;
1063
- http;
1064
1049
  showLegend = input(true, ...ngDevMode ? [{ debugName: "showLegend" }] : /* istanbul ignore next */ []);
1065
1050
  showHeader = input(true, ...ngDevMode ? [{ debugName: "showHeader" }] : /* istanbul ignore next */ []);
1066
1051
  allowPresentationMode = input(false, ...ngDevMode ? [{ debugName: "allowPresentationMode" }] : /* istanbul ignore next */ []);
@@ -1071,6 +1056,7 @@ var AdbMapComponent = class AdbMapComponent {
1071
1056
  if (this.allowPresentationMode() && (mode === "locations" || mode === "observations")) return mode;
1072
1057
  return this.presentationMode();
1073
1058
  }, ...ngDevMode ? [{ debugName: "activePresentationMode" }] : /* istanbul ignore next */ []);
1059
+ dataSource = inject(ADB_MAP_DATA_SOURCE);
1074
1060
  requestedParams = "";
1075
1061
  settingsOpen = signal(false, ...ngDevMode ? [{ debugName: "settingsOpen" }] : /* istanbul ignore next */ []);
1076
1062
  savingSettings = signal(false, ...ngDevMode ? [{ debugName: "savingSettings" }] : /* istanbul ignore next */ []);
@@ -1106,11 +1092,10 @@ var AdbMapComponent = class AdbMapComponent {
1106
1092
  map;
1107
1093
  mapReady = signal(false, ...ngDevMode ? [{ debugName: "mapReady" }] : /* istanbul ignore next */ []);
1108
1094
  queryParams = {};
1109
- constructor(activatedRoute, config, router, http) {
1095
+ constructor(activatedRoute, config, router) {
1110
1096
  this.activatedRoute = activatedRoute;
1111
1097
  this.config = config;
1112
1098
  this.router = router;
1113
- this.http = http;
1114
1099
  this.route.set(this.activatedRoute.snapshot);
1115
1100
  this.settingsForm.controls.presentationMode.valueChanges.pipe(takeUntilDestroyed()).subscribe((mode) => {
1116
1101
  const cutoff = this.settingsForm.controls.cutoff;
@@ -1296,30 +1281,15 @@ var AdbMapComponent = class AdbMapComponent {
1296
1281
  const fitView = !this.preserveViewOnNextLoad && (!qParams["bbox"] || qParams["bbox"] !== this.currentBbox());
1297
1282
  this.preserveViewOnNextLoad = false;
1298
1283
  const requestedView = this.viewKey();
1299
- const body = TempUtils.createObservationsBody(qParams);
1300
- const allowedIds = this.config.dataProviderIds;
1301
- if (allowedIds?.length) body.dataProvider = { ids: [...allowedIds] };
1302
- qParams = TempUtils.createQParams(qParams, this.getMetersPerPixel(qParams));
1303
- if (this.config.gridOnly) {
1304
- qParams["adaptiveSearchStrategy"] = "ObservationsThenGrid";
1305
- qParams["observationsLimit"] = 0;
1306
- qParams["cluster"] = false;
1307
- }
1308
- const url = this.config.observationFeatures;
1309
- this.requestSubscription = this.http.request("POST", url, {
1310
- observe: "response",
1311
- body,
1312
- params: qParams
1284
+ this.requestSubscription = this.dataSource.load({
1285
+ url: this.config.observationFeatures,
1286
+ params: qParams,
1287
+ metersPerPixel: this.getMetersPerPixel(qParams),
1288
+ dataProviderIds: this.config.dataProviderIds
1313
1289
  }).pipe(finalize(() => {
1314
1290
  this.mapLoading.set(false);
1315
1291
  })).subscribe({
1316
- next: (response) => {
1317
- if (!response.body) throw new Error("No GeoJson body");
1318
- const geo = response.body;
1319
- geo.properties = {
1320
- ...geo.properties,
1321
- count: response.headers.get("X-Observations-TotalCount") ?? geo.properties?.count
1322
- };
1292
+ next: (geo) => {
1323
1293
  this.buildMap(geo, fitView && requestedView === this.viewKey());
1324
1294
  },
1325
1295
  error: (err) => {
@@ -1424,8 +1394,7 @@ var AdbMapComponent = class AdbMapComponent {
1424
1394
  deps: [
1425
1395
  { token: i1.ActivatedRoute },
1426
1396
  { token: AdbMapConfigService },
1427
- { token: i1.Router },
1428
- { token: i3.HttpClient }
1397
+ { token: i1.Router }
1429
1398
  ],
1430
1399
  target: i0.ɵɵFactoryTarget.Component
1431
1400
  });
@@ -1474,50 +1443,50 @@ var AdbMapComponent = class AdbMapComponent {
1474
1443
  dependencies: [
1475
1444
  {
1476
1445
  kind: "directive",
1477
- type: i4.ɵNgNoValidate,
1446
+ type: i3.ɵNgNoValidate,
1478
1447
  selector: "form:not([ngNoForm]):not([ngNativeValidate])"
1479
1448
  },
1480
1449
  {
1481
1450
  kind: "directive",
1482
- type: i4.NgSelectOption,
1451
+ type: i3.NgSelectOption,
1483
1452
  selector: "option",
1484
1453
  inputs: ["ngValue", "value"]
1485
1454
  },
1486
1455
  {
1487
1456
  kind: "directive",
1488
- type: i4.ɵNgSelectMultipleOption,
1457
+ type: i3.ɵNgSelectMultipleOption,
1489
1458
  selector: "option",
1490
1459
  inputs: ["ngValue", "value"]
1491
1460
  },
1492
1461
  {
1493
1462
  kind: "directive",
1494
- type: i4.DefaultValueAccessor,
1463
+ type: i3.DefaultValueAccessor,
1495
1464
  selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
1496
1465
  },
1497
1466
  {
1498
1467
  kind: "directive",
1499
- type: i4.CheckboxControlValueAccessor,
1468
+ type: i3.CheckboxControlValueAccessor,
1500
1469
  selector: "input[type=checkbox]:not([ngNoCva])[formControlName],input[type=checkbox]:not([ngNoCva])[formControl],input[type=checkbox]:not([ngNoCva])[ngModel]"
1501
1470
  },
1502
1471
  {
1503
1472
  kind: "directive",
1504
- type: i4.SelectControlValueAccessor,
1473
+ type: i3.SelectControlValueAccessor,
1505
1474
  selector: "select:not([multiple]):not([ngNoCva])[formControlName],select:not([multiple]):not([ngNoCva])[formControl],select:not([multiple]):not([ngNoCva])[ngModel]",
1506
1475
  inputs: ["compareWith"]
1507
1476
  },
1508
1477
  {
1509
1478
  kind: "directive",
1510
- type: i4.NgControlStatus,
1479
+ type: i3.NgControlStatus,
1511
1480
  selector: "[formControlName],[ngModel],[formControl]"
1512
1481
  },
1513
1482
  {
1514
1483
  kind: "directive",
1515
- type: i4.NgControlStatusGroup,
1484
+ type: i3.NgControlStatusGroup,
1516
1485
  selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]"
1517
1486
  },
1518
1487
  {
1519
1488
  kind: "directive",
1520
- type: i4.FormGroupDirective,
1489
+ type: i3.FormGroupDirective,
1521
1490
  selector: "[formGroup]",
1522
1491
  inputs: ["formGroup"],
1523
1492
  outputs: ["ngSubmit"],
@@ -1525,7 +1494,7 @@ var AdbMapComponent = class AdbMapComponent {
1525
1494
  },
1526
1495
  {
1527
1496
  kind: "directive",
1528
- type: i4.FormControlName,
1497
+ type: i3.FormControlName,
1529
1498
  selector: "[formControlName]",
1530
1499
  inputs: [
1531
1500
  "formControlName",
@@ -1583,8 +1552,7 @@ i0.ɵɵngDeclareClassMetadata({
1583
1552
  ctorParameters: () => [
1584
1553
  { type: i1.ActivatedRoute },
1585
1554
  { type: AdbMapConfigService },
1586
- { type: i1.Router },
1587
- { type: i3.HttpClient }
1555
+ { type: i1.Router }
1588
1556
  ],
1589
1557
  propDecorators: {
1590
1558
  showLegend: [{
@@ -1966,7 +1934,7 @@ var AdbMapFilters = class AdbMapFilters {
1966
1934
  deps: [
1967
1935
  { token: i0.ChangeDetectorRef },
1968
1936
  { token: AdbMapConfigService },
1969
- { token: i3.HttpClient },
1937
+ { token: i2.HttpClient },
1970
1938
  { token: i1.Router },
1971
1939
  { token: i1.ActivatedRoute }
1972
1940
  ],
@@ -1999,45 +1967,45 @@ var AdbMapFilters = class AdbMapFilters {
1999
1967
  dependencies: [
2000
1968
  {
2001
1969
  kind: "directive",
2002
- type: i4.ɵNgNoValidate,
1970
+ type: i3.ɵNgNoValidate,
2003
1971
  selector: "form:not([ngNoForm]):not([ngNativeValidate])"
2004
1972
  },
2005
1973
  {
2006
1974
  kind: "directive",
2007
- type: i4.NgSelectOption,
1975
+ type: i3.NgSelectOption,
2008
1976
  selector: "option",
2009
1977
  inputs: ["ngValue", "value"]
2010
1978
  },
2011
1979
  {
2012
1980
  kind: "directive",
2013
- type: i4.ɵNgSelectMultipleOption,
1981
+ type: i3.ɵNgSelectMultipleOption,
2014
1982
  selector: "option",
2015
1983
  inputs: ["ngValue", "value"]
2016
1984
  },
2017
1985
  {
2018
1986
  kind: "directive",
2019
- type: i4.DefaultValueAccessor,
1987
+ type: i3.DefaultValueAccessor,
2020
1988
  selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
2021
1989
  },
2022
1990
  {
2023
1991
  kind: "directive",
2024
- type: i4.CheckboxControlValueAccessor,
1992
+ type: i3.CheckboxControlValueAccessor,
2025
1993
  selector: "input[type=checkbox]:not([ngNoCva])[formControlName],input[type=checkbox]:not([ngNoCva])[formControl],input[type=checkbox]:not([ngNoCva])[ngModel]"
2026
1994
  },
2027
1995
  {
2028
1996
  kind: "directive",
2029
- type: i4.SelectControlValueAccessor,
1997
+ type: i3.SelectControlValueAccessor,
2030
1998
  selector: "select:not([multiple]):not([ngNoCva])[formControlName],select:not([multiple]):not([ngNoCva])[formControl],select:not([multiple]):not([ngNoCva])[ngModel]",
2031
1999
  inputs: ["compareWith"]
2032
2000
  },
2033
2001
  {
2034
2002
  kind: "directive",
2035
- type: i4.NgControlStatus,
2003
+ type: i3.NgControlStatus,
2036
2004
  selector: "[formControlName],[ngModel],[formControl]"
2037
2005
  },
2038
2006
  {
2039
2007
  kind: "directive",
2040
- type: i4.NgControlStatusGroup,
2008
+ type: i3.NgControlStatusGroup,
2041
2009
  selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]"
2042
2010
  },
2043
2011
  {
@@ -2061,7 +2029,7 @@ var AdbMapFilters = class AdbMapFilters {
2061
2029
  },
2062
2030
  {
2063
2031
  kind: "directive",
2064
- type: i4.FormGroupDirective,
2032
+ type: i3.FormGroupDirective,
2065
2033
  selector: "[formGroup]",
2066
2034
  inputs: ["formGroup"],
2067
2035
  outputs: ["ngSubmit"],
@@ -2069,7 +2037,7 @@ var AdbMapFilters = class AdbMapFilters {
2069
2037
  },
2070
2038
  {
2071
2039
  kind: "directive",
2072
- type: i4.FormControlName,
2040
+ type: i3.FormControlName,
2073
2041
  selector: "[formControlName]",
2074
2042
  inputs: [
2075
2043
  "formControlName",
@@ -2080,13 +2048,13 @@ var AdbMapFilters = class AdbMapFilters {
2080
2048
  },
2081
2049
  {
2082
2050
  kind: "directive",
2083
- type: i4.FormGroupName,
2051
+ type: i3.FormGroupName,
2084
2052
  selector: "[formGroupName]",
2085
2053
  inputs: ["formGroupName"]
2086
2054
  },
2087
2055
  {
2088
2056
  kind: "directive",
2089
- type: i4.FormArrayName,
2057
+ type: i3.FormArrayName,
2090
2058
  selector: "[formArrayName]",
2091
2059
  inputs: ["formArrayName"]
2092
2060
  },
@@ -2176,7 +2144,7 @@ i0.ɵɵngDeclareClassMetadata({
2176
2144
  ctorParameters: () => [
2177
2145
  { type: i0.ChangeDetectorRef },
2178
2146
  { type: AdbMapConfigService },
2179
- { type: i3.HttpClient },
2147
+ { type: i2.HttpClient },
2180
2148
  { type: i1.Router },
2181
2149
  { type: i1.ActivatedRoute }
2182
2150
  ],
@@ -2304,6 +2272,6 @@ i0.ɵɵngDeclareClassMetadata({
2304
2272
  }]
2305
2273
  }]
2306
2274
  });
2307
- export { ADB_MAP_CONFIG, AdbLocationMapComponent, AdbMapComponent, AdbMapConfigService, AdbMapFilters, AdbMapModule, AdbMapUtils, PolygonDrawerInput };
2275
+ export { ADB_MAP_CONFIG, ADB_MAP_DATA_SOURCE, AdbBffMapDataSource, AdbLocationMapComponent, AdbMapComponent, AdbMapConfigService, AdbMapFilters, AdbMapModule, AdbMapUtils, PolygonDrawerInput };
2308
2276
 
2309
2277
  //# sourceMappingURL=adb-shared-map.mjs.map