react-native-map4d-services 1.0.1 → 1.0.2
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/reactnativemap4dservices/SClient.java +9 -4
- package/android/src/main/java/com/reactnativemap4dservices/SRequest.java +45 -45
- package/ios/SParamConvert.h +44 -0
- package/ios/SParamConvert.m +229 -0
- package/ios/SRequest.m +44 -45
- package/package.json +1 -1
- package/ios/RCTConvert+Services.h +0 -33
- package/ios/RCTConvert+Services.m +0 -146
|
@@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
|
|
|
5
5
|
|
|
6
6
|
import com.facebook.react.bridge.Promise;
|
|
7
7
|
import com.facebook.react.bridge.WritableMap;
|
|
8
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
8
9
|
|
|
9
10
|
import org.json.JSONException;
|
|
10
11
|
import org.json.JSONObject;
|
|
@@ -29,16 +30,20 @@ class SClient {
|
|
|
29
30
|
final WritableMap data = SJsonUtils.convertJsonToMap(json);
|
|
30
31
|
promise.resolve(data);
|
|
31
32
|
} catch (JSONException e) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
WritableMap result = new WritableNativeMap();
|
|
34
|
+
result.putString("code", "Map4dServices");
|
|
35
|
+
result.putString("message", "Error when parse JSON data result !");
|
|
36
|
+
promise.resolve(result);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
@Override
|
|
40
42
|
public void onError(String code, String message) {
|
|
41
|
-
|
|
43
|
+
WritableMap result = new WritableNativeMap();
|
|
44
|
+
result.putString("code", code);
|
|
45
|
+
result.putString("message", message);
|
|
46
|
+
promise.resolve(result);
|
|
42
47
|
}
|
|
43
48
|
});
|
|
44
49
|
}
|
|
@@ -19,17 +19,17 @@ public class SRequest {
|
|
|
19
19
|
serviceOptionsBuilder.method(MFMethod.GET);
|
|
20
20
|
|
|
21
21
|
MFRequestParams requestParams = new MFRequestParams();
|
|
22
|
-
if (params.hasKey("text")) {
|
|
22
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
23
23
|
String text = params.getString("text");
|
|
24
24
|
requestParams.put("text", text);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
if (params.hasKey("acronym")) {
|
|
27
|
+
if (params.hasKey("acronym") && !params.isNull("acronym")) {
|
|
28
28
|
boolean acronym = params.getBoolean("acronym");
|
|
29
29
|
requestParams.put("acronym", String.valueOf(acronym));
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
if (params.hasKey("location")) {
|
|
32
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
33
33
|
String location = SConverter.toLocation(params.getMap("location"));
|
|
34
34
|
requestParams.put("location", location);
|
|
35
35
|
}
|
|
@@ -54,22 +54,22 @@ public class SRequest {
|
|
|
54
54
|
serviceOptionsBuilder.method(MFMethod.GET);
|
|
55
55
|
|
|
56
56
|
MFRequestParams requestParams = new MFRequestParams();
|
|
57
|
-
if (params.hasKey("text")) {
|
|
57
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
58
58
|
String text = params.getString("text");
|
|
59
59
|
requestParams.put("text", text);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
if (params.hasKey("location")) {
|
|
62
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
63
63
|
String location = SConverter.toLocation(params.getMap("location"));
|
|
64
64
|
requestParams.put("location", location);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
if (params.hasKey("types")) {
|
|
67
|
+
if (params.hasKey("types") && !params.isNull("types")) {
|
|
68
68
|
String types = SConverter.toTypes(params.getArray("types"));
|
|
69
69
|
requestParams.put("types", types);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
if (params.hasKey("datetime")) {
|
|
72
|
+
if (params.hasKey("datetime") && !params.isNull("datetime")) {
|
|
73
73
|
String datetime = SConverter.toDatetime(params.getDouble("datetime"));
|
|
74
74
|
requestParams.put("datetime", datetime);
|
|
75
75
|
}
|
|
@@ -83,32 +83,32 @@ public class SRequest {
|
|
|
83
83
|
serviceOptionsBuilder.method(MFMethod.GET);
|
|
84
84
|
|
|
85
85
|
MFRequestParams requestParams = new MFRequestParams();
|
|
86
|
-
if (params.hasKey("location")) {
|
|
86
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
87
87
|
String location = SConverter.toLocation(params.getMap("location"));
|
|
88
88
|
requestParams.put("location", location);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
if (params.hasKey("radius")) {
|
|
91
|
+
if (params.hasKey("radius") && !params.isNull("radius")) {
|
|
92
92
|
String radius = String.valueOf(params.getInt("radius"));
|
|
93
93
|
requestParams.put("radius", radius);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
if (params.hasKey("text")) {
|
|
96
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
97
97
|
String text = params.getString("text");
|
|
98
98
|
requestParams.put("text", text);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
if (params.hasKey("types")) {
|
|
101
|
+
if (params.hasKey("types") && !params.isNull("types")) {
|
|
102
102
|
String types = SConverter.toTypes(params.getArray("types"));
|
|
103
103
|
requestParams.put("types", types);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (params.hasKey("tags")) {
|
|
106
|
+
if (params.hasKey("tags") && !params.isNull("tags")) {
|
|
107
107
|
String tags = SConverter.toTags(params.getArray("tags"));
|
|
108
108
|
requestParams.put("tags", tags);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
if (params.hasKey("datetime")) {
|
|
111
|
+
if (params.hasKey("datetime") && !params.isNull("datetime")) {
|
|
112
112
|
String datetime = SConverter.toDatetime(params.getDouble("datetime"));
|
|
113
113
|
requestParams.put("datetime", datetime);
|
|
114
114
|
}
|
|
@@ -123,27 +123,27 @@ public class SRequest {
|
|
|
123
123
|
serviceOptionsBuilder.method(MFMethod.GET);
|
|
124
124
|
|
|
125
125
|
MFRequestParams requestParams = new MFRequestParams();
|
|
126
|
-
if (params.hasKey("viewbox")) {
|
|
126
|
+
if (params.hasKey("viewbox") && !params.isNull("viewbox")) {
|
|
127
127
|
String viewbox = SConverter.toViewbox(params.getMap("viewbox"));
|
|
128
128
|
requestParams.put("viewbox", viewbox);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
if (params.hasKey("text")) {
|
|
131
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
132
132
|
String text = params.getString("text");
|
|
133
133
|
requestParams.put("text", text);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
if (params.hasKey("types")) {
|
|
136
|
+
if (params.hasKey("types") && !params.isNull("types")) {
|
|
137
137
|
String types = SConverter.toTypes(params.getArray("types"));
|
|
138
138
|
requestParams.put("types", types);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
if (params.hasKey("tags")) {
|
|
141
|
+
if (params.hasKey("tags") && !params.isNull("tags")) {
|
|
142
142
|
String tags = SConverter.toTags(params.getArray("tags"));
|
|
143
143
|
requestParams.put("tags", tags);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
if (params.hasKey("datetime")) {
|
|
146
|
+
if (params.hasKey("datetime") && !params.isNull("datetime")) {
|
|
147
147
|
String datetime = SConverter.toDatetime(params.getDouble("datetime"));
|
|
148
148
|
requestParams.put("datetime", datetime);
|
|
149
149
|
}
|
|
@@ -157,17 +157,17 @@ public class SRequest {
|
|
|
157
157
|
serviceOptionsBuilder.method(MFMethod.GET);
|
|
158
158
|
|
|
159
159
|
MFRequestParams requestParams = new MFRequestParams();
|
|
160
|
-
if (params.hasKey("address")) {
|
|
160
|
+
if (params.hasKey("address") && !params.isNull("address")) {
|
|
161
161
|
String address = params.getString("address");
|
|
162
162
|
requestParams.put("address", address);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
if (params.hasKey("location")) {
|
|
165
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
166
166
|
String location = SConverter.toLocation(params.getMap("location"));
|
|
167
167
|
requestParams.put("location", location);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
if (params.hasKey("viewbox")) {
|
|
170
|
+
if (params.hasKey("viewbox") && !params.isNull("viewbox")) {
|
|
171
171
|
String viewbox = SConverter.toViewbox(params.getMap("viewbox"));
|
|
172
172
|
requestParams.put("viewbox", viewbox);
|
|
173
173
|
}
|
|
@@ -182,37 +182,37 @@ public class SRequest {
|
|
|
182
182
|
|
|
183
183
|
MFRequestParams requestParams = new MFRequestParams();
|
|
184
184
|
|
|
185
|
-
if (params.hasKey("origin")) {
|
|
185
|
+
if (params.hasKey("origin") && !params.isNull("origin")) {
|
|
186
186
|
String origin = SConverter.toLocation(params.getMap("origin"));
|
|
187
187
|
requestParams.put("origin", origin);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
if (params.hasKey("destination")) {
|
|
190
|
+
if (params.hasKey("destination") && !params.isNull("destination")) {
|
|
191
191
|
String destination = SConverter.toLocation(params.getMap("destination"));
|
|
192
192
|
requestParams.put("destination", destination);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
if (params.hasKey("mode")) {
|
|
195
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
196
196
|
String mode = params.getString("mode");
|
|
197
197
|
requestParams.put("mode", mode);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
if (params.hasKey("weighting")) {
|
|
200
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
201
201
|
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
202
202
|
requestParams.put("weighting", String.valueOf(weighting));
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
if (params.hasKey("language")) {
|
|
205
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
206
206
|
String language = params.getString("language");
|
|
207
207
|
requestParams.put("language", language);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
if (params.hasKey("waypoints")) {
|
|
210
|
+
if (params.hasKey("waypoints") && !params.isNull("waypoints")) {
|
|
211
211
|
String waypoints = SConverter.toLocationList(params.getArray("waypoints"));
|
|
212
212
|
requestParams.put("points", waypoints);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
if (params.hasKey("restriction")) {
|
|
215
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
216
216
|
ReadableMap restrictionMap = params.getMap("restriction");
|
|
217
217
|
String avoid = SConverter.toAvoid(restrictionMap);
|
|
218
218
|
if (avoid != null && !avoid.isEmpty()) {
|
|
@@ -236,32 +236,32 @@ public class SRequest {
|
|
|
236
236
|
|
|
237
237
|
JSONObject jsonObject = new JSONObject();
|
|
238
238
|
try {
|
|
239
|
-
if (params.hasKey("origins")) {
|
|
239
|
+
if (params.hasKey("origins") && !params.isNull("origins")) {
|
|
240
240
|
JSONArray origins = SConverter.toOriginJsonArray(params.getArray("origins"));
|
|
241
241
|
jsonObject.put("origins", origins);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
if (params.hasKey("destination")) {
|
|
244
|
+
if (params.hasKey("destination") && !params.isNull("destination")) {
|
|
245
245
|
String destination = SConverter.toLocation(params.getMap("destination"));
|
|
246
246
|
jsonObject.put("destination", destination);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
if (params.hasKey("mode")) {
|
|
249
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
250
250
|
String mode = params.getString("mode");
|
|
251
251
|
jsonObject.put("mode", mode);
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
if (params.hasKey("weighting")) {
|
|
254
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
255
255
|
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
256
256
|
jsonObject.put("weighting", String.valueOf(weighting));
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
if (params.hasKey("language")) {
|
|
259
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
260
260
|
String language = params.getString("language");
|
|
261
261
|
jsonObject.put("language", language);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
if (params.hasKey("restriction")) {
|
|
264
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
265
265
|
ReadableMap restrictionMap = params.getMap("restriction");
|
|
266
266
|
String avoid = SConverter.toAvoid(restrictionMap);
|
|
267
267
|
if (avoid != null && !avoid.isEmpty()) {
|
|
@@ -288,32 +288,32 @@ public class SRequest {
|
|
|
288
288
|
|
|
289
289
|
MFRequestParams requestParams = new MFRequestParams();
|
|
290
290
|
|
|
291
|
-
if (params.hasKey("origins")) {
|
|
291
|
+
if (params.hasKey("origins") && !params.isNull("origins")) {
|
|
292
292
|
String origins = SConverter.toLocationList(params.getArray("origins"));
|
|
293
293
|
requestParams.put("origins", origins);
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
if (params.hasKey("destinations")) {
|
|
296
|
+
if (params.hasKey("destinations") && !params.isNull("destinations")) {
|
|
297
297
|
String destinations = SConverter.toLocationList(params.getArray("destinations"));
|
|
298
298
|
requestParams.put("destinations", destinations);
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
if (params.hasKey("mode")) {
|
|
301
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
302
302
|
String mode = params.getString("mode");
|
|
303
303
|
requestParams.put("mode", mode);
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
if (params.hasKey("weighting")) {
|
|
306
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
307
307
|
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
308
308
|
requestParams.put("weighting", String.valueOf(weighting));
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
if (params.hasKey("language")) {
|
|
311
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
312
312
|
String language = params.getString("language");
|
|
313
313
|
requestParams.put("language", language);
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
if (params.hasKey("restriction")) {
|
|
316
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
317
317
|
ReadableMap restrictionMap = params.getMap("restriction");
|
|
318
318
|
String avoid = SConverter.toAvoid(restrictionMap);
|
|
319
319
|
if (avoid != null && !avoid.isEmpty()) {
|
|
@@ -337,27 +337,27 @@ public class SRequest {
|
|
|
337
337
|
|
|
338
338
|
MFRequestParams requestParams = new MFRequestParams();
|
|
339
339
|
|
|
340
|
-
if (params.hasKey("locations")) {
|
|
340
|
+
if (params.hasKey("locations") && !params.isNull("locations")) {
|
|
341
341
|
String points = SConverter.toLocationList(params.getArray("locations"));
|
|
342
342
|
requestParams.put("points", points);
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
if (params.hasKey("mode")) {
|
|
345
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
346
346
|
String mode = params.getString("mode");
|
|
347
347
|
requestParams.put("mode", mode);
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
if (params.hasKey("weighting")) {
|
|
350
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
351
351
|
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
352
352
|
requestParams.put("weighting", String.valueOf(weighting));
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
-
if (params.hasKey("language")) {
|
|
355
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
356
356
|
String language = params.getString("language");
|
|
357
357
|
requestParams.put("language", language);
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
-
if (params.hasKey("restriction")) {
|
|
360
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
361
361
|
ReadableMap restrictionMap = params.getMap("restriction");
|
|
362
362
|
String avoid = SConverter.toAvoid(restrictionMap);
|
|
363
363
|
if (avoid != null && !avoid.isEmpty()) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SParamConvert.h
|
|
3
|
+
// react-native-map4d-services
|
|
4
|
+
//
|
|
5
|
+
// Created by Huy Dang on 26/01/2022.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef SParamConvert_h
|
|
9
|
+
#define SParamConvert_h
|
|
10
|
+
|
|
11
|
+
#import <Map4dServices/Map4dServices.h>
|
|
12
|
+
|
|
13
|
+
@interface SParamConvert : NSObject
|
|
14
|
+
|
|
15
|
+
+ (BOOL)BOOL:(id)json fallback:(BOOL)fallback;
|
|
16
|
+
|
|
17
|
+
+ (NSUInteger)NSUInteger:(id)json;
|
|
18
|
+
|
|
19
|
+
+ (NSUInteger)NSUInteger:(id)json fallback:(NSUInteger)fallback;
|
|
20
|
+
|
|
21
|
+
+ (NSString *)NSString:(id)json;
|
|
22
|
+
|
|
23
|
+
+ (NSArray<NSString *> *)NSStringArray:(id)json;
|
|
24
|
+
|
|
25
|
+
+ (NSDate *)NSDate:(id)json;
|
|
26
|
+
|
|
27
|
+
+ (MFLocationComponent *)MFLocationComponent:(id)json;
|
|
28
|
+
|
|
29
|
+
+ (NSArray<MFLocationComponent *> *)MFLocationComponentArray:(id)json;
|
|
30
|
+
|
|
31
|
+
+ (MFViewboxComponent *)MFViewboxComponent:(id)json;
|
|
32
|
+
|
|
33
|
+
+ (MFRouteRestriction *)MFRouteRestriction:(id)json;
|
|
34
|
+
|
|
35
|
+
+ (MFTravelMode)MFTravelMode:(id)json fallback:(MFTravelMode)fallback;
|
|
36
|
+
|
|
37
|
+
+ (MFRouteWeighting)MFRouteWeighting:(id)json fallback:(MFRouteWeighting)fallback;
|
|
38
|
+
|
|
39
|
+
+ (MFLanguageResult)MFLanguageResult:(id)json fallback:(MFLanguageResult)fallback;
|
|
40
|
+
|
|
41
|
+
@end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
#endif /* SParamConvert_h */
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SParamConvert.m
|
|
3
|
+
// react-native-map4d-services
|
|
4
|
+
//
|
|
5
|
+
// Created by Huy Dang on 26/01/2022.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <React/RCTConvert.h>
|
|
9
|
+
#import <React/RCTConvert+CoreLocation.h>
|
|
10
|
+
#import "SParamConvert.h"
|
|
11
|
+
|
|
12
|
+
@interface SParamConvert (Private)
|
|
13
|
+
+ (BOOL)isNull:(id)json;
|
|
14
|
+
+ (BOOL)isMFRouteType:(NSString *)type;
|
|
15
|
+
+ (MFRouteType)MFRouteType:(NSString *)type;
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
#pragma mark - SParamConvert
|
|
19
|
+
|
|
20
|
+
@implementation SParamConvert
|
|
21
|
+
|
|
22
|
+
+ (BOOL)BOOL:(id)json fallback:(BOOL)fallback {
|
|
23
|
+
return [self isNull:json] ? fallback : [RCTConvert BOOL:json];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
+ (NSUInteger)NSUInteger:(id)json {
|
|
27
|
+
return [self NSUInteger:json fallback:0];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
+ (NSUInteger)NSUInteger:(id)json fallback:(NSUInteger)fallback {
|
|
31
|
+
return [self isNull:json] ? fallback : [RCTConvert NSUInteger:json];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
+ (NSString *)NSString:(id)json {
|
|
35
|
+
return [self isNull:json] ? nil : [RCTConvert NSString:json];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
+ (NSArray<NSString *> *)NSStringArray:(id)json {
|
|
39
|
+
if ([self isNull:json]) {
|
|
40
|
+
return nil;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[json count]];
|
|
44
|
+
for (id e in json) {
|
|
45
|
+
NSString *str = [self NSString:e];
|
|
46
|
+
if (str != nil) {
|
|
47
|
+
[array addObject:str];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return array;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
+ (NSDate *)NSDate:(id)json {
|
|
54
|
+
return [self isNull:json] ? nil : [RCTConvert NSDate:json];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
+ (MFLocationComponent *)MFLocationComponent:(id)json {
|
|
58
|
+
if ([self isNull:json]) {
|
|
59
|
+
return nil;
|
|
60
|
+
}
|
|
61
|
+
CLLocationCoordinate2D coordinate = [RCTConvert CLLocationCoordinate2D:json];
|
|
62
|
+
return [[MFLocationComponent alloc] initWithCoordinate:coordinate alias:json[@"alias"]];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
+ (NSArray<MFLocationComponent *> *)MFLocationComponentArray:(id)json {
|
|
66
|
+
if ([self isNull:json]) {
|
|
67
|
+
return nil;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
NSMutableArray<MFLocationComponent *> *array = [NSMutableArray arrayWithCapacity:[json count]];
|
|
71
|
+
for (id e in json) {
|
|
72
|
+
MFLocationComponent *location = [self MFLocationComponent:e];
|
|
73
|
+
if (location != nil) {
|
|
74
|
+
[array addObject:location];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return array;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
+ (MFViewboxComponent *)MFViewboxComponent:(id)json {
|
|
81
|
+
if ([self isNull:json]) {
|
|
82
|
+
return nil;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
MFLocationComponent *southwest = [SParamConvert MFLocationComponent:json[@"southwest"]];
|
|
86
|
+
MFLocationComponent *northeast = [SParamConvert MFLocationComponent:json[@"northeast"]];
|
|
87
|
+
return [[MFViewboxComponent alloc] initWithSouthwest:southwest.coordinate northeast:northeast.coordinate];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
+ (MFRouteRestriction *)MFRouteRestriction:(id)json {
|
|
91
|
+
if ([self isNull:json]) {
|
|
92
|
+
return nil;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
MFLocationComponent *location = [SParamConvert MFLocationComponent:json[@"location"]];
|
|
96
|
+
NSUInteger radius = json[@"radius"] != nil ? [RCTConvert NSUInteger:json[@"radius"]] : 0;
|
|
97
|
+
MFViewboxComponent *viewbox = [SParamConvert MFViewboxComponent:json[@"viewbox"]];
|
|
98
|
+
NSArray<MFLocationComponent *> *path = [SParamConvert MFLocationComponentArray:json[@"path"]];
|
|
99
|
+
NSArray<NSString *> *types = [RCTConvert NSStringArray:json[@"types"]];
|
|
100
|
+
|
|
101
|
+
MFRouteRestriction *result = nil;
|
|
102
|
+
if (location != nil) {
|
|
103
|
+
result = [[MFRouteRestriction alloc] initWithLocation:location radius:radius];
|
|
104
|
+
}
|
|
105
|
+
else if (viewbox != nil) {
|
|
106
|
+
result = [[MFRouteRestriction alloc] initWithViewbox:viewbox];
|
|
107
|
+
}
|
|
108
|
+
else if (path != nil) {
|
|
109
|
+
result = [[MFRouteRestriction alloc] initWithPath:path];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (types != nil && types.count > 0) {
|
|
113
|
+
if (result != nil) {
|
|
114
|
+
for (NSUInteger i = 0; i < types.count; i++) {
|
|
115
|
+
if ([SParamConvert isMFRouteType:types[i]]) {
|
|
116
|
+
[result avoidRouteType:[SParamConvert MFRouteType:types[i]]];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
result = [[MFRouteRestriction alloc] initWithRouteType:[SParamConvert MFRouteType:types[0]]];
|
|
122
|
+
for (NSUInteger i = 1; i < types.count; i++) {
|
|
123
|
+
if ([SParamConvert isMFRouteType:types[i]]) {
|
|
124
|
+
[result avoidRouteType:[SParamConvert MFRouteType:types[i]]];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
+ (MFTravelMode)MFTravelMode:(id)json fallback:(MFTravelMode)fallback {
|
|
135
|
+
if ([self isNull:json]) {
|
|
136
|
+
return fallback;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
NSString *mode = [RCTConvert NSString:json];
|
|
140
|
+
if ([@"motorcycle" isEqualToString:mode]) {
|
|
141
|
+
return MFTravelModeMotorcycle;
|
|
142
|
+
}
|
|
143
|
+
else if ([@"foot" isEqualToString:mode]) {
|
|
144
|
+
return MFTravelModeFoot;
|
|
145
|
+
}
|
|
146
|
+
else if ([@"bike" isEqualToString:mode]) {
|
|
147
|
+
return MFTravelModeBike;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return MFTravelModeCar;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
+ (MFRouteWeighting)MFRouteWeighting:(id)json fallback:(MFRouteWeighting)fallback {
|
|
155
|
+
if ([self isNull:json]) {
|
|
156
|
+
return fallback;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
NSString *weighting = [RCTConvert NSString:json];
|
|
160
|
+
if ([@"shortest" isEqualToString:weighting]) {
|
|
161
|
+
return MFRouteWeightingShortest;
|
|
162
|
+
}
|
|
163
|
+
else if ([@"balance" isEqualToString:weighting]) {
|
|
164
|
+
return MFRouteWeightingBalance;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return MFRouteWeightingFastest;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
+ (MFLanguageResult)MFLanguageResult:(id)json fallback:(MFLanguageResult)fallback {
|
|
172
|
+
if ([self isNull:json]) {
|
|
173
|
+
return fallback;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
NSString *language = [RCTConvert NSString:json];
|
|
177
|
+
if ([@"en" isEqualToString:language]) {
|
|
178
|
+
return MFLanguageResultEnglish;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return MFLanguageResultVietnamese;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@end
|
|
186
|
+
|
|
187
|
+
#pragma mark - SParamConvert (Private)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@implementation SParamConvert (Private)
|
|
191
|
+
|
|
192
|
+
+ (BOOL)isNull:(id)json {
|
|
193
|
+
if (json == nil || [json isKindOfClass:[NSNull class]]) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
+ (BOOL)isMFRouteType:(NSString *)type {
|
|
200
|
+
if ([@"motorway" isEqualToString:type] ||
|
|
201
|
+
[@"trunk" isEqualToString:type] ||
|
|
202
|
+
[@"ferry" isEqualToString:type] ||
|
|
203
|
+
[@"bridge" isEqualToString:type] ||
|
|
204
|
+
[@"tunnel" isEqualToString:type]) {
|
|
205
|
+
return YES;
|
|
206
|
+
}
|
|
207
|
+
return NO;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
+ (MFRouteType)MFRouteType:(NSString *)type {
|
|
211
|
+
if ([@"motorway" isEqualToString:type]) {
|
|
212
|
+
return MFRouteTypeMotorway;
|
|
213
|
+
}
|
|
214
|
+
else if ([@"trunk" isEqualToString:type]) {
|
|
215
|
+
return MFRouteTypeTrunk;
|
|
216
|
+
}
|
|
217
|
+
else if ([@"ferry" isEqualToString:type]) {
|
|
218
|
+
return MFRouteTypeFerry;
|
|
219
|
+
}
|
|
220
|
+
else if ([@"bridge" isEqualToString:type]) {
|
|
221
|
+
return MFRouteTypeBridge;
|
|
222
|
+
}
|
|
223
|
+
else if ([@"tunnel" isEqualToString:type]) {
|
|
224
|
+
return MFRouteTypeTunnel;
|
|
225
|
+
}
|
|
226
|
+
return 0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@end
|
package/ios/SRequest.m
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
#import "SRequest.h"
|
|
9
|
-
#import "
|
|
9
|
+
#import "SParamConvert.h"
|
|
10
10
|
|
|
11
11
|
@implementation SRequest
|
|
12
12
|
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
+ (MFServiceRequest *)buildGeocodingRequestWithData:(NSDictionary *)data {
|
|
16
16
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/v2/geocode"];
|
|
17
17
|
MFGeocodeParams *params = [[MFGeocodeParams alloc] initWithAddress:data[@"address"]];
|
|
18
|
-
params.location = [
|
|
19
|
-
params.viewbox = [
|
|
18
|
+
params.location = [SParamConvert MFLocationComponent:data[@"location"]];
|
|
19
|
+
params.viewbox = [SParamConvert MFViewboxComponent:data[@"viewbox"]];
|
|
20
20
|
|
|
21
21
|
request.params = params;
|
|
22
22
|
return request;
|
|
@@ -32,10 +32,9 @@
|
|
|
32
32
|
+ (MFServiceRequest *)buildTextSearchRequestWithData:(NSDictionary *)data {
|
|
33
33
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/place/text-search"];
|
|
34
34
|
MFTextSearchParams *params = [[MFTextSearchParams alloc] initWithText:data[@"text"]];
|
|
35
|
-
|
|
36
|
-
params.
|
|
37
|
-
params.
|
|
38
|
-
params.datetime = [RCTConvert NSDate:data[@"datetime"]];
|
|
35
|
+
params.types = [SParamConvert NSStringArray:data[@"types"]];
|
|
36
|
+
params.location = [SParamConvert MFLocationComponent:data[@"location"]];
|
|
37
|
+
params.datetime = [SParamConvert NSDate:data[@"datetime"]];
|
|
39
38
|
|
|
40
39
|
request.params = params;
|
|
41
40
|
return request;
|
|
@@ -43,12 +42,12 @@
|
|
|
43
42
|
|
|
44
43
|
+ (MFServiceRequest *)buildNearbySearchRequestWithData:(NSDictionary *)data {
|
|
45
44
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/place/nearby-search"];
|
|
46
|
-
MFNearbySearchParams *params = [[MFNearbySearchParams alloc] initWithLocation:[
|
|
47
|
-
radius:[
|
|
48
|
-
text:data[@"text"]];
|
|
49
|
-
params.types = data[@"types"];
|
|
50
|
-
params.tags = data[@"tags"];
|
|
51
|
-
params.datetime = [
|
|
45
|
+
MFNearbySearchParams *params = [[MFNearbySearchParams alloc] initWithLocation:[SParamConvert MFLocationComponent:data[@"location"]]
|
|
46
|
+
radius:[SParamConvert NSUInteger:data[@"radius"]]
|
|
47
|
+
text:[SParamConvert NSString:data[@"text"]]];
|
|
48
|
+
params.types = [SParamConvert NSStringArray:data[@"types"]];
|
|
49
|
+
params.tags = [SParamConvert NSStringArray:data[@"tags"]];
|
|
50
|
+
params.datetime = [SParamConvert NSDate:data[@"datetime"]];
|
|
52
51
|
|
|
53
52
|
request.params = params;
|
|
54
53
|
return request;
|
|
@@ -56,11 +55,11 @@
|
|
|
56
55
|
|
|
57
56
|
+ (MFServiceRequest *)buildViewboxSearchRequestWithData:(NSDictionary *)data {
|
|
58
57
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/place/viewbox-search"];
|
|
59
|
-
MFViewboxSearchParams *params = [[MFViewboxSearchParams alloc] initWithViewbox:[
|
|
60
|
-
text:data[@"text"]];
|
|
61
|
-
params.types = data[@"types"];
|
|
62
|
-
params.tags = data[@"tags"];
|
|
63
|
-
params.datetime = [
|
|
58
|
+
MFViewboxSearchParams *params = [[MFViewboxSearchParams alloc] initWithViewbox:[SParamConvert MFViewboxComponent:data[@"viewbox"]]
|
|
59
|
+
text:[SParamConvert NSString:data[@"text"]]];
|
|
60
|
+
params.types = [SParamConvert NSStringArray:data[@"types"]];
|
|
61
|
+
params.tags = [SParamConvert NSStringArray:data[@"tags"]];
|
|
62
|
+
params.datetime = [SParamConvert NSDate:data[@"datetime"]];
|
|
64
63
|
|
|
65
64
|
request.params = params;
|
|
66
65
|
return request;
|
|
@@ -68,9 +67,9 @@
|
|
|
68
67
|
|
|
69
68
|
+ (MFServiceRequest *)buildSuggestionsRequestWithData:(NSDictionary *)data {
|
|
70
69
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/autosuggest"];
|
|
71
|
-
MFSuggestionParams *params = [[MFSuggestionParams alloc] initWithText:data[@"text"]];
|
|
72
|
-
params.
|
|
73
|
-
params.
|
|
70
|
+
MFSuggestionParams *params = [[MFSuggestionParams alloc] initWithText:[SParamConvert NSString:data[@"text"]]];
|
|
71
|
+
params.location = [SParamConvert MFLocationComponent:data[@"location"]];
|
|
72
|
+
params.acronym = [SParamConvert BOOL:data[@"acronym"] fallback:params.acronym];
|
|
74
73
|
|
|
75
74
|
request.params = params;
|
|
76
75
|
return request;
|
|
@@ -81,14 +80,14 @@
|
|
|
81
80
|
+ (MFServiceRequest *)buildDirectionsRequestWithData:(NSDictionary *)data {
|
|
82
81
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/route"];
|
|
83
82
|
|
|
84
|
-
MFLocationComponent *origin = [
|
|
85
|
-
MFLocationComponent *destination = [
|
|
83
|
+
MFLocationComponent *origin = [SParamConvert MFLocationComponent:data[@"origin"]];
|
|
84
|
+
MFLocationComponent *destination = [SParamConvert MFLocationComponent:data[@"destination"]];
|
|
86
85
|
MFDirectionsParams *params = [[MFDirectionsParams alloc] initWithOrigin:origin destination:destination];
|
|
87
|
-
params.waypoints = [
|
|
88
|
-
params.mode = [
|
|
89
|
-
params.language = [
|
|
90
|
-
params.weighting = [
|
|
91
|
-
params.restriction = [
|
|
86
|
+
params.waypoints = [SParamConvert MFLocationComponentArray:data[@"points"]];
|
|
87
|
+
params.mode = [SParamConvert MFTravelMode:data[@"mode"] fallback:params.mode];
|
|
88
|
+
params.language = [SParamConvert MFLanguageResult:data[@"language"] fallback:params.language];
|
|
89
|
+
params.weighting = [SParamConvert MFRouteWeighting:data[@"weighting"] fallback:params.weighting];
|
|
90
|
+
params.restriction = [SParamConvert MFRouteRestriction:data[@"restriction"]];
|
|
92
91
|
|
|
93
92
|
request.params = params;
|
|
94
93
|
return request;
|
|
@@ -97,13 +96,13 @@
|
|
|
97
96
|
+ (MFServiceRequest *)buildRouteETARequestWithData:(NSDictionary *)data {
|
|
98
97
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/route/eta"];
|
|
99
98
|
|
|
100
|
-
NSArray<MFLocationComponent *> *origins = [
|
|
101
|
-
MFLocationComponent *destination = [
|
|
99
|
+
NSArray<MFLocationComponent *> *origins = [SParamConvert MFLocationComponentArray:data[@"origins"]];
|
|
100
|
+
MFLocationComponent *destination = [SParamConvert MFLocationComponent:data[@"destination"]];
|
|
102
101
|
MFRouteETAParams *params = [[MFRouteETAParams alloc] initWithOrigins:origins destination:destination];
|
|
103
|
-
params.mode = [
|
|
104
|
-
params.language = [
|
|
105
|
-
params.weighting = [
|
|
106
|
-
params.restriction = [
|
|
102
|
+
params.mode = [SParamConvert MFTravelMode:data[@"mode"] fallback:params.mode];
|
|
103
|
+
params.language = [SParamConvert MFLanguageResult:data[@"language"] fallback:params.language];
|
|
104
|
+
params.weighting = [SParamConvert MFRouteWeighting:data[@"weighting"] fallback:params.weighting];
|
|
105
|
+
params.restriction = [SParamConvert MFRouteRestriction:data[@"restriction"]];
|
|
107
106
|
|
|
108
107
|
request.params = params;
|
|
109
108
|
request.method = MFRequestMethodPost;
|
|
@@ -113,13 +112,13 @@
|
|
|
113
112
|
+ (MFServiceRequest *)buildDistanceMatrixRequestWithData:(NSDictionary *)data {
|
|
114
113
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/route/matrix"];
|
|
115
114
|
|
|
116
|
-
NSArray<MFLocationComponent *> *origins = [
|
|
117
|
-
NSArray<MFLocationComponent *> *destinations = [
|
|
115
|
+
NSArray<MFLocationComponent *> *origins = [SParamConvert MFLocationComponentArray:data[@"origins"]];
|
|
116
|
+
NSArray<MFLocationComponent *> *destinations = [SParamConvert MFLocationComponentArray:data[@"destinations"]];
|
|
118
117
|
MFDistanceMatrixParams *params = [[MFDistanceMatrixParams alloc] initWithOrigins:origins destinations:destinations];
|
|
119
|
-
params.mode = [
|
|
120
|
-
params.language = [
|
|
121
|
-
params.weighting = [
|
|
122
|
-
params.restriction = [
|
|
118
|
+
params.mode = [SParamConvert MFTravelMode:data[@"mode"] fallback:params.mode];
|
|
119
|
+
params.language = [SParamConvert MFLanguageResult:data[@"language"] fallback:params.language];
|
|
120
|
+
params.weighting = [SParamConvert MFRouteWeighting:data[@"weighting"] fallback:params.weighting];
|
|
121
|
+
params.restriction = [SParamConvert MFRouteRestriction:data[@"restriction"]];
|
|
123
122
|
|
|
124
123
|
request.params = params;
|
|
125
124
|
return request;
|
|
@@ -128,12 +127,12 @@
|
|
|
128
127
|
+ (MFServiceRequest *)buildGraphRouteRequestWithData:(NSDictionary *)data {
|
|
129
128
|
MFServiceRequest *request = [[MFServiceRequest alloc] initWithPath:@"/sdk/route/graph"];
|
|
130
129
|
|
|
131
|
-
NSArray<MFLocationComponent *> *points = [
|
|
130
|
+
NSArray<MFLocationComponent *> *points = [SParamConvert MFLocationComponentArray:data[@"locations"]];
|
|
132
131
|
MFGraphRouteParams *params = [[MFGraphRouteParams alloc] initWithLocations:points];
|
|
133
|
-
params.mode = [
|
|
134
|
-
params.language = [
|
|
135
|
-
params.weighting = [
|
|
136
|
-
params.restriction = [
|
|
132
|
+
params.mode = [SParamConvert MFTravelMode:data[@"mode"] fallback:params.mode];
|
|
133
|
+
params.language = [SParamConvert MFLanguageResult:data[@"language"] fallback:params.language];
|
|
134
|
+
params.weighting = [SParamConvert MFRouteWeighting:data[@"weighting"] fallback:params.weighting];
|
|
135
|
+
params.restriction = [SParamConvert MFRouteRestriction:data[@"restriction"]];
|
|
137
136
|
|
|
138
137
|
request.params = params;
|
|
139
138
|
return request;
|
package/package.json
CHANGED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// RCTConvert+Services.h
|
|
3
|
-
// react-native-map4d-services
|
|
4
|
-
//
|
|
5
|
-
// Created by Huy Dang on 26/01/2022.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#ifndef RCTConvert_Services_h
|
|
9
|
-
#define RCTConvert_Services_h
|
|
10
|
-
|
|
11
|
-
#import <React/RCTConvert.h>
|
|
12
|
-
#import <Map4dServices/Map4dServices.h>
|
|
13
|
-
|
|
14
|
-
@interface RCTConvert (Services)
|
|
15
|
-
|
|
16
|
-
+ (MFLocationComponent *)MFLocationComponent:(id)json;
|
|
17
|
-
|
|
18
|
-
+ (NSArray<MFLocationComponent *> *)MFLocationComponentArray:(id)json;
|
|
19
|
-
|
|
20
|
-
+ (MFViewboxComponent *)MFViewboxComponent:(id)json;
|
|
21
|
-
|
|
22
|
-
+ (MFRouteRestriction *)MFRouteRestriction:(id)json;
|
|
23
|
-
|
|
24
|
-
+ (MFTravelMode)MFTravelMode:(id)json;
|
|
25
|
-
|
|
26
|
-
+ (MFRouteWeighting)MFRouteWeighting:(id)json;
|
|
27
|
-
|
|
28
|
-
+ (MFLanguageResult)MFLanguageResult:(id)json;
|
|
29
|
-
|
|
30
|
-
@end
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
#endif /* RCTConvert_Services_h */
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// RCTConvert+Services.m
|
|
3
|
-
// react-native-map4d-services
|
|
4
|
-
//
|
|
5
|
-
// Created by Huy Dang on 26/01/2022.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#import <React/RCTConvert+CoreLocation.h>
|
|
9
|
-
#import "RCTConvert+Services.h"
|
|
10
|
-
|
|
11
|
-
@implementation RCTConvert (Services)
|
|
12
|
-
|
|
13
|
-
+ (MFLocationComponent *)MFLocationComponent:(id)json {
|
|
14
|
-
if (json == nil) {
|
|
15
|
-
return nil;
|
|
16
|
-
}
|
|
17
|
-
CLLocationCoordinate2D coordinate = [RCTConvert CLLocationCoordinate2D:json];
|
|
18
|
-
return [[MFLocationComponent alloc] initWithCoordinate:coordinate alias:json[@"alias"]];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
RCT_ARRAY_CONVERTER(MFLocationComponent);
|
|
22
|
-
|
|
23
|
-
+ (MFViewboxComponent *)MFViewboxComponent:(id)json {
|
|
24
|
-
if (json == nil) {
|
|
25
|
-
return nil;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
MFLocationComponent *southwest = [RCTConvert MFLocationComponent:json[@"southwest"]];
|
|
29
|
-
MFLocationComponent *northeast = [RCTConvert MFLocationComponent:json[@"northeast"]];
|
|
30
|
-
return [[MFViewboxComponent alloc] initWithSouthwest:southwest.coordinate northeast:northeast.coordinate];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
+ (MFRouteRestriction *)MFRouteRestriction:(id)json {
|
|
34
|
-
if (json == nil) {
|
|
35
|
-
return nil;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
MFLocationComponent *location = [RCTConvert MFLocationComponent:json[@"location"]];
|
|
39
|
-
NSUInteger radius = json[@"radius"] != nil ? [RCTConvert NSUInteger:json[@"radius"]] : 0;
|
|
40
|
-
MFViewboxComponent *viewbox = [RCTConvert MFViewboxComponent:json[@"viewbox"]];
|
|
41
|
-
NSArray<MFLocationComponent *> *path = [RCTConvert MFLocationComponentArray:json[@"path"]];
|
|
42
|
-
NSArray<NSString *> *types = [RCTConvert NSStringArray:json[@"types"]];
|
|
43
|
-
|
|
44
|
-
MFRouteRestriction *result = nil;
|
|
45
|
-
if (location != nil) {
|
|
46
|
-
result = [[MFRouteRestriction alloc] initWithLocation:location radius:radius];
|
|
47
|
-
}
|
|
48
|
-
else if (viewbox != nil) {
|
|
49
|
-
result = [[MFRouteRestriction alloc] initWithViewbox:viewbox];
|
|
50
|
-
}
|
|
51
|
-
else if (path != nil) {
|
|
52
|
-
result = [[MFRouteRestriction alloc] initWithPath:path];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (types != nil && types.count > 0) {
|
|
56
|
-
if (result != nil) {
|
|
57
|
-
for (NSUInteger i = 0; i < types.count; i++) {
|
|
58
|
-
if ([RCTConvert isMFRouteType:types[i]]) {
|
|
59
|
-
[result avoidRouteType:[RCTConvert MFRouteType:types[i]]];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
result = [[MFRouteRestriction alloc] initWithRouteType:[RCTConvert MFRouteType:types[0]]];
|
|
65
|
-
for (NSUInteger i = 1; i < types.count; i++) {
|
|
66
|
-
if ([RCTConvert isMFRouteType:types[i]]) {
|
|
67
|
-
[result avoidRouteType:[RCTConvert MFRouteType:types[i]]];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return result;
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
+ (MFTravelMode)MFTravelMode:(id)json {
|
|
78
|
-
NSString *mode = [RCTConvert NSString:json];
|
|
79
|
-
if ([@"motorcycle" isEqualToString:mode]) {
|
|
80
|
-
return MFTravelModeMotorcycle;
|
|
81
|
-
}
|
|
82
|
-
else if ([@"foot" isEqualToString:mode]) {
|
|
83
|
-
return MFTravelModeFoot;
|
|
84
|
-
}
|
|
85
|
-
else if ([@"bike" isEqualToString:mode]) {
|
|
86
|
-
return MFTravelModeBike;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return MFTravelModeCar;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
+ (MFRouteWeighting)MFRouteWeighting:(id)json {
|
|
94
|
-
NSString *weighting = [RCTConvert NSString:json];
|
|
95
|
-
if ([@"shortest" isEqualToString:weighting]) {
|
|
96
|
-
return MFRouteWeightingShortest;
|
|
97
|
-
}
|
|
98
|
-
else if ([@"balance" isEqualToString:weighting]) {
|
|
99
|
-
return MFRouteWeightingBalance;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
return MFRouteWeightingFastest;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
+ (MFLanguageResult)MFLanguageResult:(id)json {
|
|
107
|
-
NSString *language = [RCTConvert NSString:json];
|
|
108
|
-
if ([@"en" isEqualToString:language]) {
|
|
109
|
-
return MFLanguageResultEnglish;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
return MFLanguageResultVietnamese;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
+ (BOOL)isMFRouteType:(NSString *)type {
|
|
117
|
-
if ([@"motorway" isEqualToString:type] ||
|
|
118
|
-
[@"trunk" isEqualToString:type] ||
|
|
119
|
-
[@"ferry" isEqualToString:type] ||
|
|
120
|
-
[@"bridge" isEqualToString:type] ||
|
|
121
|
-
[@"tunnel" isEqualToString:type]) {
|
|
122
|
-
return YES;
|
|
123
|
-
}
|
|
124
|
-
return NO;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
+ (MFRouteType)MFRouteType:(NSString *)type {
|
|
128
|
-
if ([@"motorway" isEqualToString:type]) {
|
|
129
|
-
return MFRouteTypeMotorway;
|
|
130
|
-
}
|
|
131
|
-
else if ([@"trunk" isEqualToString:type]) {
|
|
132
|
-
return MFRouteTypeTrunk;
|
|
133
|
-
}
|
|
134
|
-
else if ([@"ferry" isEqualToString:type]) {
|
|
135
|
-
return MFRouteTypeFerry;
|
|
136
|
-
}
|
|
137
|
-
else if ([@"bridge" isEqualToString:type]) {
|
|
138
|
-
return MFRouteTypeBridge;
|
|
139
|
-
}
|
|
140
|
-
else if ([@"tunnel" isEqualToString:type]) {
|
|
141
|
-
return MFRouteTypeTunnel;
|
|
142
|
-
}
|
|
143
|
-
return 0;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
@end
|