adt-js-components 1.9.2 → 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.
- package/package.json +1 -1
- package/src/Map/index.js +46 -3
package/package.json
CHANGED
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)) {
|
|
@@ -587,14 +593,33 @@ async function calculateRoute(map) {
|
|
|
587
593
|
return;
|
|
588
594
|
}
|
|
589
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
|
+
|
|
590
615
|
const params = new URLSearchParams({
|
|
591
|
-
start: `${
|
|
592
|
-
end: `${
|
|
616
|
+
start: `${startPoint.lon},${startPoint.lat}`,
|
|
617
|
+
end: `${endPoint.lon},${endPoint.lat}`,
|
|
593
618
|
routeType: routeSettings.routeType,
|
|
594
619
|
apikey: siteKey
|
|
595
620
|
});
|
|
596
621
|
|
|
597
|
-
routeMarkers.
|
|
622
|
+
routeMarkers.forEach(m => {
|
|
598
623
|
params.append('waypoints', `${m.position.lon},${m.position.lat}`);
|
|
599
624
|
});
|
|
600
625
|
|
|
@@ -620,6 +645,24 @@ async function calculateRoute(map) {
|
|
|
620
645
|
}
|
|
621
646
|
}
|
|
622
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
|
+
|
|
623
666
|
function getSelectedMarkers(mapElement) {
|
|
624
667
|
const map = mapInstances.get(mapElement);
|
|
625
668
|
if (!map) return [];
|