major performance improvements map

This commit is contained in:
Christian Beutel
2025-04-14 20:22:39 +02:00
parent a1296ebacd
commit 5390b9cf72
9 changed files with 165 additions and 17 deletions

View File

@@ -1,3 +1,7 @@
import type { GeoJSON } from "geojson";
import { bbox } from "./geojson_util";
function py2_round(value: number) {
return Math.floor(Math.abs(value) + 0.5) * (value >= 0 ? 1 : -1);
}
@@ -77,4 +81,34 @@ export function encodePolyline(coordinates: number[][], precision: number = 6) {
}
return output;
};
function flipped(coords: number[][]) {
var flipped = [];
for (var i = 0; i < coords.length; i++) {
var coord = coords[i].slice();
flipped.push([coord[1], coord[0]]);
}
return flipped;
}
export function polylineToGeoJSON(str: string, precision: number = 6) {
var coords = decodePolyline(str, precision);
const geojson = {
type: "FeatureCollection",
features: [
{
properties: {},
type: "Feature",
geometry: {
type: "LineString",
coordinates: flipped(coords),
},
}
]
} as GeoJSON;
geojson.bbox = bbox(geojson)
return geojson
};