@placemarkio/polyline 2.0.1 → 2.0.2
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.cjs +88 -104
- package/dist/index.d.cts +11 -6
- package/dist/{index.d.ts → index.d.mts} +11 -6
- package/dist/index.mjs +103 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/main.js +6 -2170
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -3
- package/package.json +6 -9
- package/dist/index.js +0 -116
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.navigationData = "eJyLrlYqSa0oUbJSSklNzk9JVdJRKkgsyVCyUkorzUsuyczPK9aHyOhllOTmKOkoZWfmpShZmZnU6sC1pubh0gqRwaM1PTXfK9jfLyQ/ID+nMiczD6spGIrwGFgAVRKS7w7Rhc1ADEUYBsYCAJfjX+0="
|
package/docs/assets/search.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
window.searchData =
|
|
2
|
-
'{"kinds":{"64":"Function"},"rows":[{"kind":64,"name":"decode","url":"functions/decode.html","classes":"tsd-kind-function"},{"kind":64,"name":"encode","url":"functions/encode.html","classes":"tsd-kind-function"},{"kind":64,"name":"geoJSONToPolyline","url":"functions/geoJSONToPolyline.html","classes":"tsd-kind-function"},{"kind":64,"name":"polylineToGeoJSON","url":"functions/polylineToGeoJSON.html","classes":"tsd-kind-function"}],"index":{"version":"2.3.9","fields":["name","comment"],"fieldVectors":[["name/0",[0,12.04]],["comment/0",[]],["name/1",[1,12.04]],["comment/1",[]],["name/2",[2,12.04]],["comment/2",[]],["name/3",[3,12.04]],["comment/3",[]]],"invertedIndex":[["decode",{"_index":0,"name":{"0":{}},"comment":{}}],["encode",{"_index":1,"name":{"1":{}},"comment":{}}],["geojsontopolyline",{"_index":2,"name":{"2":{}},"comment":{}}],["polylinetogeojson",{"_index":3,"name":{"3":{}},"comment":{}}]],"pipeline":[]}}',
|
|
3
|
-
);
|
|
1
|
+
window.searchData = "eJyNkt1qg0AQhd/lXA9G11DovkBpL9pCQ28WKUEnqa3uiD9pi/juxb+YoKXeyez5vl2OUyOXrwLa1PiMbQR9syXYfcrQiDiUiEGo8gQah8qGZSy22PQHznuZJiCEyb4ouIAGGlrQsP1D0x+s1RxZHl6eHnfyLMlPEtsl4yyzVp4N+Z3c9YoF+SyzJA8IsY34G7rGifMiFgsN5fjOLQiHmJOobbu/lxBKmrItQYgkrLrPYIi9clhK3ob79MYFGZc85bjbICAzst28G4yKadJxHsh4C5w347wrToGMWuDUjFNXnA8y/gLnz7h+0lV24rzk6L6vzpjz7tV4G/p0x59Vw4Wum2ZqT9fNRYHtWXvNuHeTwpsU3irFkeWjEFtKdt65yaYmm1plGyWlDN5Lmz/Z/P9tASGLM+6epE3QNL9V8Tza";
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@placemarkio/polyline",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "encode and decode polylines",
|
|
5
|
-
"zshy": "./src/index.ts",
|
|
6
5
|
"peerDependencies": {
|
|
7
6
|
"@types/geojson": "*"
|
|
8
7
|
},
|
|
@@ -13,18 +12,16 @@
|
|
|
13
12
|
"author": "Tom MacWright",
|
|
14
13
|
"license": "MIT",
|
|
15
14
|
"dependencies": {
|
|
16
|
-
"@types/geojson": "
|
|
15
|
+
"@types/geojson": "^7946.0.16"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"@biomejs/biome": "^2.3.
|
|
18
|
+
"@biomejs/biome": "^2.3.10",
|
|
20
19
|
"@changesets/cli": "^2.29.8",
|
|
21
20
|
"husky": "^9.1.7",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"typedoc": "^0.23.15",
|
|
21
|
+
"tsdown": "^0.18.3",
|
|
22
|
+
"typedoc": "^0.28.15",
|
|
25
23
|
"typescript": "^5.9.3",
|
|
26
|
-
"vitest": "^4.0.
|
|
27
|
-
"zshy": "^0.4.4"
|
|
24
|
+
"vitest": "^4.0.16"
|
|
28
25
|
},
|
|
29
26
|
"keywords": [
|
|
30
27
|
"polyline",
|
package/dist/index.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// https://github.com/mapbox/polyline/blob/master/src/polyline.js
|
|
2
|
-
// Based off of [the offical Google document](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)
|
|
3
|
-
//
|
|
4
|
-
// Some parts from [this implementation](http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/PolylineEncoder.js)
|
|
5
|
-
// by [Mark McClure](http://facstaff.unca.edu/mcmcclur/)
|
|
6
|
-
function py2_round(value) {
|
|
7
|
-
// Google's polyline algorithm uses the same rounding strategy as Python 2,
|
|
8
|
-
// which is different from JS for negative values
|
|
9
|
-
return Math.floor(Math.abs(value) + 0.5) * (value >= 0 ? 1 : -1);
|
|
10
|
-
}
|
|
11
|
-
function encodeNumber(current, previous, factor) {
|
|
12
|
-
current = py2_round(current * factor);
|
|
13
|
-
previous = py2_round(previous * factor);
|
|
14
|
-
let coordinate = current - previous;
|
|
15
|
-
coordinate <<= 1;
|
|
16
|
-
if (current - previous < 0) {
|
|
17
|
-
coordinate = ~coordinate;
|
|
18
|
-
}
|
|
19
|
-
let output = "";
|
|
20
|
-
while (coordinate >= 0x20) {
|
|
21
|
-
output += String.fromCharCode((0x20 | (coordinate & 0x1f)) + 63);
|
|
22
|
-
coordinate >>= 5;
|
|
23
|
-
}
|
|
24
|
-
output += String.fromCharCode(coordinate + 63);
|
|
25
|
-
return output;
|
|
26
|
-
}
|
|
27
|
-
function resultChange(result) {
|
|
28
|
-
return result & 1 ? ~(result >> 1) : result >> 1;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Decodes any string into a [longitude, latitude] coordinates array.
|
|
32
|
-
*
|
|
33
|
-
* Any string is a valid polyline, but if you provide this
|
|
34
|
-
* with an arbitrary string, it'll produce coordinates well
|
|
35
|
-
* outside of the normal range.
|
|
36
|
-
*/
|
|
37
|
-
export function decode(str, precision = 5) {
|
|
38
|
-
const factor = 10 ** precision;
|
|
39
|
-
let index = 0;
|
|
40
|
-
let lat = 0;
|
|
41
|
-
let lng = 0;
|
|
42
|
-
const coordinates = [];
|
|
43
|
-
let shift = 0;
|
|
44
|
-
let result = 0;
|
|
45
|
-
let byte = null;
|
|
46
|
-
let latitude_change;
|
|
47
|
-
let longitude_change;
|
|
48
|
-
// Coordinates have variable length when encoded, so just keep
|
|
49
|
-
// track of whether we've hit the end of the string. In each
|
|
50
|
-
// loop iteration, a single coordinate is decoded.
|
|
51
|
-
while (index < str.length) {
|
|
52
|
-
// Reset shift, result, and byte
|
|
53
|
-
byte = null;
|
|
54
|
-
shift = 0;
|
|
55
|
-
result = 0;
|
|
56
|
-
do {
|
|
57
|
-
byte = str.charCodeAt(index++) - 63;
|
|
58
|
-
result |= (byte & 0x1f) << shift;
|
|
59
|
-
shift += 5;
|
|
60
|
-
} while (byte >= 0x20);
|
|
61
|
-
latitude_change = resultChange(result);
|
|
62
|
-
shift = result = 0;
|
|
63
|
-
do {
|
|
64
|
-
byte = str.charCodeAt(index++) - 63;
|
|
65
|
-
result |= (byte & 0x1f) << shift;
|
|
66
|
-
shift += 5;
|
|
67
|
-
} while (byte >= 0x20);
|
|
68
|
-
longitude_change = resultChange(result);
|
|
69
|
-
lat += latitude_change;
|
|
70
|
-
lng += longitude_change;
|
|
71
|
-
coordinates.push([lng / factor, lat / factor]);
|
|
72
|
-
}
|
|
73
|
-
return coordinates;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Encodes the given [latitude, longitude] coordinates array.
|
|
77
|
-
*
|
|
78
|
-
* @param coordinates Coordinates, in longitude, latitude order
|
|
79
|
-
* @returns encoded polyline
|
|
80
|
-
*/
|
|
81
|
-
export function encode(coordinates, precision = 5) {
|
|
82
|
-
if (!coordinates.length) {
|
|
83
|
-
return "";
|
|
84
|
-
}
|
|
85
|
-
const factor = 10 ** precision;
|
|
86
|
-
let output = encodeNumber(coordinates[0][1], 0, factor) +
|
|
87
|
-
encodeNumber(coordinates[0][0], 0, factor);
|
|
88
|
-
for (let i = 1; i < coordinates.length; i++) {
|
|
89
|
-
const a = coordinates[i];
|
|
90
|
-
const b = coordinates[i - 1];
|
|
91
|
-
output += encodeNumber(a[1], b[1], factor);
|
|
92
|
-
output += encodeNumber(a[0], b[0], factor);
|
|
93
|
-
}
|
|
94
|
-
return output;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Encodes a GeoJSON LineString feature/geometry.
|
|
98
|
-
*
|
|
99
|
-
* @param geojson A LineString
|
|
100
|
-
*/
|
|
101
|
-
export function geoJSONToPolyline(geojson, precision = 5) {
|
|
102
|
-
return encode(geojson.coordinates, precision);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Decodes to a GeoJSON LineString geometry.
|
|
106
|
-
*
|
|
107
|
-
* @param str An encoded polyline as a string.
|
|
108
|
-
*/
|
|
109
|
-
export function polylineToGeoJSON(str, precision = 5) {
|
|
110
|
-
const coords = decode(str, precision);
|
|
111
|
-
return {
|
|
112
|
-
type: "LineString",
|
|
113
|
-
coordinates: coords,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=index.js.map
|