@mapsindoors/react-native-maps-indoors-mapbox 1.2.1 → 1.3.1

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.
Files changed (33) hide show
  1. package/README.md +1 -1
  2. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  3. package/android/.gradle/7.4/checksums/md5-checksums.bin +0 -0
  4. package/android/.gradle/7.4/checksums/sha1-checksums.bin +0 -0
  5. package/android/.gradle/7.4/fileHashes/fileHashes.bin +0 -0
  6. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  7. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  8. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  9. package/android/.gradle/file-system.probe +0 -0
  10. package/android/.idea/vcs.xml +1 -1
  11. package/android/build.gradle +3 -2
  12. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +94 -3
  13. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -2
  14. package/android/src/main/java/com/mapsindoorsrn/core/models/BitmapStopIconConfig.java +22 -0
  15. package/android/src/main/java/com/mapsindoorsrn/core/models/RouteStopIconConfigModel.java +35 -0
  16. package/index.ts +8 -1
  17. package/ios/MapsIndoorsViewManager.swift +1 -3
  18. package/ios/core/DirectionsRendererBridge.m +5 -1
  19. package/ios/core/DirectionsRendererModule.swift +80 -8
  20. package/ios/core/DirectionsServiceBridge.m +2 -0
  21. package/ios/core/DirectionsServiceModule.swift +11 -3
  22. package/ios/core/IconStopUrl.swift +17 -0
  23. package/ios/core/RouteIcon.swift +34 -0
  24. package/package.json +1 -1
  25. package/react-native-maps-indoors-mapbox.podspec +2 -2
  26. package/src/core/MPDirectionsRenderer.ts +28 -2
  27. package/src/core/MPDirectionsService.ts +10 -2
  28. package/src/core/MPRoute.ts +10 -0
  29. package/src/core/MPRouteLeg.ts +30 -0
  30. package/src/core/MPRouteStopIconConfig.ts +82 -0
  31. package/src/core/RouteStopIconConfig.ts +10 -0
  32. package/android/libs/core-4.3.0.aar +0 -0
  33. package/android/libs/mapbox-4.3.0.aar +0 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Documentation
4
4
 
5
- Visit [our reference document site](https://app.mapsindoors.com/mapsindoors/reference/react-native/mapbox/1.2.1/index.html) to get an overview of what the MapsIndoors SDK offers.
5
+ Visit [our reference document site](https://app.mapsindoors.com/mapsindoors/reference/react-native/mapbox/1.3.0/index.html) to get an overview of what the MapsIndoors SDK offers.
6
6
 
7
7
  ## Getting started
8
8
 
Binary file
@@ -3,6 +3,6 @@
3
3
  <component name="VcsDirectoryMappings">
4
4
  <mapping directory="$USER_HOME$" vcs="Git" />
5
5
  <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
6
- <mapping directory="$PROJECT_DIR$/src/main/java/com/reactlibrary/core" vcs="Git" />
6
+ <mapping directory="$PROJECT_DIR$/src/main/java/com/mapsindoorsrn/core" vcs="Git" />
7
7
  </component>
8
8
  </project>
@@ -92,10 +92,11 @@ dependencies {
92
92
  }
93
93
  }
94
94
 
95
- implementation 'com.mapbox.maps:android:10.14.1'
96
- implementation 'com.mapspeople.mapsindoors:mapbox:4.7.2'
95
+ implementation 'com.mapbox.maps:android:10.17.1'
96
+ implementation 'com.mapspeople.mapsindoors:mapbox:4.8.3'
97
97
  implementation 'com.facebook.react:react-native:+' // From node_modules
98
98
  implementation 'androidx.core:core-ktx:1.3.2'
99
+ implementation 'com.github.bumptech.glide:glide:4.16.0'
99
100
  }
100
101
 
101
102
  def configureReactNativePom(def pom) {
@@ -1,10 +1,15 @@
1
1
  package com.mapsindoorsrn.core;
2
2
 
3
+ import android.content.Context;
4
+ import android.graphics.Bitmap;
3
5
  import android.graphics.Color;
6
+ import android.os.Handler;
4
7
 
5
8
  import androidx.annotation.NonNull;
6
9
  import androidx.annotation.Nullable;
7
10
 
11
+ import com.bumptech.glide.Glide;
12
+ import com.bumptech.glide.request.FutureTarget;
8
13
  import com.facebook.react.bridge.Arguments;
9
14
  import com.facebook.react.bridge.Promise;
10
15
  import com.facebook.react.bridge.ReactApplicationContext;
@@ -12,22 +17,36 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
12
17
  import com.facebook.react.bridge.ReactMethod;
13
18
  import com.facebook.react.bridge.WritableMap;
14
19
  import com.facebook.react.modules.core.DeviceEventManagerModule;
20
+ import com.facebook.react.bridge.ReadableArray;
15
21
  import com.google.gson.Gson;
22
+ import com.google.gson.reflect.TypeToken;
16
23
  import com.mapsindoors.core.MPCameraViewFitMode;
17
24
  import com.mapsindoors.core.MPDirectionsRenderer;
18
25
  import com.mapsindoors.core.MPRoute;
26
+ import com.mapsindoors.core.MPRouteStopIconProvider;
19
27
  import com.mapsindoors.core.MapControl;
20
28
  import com.mapsindoors.core.OnMapControlReadyListener;
21
29
  import com.mapsindoors.core.errors.MIError;
22
30
  import com.mapsindoors.core.errors.MIErrorEnum;
23
31
  import com.mapsindoors.core.errors.MapsIndoorsException;
32
+ import com.mapsindoorsrn.core.models.BitmapStopIconConfig;
24
33
  import com.mapsindoorsrn.core.models.MPError;
34
+ import com.mapsindoorsrn.core.models.RouteStopIconConfigModel;
35
+
36
+ import java.util.ArrayList;
37
+ import java.util.HashMap;
38
+ import java.util.List;
39
+ import java.util.Map;
40
+ import java.util.regex.Matcher;
41
+ import java.util.regex.Pattern;
25
42
 
26
43
 
27
44
  public class DirectionsRendererModule extends ReactContextBaseJavaModule implements OnMapControlReadyListener {
28
45
  private MapControl mMapControl;
29
46
  private MPDirectionsRenderer mRenderer;
30
47
  private final ReactApplicationContext mCtx;
48
+ private final Gson gson = new Gson();
49
+
31
50
 
32
51
  public DirectionsRendererModule(@NonNull ReactApplicationContext reactContext, MapControlModule mapControl) {
33
52
  super(reactContext);
@@ -189,11 +208,76 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
189
208
  }
190
209
 
191
210
  @ReactMethod
192
- public void setRoute(String routeString, final Promise promise) {
211
+ public void setRoute(String routeString, String icons, final Promise promise) {
193
212
  if (mRenderer != null) {
213
+ Context ctx = mCtx.getApplicationContext();
194
214
  MPRoute route = new Gson().fromJson(routeString, MPRoute.class);
195
- mRenderer.setRoute(route);
196
- promise.resolve(null);
215
+ if (icons != null) {
216
+ new Handler().post(()-> {
217
+ HashMap<Integer, String> iconsMap = gson.fromJson(icons, new TypeToken<HashMap<Integer, String>>(){}.getType());
218
+ HashMap<Integer, MPRouteStopIconProvider> iconConfigs = new HashMap<>();
219
+ for (Map.Entry<Integer, String> mapEntry : iconsMap.entrySet()) {
220
+ String icon = mapEntry.getValue();
221
+ if (icon == null) {
222
+ iconConfigs.put(mapEntry.getKey(), null);
223
+ } else if (isUrl(icon)) {
224
+ FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(icon).submit();
225
+ try {
226
+ BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
227
+ iconConfigs.put(mapEntry.getKey(), iconConfig);
228
+ } catch (Exception e) {
229
+ promise.reject("something went wrong loading the image for " + icon, e);
230
+ return;
231
+ }
232
+ }else {
233
+ String json = icon.substring(0, icon.length() - 1);
234
+ RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
235
+ iconConfigs.put(mapEntry.getKey(), iconConfig.toMPRouteStopIconConfig(ctx));
236
+ }
237
+ }
238
+ mRenderer.setRoute(route, iconConfigs);
239
+ promise.resolve(null);
240
+ });
241
+ }else {
242
+ mRenderer.setRoute(route);
243
+ promise.resolve(null);
244
+ }
245
+ } else {
246
+ rejectPromise(promise);
247
+ }
248
+ }
249
+
250
+ @ReactMethod
251
+ public void setDefaultRouteStopIcon(String iconString, final Promise promise) {
252
+ if (mRenderer != null) {
253
+ //Create icon from url
254
+ if (iconString != null) {
255
+ //Handle icon
256
+ new Handler().post(()-> {
257
+ Context ctx = mCtx.getApplicationContext();
258
+ if (iconString == null || iconString.equals("null") || iconString.isEmpty()) {
259
+ mRenderer.setDefaultRouteStopIconConfig(null);
260
+ promise.resolve(null);
261
+ } else if (isUrl(iconString)) {
262
+ FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(iconString).submit();
263
+ try {
264
+ BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
265
+ mRenderer.setDefaultRouteStopIconConfig(iconConfig);
266
+ promise.resolve(null);
267
+ } catch (Exception e) {
268
+ promise.reject("something went wrong loading the image", e);
269
+ }
270
+ } else {
271
+ String json = iconString.substring(0, iconString.length() - 1);
272
+ RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
273
+ mRenderer.setDefaultRouteStopIconConfig(iconConfig.toMPRouteStopIconConfig(ctx));
274
+ promise.resolve(null);
275
+ }
276
+ });
277
+ }else {
278
+ mRenderer.setDefaultRouteStopIconConfig(null);
279
+ promise.resolve(null);
280
+ }
197
281
  } else {
198
282
  rejectPromise(promise);
199
283
  }
@@ -215,4 +299,11 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
215
299
  public void removeListeners(Integer count) {
216
300
  // we are handling listeners ourselves
217
301
  }
302
+
303
+ private boolean isUrl(String url) {
304
+ String regex = "^(http|https)://.*$";
305
+ Pattern pattern = Pattern.compile(regex);
306
+ Matcher matcher = pattern.matcher(url);
307
+ return matcher.matches();
308
+ }
218
309
  }
@@ -8,13 +8,16 @@ import com.facebook.react.bridge.ReactApplicationContext;
8
8
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
9
9
  import com.facebook.react.bridge.ReactMethod;
10
10
  import com.facebook.react.bridge.WritableMap;
11
+ import com.facebook.react.bridge.ReadableArray;
11
12
  import com.google.gson.Gson;
12
13
  import com.mapsindoors.core.MPDirectionsService;
13
14
  import com.mapsindoors.core.MPPoint;
14
15
  import com.mapsindoors.core.errors.MapsIndoorsException;
15
16
 
17
+ import java.util.ArrayList;
16
18
  import java.util.Date;
17
19
  import java.util.HashMap;
20
+ import java.util.List;
18
21
  import java.util.UUID;
19
22
 
20
23
  public class DirectionsServiceModule extends ReactContextBaseJavaModule {
@@ -91,7 +94,7 @@ public class DirectionsServiceModule extends ReactContextBaseJavaModule {
91
94
  }
92
95
 
93
96
  @ReactMethod
94
- public void getRoute(String originString, String destinationString, final String id, final Promise promise) {
97
+ public void getRoute(String originString, String destinationString, ReadableArray stops, boolean optimized, final String id, final Promise promise) {
95
98
  MPDirectionsService service = serviceMap.get(id);
96
99
  if (service != null) {
97
100
  service.setRouteResultListener((route, error) -> {
@@ -107,8 +110,19 @@ public class DirectionsServiceModule extends ReactContextBaseJavaModule {
107
110
  MPPoint origin = gson.fromJson(originString, MPPoint.class);
108
111
  MPPoint destination = gson.fromJson(destinationString, MPPoint.class);
109
112
 
113
+ List<MPPoint> points = new ArrayList<>();
114
+ if (stops != null) {
115
+ for (int i = 0; i < stops.size(); i++) {
116
+ points.add(gson.fromJson(stops.getString(i), MPPoint.class));
117
+ }
118
+ }
119
+
110
120
  if (origin != null && destination != null) {
111
- service.query(origin, destination);
121
+ if (!points.isEmpty()) {
122
+ service.query(origin, destination, points, optimized);
123
+ } else {
124
+ service.query(origin, destination);
125
+ }
112
126
  } else {
113
127
  promise.reject(new MapsIndoorsException("Origin:" + originString +
114
128
  ", or Destination:" + destinationString + ", are not parsable"));
@@ -0,0 +1,22 @@
1
+ package com.mapsindoorsrn.core.models;
2
+
3
+ import android.graphics.Bitmap;
4
+
5
+ import androidx.annotation.Nullable;
6
+
7
+ import com.mapsindoors.core.MPRouteStopIconProvider;
8
+
9
+ public class BitmapStopIconConfig extends MPRouteStopIconProvider {
10
+
11
+ private final Bitmap bitmap;
12
+
13
+ public BitmapStopIconConfig(Bitmap bitmap) {
14
+ this.bitmap = bitmap;
15
+ }
16
+
17
+ @Nullable
18
+ @Override
19
+ public Bitmap getImage() {
20
+ return bitmap;
21
+ }
22
+ }
@@ -0,0 +1,35 @@
1
+ package com.mapsindoorsrn.core.models;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.Color;
5
+
6
+ import androidx.annotation.Nullable;
7
+
8
+ import com.google.gson.annotations.SerializedName;
9
+ import com.mapsindoors.core.MPRouteStopIconConfig;
10
+
11
+ public class RouteStopIconConfigModel {
12
+ @Nullable
13
+ @SerializedName("numbered")
14
+ private Boolean numbered;
15
+ @Nullable
16
+ @SerializedName("color")
17
+ private String color;
18
+ @Nullable
19
+ @SerializedName("label")
20
+ private String label;
21
+
22
+ public MPRouteStopIconConfig toMPRouteStopIconConfig(Context context) {
23
+ MPRouteStopIconConfig.Builder builder = new MPRouteStopIconConfig.Builder(context);
24
+ if (numbered != null) {
25
+ builder.setNumbered(numbered);
26
+ }
27
+ if (color != null) {
28
+ builder.setColor(Color.parseColor(color));
29
+ }
30
+ if (label != null) {
31
+ builder.setLabel(label);
32
+ }
33
+ return builder.build();
34
+ }
35
+ }
package/index.ts CHANGED
@@ -64,6 +64,7 @@ import MPBuildingCollection from './src/core/MPBuildingCollection';
64
64
  import MPVenueCollection from './src/core/MPVenueCollection';
65
65
  import MPCategoryCollection from './src/core/MPCategoryCollection';
66
66
  import MPUserRoleCollection from './src/core/MPUserRoleCollection';
67
+ import MPRouteStopIconConfig from './src/core/MPRouteStopIconConfig';
67
68
  import { MPHighway } from './src/core/MPHighway';
68
69
  import { MPFloorParams } from './src/core/MPFloor';
69
70
  import { MPQueryParams } from './src/core/MPQuery';
@@ -90,6 +91,9 @@ import { MPFilterBehaviorParams } from './src/core/MPFilterBehavior';
90
91
  import { MPSolutionConfigParams } from './src/core/MPSolutionConfig';
91
92
  import { MPRouteCoordinateParams } from './src/core/MPRouteCoordinate';
92
93
  import { MPHighlightBehaviorParams } from './src/core/MPHighlightBehavior';
94
+ import { RouteStopIconConfig } from './src/core/RouteStopIconConfig';
95
+ import { MPRouteStopIconConfigParams } from './src/core/MPRouteStopIconConfig';
96
+
93
97
  import MapView from './src/core/MapView';
94
98
 
95
99
 
@@ -145,6 +149,7 @@ export {
145
149
  MPBadgePosition,
146
150
  MPIconPlacement,
147
151
  MPLabelType,
152
+ MPRouteStopIconConfig,
148
153
  MapView
149
154
  };
150
155
 
@@ -189,5 +194,7 @@ export type {
189
194
  MPFilterBehaviorParams,
190
195
  MPHighlightBehaviorParams,
191
196
  MPSolutionConfigParams,
192
- MPRouteCoordinateParams
197
+ MPRouteCoordinateParams,
198
+ MPRouteStopIconConfigParams,
199
+ RouteStopIconConfig
193
200
  };
@@ -71,9 +71,7 @@ struct MapBoxView: RCMapView {
71
71
  update = CameraOptions(cameraState: camera)
72
72
  update.center = position.target.coordinate
73
73
  update.bearing = CLLocationDirection(position.bearing)
74
- if (cameraUpdate.zoom != nil) {
75
- update.zoom = CGFloat(cameraUpdate.zoom!)
76
- }
74
+ update.zoom = CGFloat(position.zoom)
77
75
  default:
78
76
  throw CameraUpdateError.unknownMode(cameraUpdate.mode)
79
77
  }
@@ -45,6 +45,7 @@
45
45
  rejecter:(RCTPromiseRejectBlock) reject)
46
46
 
47
47
  RCT_EXTERN_METHOD(setRoute: (NSString *) routeString
48
+ stopIcons:(NSString *) stopIcons
48
49
  resolver:(RCTPromiseResolveBlock) resolve
49
50
  rejecter:(RCTPromiseRejectBlock) reject)
50
51
 
@@ -54,8 +55,11 @@
54
55
  resolver:(RCTPromiseResolveBlock) resolve
55
56
  rejecter:(RCTPromiseRejectBlock) reject)
56
57
 
57
- RCT_EXTERN_METHOD(showRouteLegButtons: (BOOL) value
58
+ RCT_EXTERN_METHOD(showRouteLegButtons: (BOOL) value
58
59
  resolver:(RCTPromiseResolveBlock) resolve
59
60
  rejecter:(RCTPromiseRejectBlock) reject)
60
61
 
62
+ RCT_EXTERN_METHOD(setDefaultRouteStopIcon: (NSString *) iconString
63
+ resolver:(RCTPromiseResolveBlock) resolve
64
+ rejecter:(RCTPromiseRejectBlock) reject)
61
65
  @end
@@ -5,6 +5,7 @@
5
5
  // Created by Tim Mikkelsen on 01/05/2023.
6
6
  //
7
7
 
8
+ import MapsIndoorsCore
8
9
  import MapsIndoors
9
10
  import MapsIndoorsCodable
10
11
  import React
@@ -237,6 +238,41 @@ public class DirectionsRendererModule: RCTEventEmitter {
237
238
  directionsRenderer.fitMode = camFitMode!
238
239
  return resolve(nil)
239
240
  }
241
+
242
+ @objc public func setDefaultRouteStopIcon(_ defaultIcon: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
243
+ if (MapsIndoorsData.sharedInstance.directionsRenderer == nil) {
244
+ MapsIndoorsData.sharedInstance.directionsRenderer = MapsIndoorsData.sharedInstance.mapControl?.newDirectionsRenderer()
245
+ }
246
+
247
+ let directionsRenderer = MapsIndoorsData.sharedInstance.directionsRenderer
248
+
249
+ guard let directionsRenderer else {
250
+ return doReject(reject, message: "directions renderer null. MapControl needs to have been instantiated first")
251
+ }
252
+
253
+ Task {
254
+ if (isValidUrl(defaultIcon)) {
255
+ let test = IconStopUrl(image: try await downloadImage(from: URL(string: defaultIcon)!))
256
+ directionsRenderer.defaultRouteStopIcon = IconStopUrl(image: try await downloadImage(from: URL(string: defaultIcon)!))
257
+ }else {
258
+ do {
259
+ var deficon = defaultIcon
260
+ deficon.removeLast()
261
+ let iconConfig = try JSONDecoder().decode(RouteIcon.self, from: deficon.data(using: .utf8)!)
262
+ if (iconConfig != nil) {
263
+ directionsRenderer.defaultRouteStopIcon = iconConfig.getIcon()
264
+ }else {
265
+ directionsRenderer.defaultRouteStopIcon = nil
266
+ }
267
+ }catch {
268
+ print(error)
269
+ }
270
+
271
+ }
272
+
273
+ resolve(nil)
274
+ }
275
+ }
240
276
 
241
277
  @objc public func setOnLegSelectedListener(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
242
278
  isListeningForLegChanges = true
@@ -247,7 +283,7 @@ public class DirectionsRendererModule: RCTEventEmitter {
247
283
  return resolve(nil)
248
284
  }
249
285
 
250
- @objc public func setRoute(_ routeString: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
286
+ @objc public func setRoute(_ routeString: String, stopIcons: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
251
287
  if (MapsIndoorsData.sharedInstance.directionsRenderer == nil) {
252
288
  MapsIndoorsData.sharedInstance.directionsRenderer = MapsIndoorsData.sharedInstance.mapControl?.newDirectionsRenderer()
253
289
  }
@@ -261,16 +297,52 @@ public class DirectionsRendererModule: RCTEventEmitter {
261
297
 
262
298
  directionsRenderer.padding = MapsIndoorsData.sharedInstance.mapControl!.mapPadding
263
299
 
264
- guard let route = try? JSONDecoder().decode(MPRouteCodable.self, from: Data(routeString.utf8)) else {
300
+ guard let route = try? JSONDecoder().decode(MPRouteInternal.self, from: Data(routeString.utf8)) else {
265
301
  return doReject(reject, message: "Route could not be parsed")
266
302
  }
303
+
304
+ Task {
305
+ var stopIconss: [Int: String]? = nil
306
+ stopIconss = try? JSONDecoder().decode([Int: String].self, from: Data(stopIcons.utf8))
307
+
308
+ var icons: [Int : any MPRouteStopIconProvider] = [:]
309
+ if (stopIconss != nil) {
310
+ for icon in stopIconss! {
311
+ if (isValidUrl(icon.value)) {
312
+ icons[icon.key] = IconStopUrl(image: try await downloadImage(from: URL(string: icon.value)!))
313
+ }else {
314
+ var ic = icon.value
315
+ ic.removeLast()
316
+ let iconConfig = try? JSONDecoder().decode(RouteIcon.self, from: ic.data(using: .utf8)!)
317
+ if (iconConfig != nil) {
318
+ icons[icon.key] = iconConfig!.getIcon()
319
+ }
320
+ }
321
+ }
322
+ }
323
+
267
324
 
268
- DispatchQueue.main.sync {
269
- directionsRenderer.route = route
270
- directionsRenderer.routeLegIndex = 0
271
- directionsRenderer.animate(duration: animationDuration.doubleValue)
272
- }
325
+ DispatchQueue.main.sync {
326
+ directionsRenderer.route = route
327
+ directionsRenderer.routeLegIndex = 0
328
+ directionsRenderer.render(stopIcons: icons)
329
+ }
273
330
 
274
- resolve(nil)
331
+ resolve(nil)
332
+ }
333
+ }
334
+
335
+
336
+ func downloadImage(from url: URL) async throws -> UIImage {
337
+ let (data, _) = try await URLSession.shared.data(from: url)
338
+ return UIImage(data: data)!
275
339
  }
340
+
341
+ func isValidUrl(_ urlString: String) -> Bool {
342
+ if let url = URL(string: urlString) {
343
+ return url.scheme != nil && url.host != nil
344
+ }
345
+ return false
346
+ }
347
+
276
348
  }
@@ -34,6 +34,8 @@
34
34
 
35
35
  RCT_EXTERN_METHOD(getRoute: (NSString *) originString
36
36
  destinationString: (NSString *) destinationString
37
+ stopsString: (NSArray<NSString *> _Nullable) stopsString
38
+ optimize: (BOOL) optimize
37
39
  id: (NSString *) id
38
40
  resolver:(RCTPromiseResolveBlock) resolve
39
41
  rejecter:(RCTPromiseRejectBlock) reject)
@@ -63,7 +63,7 @@ public class DirectionsServiceModule: NSObject {
63
63
  directionsVars.excludeWayTypes.removeAll()
64
64
  }
65
65
 
66
- @objc func getRoute(_ originString: String, destinationString: String, id: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
66
+ @objc func getRoute(_ originString: String, destinationString: String, stopsString: [String]?, optimize: Bool, id: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
67
67
 
68
68
  guard let directionsVars = directionsVariables[id] else {
69
69
  return doReject(reject, message: "directions service not found. Did you call create")
@@ -71,10 +71,16 @@ public class DirectionsServiceModule: NSObject {
71
71
 
72
72
  var origin: MPPoint? = nil
73
73
  var destination: MPPoint? = nil
74
+ var stops: [MPPoint]? = nil
74
75
 
75
76
  do {
76
77
  origin = try JSONDecoder().decode(MPPoint.self, from: Data(originString.utf8))
77
78
  destination = try JSONDecoder().decode(MPPoint.self, from: Data(destinationString.utf8))
79
+ if (stopsString != nil) {
80
+ stops = try stopsString!.map({
81
+ try JSONDecoder().decode(MPPoint.self, from: Data($0.utf8))
82
+ })
83
+ }
78
84
  } catch {
79
85
  return doReject(reject, message: "Unable to parse origin or destination point")
80
86
  }
@@ -85,6 +91,8 @@ public class DirectionsServiceModule: NSObject {
85
91
  query.avoidWayTypes = directionsVars.wayTypes
86
92
  }
87
93
 
94
+ query.stopsPoints = stops
95
+
88
96
  if(!directionsVars.excludeWayTypes.isEmpty) {
89
97
  query.avoidWayTypes = directionsVars.excludeWayTypes
90
98
  }
@@ -102,13 +110,13 @@ public class DirectionsServiceModule: NSObject {
102
110
  Task {
103
111
  let route = try await MPMapsIndoors.shared.directionsService.routingWith(query: query)
104
112
  if (route != nil) {
105
- let routeData = try? JSONEncoder().encode(MPRouteCodable(withRoute: route!))
113
+ let routeData = try? JSONEncoder().encode(route as! MPRouteInternal)
106
114
  if (routeData != nil) {
107
115
  let routeRoute = String(data: routeData!, encoding: String.Encoding.utf8)
108
116
  var map = Dictionary<String, String>()
109
117
  map["route"] = routeRoute
110
118
  map["error"] = "null"
111
- resolve(map)
119
+ return resolve(map)
112
120
  }else {
113
121
  return doReject(reject, message: "Route could not be parsed")
114
122
  }
@@ -0,0 +1,17 @@
1
+ //
2
+ // IconStopUrl.swift
3
+ // react-native-maps-indoors-mapbox
4
+ //
5
+ // Created by Tim Mikkelsen on 14/05/2024.
6
+ //
7
+
8
+ import Foundation
9
+ import MapsIndoors
10
+
11
+ public class IconStopUrl: MPRouteStopIconProvider {
12
+ public var image: UIImage?
13
+
14
+ init(image: UIImage) {
15
+ self.image = image
16
+ }
17
+ }
@@ -0,0 +1,34 @@
1
+ //
2
+ // RouteIcon.swift
3
+ // react-native-maps-indoors-mapbox
4
+ //
5
+ // Created by Tim Mikkelsen on 15/05/2024.
6
+ //
7
+
8
+ import MapsIndoorsCore
9
+ import Foundation
10
+
11
+ struct RouteIcon: Codable {
12
+ let numbered: Bool
13
+ let label: String
14
+ let color: String
15
+
16
+ public func getIcon() -> MPRouteStopIconConfig {
17
+ return MPRouteStopIconConfig(numbered: numbered, label: label, color: try! colorFromHexString(hex: color))
18
+ }
19
+
20
+ private func colorFromHexString(hex: String) throws -> UIColor {
21
+ let regex = try! NSRegularExpression(pattern: "^#[0-9A-Fa-f]{6}$|^#[0-9A-Fa-f]{8}$")
22
+ let range = NSRange(location: 0, length: hex.utf16.count)
23
+
24
+ if (regex.matches(in: hex, range: range).count == 1) {
25
+ return UIColor(hex: hex)!
26
+ } else {
27
+ throw HexParsingError.invalidHexString(hex)
28
+ }
29
+ }
30
+
31
+ enum HexParsingError: Error {
32
+ case invalidHexString(String)
33
+ }
34
+ }
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": "1.2.1",
4
+ "version": "1.3.1",
5
5
  "description": "React Native MapsIndoors component with mapbox",
6
6
  "react-native": "index.ts",
7
7
  "files": [
@@ -24,7 +24,7 @@ Pod::Spec.new do |s|
24
24
  s.requires_arc = true
25
25
 
26
26
  s.dependency "React"
27
- s.dependency "MapsIndoorsMapbox", "4.3.11"
28
- s.dependency "MapsIndoorsCodable", "4.3.11"
27
+ s.dependency "MapsIndoorsMapbox", "4.4.1"
28
+ s.dependency "MapsIndoorsCodable", "4.4.1"
29
29
  end
30
30
 
@@ -1,6 +1,7 @@
1
1
  import { EmitterSubscription, NativeEventEmitter, NativeModules } from 'react-native';
2
2
  import { MPCameraViewFitMode, MPError, MPRoute, OnLegSelectedListener } from "../../index";
3
3
  import { EventNames } from './EventNames';
4
+ import { RouteStopIconConfig } from './RouteStopIconConfig';
4
5
 
5
6
  const { DirectionsRenderer } = NativeModules;
6
7
 
@@ -12,6 +13,11 @@ const { DirectionsRenderer } = NativeModules;
12
13
  * @typedef {MPDirectionsRenderer}
13
14
  */
14
15
  export default class MPDirectionsRenderer {
16
+
17
+ private _defaultRouteStopIcon?: RouteStopIconConfig
18
+ get defaultRouteStopIcon(): RouteStopIconConfig {
19
+ return this._defaultRouteStopIcon;
20
+ }
15
21
  /**
16
22
  * Listener for leg selection events.
17
23
  *
@@ -81,10 +87,30 @@ export default class MPDirectionsRenderer {
81
87
  * @public
82
88
  * @async
83
89
  * @param {?MPRoute} [route]
90
+ * @param {RouteStopIconConfig[]} [stopIcons]
91
+ * @returns {Promise<void>}
92
+ */
93
+ public async setRoute(route: MPRoute, stopIcons: Map<number, RouteStopIconConfig> = null): Promise<void> {
94
+ var iconsAsString = new Map<number, string>();
95
+ if (stopIcons !== null) {
96
+ stopIcons.forEach((icon, index) => {
97
+ iconsAsString.set(index, icon.getImage().toString());
98
+ });
99
+ }
100
+ await DirectionsRenderer.setRoute(JSON.stringify(route), JSON.stringify(Object.fromEntries(iconsAsString.entries())));
101
+ }
102
+
103
+ /**
104
+ * Set the default icon for route stops.
105
+ *
106
+ * @public
107
+ * @async
108
+ * @param {RouteStopIconConfig} icon
84
109
  * @returns {Promise<void>}
85
110
  */
86
- public async setRoute(route: MPRoute): Promise<void> {
87
- await DirectionsRenderer.setRoute(JSON.stringify(route))
111
+ public async setDefaultRouteStopIcon(icon: RouteStopIconConfig): Promise<void> {
112
+ this._defaultRouteStopIcon = icon;
113
+ await DirectionsRenderer.setDefaultRouteStopIcon(icon.getImage().toString());
88
114
  }
89
115
 
90
116
  /**
@@ -101,10 +101,18 @@ export default class MPDirectionsService {
101
101
  * @async
102
102
  * @param {MPPoint} origin
103
103
  * @param {MPPoint} destination
104
+ * @param {MPPoint[]} [stops=null]
105
+ * @param {boolean} [optimze=false]
104
106
  * @returns {Promise<MPRoute>}
105
107
  */
106
- public async getRoute(origin: MPPoint, destination: MPPoint): Promise<MPRoute> {
107
- let res = await DirectionsService.getRoute(JSON.stringify(origin), JSON.stringify(destination), this.id);
108
+ public async getRoute(origin: MPPoint, destination: MPPoint, stops: MPPoint[] = null, optimze: boolean = false): Promise<MPRoute> {
109
+ var res;
110
+ if (stops === null) {
111
+ res = await DirectionsService.getRoute(JSON.stringify(origin), JSON.stringify(destination), stops, optimze, this.id);
112
+ }else {
113
+ let stopsAsJson = stops.map(stop => JSON.stringify(stop));
114
+ res = await DirectionsService.getRoute(JSON.stringify(origin), JSON.stringify(destination), stopsAsJson, optimze, this.id);
115
+ }
108
116
  if (res.route !== undefined) {
109
117
  return Promise.resolve(MPRoute.create(JSON.parse(res.route)));
110
118
  } else {
@@ -19,6 +19,7 @@ export default class MPRoute {
19
19
  * @param {?string[]} [warnings] Any warnings issued for any paths on the route.
20
20
  * @param {?string[]} [restrictions] All restrictions in place for the route.
21
21
  * @param {?MPBounds} [bounds] The outer bounds of the route.
22
+ * @param {?number[]} [orderedStopIndexes] The original indexes of the stops in the route.
22
23
  */
23
24
  private constructor(
24
25
  public readonly legs?: MPRouteLeg[],
@@ -27,6 +28,7 @@ export default class MPRoute {
27
28
  public readonly warnings?: string[],
28
29
  public readonly restrictions?: string[],
29
30
  public readonly bounds?: MPBounds,
31
+ public readonly ordered_stop_indexes?: number[],
30
32
  ) { }
31
33
 
32
34
  /**
@@ -44,6 +46,7 @@ export default class MPRoute {
44
46
  object?.warnings,
45
47
  object?.restrictions,
46
48
  object?.bounds ? MPBounds.create(object?.bounds) : undefined,
49
+ object?.ordered_stop_indexes,
47
50
  );
48
51
  }
49
52
  }
@@ -92,4 +95,11 @@ export interface MPRouteParams {
92
95
  * @type {?MPBoundsParams}
93
96
  */
94
97
  bounds?: MPBoundsParams,
98
+
99
+ /**
100
+ * The original indexes of the stops in the route.
101
+ *
102
+ * @type {?number[]}
103
+ */
104
+ ordered_stop_indexes?: number[],
95
105
  }
@@ -23,6 +23,9 @@ export default class MPRouteLeg {
23
23
  * @param {?string} [endAdress] The address at the end of the leg.
24
24
  * @param {?MPRouteCoordinate} [startLocation] The start coordinate of the leg.
25
25
  * @param {?MPRouteCoordinate} [endLocation] The end coordinate of the leg.
26
+ * @param {?string} [legStartReason] The reason for the start of the leg.
27
+ * @param {?string} [legEndReason] The reason for the end of the leg.
28
+ * @param {?number} [stopIndex] The index of the stop.
26
29
  */
27
30
  private constructor(
28
31
  public readonly steps?: MPRouteStep[],
@@ -32,6 +35,9 @@ export default class MPRouteLeg {
32
35
  public readonly endAdress?: string,
33
36
  public readonly startLocation?: MPRouteCoordinate,
34
37
  public readonly endLocation?: MPRouteCoordinate,
38
+ public readonly legStartReason?: string,
39
+ public readonly legEndReason?: string,
40
+ public readonly stopIndex?: number,
35
41
  ) { }
36
42
 
37
43
 
@@ -52,6 +58,9 @@ export default class MPRouteLeg {
52
58
  object?.end_address,
53
59
  MPRouteCoordinate.create(object?.start_location as MPRouteCoordinateParams),
54
60
  MPRouteCoordinate.create(object?.end_location as MPRouteCoordinateParams),
61
+ object?.leg_start_reason,
62
+ object?.leg_end_reason,
63
+ object?.stop_index,
55
64
  );
56
65
  }
57
66
 
@@ -71,6 +80,9 @@ export default class MPRouteLeg {
71
80
  steps: this.steps,
72
81
  distance: this.distance,
73
82
  duration: this.duration,
83
+ leg_start_reason: this.legStartReason,
84
+ leg_end_reason: this.legEndReason,
85
+ stop_index: this.stopIndex,
74
86
  };
75
87
  }
76
88
  }
@@ -125,4 +137,22 @@ export interface MPRouteLegParams {
125
137
  * @type {?MPRouteCoordinate}
126
138
  */
127
139
  end_location?: MPRouteCoordinate;
140
+ /**
141
+ * The reason for the start of the leg.
142
+ *
143
+ * @type {?string}
144
+ */
145
+ leg_start_reason?: string;
146
+ /**
147
+ * The reason for the end of the leg.
148
+ *
149
+ * @type {?string}
150
+ */
151
+ leg_end_reason?: string;
152
+ /**
153
+ * The index of the stop.
154
+ *
155
+ * @type {?number}
156
+ */
157
+ stop_index?: number;
128
158
  }
@@ -0,0 +1,82 @@
1
+ import { RouteStopIconConfig } from "./RouteStopIconConfig";
2
+
3
+ /**
4
+ * A class that creates a route stop icon for the {@link MPDirectionsRenderer}.
5
+ *
6
+ * @export
7
+ * @class MPRouteStopIconConfig
8
+ * @typedef {MPRouteStopIconConfig}
9
+ */
10
+ export default class MPRouteStopIconConfig implements RouteStopIconConfig{
11
+
12
+ readonly numbered: boolean;
13
+ readonly label: string;
14
+ readonly color: string;
15
+
16
+ /**
17
+ * Creates an instance of MPRouteStopIconConfig.
18
+ *
19
+ * @constructor
20
+ * @private
21
+ * @param {Mode} mode
22
+ * @param {*} obj
23
+ */
24
+ private constructor(numberd: boolean, label: string, color: string) {
25
+ this.numbered = numberd;
26
+ this.label = label;
27
+ this.color = color;
28
+ }
29
+
30
+ /**
31
+ * Internal
32
+ *
33
+ * @returns {URL}
34
+ */
35
+ getImage(): URL {
36
+ return new URL(JSON.stringify(this));
37
+ }
38
+
39
+ /**
40
+ * Creator for MPRouteStopIconConfig, used to decode JSON from the MapsIndoors SDK.
41
+ *
42
+ * @static
43
+ * @param {MPRouteStopIconConfigParams} obj
44
+ * @returns {MPRouteStopIconConfig}
45
+ */
46
+ static create(obj: MPRouteStopIconConfigParams): MPRouteStopIconConfig {
47
+ return new MPRouteStopIconConfig(
48
+ obj.numbered,
49
+ obj.label,
50
+ obj.color
51
+ );
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Parameter interface for {@link MPRouteStopIconConfig}.
57
+ *
58
+ * @export
59
+ * @interface MPRouteStopIconConfigParams
60
+ * @typedef {MPRouteStopIconConfigParams}
61
+ */
62
+ export interface MPRouteStopIconConfigParams {
63
+ /**
64
+ * Whether the icon should be numbered.
65
+ *
66
+ * @type {boolean}
67
+ */
68
+ numbered: boolean,
69
+ /**
70
+ * The label for the icon.
71
+ *
72
+ * @type {string}
73
+ */
74
+ label: string,
75
+ /**
76
+ * The color for the icon.
77
+ *
78
+ * @type {string}
79
+ */
80
+ color: string
81
+ }
82
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Interface used by MapsIndoors to retrieve image for route stops.
3
+ *
4
+ * @export
5
+ * @interface RouteStopIconConfig
6
+ * @typedef {RouteStopIconConfig}
7
+ */
8
+ export interface RouteStopIconConfig {
9
+ getImage(): URL;
10
+ }
Binary file
Binary file