@navigatr/core 1.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 +131 -0
- package/dist/autocomplete.d.ts +6 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.js +55 -0
- package/dist/autocomplete.js.map +1 -0
- package/dist/geocode.d.ts +4 -0
- package/dist/geocode.d.ts.map +1 -0
- package/dist/geocode.js +52 -0
- package/dist/geocode.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/mapStyle.d.ts +43 -0
- package/dist/mapStyle.d.ts.map +1 -0
- package/dist/mapStyle.js +262 -0
- package/dist/mapStyle.js.map +1 -0
- package/dist/route.d.ts +3 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/route.js +89 -0
- package/dist/route.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/format.d.ts +13 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +30 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/polyline.d.ts +7 -0
- package/dist/utils/polyline.d.ts.map +1 -0
- package/dist/utils/polyline.js +40 -0
- package/dist/utils/polyline.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 capeku
|
|
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
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @navigatr/core
|
|
2
|
+
|
|
3
|
+
Pure TypeScript routing and geocoding SDK using public Valhalla and Nominatim instances. Zero dependencies, zero API keys.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @navigatr/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { NavigatrCore } from '@navigatr/core'
|
|
15
|
+
|
|
16
|
+
const nav = new NavigatrCore()
|
|
17
|
+
|
|
18
|
+
// Geocode an address
|
|
19
|
+
const origin = await nav.geocode({ address: 'Accra Mall, Ghana' })
|
|
20
|
+
console.log(origin) // { lat: 5.6037, lng: -0.1870, displayName: '...' }
|
|
21
|
+
|
|
22
|
+
// Reverse geocode coordinates
|
|
23
|
+
const location = await nav.reverseGeocode({ lat: 5.6037, lng: -0.1870 })
|
|
24
|
+
console.log(location.displayName)
|
|
25
|
+
|
|
26
|
+
// Get a route
|
|
27
|
+
const destination = await nav.geocode({ address: 'Kotoka Airport, Ghana' })
|
|
28
|
+
const route = await nav.route({ origin, destination })
|
|
29
|
+
|
|
30
|
+
console.log(route.durationText) // "12 mins"
|
|
31
|
+
console.log(route.distanceText) // "3.2 km"
|
|
32
|
+
console.log(route.polyline) // Array of { lat, lng } coordinates
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Turn-by-Turn Directions
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const route = await nav.route({
|
|
39
|
+
origin,
|
|
40
|
+
destination,
|
|
41
|
+
maneuvers: true
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
for (const step of route.maneuvers) {
|
|
45
|
+
console.log(step.instruction) // "Turn left onto Oak Avenue"
|
|
46
|
+
console.log(step.distanceText) // "200 m"
|
|
47
|
+
console.log(step.type) // "left"
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Traffic-Aware Routing
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const route = await nav.route({
|
|
55
|
+
origin,
|
|
56
|
+
destination,
|
|
57
|
+
traffic: true // Uses traffic data when available
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const nav = new NavigatrCore({
|
|
65
|
+
valhallaUrl: 'https://your-valhalla-instance.com',
|
|
66
|
+
nominatimUrl: 'https://your-nominatim-instance.com'
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### `NavigatrCore`
|
|
73
|
+
|
|
74
|
+
#### `route(options): Promise<RouteResult>`
|
|
75
|
+
|
|
76
|
+
Get driving directions between two points.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
interface RouteOptions {
|
|
80
|
+
origin: LatLng
|
|
81
|
+
destination: LatLng
|
|
82
|
+
maneuvers?: boolean // Include turn-by-turn directions
|
|
83
|
+
traffic?: boolean // Use traffic-aware routing
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### `geocode({ address }): Promise<GeocodeResult>`
|
|
88
|
+
|
|
89
|
+
Convert an address string to coordinates.
|
|
90
|
+
|
|
91
|
+
#### `reverseGeocode({ lat, lng }): Promise<GeocodeResult>`
|
|
92
|
+
|
|
93
|
+
Convert coordinates to an address.
|
|
94
|
+
|
|
95
|
+
## Types
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
interface LatLng {
|
|
99
|
+
lat: number
|
|
100
|
+
lng: number
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface GeocodeResult {
|
|
104
|
+
lat: number
|
|
105
|
+
lng: number
|
|
106
|
+
displayName: string
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface Maneuver {
|
|
110
|
+
instruction: string
|
|
111
|
+
type: string
|
|
112
|
+
distanceMeters: number
|
|
113
|
+
distanceText: string
|
|
114
|
+
durationSeconds: number
|
|
115
|
+
durationText: string
|
|
116
|
+
startPoint: LatLng
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface RouteResult {
|
|
120
|
+
durationSeconds: number
|
|
121
|
+
durationText: string
|
|
122
|
+
distanceMeters: number
|
|
123
|
+
distanceText: string
|
|
124
|
+
polyline: LatLng[]
|
|
125
|
+
maneuvers?: Maneuver[]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../src/autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAiDjD,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAsC/B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const DEFAULT_PHOTON_URL = 'https://photon.komoot.io';
|
|
2
|
+
const USER_AGENT = 'navigatr-sdk/1.0';
|
|
3
|
+
function buildDisplayName(props) {
|
|
4
|
+
const parts = [];
|
|
5
|
+
if (props.name)
|
|
6
|
+
parts.push(props.name);
|
|
7
|
+
if (props.street) {
|
|
8
|
+
const street = props.housenumber
|
|
9
|
+
? `${props.street} ${props.housenumber}`
|
|
10
|
+
: props.street;
|
|
11
|
+
if (street !== props.name)
|
|
12
|
+
parts.push(street);
|
|
13
|
+
}
|
|
14
|
+
if (props.district && props.district !== props.name)
|
|
15
|
+
parts.push(props.district);
|
|
16
|
+
if (props.city && props.city !== props.name)
|
|
17
|
+
parts.push(props.city);
|
|
18
|
+
if (props.state)
|
|
19
|
+
parts.push(props.state);
|
|
20
|
+
if (props.country)
|
|
21
|
+
parts.push(props.country);
|
|
22
|
+
return parts.join(', ');
|
|
23
|
+
}
|
|
24
|
+
export async function autocomplete(query, options = {}) {
|
|
25
|
+
const { limit = 5, photonUrl = DEFAULT_PHOTON_URL } = options;
|
|
26
|
+
const params = new URLSearchParams({
|
|
27
|
+
q: query,
|
|
28
|
+
limit: limit.toString()
|
|
29
|
+
});
|
|
30
|
+
const response = await fetch(`${photonUrl}/api/?${params}`, {
|
|
31
|
+
headers: {
|
|
32
|
+
'User-Agent': USER_AGENT
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(`Photon autocomplete failed: ${response.status} ${response.statusText}`);
|
|
37
|
+
}
|
|
38
|
+
const data = await response.json();
|
|
39
|
+
return data.features.map((feature) => {
|
|
40
|
+
const [lng, lat] = feature.geometry.coordinates;
|
|
41
|
+
const props = feature.properties;
|
|
42
|
+
return {
|
|
43
|
+
lat,
|
|
44
|
+
lng,
|
|
45
|
+
displayName: buildDisplayName(props),
|
|
46
|
+
name: props.name || '',
|
|
47
|
+
city: props.city,
|
|
48
|
+
state: props.state,
|
|
49
|
+
country: props.country,
|
|
50
|
+
street: props.street,
|
|
51
|
+
postcode: props.postcode
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=autocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../src/autocomplete.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,0BAA0B,CAAA;AACrD,MAAM,UAAU,GAAG,kBAAkB,CAAA;AA4BrC,SAAS,gBAAgB,CAAC,KAAkC;IAC1D,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,IAAI,KAAK,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACtC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW;YAC9B,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE;YACxC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAA;QAChB,IAAI,MAAM,KAAK,KAAK,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAC/E,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACnE,IAAI,KAAK,CAAC,KAAK;QAAE,KAAK,CAA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EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GeocodeResult } from './types';
|
|
2
|
+
export declare function geocode(address: string, nominatimUrl?: string): Promise<GeocodeResult>;
|
|
3
|
+
export declare function reverseGeocode(lat: number, lng: number, nominatimUrl?: string): Promise<GeocodeResult>;
|
|
4
|
+
//# sourceMappingURL=geocode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocode.d.ts","sourceRoot":"","sources":["../src/geocode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAiB5C,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,MAA8B,GAC3C,OAAO,CAAC,aAAa,CAAC,CA+BxB;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,YAAY,GAAE,MAA8B,GAC3C,OAAO,CAAC,aAAa,CAAC,CA8BxB"}
|
package/dist/geocode.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const DEFAULT_NOMINATIM_URL = 'https://nominatim.openstreetmap.org';
|
|
2
|
+
const USER_AGENT = 'navigatr-sdk/1.0';
|
|
3
|
+
export async function geocode(address, nominatimUrl = DEFAULT_NOMINATIM_URL) {
|
|
4
|
+
const params = new URLSearchParams({
|
|
5
|
+
q: address,
|
|
6
|
+
format: 'json',
|
|
7
|
+
limit: '1'
|
|
8
|
+
});
|
|
9
|
+
const response = await fetch(`${nominatimUrl}/search?${params}`, {
|
|
10
|
+
headers: {
|
|
11
|
+
'User-Agent': USER_AGENT
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
throw new Error(`Nominatim geocoding failed: ${response.status} ${response.statusText}`);
|
|
16
|
+
}
|
|
17
|
+
const results = await response.json();
|
|
18
|
+
if (results.length === 0) {
|
|
19
|
+
throw new Error(`No results found for address: ${address}`);
|
|
20
|
+
}
|
|
21
|
+
const result = results[0];
|
|
22
|
+
return {
|
|
23
|
+
lat: parseFloat(result.lat),
|
|
24
|
+
lng: parseFloat(result.lon),
|
|
25
|
+
displayName: result.display_name
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export async function reverseGeocode(lat, lng, nominatimUrl = DEFAULT_NOMINATIM_URL) {
|
|
29
|
+
const params = new URLSearchParams({
|
|
30
|
+
lat: lat.toString(),
|
|
31
|
+
lon: lng.toString(),
|
|
32
|
+
format: 'json'
|
|
33
|
+
});
|
|
34
|
+
const response = await fetch(`${nominatimUrl}/reverse?${params}`, {
|
|
35
|
+
headers: {
|
|
36
|
+
'User-Agent': USER_AGENT
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`Nominatim reverse geocoding failed: ${response.status} ${response.statusText}`);
|
|
41
|
+
}
|
|
42
|
+
const result = await response.json();
|
|
43
|
+
if (!result.lat || !result.lon) {
|
|
44
|
+
throw new Error(`No results found for coordinates: ${lat}, ${lng}`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
lat: parseFloat(result.lat),
|
|
48
|
+
lng: parseFloat(result.lon),
|
|
49
|
+
displayName: result.display_name
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=geocode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocode.js","sourceRoot":"","sources":["../src/geocode.ts"],"names":[],"mappings":"AAEA,MAAM,qBAAqB,GAAG,qCAAqC,CAAA;AACnE,MAAM,UAAU,GAAG,kBAAkB,CAAA;AAcrC,MAAM,CAAC,KAAK,UAAU,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E,OAAO,EAAE;YACP,YAAY,EAAE,UAAU;SACzB;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,uCAAuC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAChF,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAA2B,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IAE5D,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,KAAK,GAAG,EAAE,CAAC,CAAA;IACrE,CAAC;IAED,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,GAAG,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,WAAW,EAAE,MAAM,CAAC,YAAY;KACjC,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { LatLng, GeocodeResult, RouteResult, RouteOptions, Maneuver, NavigatrConfig, AutocompleteResult, MapStyle, MapStylePreset, MapColors, LayerVisibility, MarkerStyle, PolylineStyle, MapTheme } from './types';
|
|
2
|
+
export declare class NavigatrCore {
|
|
3
|
+
private valhallaUrl;
|
|
4
|
+
private nominatimUrl;
|
|
5
|
+
private photonUrl;
|
|
6
|
+
private currentStyle;
|
|
7
|
+
constructor(config?: NavigatrConfig);
|
|
8
|
+
route(params: RouteOptions): Promise<RouteResult>;
|
|
9
|
+
geocode(params: {
|
|
10
|
+
address: string;
|
|
11
|
+
}): Promise<GeocodeResult>;
|
|
12
|
+
reverseGeocode(params: {
|
|
13
|
+
lat: number;
|
|
14
|
+
lng: number;
|
|
15
|
+
}): Promise<GeocodeResult>;
|
|
16
|
+
autocomplete(params: {
|
|
17
|
+
query: string;
|
|
18
|
+
limit?: number;
|
|
19
|
+
}): Promise<AutocompleteResult[]>;
|
|
20
|
+
getStylePresets(): MapStylePreset[];
|
|
21
|
+
getStylePreset(presetId: string): MapStylePreset | undefined;
|
|
22
|
+
setStyle(style: MapStyle): void;
|
|
23
|
+
setStyleFromPreset(presetId: string, customizations?: Partial<MapStyle>): void;
|
|
24
|
+
getStyle(): MapStyle;
|
|
25
|
+
updateStyle(updates: Partial<MapStyle>): void;
|
|
26
|
+
createCustomStyle(options?: Partial<MapStyle>): MapStyle;
|
|
27
|
+
getStyleDefaults(): {
|
|
28
|
+
colors: MapColors;
|
|
29
|
+
layers: LayerVisibility;
|
|
30
|
+
markers: MarkerStyle;
|
|
31
|
+
polyline: PolylineStyle;
|
|
32
|
+
};
|
|
33
|
+
getStyleAsCSSVariables(prefix?: string): Record<string, string>;
|
|
34
|
+
validateStyle(style: MapStyle): {
|
|
35
|
+
valid: boolean;
|
|
36
|
+
errors: string[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type { LatLng, GeocodeResult, RouteResult, RouteOptions, Maneuver, NavigatrConfig, AutocompleteResult, MapStyle, MapStylePreset, MapColors, LayerVisibility, MarkerStyle, PolylineStyle, MapTheme };
|
|
40
|
+
export { MAP_STYLE_PRESETS } from './mapStyle';
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMzN,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,YAAY,CAAQ;IAC5B,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AAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;CAGrE;AAED,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAA;AAC1M,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getRoute } from './route';
|
|
2
|
+
import { geocode as geocodeAddress, reverseGeocode as reverseGeocodeCoords } from './geocode';
|
|
3
|
+
import { autocomplete as autocompleteSearch } from './autocomplete';
|
|
4
|
+
import * as mapStyleModule from './mapStyle';
|
|
5
|
+
export class NavigatrCore {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.valhallaUrl = config?.valhallaUrl ?? 'https://valhalla1.openstreetmap.de';
|
|
8
|
+
this.nominatimUrl = config?.nominatimUrl ?? 'https://nominatim.openstreetmap.org';
|
|
9
|
+
this.photonUrl = config?.photonUrl ?? 'https://photon.komoot.io';
|
|
10
|
+
this.currentStyle = mapStyleModule.createStyle();
|
|
11
|
+
}
|
|
12
|
+
async route(params) {
|
|
13
|
+
return getRoute(params, this.valhallaUrl);
|
|
14
|
+
}
|
|
15
|
+
async geocode(params) {
|
|
16
|
+
return geocodeAddress(params.address, this.nominatimUrl);
|
|
17
|
+
}
|
|
18
|
+
async reverseGeocode(params) {
|
|
19
|
+
return reverseGeocodeCoords(params.lat, params.lng, this.nominatimUrl);
|
|
20
|
+
}
|
|
21
|
+
async autocomplete(params) {
|
|
22
|
+
return autocompleteSearch(params.query, { limit: params.limit, photonUrl: this.photonUrl });
|
|
23
|
+
}
|
|
24
|
+
// Map Customization API
|
|
25
|
+
getStylePresets() {
|
|
26
|
+
return mapStyleModule.getPresets();
|
|
27
|
+
}
|
|
28
|
+
getStylePreset(presetId) {
|
|
29
|
+
return mapStyleModule.getPreset(presetId);
|
|
30
|
+
}
|
|
31
|
+
setStyle(style) {
|
|
32
|
+
const validation = mapStyleModule.validateStyle(style);
|
|
33
|
+
if (!validation.valid) {
|
|
34
|
+
throw new Error(`Invalid style: ${validation.errors.join(', ')}`);
|
|
35
|
+
}
|
|
36
|
+
this.currentStyle = style;
|
|
37
|
+
}
|
|
38
|
+
setStyleFromPreset(presetId, customizations) {
|
|
39
|
+
this.currentStyle = mapStyleModule.createFromPreset(presetId, customizations);
|
|
40
|
+
}
|
|
41
|
+
getStyle() {
|
|
42
|
+
return { ...this.currentStyle };
|
|
43
|
+
}
|
|
44
|
+
updateStyle(updates) {
|
|
45
|
+
this.currentStyle = mapStyleModule.mergeStyles(this.currentStyle, updates);
|
|
46
|
+
}
|
|
47
|
+
createCustomStyle(options) {
|
|
48
|
+
return mapStyleModule.createStyle(options);
|
|
49
|
+
}
|
|
50
|
+
getStyleDefaults() {
|
|
51
|
+
return mapStyleModule.getDefaults();
|
|
52
|
+
}
|
|
53
|
+
getStyleAsCSSVariables(prefix) {
|
|
54
|
+
return mapStyleModule.toCSSVariables(this.currentStyle, prefix);
|
|
55
|
+
}
|
|
56
|
+
validateStyle(style) {
|
|
57
|
+
return mapStyleModule.validateStyle(style);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export { MAP_STYLE_PRESETS } from './mapStyle';
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,cAAc,IAAI,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAC7F,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACn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,UAAU,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACnE,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;IAC3B,CAAC;IAED,kBAAkB,CAAC,QAAgB,EAAE,cAAkC;QACrE,IAAI,CAAC,YAAY,GAAG,cAAc,CAAC,gBAAgB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC/E,CAAC;IAED,QAAQ;QACN,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;IACjC,CAAC;IAED,WAAW,CAAC,OAA0B;QACpC,IAAI,CAAC,YAAY,GAAG,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;IAC5E,CAAC;IAED,iBAAiB,CAAC,OAA2B;QAC3C,OAAO,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAC5C,CAAC;IAED,gBAAgB;QACd,OAAO,cAAc,CAAC,WAAW,EAAE,CAAA;IACrC,CAAC;IAED,sBAAsB,CAAC,MAAe;QACpC,OAAO,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;IACjE,CAAC;IAED,aAAa,CAAC,KAAe;QAC3B,OAAO,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;CACF;AAGD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { MapStyle, MapStylePreset, MapColors, LayerVisibility, MarkerStyle, PolylineStyle } from './types';
|
|
2
|
+
export declare const MAP_STYLE_PRESETS: MapStylePreset[];
|
|
3
|
+
/**
|
|
4
|
+
* Get a preset style by ID
|
|
5
|
+
*/
|
|
6
|
+
export declare function getPreset(presetId: string): MapStylePreset | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Get all available presets
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPresets(): MapStylePreset[];
|
|
11
|
+
/**
|
|
12
|
+
* Create a custom style by merging with defaults
|
|
13
|
+
*/
|
|
14
|
+
export declare function createStyle(options?: Partial<MapStyle>): MapStyle;
|
|
15
|
+
/**
|
|
16
|
+
* Create a style based on a preset with customizations
|
|
17
|
+
*/
|
|
18
|
+
export declare function createFromPreset(presetId: string, customizations?: Partial<MapStyle>): MapStyle;
|
|
19
|
+
/**
|
|
20
|
+
* Merge two styles, with the second taking precedence
|
|
21
|
+
*/
|
|
22
|
+
export declare function mergeStyles(base: MapStyle, override: Partial<MapStyle>): MapStyle;
|
|
23
|
+
/**
|
|
24
|
+
* Get default style values
|
|
25
|
+
*/
|
|
26
|
+
export declare function getDefaults(): {
|
|
27
|
+
colors: MapColors;
|
|
28
|
+
layers: LayerVisibility;
|
|
29
|
+
markers: MarkerStyle;
|
|
30
|
+
polyline: PolylineStyle;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Validate a map style object
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateStyle(style: MapStyle): {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
errors: string[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Convert style to CSS custom properties for use in web applications
|
|
41
|
+
*/
|
|
42
|
+
export declare function toCSSVariables(style: MapStyle, prefix?: string): Record<string, string>;
|
|
43
|
+
//# sourceMappingURL=mapStyle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapStyle.d.ts","sourceRoot":"","sources":["../src/mapStyle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAY,MAAM,SAAS,CAAA;AA2CzH,eAAO,MAAM,iBAAiB,EAAE,cAAc,EAuG7C,CAAA;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAEtE;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,cAAc,EAAE,CAE7C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,OAAO,CAAC,QAAQ,CAAM,GAAG,QAAQ,CAUrE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,GAAE,OAAO,CAAC,QAAQ,CAAM,GAAG,QAAQ,CAenG;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAUjF;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,CAO3H;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA0BnF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAE,MAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBnG"}
|
package/dist/mapStyle.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// Default style values
|
|
2
|
+
const DEFAULT_COLORS = {
|
|
3
|
+
primary: '#3b82f6',
|
|
4
|
+
secondary: '#6366f1',
|
|
5
|
+
background: '#f8fafc',
|
|
6
|
+
roads: '#94a3b8',
|
|
7
|
+
water: '#0ea5e9',
|
|
8
|
+
parks: '#22c55e',
|
|
9
|
+
buildings: '#cbd5e1',
|
|
10
|
+
labels: '#1e293b'
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_LAYERS = {
|
|
13
|
+
roads: true,
|
|
14
|
+
labels: true,
|
|
15
|
+
buildings: true,
|
|
16
|
+
water: true,
|
|
17
|
+
parks: true,
|
|
18
|
+
terrain: false,
|
|
19
|
+
traffic: false,
|
|
20
|
+
transit: true
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_MARKER = {
|
|
23
|
+
iconUrl: '',
|
|
24
|
+
iconSize: [25, 41],
|
|
25
|
+
iconAnchor: [12, 41],
|
|
26
|
+
color: '#3b82f6',
|
|
27
|
+
scale: 1
|
|
28
|
+
};
|
|
29
|
+
const DEFAULT_POLYLINE = {
|
|
30
|
+
color: '#3b82f6',
|
|
31
|
+
weight: 5,
|
|
32
|
+
opacity: 0.8,
|
|
33
|
+
dashArray: '',
|
|
34
|
+
lineCap: 'round',
|
|
35
|
+
lineJoin: 'round'
|
|
36
|
+
};
|
|
37
|
+
// Built-in style presets
|
|
38
|
+
export const MAP_STYLE_PRESETS = [
|
|
39
|
+
{
|
|
40
|
+
id: 'default',
|
|
41
|
+
name: 'Default',
|
|
42
|
+
style: {
|
|
43
|
+
theme: 'light',
|
|
44
|
+
colors: DEFAULT_COLORS,
|
|
45
|
+
layers: DEFAULT_LAYERS,
|
|
46
|
+
markers: DEFAULT_MARKER,
|
|
47
|
+
polyline: DEFAULT_POLYLINE
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'dark',
|
|
52
|
+
name: 'Dark Mode',
|
|
53
|
+
style: {
|
|
54
|
+
theme: 'dark',
|
|
55
|
+
colors: {
|
|
56
|
+
primary: '#60a5fa',
|
|
57
|
+
secondary: '#818cf8',
|
|
58
|
+
background: '#0f172a',
|
|
59
|
+
roads: '#475569',
|
|
60
|
+
water: '#0369a1',
|
|
61
|
+
parks: '#166534',
|
|
62
|
+
buildings: '#334155',
|
|
63
|
+
labels: '#e2e8f0'
|
|
64
|
+
},
|
|
65
|
+
layers: DEFAULT_LAYERS,
|
|
66
|
+
markers: { ...DEFAULT_MARKER, color: '#60a5fa' },
|
|
67
|
+
polyline: { ...DEFAULT_POLYLINE, color: '#60a5fa' }
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'satellite',
|
|
72
|
+
name: 'Satellite',
|
|
73
|
+
style: {
|
|
74
|
+
theme: 'satellite',
|
|
75
|
+
colors: {
|
|
76
|
+
...DEFAULT_COLORS,
|
|
77
|
+
labels: '#ffffff'
|
|
78
|
+
},
|
|
79
|
+
layers: {
|
|
80
|
+
...DEFAULT_LAYERS,
|
|
81
|
+
buildings: false,
|
|
82
|
+
terrain: true
|
|
83
|
+
},
|
|
84
|
+
markers: { ...DEFAULT_MARKER, color: '#fbbf24' },
|
|
85
|
+
polyline: { ...DEFAULT_POLYLINE, color: '#fbbf24', weight: 4 }
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'navigation',
|
|
90
|
+
name: 'Navigation',
|
|
91
|
+
style: {
|
|
92
|
+
theme: 'light',
|
|
93
|
+
colors: {
|
|
94
|
+
primary: '#2563eb',
|
|
95
|
+
secondary: '#7c3aed',
|
|
96
|
+
background: '#f1f5f9',
|
|
97
|
+
roads: '#64748b',
|
|
98
|
+
water: '#38bdf8',
|
|
99
|
+
parks: '#4ade80',
|
|
100
|
+
buildings: '#e2e8f0',
|
|
101
|
+
labels: '#0f172a'
|
|
102
|
+
},
|
|
103
|
+
layers: {
|
|
104
|
+
...DEFAULT_LAYERS,
|
|
105
|
+
traffic: true,
|
|
106
|
+
transit: true
|
|
107
|
+
},
|
|
108
|
+
markers: { ...DEFAULT_MARKER, color: '#2563eb' },
|
|
109
|
+
polyline: { color: '#2563eb', weight: 6, opacity: 0.9, lineCap: 'round', lineJoin: 'round', dashArray: '' }
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 'minimal',
|
|
114
|
+
name: 'Minimal',
|
|
115
|
+
style: {
|
|
116
|
+
theme: 'light',
|
|
117
|
+
colors: {
|
|
118
|
+
primary: '#000000',
|
|
119
|
+
secondary: '#404040',
|
|
120
|
+
background: '#ffffff',
|
|
121
|
+
roads: '#d4d4d4',
|
|
122
|
+
water: '#e0f2fe',
|
|
123
|
+
parks: '#ecfdf5',
|
|
124
|
+
buildings: '#f5f5f5',
|
|
125
|
+
labels: '#404040'
|
|
126
|
+
},
|
|
127
|
+
layers: {
|
|
128
|
+
roads: true,
|
|
129
|
+
labels: true,
|
|
130
|
+
buildings: false,
|
|
131
|
+
water: true,
|
|
132
|
+
parks: false,
|
|
133
|
+
terrain: false,
|
|
134
|
+
traffic: false,
|
|
135
|
+
transit: false
|
|
136
|
+
},
|
|
137
|
+
markers: { ...DEFAULT_MARKER, color: '#000000' },
|
|
138
|
+
polyline: { color: '#000000', weight: 3, opacity: 1, lineCap: 'round', lineJoin: 'round', dashArray: '' }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
/**
|
|
143
|
+
* Get a preset style by ID
|
|
144
|
+
*/
|
|
145
|
+
export function getPreset(presetId) {
|
|
146
|
+
return MAP_STYLE_PRESETS.find(p => p.id === presetId);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get all available presets
|
|
150
|
+
*/
|
|
151
|
+
export function getPresets() {
|
|
152
|
+
return [...MAP_STYLE_PRESETS];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a custom style by merging with defaults
|
|
156
|
+
*/
|
|
157
|
+
export function createStyle(options = {}) {
|
|
158
|
+
return {
|
|
159
|
+
id: options.id ?? 'custom',
|
|
160
|
+
name: options.name ?? 'Custom Style',
|
|
161
|
+
theme: options.theme ?? 'custom',
|
|
162
|
+
colors: { ...DEFAULT_COLORS, ...options.colors },
|
|
163
|
+
layers: { ...DEFAULT_LAYERS, ...options.layers },
|
|
164
|
+
markers: { ...DEFAULT_MARKER, ...options.markers },
|
|
165
|
+
polyline: { ...DEFAULT_POLYLINE, ...options.polyline }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a style based on a preset with customizations
|
|
170
|
+
*/
|
|
171
|
+
export function createFromPreset(presetId, customizations = {}) {
|
|
172
|
+
const preset = getPreset(presetId);
|
|
173
|
+
if (!preset) {
|
|
174
|
+
throw new Error(`Unknown preset: ${presetId}`);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
id: customizations.id ?? `${preset.id}-custom`,
|
|
178
|
+
name: customizations.name ?? `${preset.name} (Custom)`,
|
|
179
|
+
theme: customizations.theme ?? preset.style.theme,
|
|
180
|
+
colors: { ...preset.style.colors, ...customizations.colors },
|
|
181
|
+
layers: { ...preset.style.layers, ...customizations.layers },
|
|
182
|
+
markers: { ...preset.style.markers, ...customizations.markers },
|
|
183
|
+
polyline: { ...preset.style.polyline, ...customizations.polyline }
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Merge two styles, with the second taking precedence
|
|
188
|
+
*/
|
|
189
|
+
export function mergeStyles(base, override) {
|
|
190
|
+
return {
|
|
191
|
+
id: override.id ?? base.id,
|
|
192
|
+
name: override.name ?? base.name,
|
|
193
|
+
theme: override.theme ?? base.theme,
|
|
194
|
+
colors: { ...base.colors, ...override.colors },
|
|
195
|
+
layers: { ...base.layers, ...override.layers },
|
|
196
|
+
markers: { ...base.markers, ...override.markers },
|
|
197
|
+
polyline: { ...base.polyline, ...override.polyline }
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get default style values
|
|
202
|
+
*/
|
|
203
|
+
export function getDefaults() {
|
|
204
|
+
return {
|
|
205
|
+
colors: { ...DEFAULT_COLORS },
|
|
206
|
+
layers: { ...DEFAULT_LAYERS },
|
|
207
|
+
markers: { ...DEFAULT_MARKER },
|
|
208
|
+
polyline: { ...DEFAULT_POLYLINE }
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Validate a map style object
|
|
213
|
+
*/
|
|
214
|
+
export function validateStyle(style) {
|
|
215
|
+
const errors = [];
|
|
216
|
+
if (style.colors) {
|
|
217
|
+
const colorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
|
218
|
+
for (const [key, value] of Object.entries(style.colors)) {
|
|
219
|
+
if (value && !colorRegex.test(value)) {
|
|
220
|
+
errors.push(`Invalid color format for ${key}: ${value}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (style.polyline) {
|
|
225
|
+
if (style.polyline.weight !== undefined && (style.polyline.weight < 0 || style.polyline.weight > 50)) {
|
|
226
|
+
errors.push('Polyline weight must be between 0 and 50');
|
|
227
|
+
}
|
|
228
|
+
if (style.polyline.opacity !== undefined && (style.polyline.opacity < 0 || style.polyline.opacity > 1)) {
|
|
229
|
+
errors.push('Polyline opacity must be between 0 and 1');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (style.markers?.scale !== undefined && (style.markers.scale < 0.1 || style.markers.scale > 5)) {
|
|
233
|
+
errors.push('Marker scale must be between 0.1 and 5');
|
|
234
|
+
}
|
|
235
|
+
return { valid: errors.length === 0, errors };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Convert style to CSS custom properties for use in web applications
|
|
239
|
+
*/
|
|
240
|
+
export function toCSSVariables(style, prefix = 'navigatr') {
|
|
241
|
+
const vars = {};
|
|
242
|
+
if (style.colors) {
|
|
243
|
+
for (const [key, value] of Object.entries(style.colors)) {
|
|
244
|
+
if (value) {
|
|
245
|
+
vars[`--${prefix}-${key}`] = value;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (style.polyline) {
|
|
250
|
+
if (style.polyline.color)
|
|
251
|
+
vars[`--${prefix}-route-color`] = style.polyline.color;
|
|
252
|
+
if (style.polyline.weight)
|
|
253
|
+
vars[`--${prefix}-route-weight`] = `${style.polyline.weight}px`;
|
|
254
|
+
if (style.polyline.opacity)
|
|
255
|
+
vars[`--${prefix}-route-opacity`] = String(style.polyline.opacity);
|
|
256
|
+
}
|
|
257
|
+
if (style.markers?.color) {
|
|
258
|
+
vars[`--${prefix}-marker-color`] = style.markers.color;
|
|
259
|
+
}
|
|
260
|
+
return vars;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=mapStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapStyle.js","sourceRoot":"","sources":["../src/mapStyle.ts"],"names":[],"mappings":"AAEA,uBAAuB;AACvB,MAAM,cAAc,GAAwB;IAC1C,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,SAAS;CAClB,CAAA;AAED,MAAM,cAAc,GAA8B;IAChD,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,IAAI;CACd,CAAA;AAED,MAAM,cAAc,GAA0B;IAC5C,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAClB,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACpB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,CAAC;CACT,CAAA;AAED,MAAM,gBAAgB,GAA4B;IAChD,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,GAAG;IACZ,SAAS,EAAE,EAAE;IACb,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,OAAO;CAClB,CAA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EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,MAAM,eAAe,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAA;IACxD,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/route.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,WAAW,EAAE,YAAY,EAAY,MAAM,SAAS,CAAA;AA+E1E,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,YAAY,EACrB,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,WAAW,CAAC,CAgEtB"}
|
package/dist/route.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { decodePolyline } from './utils/polyline';
|
|
2
|
+
import { formatDuration, formatDistance } from './utils/format';
|
|
3
|
+
const DEFAULT_VALHALLA_URL = 'https://valhalla1.openstreetmap.de';
|
|
4
|
+
const MANEUVER_TYPES = {
|
|
5
|
+
0: 'none',
|
|
6
|
+
1: 'start',
|
|
7
|
+
2: 'start_right',
|
|
8
|
+
3: 'start_left',
|
|
9
|
+
4: 'destination',
|
|
10
|
+
5: 'destination_right',
|
|
11
|
+
6: 'destination_left',
|
|
12
|
+
7: 'becomes',
|
|
13
|
+
8: 'continue',
|
|
14
|
+
9: 'slight_right',
|
|
15
|
+
10: 'right',
|
|
16
|
+
11: 'sharp_right',
|
|
17
|
+
12: 'u_turn_right',
|
|
18
|
+
13: 'u_turn_left',
|
|
19
|
+
14: 'sharp_left',
|
|
20
|
+
15: 'left',
|
|
21
|
+
16: 'slight_left',
|
|
22
|
+
17: 'ramp_straight',
|
|
23
|
+
18: 'ramp_right',
|
|
24
|
+
19: 'ramp_left',
|
|
25
|
+
20: 'exit_right',
|
|
26
|
+
21: 'exit_left',
|
|
27
|
+
22: 'stay_straight',
|
|
28
|
+
23: 'stay_right',
|
|
29
|
+
24: 'stay_left',
|
|
30
|
+
25: 'merge',
|
|
31
|
+
26: 'roundabout_enter',
|
|
32
|
+
27: 'roundabout_exit',
|
|
33
|
+
28: 'ferry_enter',
|
|
34
|
+
29: 'ferry_exit'
|
|
35
|
+
};
|
|
36
|
+
export async function getRoute(options, valhallaUrl = DEFAULT_VALHALLA_URL) {
|
|
37
|
+
const { origin, destination, maneuvers: includeManeuvers, traffic } = options;
|
|
38
|
+
const requestBody = {
|
|
39
|
+
locations: [
|
|
40
|
+
{ lon: origin.lng, lat: origin.lat, type: 'break' },
|
|
41
|
+
{ lon: destination.lng, lat: destination.lat, type: 'break' }
|
|
42
|
+
],
|
|
43
|
+
costing: 'auto',
|
|
44
|
+
directions_options: { units: 'km' }
|
|
45
|
+
};
|
|
46
|
+
if (traffic) {
|
|
47
|
+
requestBody.costing_options = {
|
|
48
|
+
auto: {
|
|
49
|
+
use_traffic: 1
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const response = await fetch(`${valhallaUrl}/route`, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json'
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify(requestBody)
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const errorText = await response.text().catch(() => 'Unknown error');
|
|
62
|
+
throw new Error(`Valhalla routing failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
63
|
+
}
|
|
64
|
+
const data = await response.json();
|
|
65
|
+
const encodedPolyline = data.trip.legs[0].shape;
|
|
66
|
+
const polyline = decodePolyline(encodedPolyline);
|
|
67
|
+
const durationSeconds = data.trip.summary.time;
|
|
68
|
+
const distanceMeters = data.trip.summary.length * 1000;
|
|
69
|
+
const result = {
|
|
70
|
+
durationSeconds,
|
|
71
|
+
durationText: formatDuration(durationSeconds),
|
|
72
|
+
distanceMeters,
|
|
73
|
+
distanceText: formatDistance(distanceMeters),
|
|
74
|
+
polyline
|
|
75
|
+
};
|
|
76
|
+
if (includeManeuvers && data.trip.legs[0].maneuvers) {
|
|
77
|
+
result.maneuvers = data.trip.legs[0].maneuvers.map((m) => ({
|
|
78
|
+
instruction: m.instruction,
|
|
79
|
+
type: MANEUVER_TYPES[m.type] || 'unknown',
|
|
80
|
+
distanceMeters: m.length * 1000,
|
|
81
|
+
distanceText: formatDistance(m.length * 1000),
|
|
82
|
+
durationSeconds: m.time,
|
|
83
|
+
durationText: formatDuration(m.time),
|
|
84
|
+
startPoint: polyline[m.begin_shape_index] || polyline[0]
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/D,MAAM,oBAAoB,GAAG,oCAAoC,CAAA;AA0CjE,MAAM,cAAc,GAA2B;IAC7C,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,aAAa;IAChB,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,aAAa;IAChB,CAAC,EAAE,mBAAmB;IACtB,CAAC,EAAE,kBAAkB;IACrB,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,cAAc;IACjB,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,YAAY;IAChB,EAAE,E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Q,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;SACzD,CAAC,CAAC,CAAA;IACL,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export interface LatLng {
|
|
2
|
+
lat: number;
|
|
3
|
+
lng: number;
|
|
4
|
+
}
|
|
5
|
+
export interface GeocodeResult {
|
|
6
|
+
lat: number;
|
|
7
|
+
lng: number;
|
|
8
|
+
displayName: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Maneuver {
|
|
11
|
+
instruction: string;
|
|
12
|
+
type: string;
|
|
13
|
+
distanceMeters: number;
|
|
14
|
+
distanceText: string;
|
|
15
|
+
durationSeconds: number;
|
|
16
|
+
durationText: string;
|
|
17
|
+
startPoint: LatLng;
|
|
18
|
+
}
|
|
19
|
+
export interface RouteOptions {
|
|
20
|
+
origin: LatLng;
|
|
21
|
+
destination: LatLng;
|
|
22
|
+
maneuvers?: boolean;
|
|
23
|
+
traffic?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface RouteResult {
|
|
26
|
+
durationSeconds: number;
|
|
27
|
+
durationText: string;
|
|
28
|
+
distanceMeters: number;
|
|
29
|
+
distanceText: string;
|
|
30
|
+
polyline: LatLng[];
|
|
31
|
+
maneuvers?: Maneuver[];
|
|
32
|
+
}
|
|
33
|
+
export interface AutocompleteResult {
|
|
34
|
+
lat: number;
|
|
35
|
+
lng: number;
|
|
36
|
+
displayName: string;
|
|
37
|
+
name: string;
|
|
38
|
+
city?: string;
|
|
39
|
+
state?: string;
|
|
40
|
+
country?: string;
|
|
41
|
+
street?: string;
|
|
42
|
+
postcode?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface NavigatrConfig {
|
|
45
|
+
valhallaUrl?: string;
|
|
46
|
+
nominatimUrl?: string;
|
|
47
|
+
photonUrl?: string;
|
|
48
|
+
}
|
|
49
|
+
export type MapTheme = 'light' | 'dark' | 'satellite' | 'terrain' | 'custom';
|
|
50
|
+
export interface MapColors {
|
|
51
|
+
primary?: string;
|
|
52
|
+
secondary?: string;
|
|
53
|
+
background?: string;
|
|
54
|
+
roads?: string;
|
|
55
|
+
water?: string;
|
|
56
|
+
parks?: string;
|
|
57
|
+
buildings?: string;
|
|
58
|
+
labels?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface LayerVisibility {
|
|
61
|
+
roads?: boolean;
|
|
62
|
+
labels?: boolean;
|
|
63
|
+
buildings?: boolean;
|
|
64
|
+
water?: boolean;
|
|
65
|
+
parks?: boolean;
|
|
66
|
+
terrain?: boolean;
|
|
67
|
+
traffic?: boolean;
|
|
68
|
+
transit?: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface MarkerStyle {
|
|
71
|
+
iconUrl?: string;
|
|
72
|
+
iconSize?: [number, number];
|
|
73
|
+
iconAnchor?: [number, number];
|
|
74
|
+
color?: string;
|
|
75
|
+
scale?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface PolylineStyle {
|
|
78
|
+
color?: string;
|
|
79
|
+
weight?: number;
|
|
80
|
+
opacity?: number;
|
|
81
|
+
dashArray?: string;
|
|
82
|
+
lineCap?: 'butt' | 'round' | 'square';
|
|
83
|
+
lineJoin?: 'miter' | 'round' | 'bevel';
|
|
84
|
+
}
|
|
85
|
+
export interface MapStyle {
|
|
86
|
+
id?: string;
|
|
87
|
+
name?: string;
|
|
88
|
+
theme?: MapTheme;
|
|
89
|
+
colors?: MapColors;
|
|
90
|
+
layers?: LayerVisibility;
|
|
91
|
+
markers?: MarkerStyle;
|
|
92
|
+
polyline?: PolylineStyle;
|
|
93
|
+
}
|
|
94
|
+
export interface MapStylePreset {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
style: MapStyle;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts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B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;IACrC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;CACvC;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAA;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,QAAQ,CAAA;CAChB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats duration in seconds to a human-readable string.
|
|
3
|
+
* @param seconds - Duration in seconds
|
|
4
|
+
* @returns Formatted string like "10 mins" or "1 hr 5 mins"
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatDuration(seconds: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* Formats distance in meters to a human-readable string.
|
|
9
|
+
* @param meters - Distance in meters
|
|
10
|
+
* @returns Formatted string like "3.2 km" or "800 m"
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatDistance(meters: number): string;
|
|
13
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAetD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOrD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats duration in seconds to a human-readable string.
|
|
3
|
+
* @param seconds - Duration in seconds
|
|
4
|
+
* @returns Formatted string like "10 mins" or "1 hr 5 mins"
|
|
5
|
+
*/
|
|
6
|
+
export function formatDuration(seconds) {
|
|
7
|
+
const totalMinutes = Math.round(seconds / 60);
|
|
8
|
+
if (totalMinutes < 60) {
|
|
9
|
+
return `${totalMinutes} min${totalMinutes !== 1 ? 's' : ''}`;
|
|
10
|
+
}
|
|
11
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
12
|
+
const minutes = totalMinutes % 60;
|
|
13
|
+
if (minutes === 0) {
|
|
14
|
+
return `${hours} hr${hours !== 1 ? 's' : ''}`;
|
|
15
|
+
}
|
|
16
|
+
return `${hours} hr${hours !== 1 ? 's' : ''} ${minutes} min${minutes !== 1 ? 's' : ''}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Formats distance in meters to a human-readable string.
|
|
20
|
+
* @param meters - Distance in meters
|
|
21
|
+
* @returns Formatted string like "3.2 km" or "800 m"
|
|
22
|
+
*/
|
|
23
|
+
export function formatDistance(meters) {
|
|
24
|
+
if (meters < 1000) {
|
|
25
|
+
return `${Math.round(meters)} m`;
|
|
26
|
+
}
|
|
27
|
+
const km = meters / 1000;
|
|
28
|
+
return `${km.toFixed(1)} km`;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IAE7C,IAAI,YAAY,GAAG,EAAE,EAAE,CAAC;QACtB,OAAO,GAAG,YAAY,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC9D,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,YAAY,GAAG,EAAE,CAAA;IAEjC,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,GAAG,KAAK,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC/C,CAAC;IAED,OAAO,GAAG,KAAK,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;AACzF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,MAAM,GAAG,IAAI,EAAE,CAAC;QAClB,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAA;IAClC,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LatLng } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes an encoded polyline string into an array of coordinates.
|
|
4
|
+
* Uses the Google polyline encoding algorithm with precision 6 (for Valhalla).
|
|
5
|
+
*/
|
|
6
|
+
export declare function decodePolyline(encoded: string, precision?: number): LatLng[];
|
|
7
|
+
//# sourceMappingURL=polyline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyline.d.ts","sourceRoot":"","sources":["../../src/utils/polyline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAU,GAAG,MAAM,EAAE,CA0C/E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes an encoded polyline string into an array of coordinates.
|
|
3
|
+
* Uses the Google polyline encoding algorithm with precision 6 (for Valhalla).
|
|
4
|
+
*/
|
|
5
|
+
export function decodePolyline(encoded, precision = 6) {
|
|
6
|
+
const factor = Math.pow(10, precision);
|
|
7
|
+
const coordinates = [];
|
|
8
|
+
let index = 0;
|
|
9
|
+
let lat = 0;
|
|
10
|
+
let lng = 0;
|
|
11
|
+
while (index < encoded.length) {
|
|
12
|
+
let shift = 0;
|
|
13
|
+
let result = 0;
|
|
14
|
+
let byte;
|
|
15
|
+
// Decode latitude
|
|
16
|
+
do {
|
|
17
|
+
byte = encoded.charCodeAt(index++) - 63;
|
|
18
|
+
result |= (byte & 0x1f) << shift;
|
|
19
|
+
shift += 5;
|
|
20
|
+
} while (byte >= 0x20);
|
|
21
|
+
const deltaLat = result & 1 ? ~(result >> 1) : result >> 1;
|
|
22
|
+
lat += deltaLat;
|
|
23
|
+
// Decode longitude
|
|
24
|
+
shift = 0;
|
|
25
|
+
result = 0;
|
|
26
|
+
do {
|
|
27
|
+
byte = encoded.charCodeAt(index++) - 63;
|
|
28
|
+
result |= (byte & 0x1f) << shift;
|
|
29
|
+
shift += 5;
|
|
30
|
+
} while (byte >= 0x20);
|
|
31
|
+
const deltaLng = result & 1 ? ~(result >> 1) : result >> 1;
|
|
32
|
+
lng += deltaLng;
|
|
33
|
+
coordinates.push({
|
|
34
|
+
lat: lat / factor,
|
|
35
|
+
lng: lng / factor
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return coordinates;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=polyline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyline.js","sourceRoot":"","sources":["../../src/utils/polyline.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,YAAoB,CAAC;IACnE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;IACtC,MAAM,WAAW,GAAa,EAAE,CAAA;IAChC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,GAAG,GAAG,CAAC,CAAA;IAEX,OAAO,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC9B,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,IAAI,MAAM,GAAG,CAAC,CAAA;QACd,IAAI,IAAY,CAAA;QAEhB,kBAAkB;QAClB,GAAG,CAAC;YACF,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,CAAA;YACvC,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,CAAA;YAChC,KAAK,IAAI,CAAC,CAAA;QACZ,CAAC,QAAQ,IAAI,IAAI,IAAI,EAAC;QAEtB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAA;QAC1D,GAAG,IAAI,QAAQ,CAAA;QAEf,mBAAmB;QACnB,KAAK,GAAG,CAAC,CAAA;QACT,MAAM,GAAG,CAAC,CAAA;QAEV,GAAG,CAAC;YACF,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,CAAA;YACvC,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,CAAA;YAChC,KAAK,IAAI,CAAC,CAAA;QACZ,CAAC,QAAQ,IAAI,IAAI,IAAI,EAAC;QAEtB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAA;QAC1D,GAAG,IAAI,QAAQ,CAAA;QAEf,WAAW,CAAC,IAAI,CAAC;YACf,GAAG,EAAE,GAAG,GAAG,MAAM;YACjB,GAAG,EAAE,GAAG,GAAG,MAAM;SAClB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@navigatr/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Pure TypeScript routing and geocoding SDK using Valhalla and Nominatim - the open source alternative to Google Maps",
|
|
5
|
+
"author": "capeku",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/capeku/navigatr.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/capeku/navigatr#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/capeku/navigatr/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"dev": "tsc --watch"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^5.4.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"maps",
|
|
37
|
+
"routing",
|
|
38
|
+
"geocoding",
|
|
39
|
+
"valhalla",
|
|
40
|
+
"nominatim",
|
|
41
|
+
"openstreetmap",
|
|
42
|
+
"osm",
|
|
43
|
+
"directions",
|
|
44
|
+
"navigation",
|
|
45
|
+
"google-maps-alternative",
|
|
46
|
+
"open-source"
|
|
47
|
+
]
|
|
48
|
+
}
|