@mapsindoors/react-native-maps-indoors-mapbox 2.6.1 → 2.6.2-rc.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.
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +322 -0
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +166 -0
- package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1699 -0
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +761 -0
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +410 -0
- package/android/src/main/java/com/mapsindoorsrn/core/RCMapView.java +16 -0
- package/android/src/main/java/com/mapsindoorsrn/core/README.md +3 -0
- package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +227 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/BitmapStopIconConfig.java +22 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/Bounds.java +19 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/Filter.java +77 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/Location.java +17 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/MPCameraPosition.java +34 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/MPCameraUpdate.java +68 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/MPError.java +38 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/PositionProvider.java +46 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/PositionResult.java +117 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/Query.java +30 -0
- package/android/src/main/java/com/mapsindoorsrn/core/models/RouteStopIconConfigModel.java +35 -0
- package/ios/core/CameraPosition.swift +15 -0
- package/ios/core/CameraUpdate.swift +19 -0
- package/ios/core/CameraUpdateError.swift +11 -0
- package/ios/core/DirectionsRendererBridge.m +59 -0
- package/ios/core/DirectionsRendererModule.swift +359 -0
- package/ios/core/DirectionsServiceBridge.m +55 -0
- package/ios/core/DirectionsServiceModule.swift +186 -0
- package/ios/core/IconStopUrl.swift +17 -0
- package/ios/core/LabelGraphic.swift +15 -0
- package/ios/core/MPDisplayRuleBridge.m +696 -0
- package/ios/core/MPDisplayRuleModule.swift +1704 -0
- package/ios/core/MapControlBridge.m +213 -0
- package/ios/core/MapControlModule.swift +702 -0
- package/ios/core/MapsIndoorsBridge.m +128 -0
- package/ios/core/MapsIndoorsData.swift +288 -0
- package/ios/core/MapsIndoorsModule.swift +363 -0
- package/ios/core/RCMapView.swift +16 -0
- package/ios/core/README.md +3 -0
- package/ios/core/ReactPositionProvider.swift +27 -0
- package/ios/core/RouteIcon.swift +34 -0
- package/ios/core/UtilsBridge.m +73 -0
- package/ios/core/UtilsModule.swift +182 -0
- package/ios/core/helpers.swift +57 -0
- package/package.json +1 -1
- package/src/core/EventNames.ts +21 -0
- package/src/core/MPAdditionalDetail.ts +102 -0
- package/src/core/MPBadgePosition.ts +12 -0
- package/src/core/MPBounds.ts +155 -0
- package/src/core/MPBuilding.ts +333 -0
- package/src/core/MPBuildingCollection.ts +57 -0
- package/src/core/MPBuildingInfo.ts +63 -0
- package/src/core/MPCameraEvent.ts +17 -0
- package/src/core/MPCameraEventListener.ts +17 -0
- package/src/core/MPCameraPosition.ts +82 -0
- package/src/core/MPCameraUpdate.ts +174 -0
- package/src/core/MPCameraViewFitMode.ts +25 -0
- package/src/core/MPCategory.ts +85 -0
- package/src/core/MPCategoryCollection.ts +62 -0
- package/src/core/MPCollection.ts +59 -0
- package/src/core/MPCollisionHandling.ts +12 -0
- package/src/core/MPDailyOpeningHours.ts +67 -0
- package/src/core/MPDataField.ts +69 -0
- package/src/core/MPDetailType.ts +73 -0
- package/src/core/MPDirectionsRenderer.ts +238 -0
- package/src/core/MPDirectionsService.ts +152 -0
- package/src/core/MPDisplayRule.ts +1823 -0
- package/src/core/MPEntity.ts +60 -0
- package/src/core/MPEntityInfo.ts +28 -0
- package/src/core/MPError.ts +122 -0
- package/src/core/MPFeatureTypes.ts +8 -0
- package/src/core/MPFilter.ts +168 -0
- package/src/core/MPFilterBehavior.ts +115 -0
- package/src/core/MPFloor.ts +170 -0
- package/src/core/MPFloorSelectorInterface.ts +63 -0
- package/src/core/MPGeometry.ts +91 -0
- package/src/core/MPHighlightBehavior.ts +115 -0
- package/src/core/MPHighway.ts +14 -0
- package/src/core/MPIconPlacement.ts +13 -0
- package/src/core/MPIconSize.ts +39 -0
- package/src/core/MPLabelGraphic.ts +24 -0
- package/src/core/MPLabelPosition.ts +12 -0
- package/src/core/MPLabelType.ts +11 -0
- package/src/core/MPLocation.ts +440 -0
- package/src/core/MPLocationPropertyNames.ts +30 -0
- package/src/core/MPLocationSettings.ts +40 -0
- package/src/core/MPLocationType.ts +16 -0
- package/src/core/MPMapConfig.ts +280 -0
- package/src/core/MPMapStyle.ts +57 -0
- package/src/core/MPMultiPolygon.ts +218 -0
- package/src/core/MPOpeningHours.ts +48 -0
- package/src/core/MPPOIType.ts +43 -0
- package/src/core/MPPoint.ts +169 -0
- package/src/core/MPPolygon.ts +219 -0
- package/src/core/MPPositionProviderInterface.ts +45 -0
- package/src/core/MPPositionResultInterface.ts +42 -0
- package/src/core/MPPropertyData.ts +234 -0
- package/src/core/MPQuery.ts +69 -0
- package/src/core/MPRoute.ts +105 -0
- package/src/core/MPRouteCoordinate.ts +95 -0
- package/src/core/MPRouteLeg.ts +158 -0
- package/src/core/MPRouteProperty.ts +83 -0
- package/src/core/MPRouteStep.ts +186 -0
- package/src/core/MPRouteStopIconConfig.ts +82 -0
- package/src/core/MPSelectionBehavior.ts +114 -0
- package/src/core/MPSelectionMode.ts +4 -0
- package/src/core/MPSettings3D.ts +107 -0
- package/src/core/MPSize.ts +21 -0
- package/src/core/MPSolution.ts +189 -0
- package/src/core/MPSolutionConfig.ts +188 -0
- package/src/core/MPSolutionDisplayRule.ts +15 -0
- package/src/core/MPUserRole.ts +60 -0
- package/src/core/MPUserRoleCollection.ts +37 -0
- package/src/core/MPUtils.ts +178 -0
- package/src/core/MPVenue.ts +294 -0
- package/src/core/MPVenueCollection.ts +58 -0
- package/src/core/MPVenueInfo.ts +62 -0
- package/src/core/MPWeeklyOpeningHours.ts +129 -0
- package/src/core/MapControl.ts +961 -0
- package/src/core/MapView.tsx +34 -0
- package/src/core/MapsIndoors.ts +571 -0
- package/src/core/OnBuildingFoundAtCameraTargetListener.ts +17 -0
- package/src/core/OnFloorSelectionChangedListener.ts +17 -0
- package/src/core/OnFloorUpdateListener.ts +16 -0
- package/src/core/OnLegSelectedListener.ts +17 -0
- package/src/core/OnLiveLocationUpdateListener.ts +17 -0
- package/src/core/OnLocationSelectedListener.ts +17 -0
- package/src/core/OnMapClickListener.ts +20 -0
- package/src/core/OnMarkerClickListener.ts +17 -0
- package/src/core/OnMarkerInfoWindowClickListener.ts +17 -0
- package/src/core/OnPositionUpdateListener.ts +17 -0
- package/src/core/OnVenueFoundAtCameraTargetListener.ts +17 -0
- package/src/core/README.md +3 -0
- package/src/core/RouteStopIconConfig.ts +10 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
package com.mapsindoorsrn.core;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.Bitmap;
|
|
5
|
+
import android.graphics.Color;
|
|
6
|
+
import android.os.Handler;
|
|
7
|
+
|
|
8
|
+
import androidx.annotation.NonNull;
|
|
9
|
+
import androidx.annotation.Nullable;
|
|
10
|
+
|
|
11
|
+
import com.bumptech.glide.Glide;
|
|
12
|
+
import com.bumptech.glide.request.FutureTarget;
|
|
13
|
+
import com.facebook.react.bridge.Arguments;
|
|
14
|
+
import com.facebook.react.bridge.Promise;
|
|
15
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
17
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
18
|
+
import com.facebook.react.bridge.WritableMap;
|
|
19
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
20
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
21
|
+
import com.google.gson.Gson;
|
|
22
|
+
import com.google.gson.reflect.TypeToken;
|
|
23
|
+
import com.mapsindoors.core.MPCameraViewFitMode;
|
|
24
|
+
import com.mapsindoors.core.MPDirectionsRenderer;
|
|
25
|
+
import com.mapsindoors.core.MPRoute;
|
|
26
|
+
import com.mapsindoors.core.MPRouteStopIconProvider;
|
|
27
|
+
import com.mapsindoors.core.MapControl;
|
|
28
|
+
import com.mapsindoors.core.OnMapControlReadyListener;
|
|
29
|
+
import com.mapsindoors.core.errors.MIError;
|
|
30
|
+
import com.mapsindoors.core.errors.MIErrorEnum;
|
|
31
|
+
import com.mapsindoors.core.errors.MapsIndoorsException;
|
|
32
|
+
import com.mapsindoorsrn.core.models.BitmapStopIconConfig;
|
|
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;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
public class DirectionsRendererModule extends ReactContextBaseJavaModule implements OnMapControlReadyListener {
|
|
45
|
+
private MapControl mMapControl;
|
|
46
|
+
private MPDirectionsRenderer mRenderer;
|
|
47
|
+
private final ReactApplicationContext mCtx;
|
|
48
|
+
private final Gson gson = new Gson();
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
public DirectionsRendererModule(@NonNull ReactApplicationContext reactContext, MapControlModule mapControl) {
|
|
52
|
+
super(reactContext);
|
|
53
|
+
mapControl.setOnMapControlReadyListener(this);
|
|
54
|
+
mCtx = reactContext;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@NonNull
|
|
58
|
+
@Override
|
|
59
|
+
public String getName() {
|
|
60
|
+
return "DirectionsRenderer";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private void rejectPromise(Promise promise) {
|
|
64
|
+
promise.reject("Renderer not initialized", new MapsIndoorsException("Renderer not initialized"));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@ReactMethod
|
|
68
|
+
public void clear(final Promise promise) {
|
|
69
|
+
if (mRenderer != null) {
|
|
70
|
+
mRenderer.clear();
|
|
71
|
+
promise.resolve(null);
|
|
72
|
+
} else {
|
|
73
|
+
rejectPromise(promise);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@ReactMethod
|
|
78
|
+
public void getSelectedLegFloorIndex(final Promise promise) {
|
|
79
|
+
if (mRenderer != null) {
|
|
80
|
+
promise.resolve(mRenderer.getSelectedLegFloorIndex());
|
|
81
|
+
} else {
|
|
82
|
+
rejectPromise(promise);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@ReactMethod
|
|
87
|
+
public void nextLeg(final Promise promise) {
|
|
88
|
+
if (mRenderer != null) {
|
|
89
|
+
mRenderer.nextLeg();
|
|
90
|
+
promise.resolve(null);
|
|
91
|
+
} else {
|
|
92
|
+
rejectPromise(promise);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactMethod
|
|
97
|
+
public void previousLeg(final Promise promise) {
|
|
98
|
+
if (mRenderer != null) {
|
|
99
|
+
mRenderer.previousLeg();
|
|
100
|
+
promise.resolve(null);
|
|
101
|
+
} else {
|
|
102
|
+
rejectPromise(promise);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@ReactMethod
|
|
107
|
+
public void selectLegIndex(int legIndex, final Promise promise) {
|
|
108
|
+
if (mRenderer != null) {
|
|
109
|
+
try {
|
|
110
|
+
mRenderer.selectLegIndex(legIndex);
|
|
111
|
+
} catch (IllegalStateException e) {
|
|
112
|
+
promise.reject(e.getMessage(), new Gson().toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
promise.resolve(null);
|
|
116
|
+
} else {
|
|
117
|
+
rejectPromise(promise);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@ReactMethod
|
|
122
|
+
public void setAnimatedPolyline(boolean animated, boolean repeated, int duration, final Promise promise) {
|
|
123
|
+
if (mRenderer != null) {
|
|
124
|
+
mRenderer.setAnimatedPolyline(animated, repeated, duration);
|
|
125
|
+
promise.resolve(null);
|
|
126
|
+
} else {
|
|
127
|
+
rejectPromise(promise);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@ReactMethod
|
|
132
|
+
public void showRouteLegButtons(boolean value, final Promise promise) {
|
|
133
|
+
if (mRenderer != null) {
|
|
134
|
+
mRenderer.showRouteLegButtons(value);
|
|
135
|
+
promise.resolve(null);
|
|
136
|
+
} else {
|
|
137
|
+
rejectPromise(promise);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@ReactMethod
|
|
142
|
+
public void setCameraAnimationDuration(int duration, final Promise promise) {
|
|
143
|
+
if (mRenderer != null) {
|
|
144
|
+
mRenderer.setCameraAnimationDuration(duration);
|
|
145
|
+
promise.resolve(null);
|
|
146
|
+
} else {
|
|
147
|
+
rejectPromise(promise);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
public void setCameraViewFitMode(int cameraFitMode, final Promise promise) {
|
|
153
|
+
if (mRenderer != null) {
|
|
154
|
+
final MPCameraViewFitMode mode;
|
|
155
|
+
switch (cameraFitMode) {
|
|
156
|
+
case 0:
|
|
157
|
+
mode = MPCameraViewFitMode.NORTH_ALIGNED;
|
|
158
|
+
break;
|
|
159
|
+
case 1:
|
|
160
|
+
mode = MPCameraViewFitMode.FIRST_STEP_ALIGNED;
|
|
161
|
+
break;
|
|
162
|
+
case 2:
|
|
163
|
+
mode = MPCameraViewFitMode.START_TO_END_ALIGNED;
|
|
164
|
+
break;
|
|
165
|
+
case 3:
|
|
166
|
+
mode = MPCameraViewFitMode.NONE;
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
mode = null;
|
|
170
|
+
}
|
|
171
|
+
if (mode != null) {
|
|
172
|
+
mRenderer.setCameraViewFitMode(mode);
|
|
173
|
+
}
|
|
174
|
+
promise.resolve(null);
|
|
175
|
+
} else {
|
|
176
|
+
rejectPromise(promise);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@ReactMethod
|
|
181
|
+
public void setOnLegSelectedListener(final Promise promise) {
|
|
182
|
+
if (mRenderer != null) {
|
|
183
|
+
mRenderer.setOnLegSelectedListener(leg -> {
|
|
184
|
+
WritableMap params = Arguments.createMap();
|
|
185
|
+
params.putInt("leg", leg);
|
|
186
|
+
mCtx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onLegSelected", params);
|
|
187
|
+
});
|
|
188
|
+
promise.resolve(null);
|
|
189
|
+
} else {
|
|
190
|
+
rejectPromise(promise);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@ReactMethod
|
|
195
|
+
public void setPolyLineColors(String foregroundString, String backgroundString, final Promise promise) {
|
|
196
|
+
if (mRenderer != null) {
|
|
197
|
+
int foreground;
|
|
198
|
+
int background;
|
|
199
|
+
try {
|
|
200
|
+
foreground = Color.parseColor(foregroundString);
|
|
201
|
+
background = Color.parseColor(backgroundString);
|
|
202
|
+
} catch (IllegalArgumentException e) {
|
|
203
|
+
promise.reject(e);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
mRenderer.setPolylineColors(foreground, background);
|
|
207
|
+
promise.resolve(null);
|
|
208
|
+
} else {
|
|
209
|
+
rejectPromise(promise);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@ReactMethod
|
|
214
|
+
public void setRoute(String routeString, String icons, int legIndex, final Promise promise) {
|
|
215
|
+
if (mRenderer != null) {
|
|
216
|
+
Context ctx = mCtx.getApplicationContext();
|
|
217
|
+
MPRoute route = new Gson().fromJson(routeString, MPRoute.class);
|
|
218
|
+
if (icons != null) {
|
|
219
|
+
new Handler().post(()-> {
|
|
220
|
+
HashMap<Integer, String> iconsMap = gson.fromJson(icons, new TypeToken<HashMap<Integer, String>>(){}.getType());
|
|
221
|
+
HashMap<Integer, MPRouteStopIconProvider> iconConfigs = new HashMap<>();
|
|
222
|
+
for (Map.Entry<Integer, String> mapEntry : iconsMap.entrySet()) {
|
|
223
|
+
String icon = mapEntry.getValue();
|
|
224
|
+
if (icon == null) {
|
|
225
|
+
iconConfigs.put(mapEntry.getKey(), null);
|
|
226
|
+
} else if (isUrl(icon)) {
|
|
227
|
+
FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(icon).submit();
|
|
228
|
+
try {
|
|
229
|
+
BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
|
|
230
|
+
iconConfigs.put(mapEntry.getKey(), iconConfig);
|
|
231
|
+
} catch (Exception e) {
|
|
232
|
+
promise.reject("something went wrong loading the image for " + icon, e);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}else {
|
|
236
|
+
String json = icon.substring(0, icon.length() - 1);
|
|
237
|
+
RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
|
|
238
|
+
iconConfigs.put(mapEntry.getKey(), iconConfig.toMPRouteStopIconConfig(ctx));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
mRenderer.setRoute(route, iconConfigs);
|
|
243
|
+
if (legIndex != 0) {
|
|
244
|
+
try {
|
|
245
|
+
mRenderer.selectLegIndex(legIndex);
|
|
246
|
+
} catch (IllegalStateException e) {
|
|
247
|
+
promise.reject(e.getMessage(), new Gson().toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
promise.resolve(null);
|
|
253
|
+
});
|
|
254
|
+
}else {
|
|
255
|
+
mRenderer.setRoute(route);
|
|
256
|
+
promise.resolve(null);
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
rejectPromise(promise);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
@ReactMethod
|
|
264
|
+
public void setDefaultRouteStopIcon(String iconString, final Promise promise) {
|
|
265
|
+
if (mRenderer != null) {
|
|
266
|
+
//Create icon from url
|
|
267
|
+
if (iconString != null) {
|
|
268
|
+
//Handle icon
|
|
269
|
+
new Handler().post(()-> {
|
|
270
|
+
Context ctx = mCtx.getApplicationContext();
|
|
271
|
+
if (iconString == null || iconString.equals("null") || iconString.isEmpty()) {
|
|
272
|
+
mRenderer.setDefaultRouteStopIconConfig(null);
|
|
273
|
+
promise.resolve(null);
|
|
274
|
+
} else if (isUrl(iconString)) {
|
|
275
|
+
FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(iconString).submit();
|
|
276
|
+
try {
|
|
277
|
+
BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
|
|
278
|
+
mRenderer.setDefaultRouteStopIconConfig(iconConfig);
|
|
279
|
+
promise.resolve(null);
|
|
280
|
+
} catch (Exception e) {
|
|
281
|
+
promise.reject("something went wrong loading the image", e);
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
String json = iconString.substring(0, iconString.length() - 1);
|
|
285
|
+
RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
|
|
286
|
+
mRenderer.setDefaultRouteStopIconConfig(iconConfig.toMPRouteStopIconConfig(ctx));
|
|
287
|
+
promise.resolve(null);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}else {
|
|
291
|
+
mRenderer.setDefaultRouteStopIconConfig(null);
|
|
292
|
+
promise.resolve(null);
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
rejectPromise(promise);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@Override
|
|
300
|
+
public void onMapControlReady(@Nullable MapControl mapControl, @Nullable MIError miError) {
|
|
301
|
+
if (mapControl != null) {
|
|
302
|
+
mMapControl = mapControl;
|
|
303
|
+
mRenderer = new MPDirectionsRenderer(mMapControl);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@ReactMethod
|
|
308
|
+
public void addListener(String eventName) {
|
|
309
|
+
// we are handling listeners ourselves
|
|
310
|
+
}
|
|
311
|
+
@ReactMethod
|
|
312
|
+
public void removeListeners(Integer count) {
|
|
313
|
+
// we are handling listeners ourselves
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private boolean isUrl(String url) {
|
|
317
|
+
String regex = "^(http|https)://.*$";
|
|
318
|
+
Pattern pattern = Pattern.compile(regex);
|
|
319
|
+
Matcher matcher = pattern.matcher(url);
|
|
320
|
+
return matcher.matches();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
package com.mapsindoorsrn.core;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Arguments;
|
|
6
|
+
import com.facebook.react.bridge.Promise;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
+
import com.facebook.react.bridge.WritableMap;
|
|
11
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
12
|
+
import com.google.gson.Gson;
|
|
13
|
+
import com.mapsindoors.core.MPDirectionsService;
|
|
14
|
+
import com.mapsindoors.core.MPPoint;
|
|
15
|
+
import com.mapsindoors.core.errors.MapsIndoorsException;
|
|
16
|
+
|
|
17
|
+
import java.util.ArrayList;
|
|
18
|
+
import java.util.Date;
|
|
19
|
+
import java.util.HashMap;
|
|
20
|
+
import java.util.List;
|
|
21
|
+
import java.util.UUID;
|
|
22
|
+
|
|
23
|
+
public class DirectionsServiceModule extends ReactContextBaseJavaModule {
|
|
24
|
+
|
|
25
|
+
private HashMap<String, MPDirectionsService> serviceMap = new HashMap<>();
|
|
26
|
+
private static final String NO_DS = "This DirectionsService is not available";
|
|
27
|
+
|
|
28
|
+
private final Gson gson = new Gson();
|
|
29
|
+
public DirectionsServiceModule(@NonNull ReactApplicationContext reactContext) {
|
|
30
|
+
super(reactContext);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactMethod
|
|
34
|
+
public void create(final Promise promise) {
|
|
35
|
+
MPDirectionsService service = new MPDirectionsService();
|
|
36
|
+
String uuid = UUID.randomUUID().toString();
|
|
37
|
+
serviceMap.put(uuid, service);
|
|
38
|
+
promise.resolve(uuid);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
public void addAvoidWayType(String wayType, final String id, final Promise promise) {
|
|
43
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
44
|
+
if (service != null) {
|
|
45
|
+
service.addAvoidWayType(wayType);
|
|
46
|
+
promise.resolve(null);
|
|
47
|
+
} else {
|
|
48
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
public void clearWayType(final String id, final Promise promise) {
|
|
54
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
55
|
+
if (service != null) {
|
|
56
|
+
service.clearAvoidWayType();
|
|
57
|
+
promise.resolve(null);
|
|
58
|
+
} else {
|
|
59
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactMethod
|
|
64
|
+
public void addExcludeWayType(String wayType, final String id, final Promise promise) {
|
|
65
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
66
|
+
if (service != null) {
|
|
67
|
+
service.addExcludeWayType(wayType);
|
|
68
|
+
promise.resolve(null);
|
|
69
|
+
} else {
|
|
70
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@ReactMethod
|
|
75
|
+
public void clearExcludeWayType(final String id, final Promise promise) {
|
|
76
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
77
|
+
if (service != null) {
|
|
78
|
+
service.clearExcludeWayType();
|
|
79
|
+
promise.resolve(null);
|
|
80
|
+
} else {
|
|
81
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
public void setIsDeparture(boolean isDeparture, final String id, final Promise promise) {
|
|
87
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
88
|
+
if (service != null) {
|
|
89
|
+
service.setIsDeparture(isDeparture);
|
|
90
|
+
promise.resolve(null);
|
|
91
|
+
} else {
|
|
92
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactMethod
|
|
97
|
+
public void getRoute(String originString, String destinationString, ReadableArray stops, boolean optimized, final String id, final Promise promise) {
|
|
98
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
99
|
+
if (service != null) {
|
|
100
|
+
service.setRouteResultListener((route, error) -> {
|
|
101
|
+
WritableMap map = Arguments.createMap();
|
|
102
|
+
if (route != null) {
|
|
103
|
+
map.putString("route", gson.toJson(route));
|
|
104
|
+
}
|
|
105
|
+
if (error != null) {
|
|
106
|
+
map.putString("error", gson.toJson(error));
|
|
107
|
+
}
|
|
108
|
+
promise.resolve(map);
|
|
109
|
+
});
|
|
110
|
+
MPPoint origin = gson.fromJson(originString, MPPoint.class);
|
|
111
|
+
MPPoint destination = gson.fromJson(destinationString, MPPoint.class);
|
|
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
|
+
|
|
120
|
+
if (origin != null && destination != null) {
|
|
121
|
+
if (!points.isEmpty()) {
|
|
122
|
+
service.query(origin, destination, points, optimized);
|
|
123
|
+
} else {
|
|
124
|
+
service.query(origin, destination);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
promise.reject(new MapsIndoorsException("Origin:" + originString +
|
|
128
|
+
", or Destination:" + destinationString + ", are not parsable"));
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@ReactMethod
|
|
137
|
+
public void setTravelMode(String travelMode, final String id, final Promise promise) {
|
|
138
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
139
|
+
if (service != null) {
|
|
140
|
+
service.setTravelMode(travelMode);
|
|
141
|
+
promise.resolve(null);
|
|
142
|
+
} else {
|
|
143
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@ReactMethod
|
|
148
|
+
public void setTime(int time, final String id, final Promise promise) {
|
|
149
|
+
MPDirectionsService service = serviceMap.get(id);
|
|
150
|
+
if (service != null) {
|
|
151
|
+
Date date = new Date();
|
|
152
|
+
date.setTime(time);
|
|
153
|
+
service.setTime(date);
|
|
154
|
+
promise.resolve(null);
|
|
155
|
+
} else {
|
|
156
|
+
promise.reject(NO_DS,new MapsIndoorsException((NO_DS)));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@NonNull
|
|
162
|
+
@Override
|
|
163
|
+
public String getName() {
|
|
164
|
+
return "DirectionsService";
|
|
165
|
+
}
|
|
166
|
+
}
|