@mapsindoors/react-native-maps-indoors-mapbox 2.8.0 → 2.9.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/README.md +84 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
- package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
- package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
- package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
- package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
- package/index.ts +25 -0
- package/ios/.swift-format +79 -0
- package/ios/core/DirectionsRendererBridge.m +11 -0
- package/ios/core/DirectionsRendererModule.swift +162 -1
- package/ios/core/DirectionsRendererOptions.swift +352 -0
- package/ios/core/MapsIndoorsBridge.m +14 -1
- package/ios/core/MapsIndoorsData.swift +1 -0
- package/ios/core/MapsIndoorsModule.swift +180 -21
- package/ios/core/UtilsModule.swift +57 -45
- package/package.json +1 -1
- package/react-native-maps-indoors-mapbox.podspec +2 -2
- package/specs/NativeDirectionsRendererModule.ts +3 -0
- package/specs/NativeMapsIndoorsModule.ts +6 -1
- package/src/core/EventNames.ts +3 -0
- package/src/core/MPDirectionsRenderer.ts +76 -1
- package/src/core/MPDirectionsRendererOptions.ts +287 -0
- package/src/core/MPError.ts +48 -1
- package/src/core/MPLanguageTag.ts +222 -0
- package/src/core/MPLegBoundaryIcons.ts +130 -0
- package/src/core/MPRouteAnimationType.ts +24 -0
- package/src/core/MPRouteArrowStyle.ts +28 -0
- package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
- package/src/core/MPRouteStampType.ts +24 -0
- package/src/core/MPSolution.ts +33 -2
- package/src/core/MPStrokeStyle.ts +22 -0
- package/src/core/MapsIndoors.ts +155 -11
- package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
- package/src/core/__tests__/MPBounds.test.ts +109 -0
- package/src/core/__tests__/MPFilter.test.ts +76 -0
- package/src/core/__tests__/MPLanguageTag.test.ts +168 -0
- package/src/core/__tests__/MPPoint.test.ts +82 -0
- package/src/core/__tests__/MPSolution.test.ts +107 -0
- package/src/core/__tests__/MapsIndoors.language.test.ts +180 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { MPLegBoundaryIcons, MPRouteAnimationType, MPRouteArrowStyle, MPRouteMarkerDisplayRule, MPRouteStampType, MPStrokeStyle } from "../../index";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The styling and camera options for a route rendered by {@link MPDirectionsRenderer}.
|
|
5
|
+
*
|
|
6
|
+
* Applied with {@link MPDirectionsRenderer.setOptions}, which restyles an already
|
|
7
|
+
* rendered route in place.
|
|
8
|
+
*
|
|
9
|
+
* Every property is optional and resolves on its own, in this order: the value set
|
|
10
|
+
* here, then the solution level default configured in the CMS, then the SDK's built-in
|
|
11
|
+
* default. An omitted property is therefore inherited rather than reset, so only the
|
|
12
|
+
* properties to override need to be given. Applying a fresh set of options clears all
|
|
13
|
+
* previous overrides.
|
|
14
|
+
*
|
|
15
|
+
* @export
|
|
16
|
+
* @class MPDirectionsRendererOptions
|
|
17
|
+
* @typedef {MPDirectionsRendererOptions}
|
|
18
|
+
*/
|
|
19
|
+
export default class MPDirectionsRendererOptions {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of MPDirectionsRendererOptions.
|
|
23
|
+
*
|
|
24
|
+
* @constructor
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private constructor(
|
|
28
|
+
public readonly strokeColor?: string,
|
|
29
|
+
public readonly strokeOpacity?: number,
|
|
30
|
+
public readonly strokeWeight?: number,
|
|
31
|
+
public readonly strokeStyle?: MPStrokeStyle,
|
|
32
|
+
public readonly backgroundColorEnabled?: boolean,
|
|
33
|
+
public readonly backgroundColor?: string,
|
|
34
|
+
public readonly backgroundColorOpacity?: number,
|
|
35
|
+
public readonly backgroundColorWeight?: number,
|
|
36
|
+
public readonly animationType?: MPRouteAnimationType,
|
|
37
|
+
public readonly animationSpeed?: number,
|
|
38
|
+
public readonly animationMinDuration?: number,
|
|
39
|
+
public readonly animationRepeating?: boolean,
|
|
40
|
+
public readonly forceAnimation?: boolean,
|
|
41
|
+
public readonly animatedOverlayColor?: string,
|
|
42
|
+
public readonly animatedOverlayOpacity?: number,
|
|
43
|
+
public readonly animatedOverlayWeight?: number,
|
|
44
|
+
public readonly stampType?: MPRouteStampType,
|
|
45
|
+
public readonly stampImageUrl?: string,
|
|
46
|
+
public readonly stampSpacing?: number,
|
|
47
|
+
public readonly stampScale?: number,
|
|
48
|
+
public readonly arrowStyle?: MPRouteArrowStyle,
|
|
49
|
+
public readonly stampColor?: string,
|
|
50
|
+
public readonly startDisplayRule?: MPRouteMarkerDisplayRule,
|
|
51
|
+
public readonly endDisplayRule?: MPRouteMarkerDisplayRule,
|
|
52
|
+
public readonly legBoundaryIcons?: MPLegBoundaryIcons,
|
|
53
|
+
public readonly elevated?: boolean,
|
|
54
|
+
public readonly elevationHeight?: number,
|
|
55
|
+
public readonly fitBoundsMaxZoom?: number,
|
|
56
|
+
) { }
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creator for MPDirectionsRendererOptions, also used to decode JSON from the MapsIndoors SDK.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
* @static
|
|
63
|
+
* @param {MPDirectionsRendererOptionsParams} object
|
|
64
|
+
* @returns {MPDirectionsRendererOptions}
|
|
65
|
+
*/
|
|
66
|
+
public static create(object: MPDirectionsRendererOptionsParams): MPDirectionsRendererOptions {
|
|
67
|
+
return new MPDirectionsRendererOptions(
|
|
68
|
+
object?.strokeColor,
|
|
69
|
+
object?.strokeOpacity,
|
|
70
|
+
object?.strokeWeight,
|
|
71
|
+
object?.strokeStyle,
|
|
72
|
+
object?.backgroundColorEnabled,
|
|
73
|
+
object?.backgroundColor,
|
|
74
|
+
object?.backgroundColorOpacity,
|
|
75
|
+
object?.backgroundColorWeight,
|
|
76
|
+
object?.animationType,
|
|
77
|
+
object?.animationSpeed,
|
|
78
|
+
object?.animationMinDuration,
|
|
79
|
+
object?.animationRepeating,
|
|
80
|
+
object?.forceAnimation,
|
|
81
|
+
object?.animatedOverlayColor,
|
|
82
|
+
object?.animatedOverlayOpacity,
|
|
83
|
+
object?.animatedOverlayWeight,
|
|
84
|
+
object?.stampType,
|
|
85
|
+
object?.stampImageUrl,
|
|
86
|
+
object?.stampSpacing,
|
|
87
|
+
object?.stampScale,
|
|
88
|
+
object?.arrowStyle,
|
|
89
|
+
object?.stampColor,
|
|
90
|
+
object?.startDisplayRule ? MPRouteMarkerDisplayRule.create(object.startDisplayRule) : undefined,
|
|
91
|
+
object?.endDisplayRule ? MPRouteMarkerDisplayRule.create(object.endDisplayRule) : undefined,
|
|
92
|
+
object?.legBoundaryIcons ? MPLegBoundaryIcons.create(object.legBoundaryIcons) : undefined,
|
|
93
|
+
object?.elevated,
|
|
94
|
+
object?.elevationHeight,
|
|
95
|
+
object?.fitBoundsMaxZoom,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Parameter interface for {@link MPDirectionsRendererOptions}.
|
|
102
|
+
*
|
|
103
|
+
* All colors are given as hex strings in the form "#RRGGBB" (e.g. "#3071D9").
|
|
104
|
+
* Transparency is set with the matching opacity property rather than in the color itself.
|
|
105
|
+
*
|
|
106
|
+
* @export
|
|
107
|
+
* @interface MPDirectionsRendererOptionsParams
|
|
108
|
+
* @typedef {MPDirectionsRendererOptionsParams}
|
|
109
|
+
*/
|
|
110
|
+
export interface MPDirectionsRendererOptionsParams {
|
|
111
|
+
/**
|
|
112
|
+
* The color of the route line.
|
|
113
|
+
*
|
|
114
|
+
* @type {?string}
|
|
115
|
+
*/
|
|
116
|
+
strokeColor?: string,
|
|
117
|
+
/**
|
|
118
|
+
* The opacity of the route line, in the range 0.0 - 1.0.
|
|
119
|
+
*
|
|
120
|
+
* @type {?number}
|
|
121
|
+
*/
|
|
122
|
+
strokeOpacity?: number,
|
|
123
|
+
/**
|
|
124
|
+
* The width of the route line, in pixels.
|
|
125
|
+
*
|
|
126
|
+
* @type {?number}
|
|
127
|
+
*/
|
|
128
|
+
strokeWeight?: number,
|
|
129
|
+
/**
|
|
130
|
+
* How the route line is drawn.
|
|
131
|
+
*
|
|
132
|
+
* @type {?MPStrokeStyle}
|
|
133
|
+
*/
|
|
134
|
+
strokeStyle?: MPStrokeStyle,
|
|
135
|
+
/**
|
|
136
|
+
* Whether the background halo is drawn beneath the route line.
|
|
137
|
+
*
|
|
138
|
+
* @type {?boolean}
|
|
139
|
+
*/
|
|
140
|
+
backgroundColorEnabled?: boolean,
|
|
141
|
+
/**
|
|
142
|
+
* The color of the background halo drawn beneath the route line.
|
|
143
|
+
*
|
|
144
|
+
* @type {?string}
|
|
145
|
+
*/
|
|
146
|
+
backgroundColor?: string,
|
|
147
|
+
/**
|
|
148
|
+
* The opacity of the background halo, in the range 0.0 - 1.0.
|
|
149
|
+
*
|
|
150
|
+
* @type {?number}
|
|
151
|
+
*/
|
|
152
|
+
backgroundColorOpacity?: number,
|
|
153
|
+
/**
|
|
154
|
+
* The halo padding on each side of the route line, in pixels.
|
|
155
|
+
*
|
|
156
|
+
* @type {?number}
|
|
157
|
+
*/
|
|
158
|
+
backgroundColorWeight?: number,
|
|
159
|
+
/**
|
|
160
|
+
* The animation applied to the overlay travelling along the route line.
|
|
161
|
+
*
|
|
162
|
+
* @type {?MPRouteAnimationType}
|
|
163
|
+
*/
|
|
164
|
+
animationType?: MPRouteAnimationType,
|
|
165
|
+
/**
|
|
166
|
+
* The animation speed, in meters per second.
|
|
167
|
+
*
|
|
168
|
+
* @type {?number}
|
|
169
|
+
*/
|
|
170
|
+
animationSpeed?: number,
|
|
171
|
+
/**
|
|
172
|
+
* The lower bound for the animation duration, in seconds, which keeps short
|
|
173
|
+
* routes from animating too fast.
|
|
174
|
+
*
|
|
175
|
+
* @type {?number}
|
|
176
|
+
*/
|
|
177
|
+
animationMinDuration?: number,
|
|
178
|
+
/**
|
|
179
|
+
* Whether the animation repeats.
|
|
180
|
+
*
|
|
181
|
+
* @type {?boolean}
|
|
182
|
+
*/
|
|
183
|
+
animationRepeating?: boolean,
|
|
184
|
+
/**
|
|
185
|
+
* Whether the animation plays even when the system's reduce motion setting is enabled.
|
|
186
|
+
*
|
|
187
|
+
* @type {?boolean}
|
|
188
|
+
*/
|
|
189
|
+
forceAnimation?: boolean,
|
|
190
|
+
/**
|
|
191
|
+
* The color of the animated overlay. Defaults to {@link strokeColor}.
|
|
192
|
+
*
|
|
193
|
+
* @type {?string}
|
|
194
|
+
*/
|
|
195
|
+
animatedOverlayColor?: string,
|
|
196
|
+
/**
|
|
197
|
+
* The opacity of the animated overlay, in the range 0.0 - 1.0.
|
|
198
|
+
*
|
|
199
|
+
* @type {?number}
|
|
200
|
+
*/
|
|
201
|
+
animatedOverlayOpacity?: number,
|
|
202
|
+
/**
|
|
203
|
+
* The width of the animated overlay, in pixels.
|
|
204
|
+
*
|
|
205
|
+
* @type {?number}
|
|
206
|
+
*/
|
|
207
|
+
animatedOverlayWeight?: number,
|
|
208
|
+
/**
|
|
209
|
+
* The repeating stamp drawn along the route line.
|
|
210
|
+
*
|
|
211
|
+
* @type {?MPRouteStampType}
|
|
212
|
+
*/
|
|
213
|
+
stampType?: MPRouteStampType,
|
|
214
|
+
/**
|
|
215
|
+
* The URL of the icon repeated along the route line when {@link stampType}
|
|
216
|
+
* is {@link MPRouteStampType.custom}.
|
|
217
|
+
*
|
|
218
|
+
* @type {?string}
|
|
219
|
+
*/
|
|
220
|
+
stampImageUrl?: string,
|
|
221
|
+
/**
|
|
222
|
+
* The distance between repeated stamps, in pixels.
|
|
223
|
+
*
|
|
224
|
+
* @type {?number}
|
|
225
|
+
*/
|
|
226
|
+
stampSpacing?: number,
|
|
227
|
+
/**
|
|
228
|
+
* The scale multiplier applied to the stamp icon, where 1.0 is the intrinsic size.
|
|
229
|
+
*
|
|
230
|
+
* @type {?number}
|
|
231
|
+
*/
|
|
232
|
+
stampScale?: number,
|
|
233
|
+
/**
|
|
234
|
+
* The arrow shape drawn when {@link stampType} is {@link MPRouteStampType.arrow}.
|
|
235
|
+
*
|
|
236
|
+
* @type {?MPRouteArrowStyle}
|
|
237
|
+
*/
|
|
238
|
+
arrowStyle?: MPRouteArrowStyle,
|
|
239
|
+
/**
|
|
240
|
+
* The tint of the built-in arrow stamp. Ignored by a custom {@link stampImageUrl}.
|
|
241
|
+
*
|
|
242
|
+
* @type {?string}
|
|
243
|
+
*/
|
|
244
|
+
stampColor?: string,
|
|
245
|
+
/**
|
|
246
|
+
* The styling of the route's origin marker.
|
|
247
|
+
*
|
|
248
|
+
* @type {?MPRouteMarkerDisplayRule}
|
|
249
|
+
*/
|
|
250
|
+
startDisplayRule?: MPRouteMarkerDisplayRule,
|
|
251
|
+
/**
|
|
252
|
+
* The styling of the route's destination marker.
|
|
253
|
+
*
|
|
254
|
+
* @type {?MPRouteMarkerDisplayRule}
|
|
255
|
+
*/
|
|
256
|
+
endDisplayRule?: MPRouteMarkerDisplayRule,
|
|
257
|
+
/**
|
|
258
|
+
* The icons drawn where the route crosses a connector, by connector type.
|
|
259
|
+
*
|
|
260
|
+
* @type {?MPLegBoundaryIcons}
|
|
261
|
+
*/
|
|
262
|
+
legBoundaryIcons?: MPLegBoundaryIcons,
|
|
263
|
+
/**
|
|
264
|
+
* Whether the whole route is lifted off the base map for a 3D effect. The lift
|
|
265
|
+
* is only visible when the camera is tilted.
|
|
266
|
+
*
|
|
267
|
+
* Mapbox only, the Google Maps SDKs keep the route flat.
|
|
268
|
+
*
|
|
269
|
+
* @type {?boolean}
|
|
270
|
+
*/
|
|
271
|
+
elevated?: boolean,
|
|
272
|
+
/**
|
|
273
|
+
* How far the route is lifted above the ground, in meters, when {@link elevated}
|
|
274
|
+
* is true.
|
|
275
|
+
*
|
|
276
|
+
* Mapbox only, the Google Maps SDKs keep the route flat.
|
|
277
|
+
*
|
|
278
|
+
* @type {?number}
|
|
279
|
+
*/
|
|
280
|
+
elevationHeight?: number,
|
|
281
|
+
/**
|
|
282
|
+
* The upper bound for the zoom level used when fitting the camera to the route.
|
|
283
|
+
*
|
|
284
|
+
* @type {?number}
|
|
285
|
+
*/
|
|
286
|
+
fitBoundsMaxZoom?: number,
|
|
287
|
+
}
|
package/src/core/MPError.ts
CHANGED
|
@@ -45,6 +45,30 @@ export default class MPError {
|
|
|
45
45
|
*/
|
|
46
46
|
static readonly invalidApiKey: number = 100;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Occurs if base-map tile caching is attempted on a map provider that cannot cache base-map
|
|
50
|
+
* tiles. The Mapbox provider supports it; the Google Maps provider does not.
|
|
51
|
+
*
|
|
52
|
+
* Canonical copy. The same value is spelled out in Android's `MIError.BASEMAP_CACHE_NOT_SUPPORTED`
|
|
53
|
+
* and as a literal in iOS's `doRejectBaseMapCache`; drift silently reports "not supported" as a
|
|
54
|
+
* generic failure.
|
|
55
|
+
*
|
|
56
|
+
* @static
|
|
57
|
+
* @readonly
|
|
58
|
+
* @type {number}
|
|
59
|
+
*/
|
|
60
|
+
static readonly baseMapCachingNotSupported: number = 9000;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Occurs if base-map tile caching is attempted before a map provider's base-map cache has been
|
|
64
|
+
* registered with the SDK.
|
|
65
|
+
*
|
|
66
|
+
* @static
|
|
67
|
+
* @readonly
|
|
68
|
+
* @type {number}
|
|
69
|
+
*/
|
|
70
|
+
static readonly baseMapCacheNotRegistered: number = 9001;
|
|
71
|
+
|
|
48
72
|
/**
|
|
49
73
|
* Creates an instance of MPError.
|
|
50
74
|
*
|
|
@@ -81,8 +105,31 @@ export default class MPError {
|
|
|
81
105
|
);
|
|
82
106
|
}
|
|
83
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Turn a rejection from a native module into an {@link MPError}.
|
|
110
|
+
*
|
|
111
|
+
* The native modules reject with a JSON-encoded MPError, but a rejection reaching here can
|
|
112
|
+
* also come from the bridge itself or from JavaScript, and then the message is plain text.
|
|
113
|
+
* Parsing that blindly threw a SyntaxError and threw away the real message, so a caller saw
|
|
114
|
+
* "JSON Parse error: Unexpected character: E" instead of what actually went wrong. Fall back
|
|
115
|
+
* to wrapping the message as an unknown error, which keeps it readable and keeps this method's
|
|
116
|
+
* contract - it returns an MPError, it does not throw a different one.
|
|
117
|
+
*
|
|
118
|
+
* @public
|
|
119
|
+
* @static
|
|
120
|
+
* @param {Error} error
|
|
121
|
+
* @returns {MPError}
|
|
122
|
+
*/
|
|
84
123
|
public static parse(error: Error): MPError {
|
|
85
|
-
|
|
124
|
+
try {
|
|
125
|
+
const parsed = JSON.parse(error?.message);
|
|
126
|
+
if (parsed !== null && typeof parsed === "object" && typeof parsed.code === "number") {
|
|
127
|
+
return MPError.create(parsed);
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
// Not a native MPError payload; fall through to wrapping the raw message.
|
|
131
|
+
}
|
|
132
|
+
return new MPError(MPError.unknownError, error?.message ?? "Unknown error");
|
|
86
133
|
}
|
|
87
134
|
}
|
|
88
135
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalization and RFC 4647 lookup for BCP-47 language tags.
|
|
3
|
+
*
|
|
4
|
+
* Both native SDKs rewrite a language tag before it reaches the backend, but they do it in
|
|
5
|
+
* different places and with slightly different rules, so the same tag could be accepted on one
|
|
6
|
+
* platform and dropped on the other. This is a single TypeScript port of both, so that "is this
|
|
7
|
+
* tag supported" and "which tag should I actually pass" get the same answer on iOS and Android
|
|
8
|
+
* without a round trip to native.
|
|
9
|
+
*
|
|
10
|
+
* Ported from:
|
|
11
|
+
*
|
|
12
|
+
* * iOS `MapsIndoorsCore/util/LanguageCodeNormalizer.swift` - tag canonicalization.
|
|
13
|
+
* * Android `com.mapsindoors.core.MPLanguageManager` - `canonicalLanguage`, `buildPriorityList`
|
|
14
|
+
* and `rfc4647Lookup`.
|
|
15
|
+
*
|
|
16
|
+
* iOS's normalizer has four switch cases this port omits - `"hans-cn"`, `"hant-tw"`, `"hant-hk"`
|
|
17
|
+
* and `"hant-mo"`. They are unreachable there: the tag is split on `-` before the switch runs, so
|
|
18
|
+
* no subtag can contain one. Omitting them is not an incomplete port.
|
|
19
|
+
*
|
|
20
|
+
* Where the two natives disagree, the choice and the reason are documented at the point of
|
|
21
|
+
* divergence below. Deliberately dependency-free: this module imports nothing, so it can be unit
|
|
22
|
+
* tested without a React Native mock and cannot participate in the `index.ts` import cycle.
|
|
23
|
+
*
|
|
24
|
+
* @module MPLanguageTag
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The Chinese script implied by a region subtag.
|
|
29
|
+
*
|
|
30
|
+
* Mirrors Android's `MPLanguageManager.buildPriorityList`. iOS's normalizer omits `MY`; we follow
|
|
31
|
+
* Android, because CLDR's likely-subtags maps `zh-MY` to `zh-Hans` and Malaysian Chinese is
|
|
32
|
+
* written in Simplified. iOS's omission looks like an oversight rather than a decision - its
|
|
33
|
+
* `LanguageCodeNormalizerTests` never covers `zh-MY`, while Android's
|
|
34
|
+
* `buildPriorityListEnrichesZhMYWithHans` pins it explicitly.
|
|
35
|
+
*/
|
|
36
|
+
const CHINESE_REGION_SCRIPTS: Readonly<Record<string, "Hans" | "Hant">> = {
|
|
37
|
+
CN: "Hans",
|
|
38
|
+
SG: "Hans",
|
|
39
|
+
MY: "Hans",
|
|
40
|
+
TW: "Hant",
|
|
41
|
+
HK: "Hant",
|
|
42
|
+
MO: "Hant",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Script subtags recognized on a Chinese tag, keyed by their lower-case form. */
|
|
46
|
+
const CHINESE_SCRIPTS: Readonly<Record<string, "Hans" | "Hant">> = {
|
|
47
|
+
hans: "Hans",
|
|
48
|
+
hant: "Hant",
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Splits a tag on either separator.
|
|
53
|
+
*
|
|
54
|
+
* BCP-47 uses `-`, but ICU and `java.util.Locale.toString()` use `_`, and JavaScript i18n
|
|
55
|
+
* libraries hand out both. iOS's normalizer accepts either; Android's does not, because
|
|
56
|
+
* `Locale.forLanguageTag("zh_Hans")` returns the undetermined locale. We follow iOS: accepting `_`
|
|
57
|
+
* is strictly more permissive, so it cannot turn a tag that works today into one that doesn't.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} tag
|
|
60
|
+
* @returns {string[]} The non-empty subtags, in order.
|
|
61
|
+
*/
|
|
62
|
+
function subtagsOf(tag: string): string[] {
|
|
63
|
+
return tag.split(/[-_]+/).filter((part) => part.length > 0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns the canonical BCP-47 form of a language tag, or the trimmed input unchanged when it is
|
|
68
|
+
* not a tag this function knows how to rewrite.
|
|
69
|
+
*
|
|
70
|
+
* * Chinese script and legacy region forms collapse onto the two tags the backend actually
|
|
71
|
+
* publishes, `zh-Hans` and `zh-Hant`. So `zh_hans`, `ZH-HANS`, `zh-CN`, `zh-SG` and `zh-MY` all
|
|
72
|
+
* become `zh-Hans`, and `zh-Hant`, `zh-TW`, `zh-HK` and `zh-MO` all become `zh-Hant`.
|
|
73
|
+
* * Bare `zh` is returned as `zh`, unresolved. There is no way to tell which script the caller
|
|
74
|
+
* wants, and guessing would silently serve Traditional content to a Simplified audience, or the
|
|
75
|
+
* reverse.
|
|
76
|
+
* * Everything else gets a generic rewrite - language lower-cased, four-character script subtag
|
|
77
|
+
* Title-cased, two- and three-character subtags upper-cased. So `EN` becomes `en`, `en_us`
|
|
78
|
+
* becomes `en-US`, `pt-br` becomes `pt-BR`, and `sr_latn_rs` becomes `sr-Latn-RS`.
|
|
79
|
+
* * Empty or whitespace-only input comes back as the empty string, so the caller can apply its own
|
|
80
|
+
* fallback.
|
|
81
|
+
*
|
|
82
|
+
* @export
|
|
83
|
+
* @param {?string} [tag] A language tag in any casing, with either `-` or `_` separators.
|
|
84
|
+
* @returns {string} The canonical form, or the trimmed input if it is not recognizable.
|
|
85
|
+
*/
|
|
86
|
+
export function normalizeLanguageTag(tag?: string | null): string {
|
|
87
|
+
const trimmed = tag?.trim() ?? "";
|
|
88
|
+
if (trimmed.length === 0) {
|
|
89
|
+
return trimmed;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const parts = subtagsOf(trimmed);
|
|
93
|
+
if (parts.length === 0) {
|
|
94
|
+
return trimmed;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const language = parts[0].toLowerCase();
|
|
98
|
+
const subtags = parts.slice(1);
|
|
99
|
+
|
|
100
|
+
if (language === "zh") {
|
|
101
|
+
// Script wins over region, and the first recognized subtag wins, so `zh-Hant-TW` resolves
|
|
102
|
+
// on `Hant` rather than on `TW`. The two agree here, but the order is what iOS does.
|
|
103
|
+
for (const subtag of subtags) {
|
|
104
|
+
const script = CHINESE_SCRIPTS[subtag.toLowerCase()] ?? CHINESE_REGION_SCRIPTS[subtag.toUpperCase()];
|
|
105
|
+
if (script !== undefined) {
|
|
106
|
+
return `zh-${script}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (subtags.length === 0) {
|
|
110
|
+
return "zh";
|
|
111
|
+
}
|
|
112
|
+
// An unrecognized subtag (`zh-Foo`) deliberately falls through to the generic rewrite
|
|
113
|
+
// rather than collapsing to bare `zh`, so the caller's information is not discarded.
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const rebuilt = [language];
|
|
117
|
+
for (const subtag of subtags) {
|
|
118
|
+
if (subtag.length === 4) {
|
|
119
|
+
rebuilt.push(subtag.charAt(0).toUpperCase() + subtag.slice(1).toLowerCase());
|
|
120
|
+
} else if (subtag.length === 2 || subtag.length === 3) {
|
|
121
|
+
// Upper-casing a three-character subtag is wrong for extlangs and variants (`zh-yue`
|
|
122
|
+
// becomes `zh-YUE`), but it is what the iOS SDK does, and matching it matters more
|
|
123
|
+
// than being right about a subtag the backend never publishes.
|
|
124
|
+
rebuilt.push(subtag.toUpperCase());
|
|
125
|
+
} else {
|
|
126
|
+
rebuilt.push(subtag);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return rebuilt.join("-");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Builds the RFC 4647 priority list for a tag.
|
|
134
|
+
*
|
|
135
|
+
* Port of Android's `MPLanguageManager.buildPriorityList`: a Chinese tag that carries a region but
|
|
136
|
+
* no script gets the implied script prepended, so `zh-CN` prefers a solution's `zh-Hans` over its
|
|
137
|
+
* bare `zh`. Anything else is a single-entry list and takes the plain right-to-left walk.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} tag
|
|
140
|
+
* @returns {string[]} The ranges to try, most preferred first.
|
|
141
|
+
*/
|
|
142
|
+
function buildPriorityList(tag: string): string[] {
|
|
143
|
+
const parts = subtagsOf(tag);
|
|
144
|
+
if (parts.length < 2 || parts[0].toLowerCase() !== "zh") {
|
|
145
|
+
return [tag];
|
|
146
|
+
}
|
|
147
|
+
// A four-character subtag is a script. Android skips enrichment when one is already present
|
|
148
|
+
// rather than second-guessing an explicit choice.
|
|
149
|
+
if (parts.slice(1).some((part) => part.length === 4)) {
|
|
150
|
+
return [tag];
|
|
151
|
+
}
|
|
152
|
+
const region = parts.slice(1).find((part) => part.length === 2);
|
|
153
|
+
const script = region !== undefined ? CHINESE_REGION_SCRIPTS[region.toUpperCase()] : undefined;
|
|
154
|
+
return script !== undefined ? [`zh-${script}`, tag] : [tag];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Resolves a language tag to the exact tag a solution advertises, or `undefined` when nothing in
|
|
159
|
+
* the fallback chain matches.
|
|
160
|
+
*
|
|
161
|
+
* Port of Android's `MPLanguageManager.canonicalLanguage`: an exact case-insensitive match first,
|
|
162
|
+
* then an RFC 4647 "lookup" walk that strips subtags right to left, with the Chinese
|
|
163
|
+
* region-to-script enrichment tried ahead of the raw tag. The canonical form from
|
|
164
|
+
* {@link normalizeLanguageTag} is tried first of all, which is what lets `zh_Hans` and `ZH-CN`
|
|
165
|
+
* resolve the same way they do on iOS.
|
|
166
|
+
*
|
|
167
|
+
* The return value is the entry as `available` spells it, not as the caller spelled it, so the
|
|
168
|
+
* language reaches the backend with the casing the CMS published - `zh-Hant`, not `zh-hant`.
|
|
169
|
+
*
|
|
170
|
+
* Conservative about ambiguity by design: bare `zh` against a solution advertising only `zh-Hans`
|
|
171
|
+
* and `zh-Hant` returns `undefined`. The iOS SDK's own `isLanguageAvailable` is looser and would
|
|
172
|
+
* accept it, but Android's `setLanguage` refuses, so a permissive answer here would be a lie on
|
|
173
|
+
* the platform that actually enforces it. A resolved tag is therefore safe to pass to
|
|
174
|
+
* `MapsIndoors.setLanguage` on both platforms; an unresolved one is not necessarily rejected.
|
|
175
|
+
*
|
|
176
|
+
* @export
|
|
177
|
+
* @param {?string} [tag] A language tag in any casing, with either `-` or `_` separators.
|
|
178
|
+
* @param {?string[]} [available] The solution's advertised tags - `MPSolution.availableLanguages`.
|
|
179
|
+
* @returns {(string | undefined)} The matching entry from `available`, or `undefined`.
|
|
180
|
+
*/
|
|
181
|
+
export function resolveLanguageTag(
|
|
182
|
+
tag?: string | null,
|
|
183
|
+
available?: readonly (string | undefined | null)[] | null,
|
|
184
|
+
): string | undefined {
|
|
185
|
+
const trimmed = tag?.trim() ?? "";
|
|
186
|
+
// Android's `canonicalLanguage` rejects anything shorter than two characters outright.
|
|
187
|
+
if (trimmed.length < 2 || available == null) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const candidates = available.filter((entry): entry is string => typeof entry === "string" && entry.length > 0);
|
|
192
|
+
if (candidates.length === 0) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const matches = (candidate: string): string | undefined =>
|
|
197
|
+
candidates.find((entry) => entry.toLowerCase() === candidate.toLowerCase());
|
|
198
|
+
|
|
199
|
+
const exact = matches(trimmed);
|
|
200
|
+
if (exact !== undefined) {
|
|
201
|
+
return exact;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Putting the canonical form first only ever *adds* a candidate - the raw priority list still
|
|
205
|
+
// follows - so this is never stricter than Android's own walk.
|
|
206
|
+
const ranges = [normalizeLanguageTag(trimmed), ...buildPriorityList(trimmed)];
|
|
207
|
+
for (const range of ranges) {
|
|
208
|
+
let candidate = range;
|
|
209
|
+
while (candidate.length > 0) {
|
|
210
|
+
const match = matches(candidate);
|
|
211
|
+
if (match !== undefined) {
|
|
212
|
+
return match;
|
|
213
|
+
}
|
|
214
|
+
const dash = candidate.lastIndexOf("-");
|
|
215
|
+
if (dash < 0) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
candidate = candidate.slice(0, dash);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom icons drawn where a route crosses a connector, selected by connector type.
|
|
3
|
+
*
|
|
4
|
+
* Assigned to {@link MPDirectionsRendererOptionsParams.legBoundaryIcons}.
|
|
5
|
+
*
|
|
6
|
+
* Each icon is a media library URL, which the SDK downloads and caches. Every property
|
|
7
|
+
* is optional and resolves on its own, so only the connector types set here are
|
|
8
|
+
* overridden, the rest keep the icon configured for the solution, or the built-in glyph.
|
|
9
|
+
* A connector without its own icon falls back to {@link defaultIcon}.
|
|
10
|
+
*
|
|
11
|
+
* @export
|
|
12
|
+
* @class MPLegBoundaryIcons
|
|
13
|
+
* @typedef {MPLegBoundaryIcons}
|
|
14
|
+
*/
|
|
15
|
+
export default class MPLegBoundaryIcons {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of MPLegBoundaryIcons.
|
|
19
|
+
*
|
|
20
|
+
* @constructor
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private constructor(
|
|
24
|
+
public readonly defaultIcon?: string,
|
|
25
|
+
public readonly elevator?: string,
|
|
26
|
+
public readonly escalator?: string,
|
|
27
|
+
public readonly stairs?: string,
|
|
28
|
+
public readonly ramp?: string,
|
|
29
|
+
public readonly wheelchairRamp?: string,
|
|
30
|
+
public readonly wheelchairLift?: string,
|
|
31
|
+
public readonly ladder?: string,
|
|
32
|
+
public readonly entry?: string,
|
|
33
|
+
public readonly scale?: number,
|
|
34
|
+
) { }
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creator for MPLegBoundaryIcons.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
* @static
|
|
41
|
+
* @param {MPLegBoundaryIconsParams} object
|
|
42
|
+
* @returns {MPLegBoundaryIcons}
|
|
43
|
+
*/
|
|
44
|
+
public static create(object: MPLegBoundaryIconsParams): MPLegBoundaryIcons {
|
|
45
|
+
return new MPLegBoundaryIcons(
|
|
46
|
+
object?.defaultIcon,
|
|
47
|
+
object?.elevator,
|
|
48
|
+
object?.escalator,
|
|
49
|
+
object?.stairs,
|
|
50
|
+
object?.ramp,
|
|
51
|
+
object?.wheelchairRamp,
|
|
52
|
+
object?.wheelchairLift,
|
|
53
|
+
object?.ladder,
|
|
54
|
+
object?.entry,
|
|
55
|
+
object?.scale,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parameter interface for {@link MPLegBoundaryIcons}.
|
|
62
|
+
*
|
|
63
|
+
* Every icon is a media library URL.
|
|
64
|
+
*
|
|
65
|
+
* @export
|
|
66
|
+
* @interface MPLegBoundaryIconsParams
|
|
67
|
+
* @typedef {MPLegBoundaryIconsParams}
|
|
68
|
+
*/
|
|
69
|
+
export interface MPLegBoundaryIconsParams {
|
|
70
|
+
/**
|
|
71
|
+
* Fallback icon for any connector type without its own icon.
|
|
72
|
+
*
|
|
73
|
+
* @type {?string}
|
|
74
|
+
*/
|
|
75
|
+
defaultIcon?: string,
|
|
76
|
+
/**
|
|
77
|
+
* Icon for elevator floor changes.
|
|
78
|
+
*
|
|
79
|
+
* @type {?string}
|
|
80
|
+
*/
|
|
81
|
+
elevator?: string,
|
|
82
|
+
/**
|
|
83
|
+
* Icon for escalator floor changes.
|
|
84
|
+
*
|
|
85
|
+
* @type {?string}
|
|
86
|
+
*/
|
|
87
|
+
escalator?: string,
|
|
88
|
+
/**
|
|
89
|
+
* Icon for stairs floor changes.
|
|
90
|
+
*
|
|
91
|
+
* @type {?string}
|
|
92
|
+
*/
|
|
93
|
+
stairs?: string,
|
|
94
|
+
/**
|
|
95
|
+
* Icon for ramp floor changes.
|
|
96
|
+
*
|
|
97
|
+
* @type {?string}
|
|
98
|
+
*/
|
|
99
|
+
ramp?: string,
|
|
100
|
+
/**
|
|
101
|
+
* Icon for wheelchair ramp floor changes.
|
|
102
|
+
*
|
|
103
|
+
* @type {?string}
|
|
104
|
+
*/
|
|
105
|
+
wheelchairRamp?: string,
|
|
106
|
+
/**
|
|
107
|
+
* Icon for wheelchair lift floor changes.
|
|
108
|
+
*
|
|
109
|
+
* @type {?string}
|
|
110
|
+
*/
|
|
111
|
+
wheelchairLift?: string,
|
|
112
|
+
/**
|
|
113
|
+
* Icon for ladder floor changes.
|
|
114
|
+
*
|
|
115
|
+
* @type {?string}
|
|
116
|
+
*/
|
|
117
|
+
ladder?: string,
|
|
118
|
+
/**
|
|
119
|
+
* Icon for building entrances, where the route crosses an external door.
|
|
120
|
+
*
|
|
121
|
+
* @type {?string}
|
|
122
|
+
*/
|
|
123
|
+
entry?: string,
|
|
124
|
+
/**
|
|
125
|
+
* Scale multiplier applied to every connector icon, where 1.0 is the intrinsic size.
|
|
126
|
+
*
|
|
127
|
+
* @type {?number}
|
|
128
|
+
*/
|
|
129
|
+
scale?: number,
|
|
130
|
+
}
|