@hestia-earth/ui-components 0.42.1 → 0.42.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.
@@ -716,7 +716,7 @@ const HE_MAP_LOADED = new InjectionToken('Google Maps API Loaded');
716
716
  * @param libraries
717
717
  * @returns
718
718
  */
719
- const loadMapApi = (apiKey, libraries = ['visualization', 'drawing']) => (httpClient) => of(`${loadMapUrl}?${buildMapsUrl({ key: [apiKey], libraries })}`).pipe(mergeMap(url => httpClient.jsonp(url, 'callback')), shareReplay({ bufferSize: 1, refCount: true }), delay(100), map(() => true), catchError(e => {
719
+ const loadMapApi = (apiKey, libraries = ['visualization']) => (httpClient) => of(`${loadMapUrl}?${buildMapsUrl({ key: [apiKey], libraries })}`).pipe(mergeMap(url => httpClient.jsonp(url, 'callback')), shareReplay({ bufferSize: 1, refCount: true }), delay(100), map(() => true), catchError(e => {
720
720
  console.error(e);
721
721
  return of(false);
722
722
  }));
@@ -2595,16 +2595,44 @@ class MapsDrawingComponent {
2595
2595
  loadData() {
2596
2596
  this.shapes = polygonsFromFeature(this.feature());
2597
2597
  this.shapes.forEach(polygon => polygon.setMap(this.map()?.googleMap));
2598
- const drawingManager = new google.maps.drawing.DrawingManager({
2599
- drawingControlOptions: {
2600
- position: google.maps.ControlPosition.TOP_CENTER,
2601
- drawingModes: this.modes() || [google.maps.drawing.OverlayType.POLYGON]
2602
- },
2603
- polygonOptions: strokeStyle
2604
- });
2605
- drawingManager.setMap(this.map()?.googleMap);
2606
- this.listeners.push(google.maps.event.addListener(drawingManager, 'polygoncomplete', polygon => this.onPolygonAdded(polygon)));
2607
- this.listeners.push(google.maps.event.addListener(drawingManager, 'markercomplete', marker => this.onMarkerAdded(marker)));
2598
+ const map = this.map()?.googleMap;
2599
+ if (!map) {
2600
+ return;
2601
+ }
2602
+ const modes = this.modes() || ['polygon'];
2603
+ const controls = modes
2604
+ .map(mode => {
2605
+ const m = mode.toLowerCase();
2606
+ if (m === 'polygon')
2607
+ return 'Polygon';
2608
+ if (m === 'marker' || m === 'point')
2609
+ return 'Point';
2610
+ return null;
2611
+ })
2612
+ .filter(Boolean);
2613
+ map.data.setControls(controls);
2614
+ map.data.setControlPosition(google.maps.ControlPosition.TOP_CENTER);
2615
+ map.data.setStyle(strokeStyle);
2616
+ this.listeners.push(map.data.addListener('addfeature', (event) => {
2617
+ const feature = event.feature;
2618
+ const geometry = feature.getGeometry();
2619
+ map.data.remove(feature);
2620
+ if (geometry?.getType() === 'Polygon') {
2621
+ const polygon = new google.maps.Polygon({
2622
+ paths: geometry.getArray().map(path => path.getArray()),
2623
+ ...strokeStyle
2624
+ });
2625
+ polygon.setMap(map);
2626
+ this.onPolygonAdded(polygon);
2627
+ }
2628
+ else if (geometry?.getType() === 'Point') {
2629
+ const marker = new google.maps.Marker({
2630
+ position: geometry.get(),
2631
+ map: map
2632
+ });
2633
+ this.onMarkerAdded(marker);
2634
+ }
2635
+ }));
2608
2636
  }
2609
2637
  mapInitialized() {
2610
2638
  setTimeout(() => this.loadData());
@@ -5566,23 +5594,23 @@ class HeSearchService {
5566
5594
  this.http = inject(HttpClient);
5567
5595
  this.commonService = inject(HeCommonService);
5568
5596
  }
5569
- search$(params, dataVersion) {
5597
+ search$(params, dataVersion, searchPath = 'search') {
5570
5598
  return this.http
5571
- .post(`${this.commonService.apiBaseUrl}/search`, params, {
5599
+ .post(`${this.commonService.apiBaseUrl}/${searchPath}`, params, {
5572
5600
  headers: dataVersionHeader(dataVersion)
5573
5601
  })
5574
5602
  .pipe(catchError(() => of(emptySearchResult())));
5575
5603
  }
5576
- count$(params = {}, dataVersion) {
5604
+ count$(params = {}, dataVersion, countPath = 'count') {
5577
5605
  return this.http
5578
- .post(`${this.commonService.apiBaseUrl}/count`, params, {
5606
+ .post(`${this.commonService.apiBaseUrl}/${countPath}`, params, {
5579
5607
  headers: dataVersionHeader(dataVersion)
5580
5608
  })
5581
5609
  .pipe(catchError(() => of(0)));
5582
5610
  }
5583
- get$(type, id) {
5611
+ get$(type, id, searchPath = 'search') {
5584
5612
  return this.http
5585
- .post(`${this.commonService.apiBaseUrl}/search`, {
5613
+ .post(`${this.commonService.apiBaseUrl}/${searchPath}`, {
5586
5614
  limit: 1,
5587
5615
  query: {
5588
5616
  bool: {
@@ -5592,10 +5620,10 @@ class HeSearchService {
5592
5620
  })
5593
5621
  .pipe(catchError(() => of(emptySearchResult())), map(({ results }) => results[0] || null));
5594
5622
  }
5595
- suggest$(term, type, extraQueries = [], fullQuery, limit = 10, includes = []) {
5623
+ suggest$(term, type, extraQueries = [], fullQuery, limit = 10, includes = [], searchPath = 'search') {
5596
5624
  const query = fullQuery || suggestQuery(term, type, extraQueries);
5597
5625
  return this.http
5598
- .post(`${this.commonService.apiBaseUrl}/search`, {
5626
+ .post(`${this.commonService.apiBaseUrl}/${searchPath}`, {
5599
5627
  limit,
5600
5628
  fields: ['name', '@id', type ? '' : '@type', 'termType', 'aggregated', ...includes].filter(val => !!val),
5601
5629
  query