adt-js-components 1.9.1 → 1.9.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Map/index.js +63 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Map/index.js CHANGED
@@ -17,6 +17,11 @@ const markersDataMap = new WeakMap();
17
17
  const markerClusters = new WeakMap();
18
18
  const onSelectionChangeMap = new WeakMap();
19
19
 
20
+ const DEPOT_TYPE = {
21
+ START: 'depot-start',
22
+ END: 'depot-end'
23
+ };
24
+
20
25
  async function run(options) {
21
26
  siteKey = options.siteKey;
22
27
  markerImg = options.markerImg;
@@ -41,6 +46,7 @@ async function run(options) {
41
46
  const routeSettings = {
42
47
  ...defaultRouteSettings,
43
48
  ...route,
49
+ customMarkers: customMarkers,
44
50
  };
45
51
 
46
52
  if (mapInstances.has(el)) {
@@ -356,9 +362,26 @@ function createMarker(marker, options, selectedOptions, cluster = null, selectab
356
362
  mapMarker._selectedIcon = selectedOptions.icon;
357
363
  mapMarker._markerData = marker;
358
364
 
365
+ const markerElement = mapMarker.getElement();
366
+ if (markerElement && markerElement.parentElement) {
367
+ markerElement.parentElement.style.pointerEvents = 'visible';
368
+ }
369
+
359
370
  if (map) {
360
371
  const markers = markerInstances.get(map);
361
372
  markers.set(marker.id, mapMarker);
373
+
374
+ mapMarker.on('add', function() {
375
+ const el = mapMarker.getElement();
376
+ if (el) {
377
+ el.style.cursor = 'pointer';
378
+
379
+ const parent = el.parentElement;
380
+ if (parent) {
381
+ parent.style.pointerEvents = 'all';
382
+ }
383
+ }
384
+ });
362
385
  }
363
386
 
364
387
  const originalCallback = marker.callback;
@@ -570,14 +593,33 @@ async function calculateRoute(map) {
570
593
  return;
571
594
  }
572
595
 
596
+ let startPoint = routeMarkers[0].position;
597
+ const hasCustomStart = routeSettings.startPoint !== null && routeSettings.startPoint !== undefined;
598
+ if (hasCustomStart) {
599
+ startPoint = routeSettings.startPoint;
600
+ }
601
+
602
+ let endPoint = routeMarkers[routeMarkers.length - 1].position;
603
+ const hasCustomEnd = routeSettings.endPoint !== null && routeSettings.endPoint !== undefined;
604
+ if (hasCustomEnd) {
605
+ endPoint = routeSettings.endPoint;
606
+ }
607
+
608
+ if (hasCustomStart) {
609
+ addDepotMarker(map, startPoint, DEPOT_TYPE.START);
610
+ }
611
+ if (hasCustomEnd) {
612
+ addDepotMarker(map, endPoint, DEPOT_TYPE.END);
613
+ }
614
+
573
615
  const params = new URLSearchParams({
574
- start: `${routeMarkers[0].position.lon},${routeMarkers[0].position.lat}`,
575
- end: `${routeMarkers[routeMarkers.length-1].position.lon},${routeMarkers[routeMarkers.length-1].position.lat}`,
616
+ start: `${startPoint.lon},${startPoint.lat}`,
617
+ end: `${endPoint.lon},${endPoint.lat}`,
576
618
  routeType: routeSettings.routeType,
577
619
  apikey: siteKey
578
620
  });
579
621
 
580
- routeMarkers.slice(1, -1).forEach(m => {
622
+ routeMarkers.forEach(m => {
581
623
  params.append('waypoints', `${m.position.lon},${m.position.lat}`);
582
624
  });
583
625
 
@@ -603,6 +645,24 @@ async function calculateRoute(map) {
603
645
  }
604
646
  }
605
647
 
648
+ function addDepotMarker(map, position, depotType) {
649
+ const routeSettings = routeSettingsMap.get(map);
650
+ const customMarkers = routeSettings.customMarkers || {};
651
+ const iconUrl = customMarkers.depot || markerImg;
652
+
653
+ const img = new Image();
654
+ img.src = iconUrl;
655
+ img.onload = function () {
656
+ const icon = L.icon({
657
+ iconUrl: iconUrl,
658
+ iconSize: [img.width, img.height],
659
+ iconAnchor: [img.width / 2, img.height]
660
+ });
661
+
662
+ L.marker(position, { icon: icon }).addTo(map);
663
+ };
664
+ }
665
+
606
666
  function getSelectedMarkers(mapElement) {
607
667
  const map = mapInstances.get(mapElement);
608
668
  if (!map) return [];