make packages for dart and npm
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Utilities for Intaleq Map SDK.
|
||||
*/
|
||||
export class PolylineUtils {
|
||||
/**
|
||||
* Decodes a Google-encoded polyline string into an array of [lng, lat] coordinates.
|
||||
* Note: MapLibre and GeoJSON use [lng, lat] while Google/Flutter use [lat, lng].
|
||||
*/
|
||||
static decode(encoded: string): [number, number][] {
|
||||
const points: [number, number][] = [];
|
||||
let index = 0;
|
||||
const len = encoded.length;
|
||||
let lat = 0;
|
||||
let lng = 0;
|
||||
|
||||
while (index < len) {
|
||||
let b: number;
|
||||
let shift = 0;
|
||||
let result = 0;
|
||||
do {
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
const dlat = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
||||
lat += dlat;
|
||||
|
||||
shift = 0;
|
||||
result = 0;
|
||||
do {
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
const dlng = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
||||
lng += dlng;
|
||||
|
||||
// MapLibre uses [lng, lat]
|
||||
points.push([lng / 1E5, lat / 1E5]);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user