@mapsindoors/react-native-maps-indoors-mapbox 2.9.1 → 2.10.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 +47 -21
- package/android/build.gradle +1 -13
- package/android/src/main/java/com/mapsindoorsrn/MapboxMapView.java +4 -0
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsViewManager.java +28 -2
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +10 -2
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +1 -0
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +335 -99
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +17 -1
- package/android/src/main/java/com/mapsindoorsrn/core/RouteStore.java +59 -0
- package/app.plugin.js +8 -86
- package/ios/core/DirectionsRendererBridge.m +1 -0
- package/ios/core/DirectionsRendererModule.swift +6 -3
- package/ios/core/DirectionsServiceModule.swift +7 -1
- package/ios/core/MapControlModule.swift +8 -4
- package/ios/core/MapsIndoorsBridge.m +1 -0
- package/ios/core/MapsIndoorsModule.swift +33 -2
- package/ios/core/ReactPositionProvider.swift +6 -7
- package/ios/core/Sources/RouteStore/RouteStore.swift +62 -0
- package/package.json +6 -2
- package/specs/NativeDirectionsRendererModule.ts +1 -1
- package/specs/NativeMapsIndoorsModule.ts +1 -1
- package/src/core/MPDirectionsRenderer.ts +7 -1
- package/src/core/MPDirectionsService.ts +4 -1
- package/src/core/MapsIndoors.ts +36 -3
- package/src/core/RouteHandles.ts +76 -0
|
@@ -25,6 +25,7 @@ import com.mapsindoors.core.MPDataSetManagerStatus;
|
|
|
25
25
|
import com.mapsindoors.core.MPDisplayRule;
|
|
26
26
|
import com.mapsindoors.core.MPFilter;
|
|
27
27
|
import com.mapsindoors.core.MPLocation;
|
|
28
|
+
import com.mapsindoors.core.MPLogger;
|
|
28
29
|
import com.mapsindoors.core.MPPoint;
|
|
29
30
|
import com.mapsindoors.core.MPQuery;
|
|
30
31
|
import com.mapsindoors.core.MPSolution;
|
|
@@ -98,9 +99,23 @@ public class MapsIndoorsModule extends ReactContextBaseJavaModule {
|
|
|
98
99
|
promise.reject("MapsIndoorsError", errorString);
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Names this wrapper as the component behind the MapsIndoors Insights session, so React Native
|
|
104
|
+
* apps are told apart from native ones in the rollups.
|
|
105
|
+
*
|
|
106
|
+
* The SDK snapshots the component into the session when the session starts, inside
|
|
107
|
+
* {@code MapsIndoors.load}, so this has to run on the same call, right before it. The version
|
|
108
|
+
* comes from JS, which reads it from the map package's own package.json.
|
|
109
|
+
*/
|
|
110
|
+
private void setReactNativeComponent(@Nullable String sdkVersion) {
|
|
111
|
+
MPLogger.setCustomComponent("React Native/android SDK", sdkVersion != null ? sdkVersion : "unknown");
|
|
112
|
+
}
|
|
113
|
+
|
|
101
114
|
@ReactMethod
|
|
102
|
-
public void loadMapsIndoors(String apiKey, ReadableArray optionalStrings, Promise promise) {
|
|
115
|
+
public void loadMapsIndoors(String apiKey, ReadableArray optionalStrings, @Nullable String sdkVersion, Promise promise) {
|
|
103
116
|
try {
|
|
117
|
+
setReactNativeComponent(sdkVersion);
|
|
118
|
+
RouteStore.clear();
|
|
104
119
|
if (optionalStrings != null) {
|
|
105
120
|
List<String> venueList = new ArrayList<>();
|
|
106
121
|
for (int i = 0; i < optionalStrings.size(); i++) {
|
|
@@ -352,6 +367,7 @@ public class MapsIndoorsModule extends ReactContextBaseJavaModule {
|
|
|
352
367
|
|
|
353
368
|
@ReactMethod
|
|
354
369
|
public void destroy(final Promise promise) {
|
|
370
|
+
RouteStore.clear();
|
|
355
371
|
MapsIndoors.destroy();
|
|
356
372
|
promise.resolve(null);
|
|
357
373
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.mapsindoorsrn.core;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.mapsindoors.core.MPRoute;
|
|
7
|
+
|
|
8
|
+
import java.util.LinkedHashMap;
|
|
9
|
+
import java.util.Map;
|
|
10
|
+
import java.util.UUID;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Keeps the routes {@link DirectionsServiceModule#getRoute} returned, so
|
|
14
|
+
* {@link DirectionsRendererModule#setRoute} can render the very instance instead of parsing the copy
|
|
15
|
+
* that comes back from JavaScript (SPEX-2782).
|
|
16
|
+
*
|
|
17
|
+
* Only that instance carries the endpoints the SDK reports with the directions Insights events, and
|
|
18
|
+
* the SDK keeps them out of Gson, so a parsed copy reports none.
|
|
19
|
+
*
|
|
20
|
+
* Shared by the two modules, since neither can reach the other's instance. Holds at most
|
|
21
|
+
* {@link #CAPACITY} routes and forgets the least recently used, since JavaScript never says when it is
|
|
22
|
+
* done with one. A forgotten route still renders, from its JSON, just without endpoints. Rendering
|
|
23
|
+
* a kept route again is safe: the SDK resolves its endpoints once and reads them on every event.
|
|
24
|
+
*/
|
|
25
|
+
final class RouteStore {
|
|
26
|
+
static final int CAPACITY = 10;
|
|
27
|
+
|
|
28
|
+
// Access order, so a lookup counts as use and a route the app keeps setting stays.
|
|
29
|
+
private static final Map<String, MPRoute> sRoutes = new LinkedHashMap<String, MPRoute>(CAPACITY + 1, 1f, true) {
|
|
30
|
+
@Override
|
|
31
|
+
protected boolean removeEldestEntry(Map.Entry<String, MPRoute> eldest) {
|
|
32
|
+
return size() > CAPACITY;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
private RouteStore() {}
|
|
37
|
+
|
|
38
|
+
/** Keeps {@code route} and returns the key to look it up by. */
|
|
39
|
+
@NonNull
|
|
40
|
+
static synchronized String keep(@NonNull MPRoute route) {
|
|
41
|
+
String key = UUID.randomUUID().toString();
|
|
42
|
+
sRoutes.put(key, route);
|
|
43
|
+
return key;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The route kept under {@code key}, if it is still kept. */
|
|
47
|
+
@Nullable
|
|
48
|
+
static synchronized MPRoute get(@Nullable String key) {
|
|
49
|
+
return key == null ? null : sRoutes.get(key);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Forgets every route, when MapsIndoors loads or is destroyed: a route belongs to the solution
|
|
54
|
+
* that was loaded when it was requested.
|
|
55
|
+
*/
|
|
56
|
+
static synchronized void clear() {
|
|
57
|
+
sRoutes.clear();
|
|
58
|
+
}
|
|
59
|
+
}
|
package/app.plugin.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const {
|
|
2
2
|
withProjectBuildGradle,
|
|
3
|
-
withGradleProperties,
|
|
4
3
|
withPlugins,
|
|
5
4
|
withDangerousMod,
|
|
6
5
|
withInfoPlist,
|
|
@@ -46,24 +45,6 @@ const {
|
|
|
46
45
|
]);
|
|
47
46
|
};
|
|
48
47
|
|
|
49
|
-
/**
|
|
50
|
-
* Plugin to add mapbox private token to gradle properties
|
|
51
|
-
* @param {*} config expo project config
|
|
52
|
-
* @param {*} token private token to set
|
|
53
|
-
* @returns modified config
|
|
54
|
-
*/
|
|
55
|
-
const withGradleProps = (token) => (config) => {
|
|
56
|
-
return withGradleProperties(config, (modConf) => {
|
|
57
|
-
modConf.modResults.push({
|
|
58
|
-
type: "property",
|
|
59
|
-
key: "MAPBOX_DOWNLOADS_TOKEN",
|
|
60
|
-
value: token,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return modConf;
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
48
|
/**
|
|
68
49
|
* Plugin to add mapsindoors maven repository
|
|
69
50
|
* @param {*} config expo project config
|
|
@@ -76,19 +57,7 @@ const {
|
|
|
76
57
|
|
|
77
58
|
`maven { url 'https://www.jitpack.io' }
|
|
78
59
|
maven { url 'https://maven.mapsindoors.com/' }
|
|
79
|
-
maven {
|
|
80
|
-
url 'https://api.mapbox.com/downloads/v2/releases/maven'
|
|
81
|
-
authentication {
|
|
82
|
-
basic(BasicAuthentication)
|
|
83
|
-
}
|
|
84
|
-
credentials {
|
|
85
|
-
// Do not change the username below.
|
|
86
|
-
// This should always be 'mapbox' (not your username).
|
|
87
|
-
username = "mapbox"
|
|
88
|
-
// Use the secret token you stored in gradle.properties as the password
|
|
89
|
-
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
|
|
90
|
-
}
|
|
91
|
-
}`
|
|
60
|
+
maven { url 'https://api.mapbox.com/downloads/v2/releases/maven' }`
|
|
92
61
|
);
|
|
93
62
|
|
|
94
63
|
modConf.modResults.contents = content;
|
|
@@ -109,57 +78,6 @@ const {
|
|
|
109
78
|
});
|
|
110
79
|
};
|
|
111
80
|
|
|
112
|
-
/**
|
|
113
|
-
* Plugin to add mapsindoors user system setup
|
|
114
|
-
* @param {*} token private token to set
|
|
115
|
-
* @param {*} config expo project config
|
|
116
|
-
*/
|
|
117
|
-
const withiOSSecret = (token) => (config) => {
|
|
118
|
-
return withDangerousMod(config, [
|
|
119
|
-
"ios",
|
|
120
|
-
async (modConf) => {
|
|
121
|
-
const home = path.resolve(process.env.HOME);
|
|
122
|
-
const netrc = path.resolve(home, ".netrc");
|
|
123
|
-
|
|
124
|
-
// conf to add
|
|
125
|
-
const conf = `machine api.mapbox.com
|
|
126
|
-
login mapbox
|
|
127
|
-
password ${token}
|
|
128
|
-
`;
|
|
129
|
-
|
|
130
|
-
const exists = fs.existsSync(netrc);
|
|
131
|
-
|
|
132
|
-
if (!exists) {
|
|
133
|
-
// no previous conf, write new one
|
|
134
|
-
fs.writeFileSync(netrc, conf, { flag: "w" });
|
|
135
|
-
fs.chmodSync(netrc, 0o600);
|
|
136
|
-
} else {
|
|
137
|
-
// get content
|
|
138
|
-
let content = fs.readFileSync(netrc, "utf-8");
|
|
139
|
-
const lines = content.split("\n");
|
|
140
|
-
|
|
141
|
-
// check if mapbox conf exist
|
|
142
|
-
const found = lines.findIndex((line) =>
|
|
143
|
-
line.includes("machine api.mapbox.com")
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
if (found >= 0) {
|
|
147
|
-
// remove previous mapbox conf
|
|
148
|
-
content = lines
|
|
149
|
-
.filter((_, idx) => ![found, found + 1, found + 2].includes(idx))
|
|
150
|
-
.join("\n");
|
|
151
|
-
fs.writeFileSync(netrc, content, { flag: "w" });
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// write new conf
|
|
155
|
-
fs.writeFileSync(netrc, conf, { flag: "a+" });
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return modConf;
|
|
159
|
-
},
|
|
160
|
-
]);
|
|
161
|
-
};
|
|
162
|
-
|
|
163
81
|
/**
|
|
164
82
|
* Plugin to add podfile script
|
|
165
83
|
* @param {*} config expo project config
|
|
@@ -255,7 +173,7 @@ const {
|
|
|
255
173
|
/**
|
|
256
174
|
* Combine Expo configuration and properties
|
|
257
175
|
* @param {*} config expo project config
|
|
258
|
-
* @param {*} {downloadToken} Mapbox
|
|
176
|
+
* @param {*} {downloadToken} deprecated and ignored: Mapbox SDK downloads need no token
|
|
259
177
|
* @param {*} {publicToken} Mapbox public token
|
|
260
178
|
* @returns modified config
|
|
261
179
|
*/
|
|
@@ -263,12 +181,16 @@ const {
|
|
|
263
181
|
config,
|
|
264
182
|
{ downloadToken, publicToken, staticPods }
|
|
265
183
|
) => {
|
|
184
|
+
if (downloadToken !== undefined) {
|
|
185
|
+
console.warn(
|
|
186
|
+
"@mapsindoors/react-native-maps-indoors-mapbox: `downloadToken` is deprecated and ignored. Mapbox SDK downloads need no token; remove it from your plugin config."
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
266
190
|
const plugins = [
|
|
267
|
-
withGradleProps(downloadToken),
|
|
268
191
|
withAPIKeys(publicToken),
|
|
269
192
|
withMavenRepo,
|
|
270
193
|
withTokenInfoPlist(publicToken),
|
|
271
|
-
withiOSSecret(downloadToken),
|
|
272
194
|
withPodfile,
|
|
273
195
|
withStaticLinkage(staticPods),
|
|
274
196
|
];
|
|
@@ -401,9 +401,12 @@ public class DirectionsRendererModule: RCTEventEmitter {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
@objc public func setRoute(_ routeString: String, stopIcons: String, legIndex: NSNumber, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
405
|
-
//
|
|
406
|
-
|
|
404
|
+
@objc public func setRoute(_ routeString: String, stopIcons: String, legIndex: NSNumber, routeId: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
405
|
+
// The route `getRoute` kept, when JavaScript names one: only that instance carries the endpoints
|
|
406
|
+
// the directions Insights events report. Otherwise decoded here, off the main thread: a route can
|
|
407
|
+
// be large, and none of this touches the map.
|
|
408
|
+
guard let route = routeId.flatMap(keptRoutes.route(for:))
|
|
409
|
+
?? (try? JSONDecoder().decode(MPRouteInternal.self, from: Data(routeString.utf8))) else {
|
|
407
410
|
return doReject(reject, message: "Route could not be parsed")
|
|
408
411
|
}
|
|
409
412
|
|
|
@@ -9,6 +9,10 @@ import MapsIndoors
|
|
|
9
9
|
import MapsIndoorsCodable
|
|
10
10
|
import MapsIndoorsCore
|
|
11
11
|
|
|
12
|
+
/// The routes ``DirectionsServiceModule/getRoute`` returned, for ``DirectionsRendererModule/setRoute`` to
|
|
13
|
+
/// render as they are. Shared by the two modules, since neither can reach the other's instance.
|
|
14
|
+
let keptRoutes = RouteStore<MPRouteInternal>(capacity: 10)
|
|
15
|
+
|
|
12
16
|
@objc(DirectionsService)
|
|
13
17
|
public class DirectionsServiceModule: NSObject {
|
|
14
18
|
var directionsVariables = [String: DirectionsVariables]()
|
|
@@ -110,11 +114,13 @@ public class DirectionsServiceModule: NSObject {
|
|
|
110
114
|
Task {
|
|
111
115
|
do {
|
|
112
116
|
if let route = try await MPMapsIndoors.shared.directionsService.routingWith(query: query) {
|
|
113
|
-
|
|
117
|
+
let internalRoute = route as? MPRouteInternal
|
|
118
|
+
if let routeData = try? JSONEncoder().encode(internalRoute) {
|
|
114
119
|
let routeRoute = String(data: routeData, encoding: String.Encoding.utf8)
|
|
115
120
|
var map = [String: String]()
|
|
116
121
|
map["route"] = routeRoute
|
|
117
122
|
map["error"] = "null"
|
|
123
|
+
map["routeId"] = internalRoute.map(keptRoutes.keep)
|
|
118
124
|
return resolve(map)
|
|
119
125
|
} else {
|
|
120
126
|
return doReject(reject, message: "Route could not be parsed")
|
|
@@ -172,7 +172,8 @@ public class MapControlModule: RCTEventEmitter {
|
|
|
172
172
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
173
173
|
) {
|
|
174
174
|
onMainThread {
|
|
175
|
-
|
|
175
|
+
guard let mapControl = self.requireMapControl(reject) else { return }
|
|
176
|
+
resolve(mapControl.showUserPosition)
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
|
|
@@ -449,7 +450,8 @@ public class MapControlModule: RCTEventEmitter {
|
|
|
449
450
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
450
451
|
) {
|
|
451
452
|
onMainThread {
|
|
452
|
-
|
|
453
|
+
guard let mapControl = self.requireMapControl(reject) else { return }
|
|
454
|
+
resolve(mapControl.currentFloorIndex)
|
|
453
455
|
}
|
|
454
456
|
}
|
|
455
457
|
|
|
@@ -458,7 +460,8 @@ public class MapControlModule: RCTEventEmitter {
|
|
|
458
460
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
459
461
|
) {
|
|
460
462
|
onMainThread {
|
|
461
|
-
|
|
463
|
+
guard let mapControl = self.requireMapControl(reject) else { return }
|
|
464
|
+
resolve(mapControl.cameraPosition.zoom)
|
|
462
465
|
}
|
|
463
466
|
}
|
|
464
467
|
|
|
@@ -479,7 +482,8 @@ public class MapControlModule: RCTEventEmitter {
|
|
|
479
482
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
480
483
|
) {
|
|
481
484
|
onMainThread {
|
|
482
|
-
|
|
485
|
+
guard let mapControl = self.requireMapControl(reject) else { return }
|
|
486
|
+
resolve(mapControl.hideFloorSelector)
|
|
483
487
|
}
|
|
484
488
|
}
|
|
485
489
|
|
|
@@ -35,8 +35,22 @@ public class MapsIndoorsModule: RCTEventEmitter {
|
|
|
35
35
|
/// Keeps the `cacheData` delegate alive while a dataset sync runs - see the note in `cacheData`.
|
|
36
36
|
private var datasetDelegate: DatasetDelegate?
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
/// Names this wrapper as the component behind the MapsIndoors Insights session, so React Native
|
|
39
|
+
/// apps are told apart from native ones in the rollups.
|
|
40
|
+
///
|
|
41
|
+
/// The SDK stamps the component into the session when the session starts, inside `load`, so this
|
|
42
|
+
/// has to run on the same call, right before it. The version comes from JS, which reads it from
|
|
43
|
+
/// the map package's own package.json.
|
|
44
|
+
private func setReactNativeComponent(_ sdkVersion: String?) {
|
|
45
|
+
MPLogger.sharedInstance.component = "React Native/iOS SDK"
|
|
46
|
+
MPLogger.sharedInstance.componentVersion = sdkVersion ?? "unknown"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc(loadMapsIndoors:optionalStrings:sdkVersion:resolver:rejecter:)
|
|
50
|
+
func loadMapsIndoors(apiKey: String, optionalStrings: [String]?, sdkVersion: String?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
51
|
+
setReactNativeComponent(sdkVersion)
|
|
52
|
+
keptRoutes.removeAll()
|
|
53
|
+
|
|
40
54
|
Task {
|
|
41
55
|
do {
|
|
42
56
|
if optionalStrings != nil {
|
|
@@ -211,6 +225,7 @@ public class MapsIndoorsModule: RCTEventEmitter {
|
|
|
211
225
|
|
|
212
226
|
positionProvider = provider
|
|
213
227
|
MPMapsIndoors.shared.positionProvider = positionProvider
|
|
228
|
+
setOnMapControl(provider)
|
|
214
229
|
|
|
215
230
|
return resolve(nil)
|
|
216
231
|
}
|
|
@@ -218,10 +233,25 @@ public class MapsIndoorsModule: RCTEventEmitter {
|
|
|
218
233
|
@objc public func removePositionProvider(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
219
234
|
positionProvider = nil
|
|
220
235
|
MPMapsIndoors.shared.positionProvider = nil
|
|
236
|
+
setOnMapControl(nil)
|
|
221
237
|
|
|
222
238
|
return resolve(nil)
|
|
223
239
|
}
|
|
224
240
|
|
|
241
|
+
/// Hands the provider to this wrapper's map control directly, not only through the SDK.
|
|
242
|
+
///
|
|
243
|
+
/// The SDK passes `MPMapsIndoors.shared.positionProvider` on only to the map controls it has
|
|
244
|
+
/// registered, and every `load` clears that registry. The wrapper keeps its existing map control
|
|
245
|
+
/// across a reload (`initMapControl` returns early), so after a second `load` the control is no
|
|
246
|
+
/// longer registered, the provider's delegate is never set, and the blue dot never shows
|
|
247
|
+
/// (MS-3929). Setting it here wires the delegate whatever the SDK's registry holds; for a
|
|
248
|
+
/// registered control it is the same assignment the SDK makes.
|
|
249
|
+
private func setOnMapControl(_ provider: MPPositionProvider?) {
|
|
250
|
+
onMainThread {
|
|
251
|
+
MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.positionProvider = provider
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
225
255
|
@objc public func onPositionUpdate(_ positionJSON: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
226
256
|
do {
|
|
227
257
|
let positionResult: MPPositionResult = try fromJSON(positionJSON)
|
|
@@ -290,6 +320,7 @@ public class MapsIndoorsModule: RCTEventEmitter {
|
|
|
290
320
|
}
|
|
291
321
|
|
|
292
322
|
@objc public func destroy(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
323
|
+
keptRoutes.removeAll()
|
|
293
324
|
Task {
|
|
294
325
|
MPMapsIndoors.shared.shutdown()
|
|
295
326
|
MapsIndoorsData.sharedInstance.isInitialized = false
|
|
@@ -5,17 +5,16 @@ public class ReactPositionProvider: MPPositionProvider {
|
|
|
5
5
|
public var latestPosition: MapsIndoors.MPPositionResult?
|
|
6
6
|
|
|
7
7
|
public var name = "default"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
init() {
|
|
12
|
-
mapsIndoorsData = MapsIndoorsData.sharedInstance
|
|
13
|
-
}
|
|
8
|
+
// Weak: the delegate is the map control, which holds this provider. Strong, the pair kept each
|
|
9
|
+
// other, and the map, alive after the map view was gone (SPEX-2885).
|
|
10
|
+
public weak var delegate: MapsIndoors.MPPositionProviderDelegate?
|
|
14
11
|
|
|
15
12
|
public func setLatestPosition(positionResult: MPPositionResult) {
|
|
16
13
|
DispatchQueue.main.async {
|
|
17
14
|
if self.latestPosition?.floorIndex != positionResult.floorIndex {
|
|
18
|
-
|
|
15
|
+
// Read per call, not kept: every new map view resets `sharedInstance`, and a kept
|
|
16
|
+
// instance closed the cycle provider -> data -> map view -> map control -> provider.
|
|
17
|
+
let floorSelector = MapsIndoorsData.sharedInstance.floorSelector
|
|
19
18
|
floorSelector?.onUserPositionFloorChange(floorIndex: positionResult.floorIndex)
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RouteStore.swift
|
|
3
|
+
// react-native-maps-indoors
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
/// Keeps the routes the directions service module returned, so the renderer module can render the
|
|
9
|
+
/// very instance instead of decoding the copy that comes back from JavaScript (SPEX-2782).
|
|
10
|
+
///
|
|
11
|
+
/// Only that instance carries the endpoints the SDK reports with the directions Insights events,
|
|
12
|
+
/// and neither SDK encodes them, so a decoded copy reports none.
|
|
13
|
+
///
|
|
14
|
+
/// Holds at most `capacity` routes and forgets the least recently used, since JavaScript never says
|
|
15
|
+
/// when it is done with one. A forgotten route still renders, from its JSON, just without endpoints.
|
|
16
|
+
/// Lookups count as use, so a route the app keeps setting stays. Rendering a kept route again is
|
|
17
|
+
/// safe: the SDK resolves its endpoints once and reads them on every event.
|
|
18
|
+
final class RouteStore<Route>: @unchecked Sendable {
|
|
19
|
+
private let lock = NSLock()
|
|
20
|
+
private let capacity: Int
|
|
21
|
+
private var routes: [String: Route] = [:]
|
|
22
|
+
/// Keys in `routes`, least recently used first.
|
|
23
|
+
private var order: [String] = []
|
|
24
|
+
|
|
25
|
+
init(capacity: Int) {
|
|
26
|
+
precondition(capacity > 0, "A RouteStore must be able to hold a route")
|
|
27
|
+
self.capacity = capacity
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// Keeps `route` and returns the key to look it up by.
|
|
31
|
+
func keep(_ route: Route) -> String {
|
|
32
|
+
let key = UUID().uuidString
|
|
33
|
+
lock.lock()
|
|
34
|
+
defer { lock.unlock() }
|
|
35
|
+
routes[key] = route
|
|
36
|
+
order.append(key)
|
|
37
|
+
if order.count > capacity {
|
|
38
|
+
routes[order.removeFirst()] = nil
|
|
39
|
+
}
|
|
40
|
+
return key
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// The route kept under `key`, if it is still kept.
|
|
44
|
+
func route(for key: String) -> Route? {
|
|
45
|
+
lock.lock()
|
|
46
|
+
defer { lock.unlock() }
|
|
47
|
+
guard let route = routes[key], let index = order.firstIndex(of: key) else {
|
|
48
|
+
return nil
|
|
49
|
+
}
|
|
50
|
+
order.append(order.remove(at: index))
|
|
51
|
+
return route
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// Forgets every route, when MapsIndoors loads or is destroyed: a route belongs to the solution that
|
|
55
|
+
/// was loaded when it was requested.
|
|
56
|
+
func removeAll() {
|
|
57
|
+
lock.lock()
|
|
58
|
+
defer { lock.unlock() }
|
|
59
|
+
routes.removeAll()
|
|
60
|
+
order.removeAll()
|
|
61
|
+
}
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapsindoors/react-native-maps-indoors-mapbox",
|
|
3
3
|
"title": "React Native MapsIndoors Mapbox",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.10.0",
|
|
5
5
|
"description": "React Native MapsIndoors component with mapbox",
|
|
6
6
|
"react-native": "index.ts",
|
|
7
7
|
"files": [
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"app.plugin.js"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"test": "
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"test:watch": "jest --watch"
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
|
26
27
|
"type": "git",
|
|
@@ -44,7 +45,10 @@
|
|
|
44
45
|
"react-native": ">=0.75.0 <1.0.x"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
48
|
+
"@types/jest": "^29.5.14",
|
|
47
49
|
"@types/react": "^19.0.0",
|
|
50
|
+
"jest": "^29.7.0",
|
|
51
|
+
"ts-jest": "^29.4.12",
|
|
48
52
|
"typedoc": "^0.24.8",
|
|
49
53
|
"typescript": "^5.0.4"
|
|
50
54
|
},
|
|
@@ -13,7 +13,7 @@ export interface Spec extends TurboModule {
|
|
|
13
13
|
setCameraViewFitMode(cameraFitMode: number): Promise<null>;
|
|
14
14
|
setCameraAnimationDuration(duration: number): Promise<null>;
|
|
15
15
|
setOnLegSelectedListener(): Promise<null>;
|
|
16
|
-
setRoute(routeString: string, stopIcons: string, legIndex: number): Promise<null>;
|
|
16
|
+
setRoute(routeString: string, stopIcons: string, legIndex: number, routeId: string | null): Promise<null>;
|
|
17
17
|
setAnimatedPolyline(animated: boolean, repeated: boolean, duration: number): Promise<null>;
|
|
18
18
|
setPolyLineColors(foregroundString: string, backgroundString: string): Promise<null>;
|
|
19
19
|
setOptions(optionsString: string): Promise<null>;
|
|
@@ -4,7 +4,7 @@ import {TurboModuleRegistry} from 'react-native';
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
5
|
addListener(eventName: string): void;
|
|
6
6
|
removeListeners(count: number): void;
|
|
7
|
-
loadMapsIndoors(apiKey: string, optionalStrings: Array<string> | null): Promise<null>;
|
|
7
|
+
loadMapsIndoors(apiKey: string, optionalStrings: Array<string> | null, sdkVersion: string | null): Promise<null>;
|
|
8
8
|
getDefaultVenue(): Promise<string | null>;
|
|
9
9
|
getVenues(): Promise<string>;
|
|
10
10
|
getBuildings(): Promise<string>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EmitterSubscription, NativeEventEmitter, NativeModules } from 'react-native';
|
|
2
2
|
import { MPCameraViewFitMode, MPDirectionsRendererOptions, MPError, MPRoute, OnLegSelectedListener } from "../../index";
|
|
3
3
|
import { EventNames } from './EventNames';
|
|
4
|
+
import { nativeRouteId } from './RouteHandles';
|
|
4
5
|
import { RouteStopIconConfig } from './RouteStopIconConfig';
|
|
5
6
|
|
|
6
7
|
const { DirectionsRenderer } = NativeModules;
|
|
@@ -104,6 +105,10 @@ export default class MPDirectionsRenderer {
|
|
|
104
105
|
/**
|
|
105
106
|
* Set a route to be rendered. This also resets the selected leg and step indices to 0.
|
|
106
107
|
*
|
|
108
|
+
* Directions analytics attribute the route to its origin and destination only when it has the
|
|
109
|
+
* content of a route {@link MPDirectionsService.getRoute} returned since MapsIndoors last loaded,
|
|
110
|
+
* among its ten most recently used. A copy made through JSON qualifies; an edited route does not.
|
|
111
|
+
*
|
|
107
112
|
* @public
|
|
108
113
|
* @async
|
|
109
114
|
* @param {?MPRoute} [route]
|
|
@@ -118,7 +123,8 @@ export default class MPDirectionsRenderer {
|
|
|
118
123
|
iconsAsString.set(index, encodeStopIcon(icon));
|
|
119
124
|
});
|
|
120
125
|
}
|
|
121
|
-
|
|
126
|
+
const routeJson = JSON.stringify(route);
|
|
127
|
+
await DirectionsRenderer.setRoute(routeJson, JSON.stringify(Object.fromEntries(iconsAsString.entries())), legIndex, nativeRouteId(routeJson));
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
2
|
import { MPError, MPPoint, MPRoute, MPHighway } from "../../index";
|
|
3
|
+
import { attachNativeRoute } from './RouteHandles';
|
|
3
4
|
|
|
4
5
|
const { DirectionsService } = NativeModules;
|
|
5
6
|
|
|
@@ -114,7 +115,9 @@ export default class MPDirectionsService {
|
|
|
114
115
|
res = await DirectionsService.getRoute(JSON.stringify(origin), JSON.stringify(destination), stopsAsJson, optimze, this.id);
|
|
115
116
|
}
|
|
116
117
|
if (res.route !== undefined) {
|
|
117
|
-
|
|
118
|
+
const route = MPRoute.create(JSON.parse(res.route));
|
|
119
|
+
attachNativeRoute(route, res.routeId);
|
|
120
|
+
return Promise.resolve(route);
|
|
118
121
|
} else {
|
|
119
122
|
return Promise.reject(MPError.create(JSON.parse(res.error)));
|
|
120
123
|
}
|