adt-js-components 1.9.3 → 1.9.4
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 +99 -34
package/package.json
CHANGED
package/src/Map/index.js
CHANGED
|
@@ -581,6 +581,16 @@ async function calculateRoute(map) {
|
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
+
const hasCustomStart = routeSettings.startPoint !== null && routeSettings.startPoint !== undefined;
|
|
585
|
+
const hasCustomEnd = routeSettings.endPoint !== null && routeSettings.endPoint !== undefined;
|
|
586
|
+
|
|
587
|
+
if (hasCustomStart) {
|
|
588
|
+
addDepotMarker(map, routeSettings.startPoint, DEPOT_TYPE.START);
|
|
589
|
+
}
|
|
590
|
+
if (hasCustomEnd) {
|
|
591
|
+
addDepotMarker(map, routeSettings.endPoint, DEPOT_TYPE.END);
|
|
592
|
+
}
|
|
593
|
+
|
|
584
594
|
if (selectedSet && selectedSet.size > 0) {
|
|
585
595
|
const orderedIds = Array.from(order.entries())
|
|
586
596
|
.sort((a, b) => a[1] - b[1])
|
|
@@ -594,53 +604,108 @@ async function calculateRoute(map) {
|
|
|
594
604
|
}
|
|
595
605
|
|
|
596
606
|
let startPoint = routeMarkers[0].position;
|
|
597
|
-
const hasCustomStart = routeSettings.startPoint !== null && routeSettings.startPoint !== undefined;
|
|
598
607
|
if (hasCustomStart) {
|
|
599
608
|
startPoint = routeSettings.startPoint;
|
|
600
609
|
}
|
|
601
610
|
|
|
602
611
|
let endPoint = routeMarkers[routeMarkers.length - 1].position;
|
|
603
|
-
const hasCustomEnd = routeSettings.endPoint !== null && routeSettings.endPoint !== undefined;
|
|
604
612
|
if (hasCustomEnd) {
|
|
605
613
|
endPoint = routeSettings.endPoint;
|
|
606
614
|
}
|
|
607
615
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
616
|
+
// API mapy.cz povoluje max 15 waypointů, viz https://developer.mapy.com/cs/rest-api/funkce/planovani/
|
|
617
|
+
const WAYPOINTS_LIMIT = 15;
|
|
618
|
+
const allCoords = [];
|
|
619
|
+
|
|
620
|
+
if (routeMarkers.length <= WAYPOINTS_LIMIT) {
|
|
621
|
+
// Pokud je markerů méně nebo rovno 15, použijeme původní logiku
|
|
622
|
+
const params = new URLSearchParams({
|
|
623
|
+
start: `${startPoint.lon},${startPoint.lat}`,
|
|
624
|
+
end: `${endPoint.lon},${endPoint.lat}`,
|
|
625
|
+
routeType: routeSettings.routeType,
|
|
626
|
+
apikey: siteKey
|
|
627
|
+
});
|
|
614
628
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
routeType: routeSettings.routeType,
|
|
619
|
-
apikey: siteKey
|
|
620
|
-
});
|
|
629
|
+
routeMarkers.forEach(m => {
|
|
630
|
+
params.append('waypoints', `${m.position.lon},${m.position.lat}`);
|
|
631
|
+
});
|
|
621
632
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
633
|
+
try {
|
|
634
|
+
const response = await fetch(
|
|
635
|
+
`https://api.mapy.cz/v1/routing/route?${params.toString()}`
|
|
636
|
+
);
|
|
637
|
+
const data = await response.json();
|
|
625
638
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const coords = data.geometry.geometry.coordinates.map(c => [c[1], c[0]]);
|
|
634
|
-
const polyline = L.polyline(coords, {
|
|
635
|
-
color: routeSettings.color,
|
|
636
|
-
weight: routeSettings.weight,
|
|
637
|
-
opacity: routeSettings.opacity
|
|
638
|
-
}).addTo(map);
|
|
639
|
-
|
|
640
|
-
routePolylines.set(map, polyline);
|
|
639
|
+
if (data.geometry?.geometry?.coordinates) {
|
|
640
|
+
const coords = data.geometry.geometry.coordinates.map(c => [c[1], c[0]]);
|
|
641
|
+
allCoords.push(...coords);
|
|
642
|
+
}
|
|
643
|
+
} catch (error) {
|
|
644
|
+
console.error('Error calculating route:', error);
|
|
645
|
+
return;
|
|
641
646
|
}
|
|
642
|
-
}
|
|
643
|
-
|
|
647
|
+
} else {
|
|
648
|
+
const chunks = [];
|
|
649
|
+
for (let i = 0; i < routeMarkers.length; i += WAYPOINTS_LIMIT) {
|
|
650
|
+
chunks.push(routeMarkers.slice(i, i + WAYPOINTS_LIMIT));
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
654
|
+
const chunk = chunks[i];
|
|
655
|
+
const isFirstChunk = i === 0;
|
|
656
|
+
const isLastChunk = i === chunks.length - 1;
|
|
657
|
+
|
|
658
|
+
let chunkStart, chunkEnd;
|
|
659
|
+
|
|
660
|
+
if (isFirstChunk) {
|
|
661
|
+
chunkStart = startPoint; // Použije custom start nebo první marker
|
|
662
|
+
chunkEnd = isLastChunk ? endPoint : chunk[chunk.length - 1].position;
|
|
663
|
+
} else if (isLastChunk) {
|
|
664
|
+
chunkStart = chunks[i - 1][chunks[i - 1].length - 1].position;
|
|
665
|
+
chunkEnd = endPoint; // Použije custom end nebo poslední marker
|
|
666
|
+
} else {
|
|
667
|
+
chunkStart = chunks[i - 1][chunks[i - 1].length - 1].position;
|
|
668
|
+
chunkEnd = chunk[chunk.length - 1].position;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const params = new URLSearchParams({
|
|
672
|
+
start: `${chunkStart.lon},${chunkStart.lat}`,
|
|
673
|
+
end: `${chunkEnd.lon},${chunkEnd.lat}`,
|
|
674
|
+
routeType: routeSettings.routeType,
|
|
675
|
+
apikey: siteKey
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
const markersToAdd = isFirstChunk ? chunk : chunk.slice(1);
|
|
679
|
+
|
|
680
|
+
markersToAdd.forEach(m => {
|
|
681
|
+
params.append('waypoints', `${m.position.lon},${m.position.lat}`);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
try {
|
|
685
|
+
const response = await fetch(
|
|
686
|
+
`https://api.mapy.cz/v1/routing/route?${params.toString()}`
|
|
687
|
+
);
|
|
688
|
+
const data = await response.json();
|
|
689
|
+
|
|
690
|
+
if (data.geometry?.geometry?.coordinates) {
|
|
691
|
+
const coords = data.geometry.geometry.coordinates.map(c => [c[1], c[0]]);
|
|
692
|
+
allCoords.push(...coords);
|
|
693
|
+
}
|
|
694
|
+
} catch (error) {
|
|
695
|
+
console.error(`Error calculating route chunk ${i + 1}:`, error);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
if (allCoords.length > 0) {
|
|
702
|
+
const polyline = L.polyline(allCoords, {
|
|
703
|
+
color: routeSettings.color,
|
|
704
|
+
weight: routeSettings.weight,
|
|
705
|
+
opacity: routeSettings.opacity
|
|
706
|
+
}).addTo(map);
|
|
707
|
+
|
|
708
|
+
routePolylines.set(map, polyline);
|
|
644
709
|
}
|
|
645
710
|
}
|
|
646
711
|
}
|