@placemarkio/polyline 1.1.1 → 2.0.0
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/LICENSE +21 -0
- package/README.md +7 -1
- package/dist/{polyline.cjs → index.cjs} +15 -17
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +5 -4
- package/dist/{polyline.es.mjs → index.js} +9 -10
- package/docs/assets/main.js +2224 -0
- package/docs/assets/search.js +3 -0
- package/package.json +37 -36
- package/dist/polyline.cjs.map +0 -1
- package/dist/polyline.es.mjs.map +0 -1
- package/dist/polyline.umd.js +0 -2
- package/dist/polyline.umd.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Placemark
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
# polyline
|
|
1
|
+
# @placemarkio/polyline
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/@placemarkio%2Fpolyline)
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
@placemarkio/polyline
|
|
7
|
+
```
|
|
2
8
|
|
|
3
9
|
_polyline development is supported by 🌎 [placemark.io](https://placemark.io/)_
|
|
4
10
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decode = decode;
|
|
4
|
+
exports.encode = encode;
|
|
5
|
+
exports.geoJSONToPolyline = geoJSONToPolyline;
|
|
6
|
+
exports.polylineToGeoJSON = polylineToGeoJSON;
|
|
6
7
|
// https://github.com/mapbox/polyline/blob/master/src/polyline.js
|
|
7
8
|
// Based off of [the offical Google document](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)
|
|
8
9
|
//
|
|
@@ -39,7 +40,8 @@ function resultChange(result) {
|
|
|
39
40
|
* with an arbitrary string, it'll produce coordinates well
|
|
40
41
|
* outside of the normal range.
|
|
41
42
|
*/
|
|
42
|
-
function decode(str) {
|
|
43
|
+
function decode(str, precision = 5) {
|
|
44
|
+
const factor = 10 ** precision;
|
|
43
45
|
let index = 0;
|
|
44
46
|
let lat = 0;
|
|
45
47
|
let lng = 0;
|
|
@@ -82,10 +84,11 @@ function decode(str) {
|
|
|
82
84
|
* @param coordinates Coordinates, in longitude, latitude order
|
|
83
85
|
* @returns encoded polyline
|
|
84
86
|
*/
|
|
85
|
-
function encode(coordinates) {
|
|
87
|
+
function encode(coordinates, precision = 5) {
|
|
86
88
|
if (!coordinates.length) {
|
|
87
89
|
return "";
|
|
88
90
|
}
|
|
91
|
+
const factor = 10 ** precision;
|
|
89
92
|
let output = encodeNumber(coordinates[0][1], 0, factor) +
|
|
90
93
|
encodeNumber(coordinates[0][0], 0, factor);
|
|
91
94
|
for (let i = 1; i < coordinates.length; i++) {
|
|
@@ -101,24 +104,19 @@ function encode(coordinates) {
|
|
|
101
104
|
*
|
|
102
105
|
* @param geojson A LineString
|
|
103
106
|
*/
|
|
104
|
-
function geoJSONToPolyline(geojson) {
|
|
105
|
-
return encode(geojson.coordinates);
|
|
107
|
+
function geoJSONToPolyline(geojson, precision = 5) {
|
|
108
|
+
return encode(geojson.coordinates, precision);
|
|
106
109
|
}
|
|
107
110
|
/**
|
|
108
111
|
* Decodes to a GeoJSON LineString geometry.
|
|
109
112
|
*
|
|
110
113
|
* @param str An encoded polyline as a string.
|
|
111
114
|
*/
|
|
112
|
-
function polylineToGeoJSON(str) {
|
|
113
|
-
const coords = decode(str);
|
|
115
|
+
function polylineToGeoJSON(str, precision = 5) {
|
|
116
|
+
const coords = decode(str, precision);
|
|
114
117
|
return {
|
|
115
118
|
type: "LineString",
|
|
116
119
|
coordinates: coords,
|
|
117
120
|
};
|
|
118
121
|
}
|
|
119
|
-
|
|
120
|
-
exports.decode = decode;
|
|
121
|
-
exports.encode = encode;
|
|
122
|
-
exports.geoJSONToPolyline = geoJSONToPolyline;
|
|
123
|
-
exports.polylineToGeoJSON = polylineToGeoJSON;
|
|
124
|
-
//# sourceMappingURL=polyline.cjs.map
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LineString, Position } from "geojson";
|
|
2
|
+
/**
|
|
3
|
+
* Decodes any string into a [longitude, latitude] coordinates array.
|
|
4
|
+
*
|
|
5
|
+
* Any string is a valid polyline, but if you provide this
|
|
6
|
+
* with an arbitrary string, it'll produce coordinates well
|
|
7
|
+
* outside of the normal range.
|
|
8
|
+
*/
|
|
9
|
+
export declare function decode(str: string, precision?: number): Position[];
|
|
10
|
+
/**
|
|
11
|
+
* Encodes the given [latitude, longitude] coordinates array.
|
|
12
|
+
*
|
|
13
|
+
* @param coordinates Coordinates, in longitude, latitude order
|
|
14
|
+
* @returns encoded polyline
|
|
15
|
+
*/
|
|
16
|
+
export declare function encode(coordinates: number[][], precision?: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Encodes a GeoJSON LineString feature/geometry.
|
|
19
|
+
*
|
|
20
|
+
* @param geojson A LineString
|
|
21
|
+
*/
|
|
22
|
+
export declare function geoJSONToPolyline(geojson: LineString, precision?: number): string;
|
|
23
|
+
/**
|
|
24
|
+
* Decodes to a GeoJSON LineString geometry.
|
|
25
|
+
*
|
|
26
|
+
* @param str An encoded polyline as a string.
|
|
27
|
+
*/
|
|
28
|
+
export declare function polylineToGeoJSON(str: string, precision?: number): LineString;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -6,23 +6,24 @@ import type { LineString, Position } from "geojson";
|
|
|
6
6
|
* with an arbitrary string, it'll produce coordinates well
|
|
7
7
|
* outside of the normal range.
|
|
8
8
|
*/
|
|
9
|
-
export declare function decode(str: string): Position[];
|
|
9
|
+
export declare function decode(str: string, precision?: number): Position[];
|
|
10
10
|
/**
|
|
11
11
|
* Encodes the given [latitude, longitude] coordinates array.
|
|
12
12
|
*
|
|
13
13
|
* @param coordinates Coordinates, in longitude, latitude order
|
|
14
14
|
* @returns encoded polyline
|
|
15
15
|
*/
|
|
16
|
-
export declare function encode(coordinates: number[][]): string;
|
|
16
|
+
export declare function encode(coordinates: number[][], precision?: number): string;
|
|
17
17
|
/**
|
|
18
18
|
* Encodes a GeoJSON LineString feature/geometry.
|
|
19
19
|
*
|
|
20
20
|
* @param geojson A LineString
|
|
21
21
|
*/
|
|
22
|
-
export declare function geoJSONToPolyline(geojson: LineString): string;
|
|
22
|
+
export declare function geoJSONToPolyline(geojson: LineString, precision?: number): string;
|
|
23
23
|
/**
|
|
24
24
|
* Decodes to a GeoJSON LineString geometry.
|
|
25
25
|
*
|
|
26
26
|
* @param str An encoded polyline as a string.
|
|
27
27
|
*/
|
|
28
|
-
export declare function polylineToGeoJSON(str: string): LineString;
|
|
28
|
+
export declare function polylineToGeoJSON(str: string, precision?: number): LineString;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const factor = 100000; // Math.pow(10, 5);
|
|
2
1
|
// https://github.com/mapbox/polyline/blob/master/src/polyline.js
|
|
3
2
|
// Based off of [the offical Google document](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)
|
|
4
3
|
//
|
|
@@ -35,7 +34,8 @@ function resultChange(result) {
|
|
|
35
34
|
* with an arbitrary string, it'll produce coordinates well
|
|
36
35
|
* outside of the normal range.
|
|
37
36
|
*/
|
|
38
|
-
function decode(str) {
|
|
37
|
+
export function decode(str, precision = 5) {
|
|
38
|
+
const factor = 10 ** precision;
|
|
39
39
|
let index = 0;
|
|
40
40
|
let lat = 0;
|
|
41
41
|
let lng = 0;
|
|
@@ -78,10 +78,11 @@ function decode(str) {
|
|
|
78
78
|
* @param coordinates Coordinates, in longitude, latitude order
|
|
79
79
|
* @returns encoded polyline
|
|
80
80
|
*/
|
|
81
|
-
function encode(coordinates) {
|
|
81
|
+
export function encode(coordinates, precision = 5) {
|
|
82
82
|
if (!coordinates.length) {
|
|
83
83
|
return "";
|
|
84
84
|
}
|
|
85
|
+
const factor = 10 ** precision;
|
|
85
86
|
let output = encodeNumber(coordinates[0][1], 0, factor) +
|
|
86
87
|
encodeNumber(coordinates[0][0], 0, factor);
|
|
87
88
|
for (let i = 1; i < coordinates.length; i++) {
|
|
@@ -97,21 +98,19 @@ function encode(coordinates) {
|
|
|
97
98
|
*
|
|
98
99
|
* @param geojson A LineString
|
|
99
100
|
*/
|
|
100
|
-
function geoJSONToPolyline(geojson) {
|
|
101
|
-
return encode(geojson.coordinates);
|
|
101
|
+
export function geoJSONToPolyline(geojson, precision = 5) {
|
|
102
|
+
return encode(geojson.coordinates, precision);
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Decodes to a GeoJSON LineString geometry.
|
|
105
106
|
*
|
|
106
107
|
* @param str An encoded polyline as a string.
|
|
107
108
|
*/
|
|
108
|
-
function polylineToGeoJSON(str) {
|
|
109
|
-
const coords = decode(str);
|
|
109
|
+
export function polylineToGeoJSON(str, precision = 5) {
|
|
110
|
+
const coords = decode(str, precision);
|
|
110
111
|
return {
|
|
111
112
|
type: "LineString",
|
|
112
113
|
coordinates: coords,
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
-
export { decode, encode, geoJSONToPolyline, polylineToGeoJSON };
|
|
117
|
-
//# sourceMappingURL=polyline.es.mjs.map
|
|
116
|
+
//# sourceMappingURL=index.js.map
|