@hestia-earth/ui-components 0.42.0 → 0.42.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.
@@ -47,8 +47,8 @@ import * as semver from 'semver';
47
47
  import { parse } from 'papaparse';
48
48
  import omit from 'lodash.omit';
49
49
  import { validationsByMessage } from '@hestia-earth/data-validation';
50
- import moment from 'moment';
51
- import 'moment/locale/en-gb';
50
+ import { format, subDays, parseISO } from 'date-fns';
51
+ import { enGB } from 'date-fns/locale';
52
52
  import { v4 } from 'uuid';
53
53
  import { MarkdownComponent } from 'ngx-markdown';
54
54
  import { linkHorizontal } from 'd3-shape';
@@ -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());
@@ -12510,7 +12538,7 @@ const calculateCycleStartDateEnabled = (properties, property) => {
12510
12538
  const calculateCycleStartDate = (properties, property) => {
12511
12539
  const cycleDuration = siblingProperty(properties, property, 'cycleDuration');
12512
12540
  const endDate = siblingProperty(properties, property, 'endDate');
12513
- return moment(endDate.value).locale('en-gb').subtract(cycleDuration.value, 'days').format('YYYY-MM-DD');
12541
+ return format(subDays(parseISO(endDate.value), cycleDuration.value), 'yyyy-MM-dd', { locale: enGB });
12514
12542
  };
12515
12543
 
12516
12544
  const siteLocation = ({ latitude, longitude }) => latitude && longitude