fix: 修正 Cesium 巡航车道中心对齐
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { laneCenterline } = require("./lane-geometry");
|
||||
|
||||
const ASSET_MANIFEST = path.resolve(__dirname, "..", "..", "assets", "lane-icons", "manifest.json");
|
||||
const LANE_WIDTH_METERS = 3.2;
|
||||
@@ -262,23 +263,6 @@ function closestPointOnSegment(point, start, end, meters) {
|
||||
return [start[0] + ratio * (end[0] - start[0]), start[1] + ratio * (end[1] - start[1])];
|
||||
}
|
||||
|
||||
function laneCenterline(lane) {
|
||||
const ring = lane?.geometry?.type === "Polygon" ? lane.geometry.coordinates?.[0] : null;
|
||||
// A straight osm2streets Driving lane is commonly a closed quadrilateral:
|
||||
// four distinct vertices plus the repeated closing vertex. Its opposing
|
||||
// edges still provide the same two-point centerline as longer lane shapes.
|
||||
if (!ring || ring.length < 5) return null;
|
||||
// osm2streets Driving polygons are ordered along one boundary then back
|
||||
// along the other. Midpoints of paired vertices form the rendered lane axis.
|
||||
const vertices = ring.slice(0, -1);
|
||||
const half = vertices.length / 2;
|
||||
if (!Number.isInteger(half) || half < 2) return null;
|
||||
return vertices.slice(0, half).map((point, index) => [
|
||||
(point[0] + vertices[vertices.length - 1 - index][0]) / 2,
|
||||
(point[1] + vertices[vertices.length - 1 - index][1]) / 2,
|
||||
]);
|
||||
}
|
||||
|
||||
function axisForLane(ordered, meters) {
|
||||
return normalizeMetersVector(subtractPoint(ordered[0], ordered[1]), meters);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user