react-native-map4d-services 0.1.0 → 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/LICENSE +21 -21
- package/README.md +24 -24
- package/android/build.gradle +60 -59
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/com/reactnativemap4dservices/Map4dServicesModule.java +91 -34
- package/android/src/main/java/com/reactnativemap4dservices/Map4dServicesPackage.java +28 -28
- package/android/src/main/java/com/reactnativemap4dservices/SClient.java +50 -0
- package/android/src/main/java/com/reactnativemap4dservices/SConverter.java +166 -0
- package/android/src/main/java/com/reactnativemap4dservices/SJsonUtils.java +130 -0
- package/android/src/main/java/com/reactnativemap4dservices/SRequest.java +376 -0
- package/ios/Map4dServices.h +5 -5
- package/ios/Map4dServices.m +81 -81
- package/ios/SClient.h +23 -23
- package/ios/SClient.m +47 -47
- package/ios/SParamConvert.h +44 -0
- package/ios/SParamConvert.m +229 -0
- package/ios/SRequest.h +40 -40
- package/ios/SRequest.m +142 -143
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +111 -111
- package/package.json +150 -150
- package/react-native-map4d-services.podspec +20 -20
- package/src/index.tsx +174 -174
- package/android/.gradle/7.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.1.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.1.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.1.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/ios/.DS_Store +0 -0
- package/ios/Map4dServices.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/RCTConvert+Services.h +0 -33
- package/ios/RCTConvert+Services.m +0 -146
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
package com.reactnativemap4dservices;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
6
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
7
|
+
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
8
|
+
import com.facebook.react.bridge.WritableArray;
|
|
9
|
+
import com.facebook.react.bridge.WritableMap;
|
|
10
|
+
import com.facebook.react.bridge.WritableNativeArray;
|
|
11
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
12
|
+
|
|
13
|
+
import org.json.JSONArray;
|
|
14
|
+
import org.json.JSONException;
|
|
15
|
+
import org.json.JSONObject;
|
|
16
|
+
|
|
17
|
+
import java.util.Iterator;
|
|
18
|
+
|
|
19
|
+
class SJsonUtils {
|
|
20
|
+
@NonNull
|
|
21
|
+
static WritableMap convertJsonToMap(@NonNull JSONObject jsonObject) throws JSONException {
|
|
22
|
+
WritableMap map = new WritableNativeMap();
|
|
23
|
+
|
|
24
|
+
Iterator<String> iterator = jsonObject.keys();
|
|
25
|
+
while (iterator.hasNext()) {
|
|
26
|
+
String key = iterator.next();
|
|
27
|
+
Object value = jsonObject.get(key);
|
|
28
|
+
if (value instanceof JSONObject) {
|
|
29
|
+
map.putMap(key, convertJsonToMap((JSONObject) value));
|
|
30
|
+
} else if (value instanceof JSONArray) {
|
|
31
|
+
map.putArray(key, convertJsonToArray((JSONArray) value));
|
|
32
|
+
if (("option_values").equals(key)) {
|
|
33
|
+
map.putArray("options", convertJsonToArray((JSONArray) value));
|
|
34
|
+
}
|
|
35
|
+
} else if (value instanceof Boolean) {
|
|
36
|
+
map.putBoolean(key, (Boolean) value);
|
|
37
|
+
} else if (value instanceof Integer) {
|
|
38
|
+
map.putInt(key, (Integer) value);
|
|
39
|
+
} else if (value instanceof Double) {
|
|
40
|
+
map.putDouble(key, (Double) value);
|
|
41
|
+
} else if (value instanceof String) {
|
|
42
|
+
map.putString(key, (String) value);
|
|
43
|
+
} else {
|
|
44
|
+
map.putString(key, value.toString());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return map;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@NonNull
|
|
51
|
+
static WritableArray convertJsonToArray(@NonNull JSONArray jsonArray) throws JSONException {
|
|
52
|
+
WritableArray array = new WritableNativeArray();
|
|
53
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
|
54
|
+
Object value = jsonArray.get(i);
|
|
55
|
+
if (value instanceof JSONObject) {
|
|
56
|
+
array.pushMap(convertJsonToMap((JSONObject) value));
|
|
57
|
+
} else if (value instanceof JSONArray) {
|
|
58
|
+
array.pushArray(convertJsonToArray((JSONArray) value));
|
|
59
|
+
} else if (value instanceof Boolean) {
|
|
60
|
+
array.pushBoolean((Boolean) value);
|
|
61
|
+
} else if (value instanceof Integer) {
|
|
62
|
+
array.pushInt((Integer) value);
|
|
63
|
+
} else if (value instanceof Double) {
|
|
64
|
+
array.pushDouble((Double) value);
|
|
65
|
+
} else if (value instanceof String) {
|
|
66
|
+
array.pushString((String) value);
|
|
67
|
+
} else {
|
|
68
|
+
array.pushString(value.toString());
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return array;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@NonNull
|
|
75
|
+
static JSONObject convertMapToJson(@NonNull ReadableMap readableMap) throws JSONException {
|
|
76
|
+
JSONObject object = new JSONObject();
|
|
77
|
+
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
|
|
78
|
+
while (iterator.hasNextKey()) {
|
|
79
|
+
String key = iterator.nextKey();
|
|
80
|
+
switch (readableMap.getType(key)) {
|
|
81
|
+
case Null:
|
|
82
|
+
object.put(key, JSONObject.NULL);
|
|
83
|
+
break;
|
|
84
|
+
case Boolean:
|
|
85
|
+
object.put(key, readableMap.getBoolean(key));
|
|
86
|
+
break;
|
|
87
|
+
case Number:
|
|
88
|
+
object.put(key, readableMap.getDouble(key));
|
|
89
|
+
break;
|
|
90
|
+
case String:
|
|
91
|
+
object.put(key, readableMap.getString(key));
|
|
92
|
+
break;
|
|
93
|
+
case Map:
|
|
94
|
+
object.put(key, convertMapToJson(readableMap.getMap(key)));
|
|
95
|
+
break;
|
|
96
|
+
case Array:
|
|
97
|
+
object.put(key, convertArrayToJson(readableMap.getArray(key)));
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return object;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@NonNull
|
|
105
|
+
static JSONArray convertArrayToJson(@NonNull ReadableArray readableArray) throws JSONException {
|
|
106
|
+
JSONArray array = new JSONArray();
|
|
107
|
+
for (int i = 0; i < readableArray.size(); i++) {
|
|
108
|
+
switch (readableArray.getType(i)) {
|
|
109
|
+
case Null:
|
|
110
|
+
break;
|
|
111
|
+
case Boolean:
|
|
112
|
+
array.put(readableArray.getBoolean(i));
|
|
113
|
+
break;
|
|
114
|
+
case Number:
|
|
115
|
+
array.put(readableArray.getDouble(i));
|
|
116
|
+
break;
|
|
117
|
+
case String:
|
|
118
|
+
array.put(readableArray.getString(i));
|
|
119
|
+
break;
|
|
120
|
+
case Map:
|
|
121
|
+
array.put(convertMapToJson(readableArray.getMap(i)));
|
|
122
|
+
break;
|
|
123
|
+
case Array:
|
|
124
|
+
array.put(convertArrayToJson(readableArray.getArray(i)));
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return array;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
package com.reactnativemap4dservices;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
6
|
+
|
|
7
|
+
import org.json.JSONArray;
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
import vn.map4d.services.MFMethod;
|
|
12
|
+
import vn.map4d.services.MFRequestParams;
|
|
13
|
+
import vn.map4d.services.MFServiceOptions;
|
|
14
|
+
|
|
15
|
+
public class SRequest {
|
|
16
|
+
static MFServiceOptions buildSuggestionsRequestWithData(@NonNull ReadableMap params) {
|
|
17
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
18
|
+
serviceOptionsBuilder.url("/sdk/autosuggest");
|
|
19
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
20
|
+
|
|
21
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
22
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
23
|
+
String text = params.getString("text");
|
|
24
|
+
requestParams.put("text", text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (params.hasKey("acronym") && !params.isNull("acronym")) {
|
|
28
|
+
boolean acronym = params.getBoolean("acronym");
|
|
29
|
+
requestParams.put("acronym", String.valueOf(acronym));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
33
|
+
String location = SConverter.toLocation(params.getMap("location"));
|
|
34
|
+
requestParams.put("location", location);
|
|
35
|
+
}
|
|
36
|
+
serviceOptionsBuilder.params(requestParams);
|
|
37
|
+
return serviceOptionsBuilder.build();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static MFServiceOptions buildPlaceDetailRequestWithId(@NonNull String placeId) {
|
|
41
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
42
|
+
StringBuilder urlBuilder = new StringBuilder("/sdk/place/detail");
|
|
43
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
44
|
+
if (placeId != null) {
|
|
45
|
+
urlBuilder.append("/").append(placeId);
|
|
46
|
+
}
|
|
47
|
+
serviceOptionsBuilder.url(urlBuilder.toString());
|
|
48
|
+
return serviceOptionsBuilder.build();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static MFServiceOptions buildTextSearchRequestWithData(@NonNull ReadableMap params) {
|
|
52
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
53
|
+
serviceOptionsBuilder.url("/sdk/place/text-search");
|
|
54
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
55
|
+
|
|
56
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
57
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
58
|
+
String text = params.getString("text");
|
|
59
|
+
requestParams.put("text", text);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
63
|
+
String location = SConverter.toLocation(params.getMap("location"));
|
|
64
|
+
requestParams.put("location", location);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (params.hasKey("types") && !params.isNull("types")) {
|
|
68
|
+
String types = SConverter.toTypes(params.getArray("types"));
|
|
69
|
+
requestParams.put("types", types);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (params.hasKey("datetime") && !params.isNull("datetime")) {
|
|
73
|
+
String datetime = SConverter.toDatetime(params.getDouble("datetime"));
|
|
74
|
+
requestParams.put("datetime", datetime);
|
|
75
|
+
}
|
|
76
|
+
serviceOptionsBuilder.params(requestParams);
|
|
77
|
+
return serviceOptionsBuilder.build();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static MFServiceOptions buildNearbySearchRequestWithData(@NonNull ReadableMap params) {
|
|
81
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
82
|
+
serviceOptionsBuilder.url("/sdk/place/nearby-search");
|
|
83
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
84
|
+
|
|
85
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
86
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
87
|
+
String location = SConverter.toLocation(params.getMap("location"));
|
|
88
|
+
requestParams.put("location", location);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (params.hasKey("radius") && !params.isNull("radius")) {
|
|
92
|
+
String radius = String.valueOf(params.getInt("radius"));
|
|
93
|
+
requestParams.put("radius", radius);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
97
|
+
String text = params.getString("text");
|
|
98
|
+
requestParams.put("text", text);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (params.hasKey("types") && !params.isNull("types")) {
|
|
102
|
+
String types = SConverter.toTypes(params.getArray("types"));
|
|
103
|
+
requestParams.put("types", types);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (params.hasKey("tags") && !params.isNull("tags")) {
|
|
107
|
+
String tags = SConverter.toTags(params.getArray("tags"));
|
|
108
|
+
requestParams.put("tags", tags);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (params.hasKey("datetime") && !params.isNull("datetime")) {
|
|
112
|
+
String datetime = SConverter.toDatetime(params.getDouble("datetime"));
|
|
113
|
+
requestParams.put("datetime", datetime);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
serviceOptionsBuilder.params(requestParams);
|
|
117
|
+
return serviceOptionsBuilder.build();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static MFServiceOptions buildViewboxSearchRequestWithData(@NonNull ReadableMap params) {
|
|
121
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
122
|
+
serviceOptionsBuilder.url("/sdk/place/viewbox-search");
|
|
123
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
124
|
+
|
|
125
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
126
|
+
if (params.hasKey("viewbox") && !params.isNull("viewbox")) {
|
|
127
|
+
String viewbox = SConverter.toViewbox(params.getMap("viewbox"));
|
|
128
|
+
requestParams.put("viewbox", viewbox);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (params.hasKey("text") && !params.isNull("text")) {
|
|
132
|
+
String text = params.getString("text");
|
|
133
|
+
requestParams.put("text", text);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (params.hasKey("types") && !params.isNull("types")) {
|
|
137
|
+
String types = SConverter.toTypes(params.getArray("types"));
|
|
138
|
+
requestParams.put("types", types);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (params.hasKey("tags") && !params.isNull("tags")) {
|
|
142
|
+
String tags = SConverter.toTags(params.getArray("tags"));
|
|
143
|
+
requestParams.put("tags", tags);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (params.hasKey("datetime") && !params.isNull("datetime")) {
|
|
147
|
+
String datetime = SConverter.toDatetime(params.getDouble("datetime"));
|
|
148
|
+
requestParams.put("datetime", datetime);
|
|
149
|
+
}
|
|
150
|
+
serviceOptionsBuilder.params(requestParams);
|
|
151
|
+
return serviceOptionsBuilder.build();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static MFServiceOptions buildGeocodingRequestWithData(@NonNull ReadableMap params) {
|
|
155
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
156
|
+
serviceOptionsBuilder.url("/sdk/v2/geocode");
|
|
157
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
158
|
+
|
|
159
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
160
|
+
if (params.hasKey("address") && !params.isNull("address")) {
|
|
161
|
+
String address = params.getString("address");
|
|
162
|
+
requestParams.put("address", address);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (params.hasKey("location") && !params.isNull("location")) {
|
|
166
|
+
String location = SConverter.toLocation(params.getMap("location"));
|
|
167
|
+
requestParams.put("location", location);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (params.hasKey("viewbox") && !params.isNull("viewbox")) {
|
|
171
|
+
String viewbox = SConverter.toViewbox(params.getMap("viewbox"));
|
|
172
|
+
requestParams.put("viewbox", viewbox);
|
|
173
|
+
}
|
|
174
|
+
serviceOptionsBuilder.params(requestParams);
|
|
175
|
+
return serviceOptionsBuilder.build();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static MFServiceOptions buildDirectionsRequestWithData(@NonNull ReadableMap params) {
|
|
179
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
180
|
+
serviceOptionsBuilder.url("/sdk/route");
|
|
181
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
182
|
+
|
|
183
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
184
|
+
|
|
185
|
+
if (params.hasKey("origin") && !params.isNull("origin")) {
|
|
186
|
+
String origin = SConverter.toLocation(params.getMap("origin"));
|
|
187
|
+
requestParams.put("origin", origin);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (params.hasKey("destination") && !params.isNull("destination")) {
|
|
191
|
+
String destination = SConverter.toLocation(params.getMap("destination"));
|
|
192
|
+
requestParams.put("destination", destination);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
196
|
+
String mode = params.getString("mode");
|
|
197
|
+
requestParams.put("mode", mode);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
201
|
+
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
202
|
+
requestParams.put("weighting", String.valueOf(weighting));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
206
|
+
String language = params.getString("language");
|
|
207
|
+
requestParams.put("language", language);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (params.hasKey("waypoints") && !params.isNull("waypoints")) {
|
|
211
|
+
String waypoints = SConverter.toLocationList(params.getArray("waypoints"));
|
|
212
|
+
requestParams.put("points", waypoints);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
216
|
+
ReadableMap restrictionMap = params.getMap("restriction");
|
|
217
|
+
String avoid = SConverter.toAvoid(restrictionMap);
|
|
218
|
+
if (avoid != null && !avoid.isEmpty()) {
|
|
219
|
+
requestParams.put("avoid", avoid);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
String avoidRoads = SConverter.toAvoidRoads(restrictionMap);
|
|
223
|
+
if (avoidRoads != null) {
|
|
224
|
+
requestParams.put("avoidRoads", avoidRoads);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
serviceOptionsBuilder.params(requestParams);
|
|
229
|
+
return serviceOptionsBuilder.build();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static MFServiceOptions buildRouteETARequestWithData(@NonNull ReadableMap params) {
|
|
233
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
234
|
+
serviceOptionsBuilder.url("/sdk/route/eta");
|
|
235
|
+
serviceOptionsBuilder.method(MFMethod.POST);
|
|
236
|
+
|
|
237
|
+
JSONObject jsonObject = new JSONObject();
|
|
238
|
+
try {
|
|
239
|
+
if (params.hasKey("origins") && !params.isNull("origins")) {
|
|
240
|
+
JSONArray origins = SConverter.toOriginJsonArray(params.getArray("origins"));
|
|
241
|
+
jsonObject.put("origins", origins);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (params.hasKey("destination") && !params.isNull("destination")) {
|
|
245
|
+
String destination = SConverter.toLocation(params.getMap("destination"));
|
|
246
|
+
jsonObject.put("destination", destination);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
250
|
+
String mode = params.getString("mode");
|
|
251
|
+
jsonObject.put("mode", mode);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
255
|
+
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
256
|
+
jsonObject.put("weighting", String.valueOf(weighting));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
260
|
+
String language = params.getString("language");
|
|
261
|
+
jsonObject.put("language", language);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
265
|
+
ReadableMap restrictionMap = params.getMap("restriction");
|
|
266
|
+
String avoid = SConverter.toAvoid(restrictionMap);
|
|
267
|
+
if (avoid != null && !avoid.isEmpty()) {
|
|
268
|
+
jsonObject.put("avoid", avoid);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
String avoidRoads = SConverter.toAvoidRoads(restrictionMap);
|
|
272
|
+
if (avoidRoads != null) {
|
|
273
|
+
jsonObject.put("avoidRoads", avoidRoads);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} catch (JSONException e) {
|
|
277
|
+
e.printStackTrace();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
serviceOptionsBuilder.json(jsonObject.toString());
|
|
281
|
+
return serviceOptionsBuilder.build();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static MFServiceOptions buildDistanceMatrixRequestWithData(@NonNull ReadableMap params) {
|
|
285
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
286
|
+
serviceOptionsBuilder.url("/sdk/route/matrix");
|
|
287
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
288
|
+
|
|
289
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
290
|
+
|
|
291
|
+
if (params.hasKey("origins") && !params.isNull("origins")) {
|
|
292
|
+
String origins = SConverter.toLocationList(params.getArray("origins"));
|
|
293
|
+
requestParams.put("origins", origins);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (params.hasKey("destinations") && !params.isNull("destinations")) {
|
|
297
|
+
String destinations = SConverter.toLocationList(params.getArray("destinations"));
|
|
298
|
+
requestParams.put("destinations", destinations);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
302
|
+
String mode = params.getString("mode");
|
|
303
|
+
requestParams.put("mode", mode);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
307
|
+
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
308
|
+
requestParams.put("weighting", String.valueOf(weighting));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
312
|
+
String language = params.getString("language");
|
|
313
|
+
requestParams.put("language", language);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
317
|
+
ReadableMap restrictionMap = params.getMap("restriction");
|
|
318
|
+
String avoid = SConverter.toAvoid(restrictionMap);
|
|
319
|
+
if (avoid != null && !avoid.isEmpty()) {
|
|
320
|
+
requestParams.put("avoid", avoid);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
String avoidRoads = SConverter.toAvoidRoads(restrictionMap);
|
|
324
|
+
if (avoidRoads != null) {
|
|
325
|
+
requestParams.put("avoidRoads", avoidRoads);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
serviceOptionsBuilder.params(requestParams);
|
|
330
|
+
return serviceOptionsBuilder.build();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
static MFServiceOptions buildGraphRouteRequestWithData(@NonNull ReadableMap params) {
|
|
334
|
+
MFServiceOptions.Builder serviceOptionsBuilder = new MFServiceOptions.Builder();
|
|
335
|
+
serviceOptionsBuilder.url("/sdk/route/graph");
|
|
336
|
+
serviceOptionsBuilder.method(MFMethod.GET);
|
|
337
|
+
|
|
338
|
+
MFRequestParams requestParams = new MFRequestParams();
|
|
339
|
+
|
|
340
|
+
if (params.hasKey("locations") && !params.isNull("locations")) {
|
|
341
|
+
String points = SConverter.toLocationList(params.getArray("locations"));
|
|
342
|
+
requestParams.put("points", points);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (params.hasKey("mode") && !params.isNull("mode")) {
|
|
346
|
+
String mode = params.getString("mode");
|
|
347
|
+
requestParams.put("mode", mode);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (params.hasKey("weighting") && !params.isNull("weighting")) {
|
|
351
|
+
int weighting = SConverter.toWeighting(params.getString("weighting"));
|
|
352
|
+
requestParams.put("weighting", String.valueOf(weighting));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (params.hasKey("language") && !params.isNull("language")) {
|
|
356
|
+
String language = params.getString("language");
|
|
357
|
+
requestParams.put("language", language);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (params.hasKey("restriction") && !params.isNull("restriction")) {
|
|
361
|
+
ReadableMap restrictionMap = params.getMap("restriction");
|
|
362
|
+
String avoid = SConverter.toAvoid(restrictionMap);
|
|
363
|
+
if (avoid != null && !avoid.isEmpty()) {
|
|
364
|
+
requestParams.put("avoid", avoid);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
String avoidRoads = SConverter.toAvoidRoads(restrictionMap);
|
|
368
|
+
if (avoidRoads != null) {
|
|
369
|
+
requestParams.put("avoidRoads", avoidRoads);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
serviceOptionsBuilder.params(requestParams);
|
|
374
|
+
return serviceOptionsBuilder.build();
|
|
375
|
+
}
|
|
376
|
+
}
|
package/ios/Map4dServices.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#import <React/RCTBridgeModule.h>
|
|
2
|
-
|
|
3
|
-
@interface Map4dServices : NSObject <RCTBridgeModule>
|
|
4
|
-
|
|
5
|
-
@end
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface Map4dServices : NSObject <RCTBridgeModule>
|
|
4
|
+
|
|
5
|
+
@end
|
package/ios/Map4dServices.m
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
#import "Map4dServices.h"
|
|
2
|
-
#import "SRequest.h"
|
|
3
|
-
#import "SClient.h"
|
|
4
|
-
|
|
5
|
-
@implementation Map4dServices
|
|
6
|
-
|
|
7
|
-
RCT_EXPORT_MODULE()
|
|
8
|
-
|
|
9
|
-
// https://reactnative.dev/docs/native-modules-ios
|
|
10
|
-
|
|
11
|
-
/* Place | Suggestions */
|
|
12
|
-
RCT_EXPORT_METHOD(fetchSuggestion:(id)params
|
|
13
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
14
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
15
|
-
[SClient fireRequest:[SRequest buildSuggestionsRequestWithData:params] resolve:resolve reject:reject];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* Place | Detail */
|
|
19
|
-
RCT_EXPORT_METHOD(fetchPlaceDetail:(NSString *)placeId
|
|
20
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
21
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
22
|
-
[SClient fireRequest:[SRequest buildPlaceDetailRequestWithId:placeId] resolve:resolve reject:reject];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* Place | Text search */
|
|
26
|
-
RCT_EXPORT_METHOD(fetchTextSearch:(id)params
|
|
27
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
28
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
29
|
-
[SClient fireRequest:[SRequest buildTextSearchRequestWithData:params] resolve:resolve reject:reject];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/* Place | Nearby search */
|
|
33
|
-
RCT_EXPORT_METHOD(fetchNearbySearch:(id)params
|
|
34
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
35
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
36
|
-
[SClient fireRequest:[SRequest buildNearbySearchRequestWithData:params] resolve:resolve reject:reject];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/* Place | Viewbox search */
|
|
40
|
-
RCT_EXPORT_METHOD(fetchViewboxSearch:(id)params
|
|
41
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
42
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
43
|
-
[SClient fireRequest:[SRequest buildViewboxSearchRequestWithData:params] resolve:resolve reject:reject];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/* Place | Geocode */
|
|
47
|
-
RCT_EXPORT_METHOD(fetchGeocode:(id)params
|
|
48
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
49
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
50
|
-
[SClient fireRequest:[SRequest buildGeocodingRequestWithData:params] resolve:resolve reject:reject];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* Route | Directions */
|
|
54
|
-
RCT_EXPORT_METHOD(fetchDirections:(id)params
|
|
55
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
56
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
57
|
-
[SClient fireRequest:[SRequest buildDirectionsRequestWithData:params] resolve:resolve reject:reject];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/* Route | ETA */
|
|
61
|
-
RCT_EXPORT_METHOD(fetchRouteETA:(id)params
|
|
62
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
63
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
64
|
-
[SClient fireRequest:[SRequest buildRouteETARequestWithData:params] resolve:resolve reject:reject];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* Route | Distance matrix */
|
|
68
|
-
RCT_EXPORT_METHOD(fetchDistanceMatrix:(id)params
|
|
69
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
70
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
71
|
-
[SClient fireRequest:[SRequest buildDistanceMatrixRequestWithData:params] resolve:resolve reject:reject];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* Route | Graph route */
|
|
75
|
-
RCT_EXPORT_METHOD(fetchGraphRoute:(id)params
|
|
76
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
77
|
-
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
78
|
-
[SClient fireRequest:[SRequest buildGraphRouteRequestWithData:params] resolve:resolve reject:reject];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@end
|
|
1
|
+
#import "Map4dServices.h"
|
|
2
|
+
#import "SRequest.h"
|
|
3
|
+
#import "SClient.h"
|
|
4
|
+
|
|
5
|
+
@implementation Map4dServices
|
|
6
|
+
|
|
7
|
+
RCT_EXPORT_MODULE()
|
|
8
|
+
|
|
9
|
+
// https://reactnative.dev/docs/native-modules-ios
|
|
10
|
+
|
|
11
|
+
/* Place | Suggestions */
|
|
12
|
+
RCT_EXPORT_METHOD(fetchSuggestion:(id)params
|
|
13
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
14
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
15
|
+
[SClient fireRequest:[SRequest buildSuggestionsRequestWithData:params] resolve:resolve reject:reject];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Place | Detail */
|
|
19
|
+
RCT_EXPORT_METHOD(fetchPlaceDetail:(NSString *)placeId
|
|
20
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
21
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
22
|
+
[SClient fireRequest:[SRequest buildPlaceDetailRequestWithId:placeId] resolve:resolve reject:reject];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Place | Text search */
|
|
26
|
+
RCT_EXPORT_METHOD(fetchTextSearch:(id)params
|
|
27
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
28
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
29
|
+
[SClient fireRequest:[SRequest buildTextSearchRequestWithData:params] resolve:resolve reject:reject];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Place | Nearby search */
|
|
33
|
+
RCT_EXPORT_METHOD(fetchNearbySearch:(id)params
|
|
34
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
35
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
36
|
+
[SClient fireRequest:[SRequest buildNearbySearchRequestWithData:params] resolve:resolve reject:reject];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Place | Viewbox search */
|
|
40
|
+
RCT_EXPORT_METHOD(fetchViewboxSearch:(id)params
|
|
41
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
42
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
43
|
+
[SClient fireRequest:[SRequest buildViewboxSearchRequestWithData:params] resolve:resolve reject:reject];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* Place | Geocode */
|
|
47
|
+
RCT_EXPORT_METHOD(fetchGeocode:(id)params
|
|
48
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
49
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
50
|
+
[SClient fireRequest:[SRequest buildGeocodingRequestWithData:params] resolve:resolve reject:reject];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Route | Directions */
|
|
54
|
+
RCT_EXPORT_METHOD(fetchDirections:(id)params
|
|
55
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
56
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
57
|
+
[SClient fireRequest:[SRequest buildDirectionsRequestWithData:params] resolve:resolve reject:reject];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Route | ETA */
|
|
61
|
+
RCT_EXPORT_METHOD(fetchRouteETA:(id)params
|
|
62
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
63
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
64
|
+
[SClient fireRequest:[SRequest buildRouteETARequestWithData:params] resolve:resolve reject:reject];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Route | Distance matrix */
|
|
68
|
+
RCT_EXPORT_METHOD(fetchDistanceMatrix:(id)params
|
|
69
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
70
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
71
|
+
[SClient fireRequest:[SRequest buildDistanceMatrixRequestWithData:params] resolve:resolve reject:reject];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Route | Graph route */
|
|
75
|
+
RCT_EXPORT_METHOD(fetchGraphRoute:(id)params
|
|
76
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
77
|
+
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
78
|
+
[SClient fireRequest:[SRequest buildGraphRouteRequestWithData:params] resolve:resolve reject:reject];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@end
|