@wemap/routers 12.0.0-alpha.10 → 12.0.0-alpha.12
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/dist/index.js +39 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -7
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -1
- package/package.json +4 -4
- package/src/model/Itinerary.ts +32 -8
- package/src/model/Leg.ts +2 -0
- package/src/model/RouterRequest.ts +10 -0
- package/src/wemap-multi/WemapMultiRouter.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -14,6 +14,15 @@ const osm = require("@wemap/osm");
|
|
|
14
14
|
const Polyline = require("@mapbox/polyline");
|
|
15
15
|
const pointInPolygon = require("@turf/boolean-point-in-polygon");
|
|
16
16
|
const convexHullFn = require("@turf/convex");
|
|
17
|
+
function routerRequestToJson(routerRequest) {
|
|
18
|
+
const { origin, destination, waypoints, ...rest } = routerRequest;
|
|
19
|
+
return {
|
|
20
|
+
origin: origin.toJson(),
|
|
21
|
+
destination: destination.toJson(),
|
|
22
|
+
...waypoints && { waypoints: waypoints.map((w) => w.toJson()) },
|
|
23
|
+
...rest
|
|
24
|
+
};
|
|
25
|
+
}
|
|
17
26
|
const _Edge = class _Edge {
|
|
18
27
|
constructor(vertex1, vertex2, properties = {}) {
|
|
19
28
|
__publicField(this, "id", _Edge.currentUniqueId++);
|
|
@@ -591,6 +600,7 @@ class Leg {
|
|
|
591
600
|
coords: this.end.coords.toCompressedJson(),
|
|
592
601
|
...this.end.name && { name: this.end.name }
|
|
593
602
|
},
|
|
603
|
+
distance: Number(this.distance.toFixed(1)),
|
|
594
604
|
duration: Number(this.duration.toFixed(1)),
|
|
595
605
|
coords: this.coords.map((coords) => coords.toCompressedJson()),
|
|
596
606
|
steps: this.steps.map(stepToJson),
|
|
@@ -774,6 +784,7 @@ class Itinerary {
|
|
|
774
784
|
return {
|
|
775
785
|
origin: this.origin.toJson(),
|
|
776
786
|
destination: this.destination.toJson(),
|
|
787
|
+
distance: Number(this.distance.toFixed(1)),
|
|
777
788
|
duration: Number(this.duration.toFixed(1)),
|
|
778
789
|
transitMode: this.transitMode,
|
|
779
790
|
legs: this.legs.map((leg) => leg.toJson()),
|
|
@@ -831,13 +842,34 @@ class Itinerary {
|
|
|
831
842
|
}
|
|
832
843
|
}
|
|
833
844
|
toGeoJson() {
|
|
834
|
-
|
|
845
|
+
const transformToPoint = (point, name) => ({
|
|
835
846
|
type: "Feature",
|
|
836
|
-
properties: {},
|
|
847
|
+
properties: { name, level: point.level },
|
|
837
848
|
geometry: {
|
|
838
|
-
type: "
|
|
839
|
-
coordinates:
|
|
849
|
+
type: "Point",
|
|
850
|
+
coordinates: [point.lng, point.lat]
|
|
840
851
|
}
|
|
852
|
+
});
|
|
853
|
+
const transformToMultiLineStrings = (segments, level) => {
|
|
854
|
+
return {
|
|
855
|
+
type: "Feature",
|
|
856
|
+
properties: { level, name: level == null ? void 0 : level.toString() },
|
|
857
|
+
geometry: {
|
|
858
|
+
type: "MultiLineString",
|
|
859
|
+
coordinates: segments.map((s) => s.map(({ lat, lng }) => [lng, lat]))
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
};
|
|
863
|
+
const levelsOfItinerary = [...new Set(this.coords.map((c) => geo.Level.toString(c.level)))].map(geo.Level.fromString);
|
|
864
|
+
const segmentsSplitted = levelsOfItinerary.map((loi) => [loi, geo.Utils.createSegmentsAtLevel(this.coords, loi, true)]);
|
|
865
|
+
const multiLineStrings = segmentsSplitted.map(([loi, segments]) => transformToMultiLineStrings(segments, loi));
|
|
866
|
+
return {
|
|
867
|
+
type: "FeatureCollection",
|
|
868
|
+
features: [
|
|
869
|
+
transformToPoint(this.origin, "origin"),
|
|
870
|
+
transformToPoint(this.destination, "destination"),
|
|
871
|
+
...multiLineStrings
|
|
872
|
+
]
|
|
841
873
|
};
|
|
842
874
|
}
|
|
843
875
|
/**
|
|
@@ -2493,8 +2525,8 @@ class WemapMultiRouter {
|
|
|
2493
2525
|
}
|
|
2494
2526
|
const newRouterRequest = {
|
|
2495
2527
|
...routerRequest,
|
|
2496
|
-
origin
|
|
2497
|
-
destination,
|
|
2528
|
+
origin,
|
|
2529
|
+
destination: ioMapRoute.start,
|
|
2498
2530
|
waypoints: []
|
|
2499
2531
|
};
|
|
2500
2532
|
try {
|
|
@@ -2838,4 +2870,5 @@ exports.WemapMultiRemoteRouter = WemapMultiRemoteRouter$1;
|
|
|
2838
2870
|
exports.WemapMultiRouter = WemapMultiRouter;
|
|
2839
2871
|
exports.WemapMultiRoutingError = WemapMultiRoutingError;
|
|
2840
2872
|
exports.getDurationFromLength = getDurationFromLength;
|
|
2873
|
+
exports.routerRequestToJson = routerRequestToJson;
|
|
2841
2874
|
//# sourceMappingURL=index.js.map
|