@classic-homes/maps-core 0.4.1 → 0.5.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/dist/route/index.cjs +15 -5
- package/dist/route/index.d.cts +10 -6
- package/dist/route/index.d.ts +10 -6
- package/dist/route/index.js +15 -5
- package/package.json +1 -1
package/dist/route/index.cjs
CHANGED
|
@@ -179,15 +179,25 @@ function googleDirectionsUrl(stops, origin, travelmode) {
|
|
|
179
179
|
if (travelmode) url += `&travelmode=${encodeURIComponent(travelmode)}`;
|
|
180
180
|
return url;
|
|
181
181
|
}
|
|
182
|
+
var APPLE_MODES = { d: "driving", w: "walking", r: "transit" };
|
|
182
183
|
function appleDirectionsUrl(stops, origin, dirflg = "d") {
|
|
183
184
|
const encoded = usableTargets(stops);
|
|
184
185
|
if (encoded.length === 0) return "";
|
|
185
186
|
const encodedOrigin = origin ? encodeTarget(origin) : null;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
if (encoded.length === 1) {
|
|
188
|
+
let url = `${APPLE_BASE}?`;
|
|
189
|
+
if (encodedOrigin) url += `saddr=${encodedOrigin}&`;
|
|
190
|
+
url += `daddr=${encoded[0]}&dirflg=${encodeURIComponent(dirflg)}`;
|
|
191
|
+
return url;
|
|
192
|
+
}
|
|
193
|
+
const destination = encoded[encoded.length - 1];
|
|
194
|
+
const waypoints = encoded.slice(0, -1);
|
|
195
|
+
const mode = APPLE_MODES[dirflg] ?? APPLE_MODES.d;
|
|
196
|
+
const params = [];
|
|
197
|
+
if (encodedOrigin) params.push(`source=${encodedOrigin}`);
|
|
198
|
+
for (const waypoint of waypoints) params.push(`waypoint=${waypoint}`);
|
|
199
|
+
params.push(`destination=${destination}`, `mode=${mode}`);
|
|
200
|
+
return `${APPLE_BASE}directions?${params.join("&")}`;
|
|
191
201
|
}
|
|
192
202
|
function googleSearchUrl(query) {
|
|
193
203
|
return `${GOOGLE_SEARCH_BASE}&query=${encodeURIComponent(query)}`;
|
package/dist/route/index.d.cts
CHANGED
|
@@ -112,13 +112,17 @@ declare const GOOGLE_MAX_LEG_STOPS: number;
|
|
|
112
112
|
*/
|
|
113
113
|
declare function googleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, travelmode?: TravelMode): string;
|
|
114
114
|
/**
|
|
115
|
-
* An Apple Maps URL.
|
|
115
|
+
* An Apple Maps directions URL.
|
|
116
116
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
117
|
+
* With one stop this returns the legacy `saddr`/`daddr` form, exactly
|
|
118
|
+
* `https://maps.apple.com/?daddr=<lat>,<lng>&dirflg=d` with no origin - the
|
|
119
|
+
* form consumer apps already link to, and one every iOS version opens.
|
|
120
|
+
*
|
|
121
|
+
* With several stops it returns Apple's unified Maps URL (iOS 18.4, macOS 15.4
|
|
122
|
+
* and later): `/directions` with the last stop as `destination` and the rest as
|
|
123
|
+
* repeated `waypoint` parameters, in order. Apple documents no waypoint limit.
|
|
124
|
+
* Older OS versions predate the unified scheme, so what they do with a
|
|
125
|
+
* multi-stop link is not guaranteed. Returns '' when no target is usable.
|
|
122
126
|
*/
|
|
123
127
|
declare function appleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, dirflg?: 'd' | 'w' | 'r'): string;
|
|
124
128
|
/** A Google Maps search URL - the fallback for a stop with no coordinate */
|
package/dist/route/index.d.ts
CHANGED
|
@@ -112,13 +112,17 @@ declare const GOOGLE_MAX_LEG_STOPS: number;
|
|
|
112
112
|
*/
|
|
113
113
|
declare function googleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, travelmode?: TravelMode): string;
|
|
114
114
|
/**
|
|
115
|
-
* An Apple Maps URL.
|
|
115
|
+
* An Apple Maps directions URL.
|
|
116
116
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
117
|
+
* With one stop this returns the legacy `saddr`/`daddr` form, exactly
|
|
118
|
+
* `https://maps.apple.com/?daddr=<lat>,<lng>&dirflg=d` with no origin - the
|
|
119
|
+
* form consumer apps already link to, and one every iOS version opens.
|
|
120
|
+
*
|
|
121
|
+
* With several stops it returns Apple's unified Maps URL (iOS 18.4, macOS 15.4
|
|
122
|
+
* and later): `/directions` with the last stop as `destination` and the rest as
|
|
123
|
+
* repeated `waypoint` parameters, in order. Apple documents no waypoint limit.
|
|
124
|
+
* Older OS versions predate the unified scheme, so what they do with a
|
|
125
|
+
* multi-stop link is not guaranteed. Returns '' when no target is usable.
|
|
122
126
|
*/
|
|
123
127
|
declare function appleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, dirflg?: 'd' | 'w' | 'r'): string;
|
|
124
128
|
/** A Google Maps search URL - the fallback for a stop with no coordinate */
|
package/dist/route/index.js
CHANGED
|
@@ -164,15 +164,25 @@ function googleDirectionsUrl(stops, origin, travelmode) {
|
|
|
164
164
|
if (travelmode) url += `&travelmode=${encodeURIComponent(travelmode)}`;
|
|
165
165
|
return url;
|
|
166
166
|
}
|
|
167
|
+
var APPLE_MODES = { d: "driving", w: "walking", r: "transit" };
|
|
167
168
|
function appleDirectionsUrl(stops, origin, dirflg = "d") {
|
|
168
169
|
const encoded = usableTargets(stops);
|
|
169
170
|
if (encoded.length === 0) return "";
|
|
170
171
|
const encodedOrigin = origin ? encodeTarget(origin) : null;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
if (encoded.length === 1) {
|
|
173
|
+
let url = `${APPLE_BASE}?`;
|
|
174
|
+
if (encodedOrigin) url += `saddr=${encodedOrigin}&`;
|
|
175
|
+
url += `daddr=${encoded[0]}&dirflg=${encodeURIComponent(dirflg)}`;
|
|
176
|
+
return url;
|
|
177
|
+
}
|
|
178
|
+
const destination = encoded[encoded.length - 1];
|
|
179
|
+
const waypoints = encoded.slice(0, -1);
|
|
180
|
+
const mode = APPLE_MODES[dirflg] ?? APPLE_MODES.d;
|
|
181
|
+
const params = [];
|
|
182
|
+
if (encodedOrigin) params.push(`source=${encodedOrigin}`);
|
|
183
|
+
for (const waypoint of waypoints) params.push(`waypoint=${waypoint}`);
|
|
184
|
+
params.push(`destination=${destination}`, `mode=${mode}`);
|
|
185
|
+
return `${APPLE_BASE}directions?${params.join("&")}`;
|
|
176
186
|
}
|
|
177
187
|
function googleSearchUrl(query) {
|
|
178
188
|
return `${GOOGLE_SEARCH_BASE}&query=${encodeURIComponent(query)}`;
|