react-native-ipostmap-navigation 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +109 -0
- package/android/build.gradle +86 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +10 -0
- package/android/src/main/java/com/map4dnavigationreactnative/JsonUtils.java +303 -0
- package/android/src/main/java/com/map4dnavigationreactnative/Map4dNavigationReactNativeModule.kt +34 -0
- package/android/src/main/java/com/map4dnavigationreactnative/Map4dNavigationReactNativePackage.kt +33 -0
- package/android/src/main/java/com/map4dnavigationreactnative/PolylineUtils.java +52 -0
- package/android/src/main/java/com/map4dnavigationreactnative/RMFNavigationActivity.java +112 -0
- package/iPostMapNavigationReactNative.podspec +22 -0
- package/ios/Map4dNavigationReactNative.h +5 -0
- package/ios/Map4dNavigationReactNative.mm +89 -0
- package/lib/module/NativeMap4dNavigationReactNative.js +5 -0
- package/lib/module/NativeMap4dNavigationReactNative.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeMap4dNavigationReactNative.d.ts +7 -0
- package/lib/typescript/src/NativeMap4dNavigationReactNative.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +161 -0
- package/src/NativeMap4dNavigationReactNative.ts +7 -0
- package/src/index.tsx +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IOTLink
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# react-native-ipostmap-navigation
|
|
2
|
+
|
|
3
|
+
iPostMap Navigation SDK for React Native
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install react-native-ipostmap-navigation
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Setup API key
|
|
13
|
+
|
|
14
|
+
The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.
|
|
15
|
+
|
|
16
|
+
Get an API key at <https://map.ipostmap.vn/user> > Developer > Key
|
|
17
|
+
|
|
18
|
+
### Android
|
|
19
|
+
|
|
20
|
+
Provide access key from `android/app/src/main/AndroidManifest.xml`
|
|
21
|
+
|
|
22
|
+
```xml
|
|
23
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
24
|
+
<application>
|
|
25
|
+
<meta-data
|
|
26
|
+
android:name="vn.map4d.map.ACCESS_KEY"
|
|
27
|
+
android:value="YOUR_MAP_ACCESS_KEY"/>
|
|
28
|
+
<meta-data
|
|
29
|
+
android:name="vn.map4d.services.ACCESS_KEY"
|
|
30
|
+
android:value="YOUR_SERVICES_ACCESS_KEY"/>
|
|
31
|
+
</application>
|
|
32
|
+
</manifest>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### iOS
|
|
36
|
+
|
|
37
|
+
Provide access key from `ios/Runner/Info.plist`
|
|
38
|
+
|
|
39
|
+
```xml
|
|
40
|
+
<key>Map4dMapAccessKey</key>
|
|
41
|
+
<string>YOUR_MAP_ACCESS_KEY</string>
|
|
42
|
+
<key>Map4dServicesAccessKey</key>
|
|
43
|
+
<string>YOUR_SERVICES_ACCESS_KEY</string>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { View, StyleSheet, Button, Alert } from 'react-native';
|
|
51
|
+
import { startMapNavigation } from 'react-native-ipostmap-navigation';
|
|
52
|
+
import { fetchDirections, type MFDirectionsParams } from 'react-native-ipostmap-services';
|
|
53
|
+
|
|
54
|
+
const startNavigation = async () => {
|
|
55
|
+
const params: MFDirectionsParams = {
|
|
56
|
+
origin: { latitude: 16.039572, longitude: 108.212173 },
|
|
57
|
+
destination: { latitude: 16.048087, longitude: 108.246115 },
|
|
58
|
+
mode: "car"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const response = await fetchDirections(params)
|
|
62
|
+
|
|
63
|
+
if (response.code !== 'ok') {
|
|
64
|
+
console.log(`Get directions error with code: ${response.code}, message: ${response.message}`)
|
|
65
|
+
Alert.alert(response.code, response.message)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const result = response.result
|
|
70
|
+
if (!result || typeof result !== 'object') {
|
|
71
|
+
Alert.alert('Invalid directions result', result)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const routes = result.routes
|
|
76
|
+
if (!routes || !Array.isArray(routes)) {
|
|
77
|
+
Alert.alert('Invalid directions routes', routes)
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (routes.length == 0) {
|
|
82
|
+
Alert.alert('Direction rout not found')
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const routeIndex = Math.floor(Math.random() * routes.length)
|
|
87
|
+
startMapNavigation(result, routeIndex, params)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default function App() {
|
|
91
|
+
return (
|
|
92
|
+
<View style={styles.container}>
|
|
93
|
+
<Button
|
|
94
|
+
onPress={startNavigation}
|
|
95
|
+
title='Start Navigation'
|
|
96
|
+
/>
|
|
97
|
+
</View>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const styles = StyleSheet.create({
|
|
102
|
+
container: {
|
|
103
|
+
flex: 1,
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
justifyContent: 'center',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Map4dNavigationReactNative_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Map4dNavigationReactNative_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.map4dnavigationreactnative"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
|
|
78
|
+
implementation 'com.google.android.material:material:1.4.0'
|
|
79
|
+
|
|
80
|
+
implementation 'vn.map4d:iPostMapNavigationCore:1.0.+'
|
|
81
|
+
implementation 'vn.map4d:iPostMapNavigation:1.0.+'
|
|
82
|
+
|
|
83
|
+
implementation 'vn.map4d:iPostMap:1.0.+'
|
|
84
|
+
implementation 'vn.map4d:iPostMapServices:1.0.+'
|
|
85
|
+
implementation 'vn.map4d:Map4dTypes:1.1.+'
|
|
86
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
package com.map4dnavigationreactnative;
|
|
2
|
+
|
|
3
|
+
import org.json.JSONArray;
|
|
4
|
+
import org.json.JSONException;
|
|
5
|
+
import org.json.JSONObject;
|
|
6
|
+
|
|
7
|
+
import java.util.ArrayList;
|
|
8
|
+
import java.util.List;
|
|
9
|
+
import java.util.Objects;
|
|
10
|
+
|
|
11
|
+
import javax.annotation.Nonnull;
|
|
12
|
+
import javax.annotation.Nullable;
|
|
13
|
+
|
|
14
|
+
import vn.map4d.services.MFLocationComponent;
|
|
15
|
+
import vn.map4d.services.directions.MFDirectionOptions;
|
|
16
|
+
import vn.map4d.services.directions.MFManeuver;
|
|
17
|
+
import vn.map4d.services.directions.MFRoute;
|
|
18
|
+
import vn.map4d.services.directions.MFRouteRestriction;
|
|
19
|
+
import vn.map4d.services.directions.MFTravelMode;
|
|
20
|
+
import vn.map4d.services.directions.MFWeighting;
|
|
21
|
+
import vn.map4d.services.internal.JsonParser;
|
|
22
|
+
|
|
23
|
+
class JsonUtils {
|
|
24
|
+
|
|
25
|
+
static MFDirectionOptions toDirectionOptions(String json) {
|
|
26
|
+
try {
|
|
27
|
+
JSONObject jsonObject = new JSONObject(json);
|
|
28
|
+
MFLocationComponent origin = toLocationComponent(JsonParser.getJsonObject("origin", jsonObject));
|
|
29
|
+
MFLocationComponent destination = toLocationComponent(JsonParser.getJsonObject("destination", jsonObject));
|
|
30
|
+
MFDirectionOptions.Builder directionOptionsBuilder = new MFDirectionOptions.Builder()
|
|
31
|
+
.origin(origin)
|
|
32
|
+
.destination(destination);
|
|
33
|
+
|
|
34
|
+
String mode = JsonParser.getString("mode", jsonObject);
|
|
35
|
+
if (mode != null) {
|
|
36
|
+
MFTravelMode travelMode = MFTravelMode.fromValue(mode);
|
|
37
|
+
if (travelMode != null) {
|
|
38
|
+
directionOptionsBuilder.mode(travelMode);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
String weightingString = JsonParser.getString("weighting", jsonObject);
|
|
43
|
+
if (weightingString != null) {
|
|
44
|
+
MFWeighting weighting = weightingFromValue(weightingString);
|
|
45
|
+
if (weighting != null) {
|
|
46
|
+
directionOptionsBuilder.weighting(weighting);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
String language = JsonParser.getString("language", jsonObject);
|
|
51
|
+
if (language != null) {
|
|
52
|
+
directionOptionsBuilder.language(language);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
List<MFLocationComponent> waypoints = new ArrayList<>();
|
|
56
|
+
JSONArray waypointsArray = JsonParser.getJsonArray("waypoints", jsonObject);
|
|
57
|
+
if (waypointsArray != null) {
|
|
58
|
+
for (int i = 0; i < waypointsArray.length(); ++i) {
|
|
59
|
+
JSONObject waypointJsonObject = waypointsArray.getJSONObject(i);
|
|
60
|
+
if (waypointJsonObject != null) {
|
|
61
|
+
waypoints.add(toLocationComponent(waypointJsonObject));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!waypoints.isEmpty()) {
|
|
66
|
+
directionOptionsBuilder.waypoints(waypoints);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
JSONObject restrictionJsonObject = JsonParser.getJsonObject("restriction", jsonObject);
|
|
70
|
+
if (restrictionJsonObject != null) {
|
|
71
|
+
directionOptionsBuilder.restriction(routeRestrictionFromJsonObject(restrictionJsonObject));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
MFDirectionOptions directionOptions = directionOptionsBuilder.build();
|
|
75
|
+
return directionOptions;
|
|
76
|
+
} catch (JSONException e) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static ArrayList<MFRoute> toDirectionsRoute(String json) {
|
|
82
|
+
try {
|
|
83
|
+
ArrayList<MFRoute> routes = new ArrayList<>();
|
|
84
|
+
JSONObject jsonObject = new JSONObject(json);
|
|
85
|
+
JSONArray routesArrays = JsonParser.getJsonArray("routes", jsonObject);
|
|
86
|
+
for (int i = 0; i < Objects.requireNonNull(routesArrays).length(); ++i) {
|
|
87
|
+
JSONObject routeObject = routesArrays.getJSONObject(i);
|
|
88
|
+
if (routeObject != null) {
|
|
89
|
+
MFRoute route = toRoute(routeObject);
|
|
90
|
+
if (route != null) {
|
|
91
|
+
routes.add(route);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return routes;
|
|
96
|
+
} catch (Exception e) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Nullable
|
|
102
|
+
private static MFWeighting weightingFromValue(@Nonnull String value) {
|
|
103
|
+
switch (value.toLowerCase()) {
|
|
104
|
+
case "shortest":
|
|
105
|
+
return MFWeighting.SHORTEST;
|
|
106
|
+
case "fastest":
|
|
107
|
+
return MFWeighting.FASTEST;
|
|
108
|
+
case "balance":
|
|
109
|
+
return MFWeighting.BALANCE;
|
|
110
|
+
default:
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Nullable
|
|
116
|
+
private static MFRouteRestriction routeRestrictionFromJsonObject(@Nullable JSONObject jsonObject) {
|
|
117
|
+
// Types
|
|
118
|
+
List<MFRouteRestriction.MFRouteType> types = null;
|
|
119
|
+
JSONArray typesArr = jsonObject.optJSONArray("types");
|
|
120
|
+
if (typesArr != null) {
|
|
121
|
+
types = new ArrayList<>();
|
|
122
|
+
for (int i = 0; i < typesArr.length(); i++) {
|
|
123
|
+
String t = typesArr.optString(i, null);
|
|
124
|
+
MFRouteRestriction.MFRouteType type = MFRouteRestriction.MFRouteType.fromValue(t);
|
|
125
|
+
if (type != null) types.add(type);
|
|
126
|
+
}
|
|
127
|
+
if (types.isEmpty()) types = null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Location
|
|
131
|
+
if (jsonObject.has("location")) {
|
|
132
|
+
JSONObject loc = jsonObject.optJSONObject("location");
|
|
133
|
+
MFLocationComponent point = toLocationComponent(loc);
|
|
134
|
+
return MFRouteRestriction.restrictLocation(point, types);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Circle
|
|
138
|
+
if (jsonObject.has("location") && jsonObject.has("radius")) {
|
|
139
|
+
JSONObject loc = jsonObject.optJSONObject("location");
|
|
140
|
+
Integer radius = jsonObject.has("radius") ? jsonObject.optInt("radius") : null;
|
|
141
|
+
MFLocationComponent point = toLocationComponent(loc);
|
|
142
|
+
return MFRouteRestriction.restrictCircleArea(point, radius, types);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// View box
|
|
146
|
+
if (jsonObject.has("viewbox")) {
|
|
147
|
+
JSONObject box = jsonObject.optJSONObject("viewbox");
|
|
148
|
+
JSONObject sw = box.optJSONObject("southwest");
|
|
149
|
+
JSONObject ne = box.optJSONObject("northeast");
|
|
150
|
+
MFLocationComponent southWest = toLocationComponent(sw);
|
|
151
|
+
MFLocationComponent northEast = toLocationComponent(ne);
|
|
152
|
+
return MFRouteRestriction.restrictCoordinateBounds(southWest, northEast, types);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Path (polygon)
|
|
156
|
+
JSONArray pathArr = jsonObject.optJSONArray("path");
|
|
157
|
+
if (pathArr != null) {
|
|
158
|
+
List<MFLocationComponent> points = new ArrayList<>();
|
|
159
|
+
for (int i = 0; i < pathArr.length(); i++) {
|
|
160
|
+
JSONObject p = pathArr.optJSONObject(i);
|
|
161
|
+
MFLocationComponent c = toLocationComponent(p);
|
|
162
|
+
if (c != null) points.add(c);
|
|
163
|
+
}
|
|
164
|
+
if (!points.isEmpty()) {
|
|
165
|
+
return MFRouteRestriction.restrictPolygonArea(points, types);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Only types
|
|
170
|
+
if (types != null) {
|
|
171
|
+
return MFRouteRestriction.restrictRouteTypes(types);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private static MFRoute toRoute(JSONObject jsonObject) {
|
|
178
|
+
List<MFRoute.Leg> legs = new ArrayList<>();
|
|
179
|
+
JSONArray legsArray = JsonParser.getJsonArray("legs", jsonObject);
|
|
180
|
+
if (legsArray != null) {
|
|
181
|
+
for (int i = 0; i < legsArray.length(); ++i) {
|
|
182
|
+
try {
|
|
183
|
+
JSONObject legJsonObject = legsArray.getJSONObject(i);
|
|
184
|
+
MFRoute.Leg leg = toLeg(legJsonObject);
|
|
185
|
+
legs.add(leg);
|
|
186
|
+
} catch (JSONException e) {
|
|
187
|
+
e.printStackTrace();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
String overviewPolyline = JsonParser.getString("overviewPolyline", jsonObject);
|
|
192
|
+
String summary = JsonParser.getString("summary", jsonObject);
|
|
193
|
+
MFRoute.Info distance = toInfo(JsonParser.getJsonObject("distance", jsonObject));
|
|
194
|
+
MFRoute.Info duration = toInfo(JsonParser.getJsonObject("duration", jsonObject));
|
|
195
|
+
List<MFLocationComponent> snappedWaypoints = new ArrayList<>();
|
|
196
|
+
JSONArray snappedWaypointsArray = JsonParser.getJsonArray("snappedWaypoints", jsonObject);
|
|
197
|
+
if (snappedWaypointsArray != null) {
|
|
198
|
+
for (int i = 0; i < snappedWaypointsArray.length(); ++i) {
|
|
199
|
+
try {
|
|
200
|
+
JSONObject locationJsonObject = snappedWaypointsArray.getJSONObject(i);
|
|
201
|
+
MFLocationComponent location = toLocationComponent(locationJsonObject);
|
|
202
|
+
snappedWaypoints.add(location);
|
|
203
|
+
} catch (JSONException e) {
|
|
204
|
+
e.printStackTrace();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
List<MFLocationComponent> overviewCoordinates = PolylineUtils.decodePolyline(overviewPolyline != null ? overviewPolyline : "");
|
|
210
|
+
return new MFRoute(
|
|
211
|
+
summary,
|
|
212
|
+
overviewCoordinates.toArray(new MFLocationComponent[0]),
|
|
213
|
+
legs.toArray(new MFRoute.Leg[0]),
|
|
214
|
+
distance,
|
|
215
|
+
duration,
|
|
216
|
+
snappedWaypoints.toArray(new MFLocationComponent[0]),
|
|
217
|
+
new byte[0]
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private static MFRoute.Leg toLeg(JSONObject jsonObject) {
|
|
222
|
+
MFRoute.Info distance = toInfo(JsonParser.getJsonObject("distance", jsonObject));
|
|
223
|
+
MFRoute.Info duration = toInfo(JsonParser.getJsonObject("duration", jsonObject));
|
|
224
|
+
String startAddress = JsonParser.getString("startAddress", jsonObject);
|
|
225
|
+
String endAddress = JsonParser.getString("endAddress", jsonObject);
|
|
226
|
+
JSONObject startLocationJson = JsonParser.getJsonObject("startLocation", jsonObject);
|
|
227
|
+
MFLocationComponent startLocation = toLocationComponent(startLocationJson);
|
|
228
|
+
JSONObject endLocationJson = JsonParser.getJsonObject("endLocation", jsonObject);
|
|
229
|
+
MFLocationComponent endLocation = toLocationComponent(endLocationJson);
|
|
230
|
+
List<MFRoute.Step> steps = new ArrayList<>();
|
|
231
|
+
JSONArray stepsJsonArray = JsonParser.getJsonArray("steps", jsonObject);
|
|
232
|
+
|
|
233
|
+
if (stepsJsonArray != null) {
|
|
234
|
+
for (int i = 0; i < stepsJsonArray.length(); ++i) {
|
|
235
|
+
try {
|
|
236
|
+
JSONObject stepJsonObject = stepsJsonArray.getJSONObject(i);
|
|
237
|
+
MFRoute.Step step = toStep(stepJsonObject);
|
|
238
|
+
steps.add(step);
|
|
239
|
+
} catch (JSONException e) {
|
|
240
|
+
e.printStackTrace();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
MFRoute.Step[] stepsArray = new MFRoute.Step[steps.size()];
|
|
246
|
+
stepsArray = steps.toArray(stepsArray);
|
|
247
|
+
return new MFRoute.Leg(distance, duration, startAddress, endAddress, startLocation, endLocation, stepsArray);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private static MFRoute.Step toStep(JSONObject jsonObject) {
|
|
251
|
+
MFRoute.Info distance = toInfo(JsonParser.getJsonObject("distance", jsonObject));
|
|
252
|
+
MFRoute.Info duration = toInfo(JsonParser.getJsonObject("duration", jsonObject));
|
|
253
|
+
MFLocationComponent startLocation = toLocationComponent(JsonParser.getJsonObject("startLocation", jsonObject));
|
|
254
|
+
MFLocationComponent endLocation = toLocationComponent(JsonParser.getJsonObject("endLocation", jsonObject));
|
|
255
|
+
String htmlInstructions = JsonParser.getString("htmlInstructions", jsonObject);
|
|
256
|
+
MFManeuver maneuver = MFManeuver.fromValue(JsonParser.getString("maneuver", jsonObject));
|
|
257
|
+
String polyline = JsonParser.getString("polyline", jsonObject);
|
|
258
|
+
MFTravelMode travelMode = MFTravelMode.fromValue(JsonParser.getString("travelMode", jsonObject));
|
|
259
|
+
String streetName = JsonParser.getString("streetName", jsonObject);
|
|
260
|
+
return new MFRoute.Step(
|
|
261
|
+
htmlInstructions,
|
|
262
|
+
maneuver,
|
|
263
|
+
distance,
|
|
264
|
+
duration,
|
|
265
|
+
startLocation,
|
|
266
|
+
endLocation,
|
|
267
|
+
PolylineUtils.decodePolyline(polyline == null ? "" : polyline).toArray(new MFLocationComponent[0]),
|
|
268
|
+
streetName,
|
|
269
|
+
travelMode == null ? MFTravelMode.CAR : travelMode
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private static MFRoute.Info toInfo(JSONObject jsonObject) {
|
|
274
|
+
if (jsonObject == null) {
|
|
275
|
+
return new MFRoute.Info(null, null);
|
|
276
|
+
} else {
|
|
277
|
+
String text = JsonParser.getString("text", jsonObject);
|
|
278
|
+
Double value = JsonParser.getDouble("value", jsonObject);
|
|
279
|
+
return new MFRoute.Info(text, value);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private static MFLocationComponent toLocationComponent(JSONObject jsonObject) {
|
|
284
|
+
if (jsonObject == null) {
|
|
285
|
+
return new MFLocationComponent(0.0, 0.0);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
Double lat = JsonParser.getDouble("lat", jsonObject);
|
|
289
|
+
if (lat == null) {
|
|
290
|
+
lat = JsonParser.getDouble("latitude", jsonObject);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
Double lng = JsonParser.getDouble("lng", jsonObject);
|
|
294
|
+
if (lng == null) {
|
|
295
|
+
lng = JsonParser.getDouble("longitude", jsonObject);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return new MFLocationComponent(
|
|
299
|
+
lat != null ? lat : 0.0,
|
|
300
|
+
lng != null ? lng : 0.0
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
package/android/src/main/java/com/map4dnavigationreactnative/Map4dNavigationReactNativeModule.kt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.map4dnavigationreactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
6
|
+
|
|
7
|
+
@ReactModule(name = Map4dNavigationReactNativeModule.NAME)
|
|
8
|
+
class Map4dNavigationReactNativeModule(reactContext: ReactApplicationContext) :
|
|
9
|
+
NativeMap4dNavigationReactNativeSpec(reactContext) {
|
|
10
|
+
|
|
11
|
+
override fun getName(): String {
|
|
12
|
+
return NAME
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override fun startMapNavigation(
|
|
16
|
+
directions: String?,
|
|
17
|
+
routeIndex: Double,
|
|
18
|
+
params: String?
|
|
19
|
+
) {
|
|
20
|
+
val navigationIntent = Intent(reactApplicationContext, RMFNavigationActivity::class.java)
|
|
21
|
+
navigationIntent.putExtra(DIRECTIONS_KEY, directions)
|
|
22
|
+
navigationIntent.putExtra(ROUTE_INDEX_KEY, routeIndex)
|
|
23
|
+
navigationIntent.putExtra(PARAMS_KEY, params)
|
|
24
|
+
navigationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
|
25
|
+
reactApplicationContext.startActivity(navigationIntent)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
companion object {
|
|
29
|
+
const val NAME = "Map4dNavigationReactNative"
|
|
30
|
+
const val DIRECTIONS_KEY = "directions"
|
|
31
|
+
const val ROUTE_INDEX_KEY = "routeIndex"
|
|
32
|
+
const val PARAMS_KEY = "params"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/android/src/main/java/com/map4dnavigationreactnative/Map4dNavigationReactNativePackage.kt
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.map4dnavigationreactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class Map4dNavigationReactNativePackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == Map4dNavigationReactNativeModule.NAME) {
|
|
13
|
+
Map4dNavigationReactNativeModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
return ReactModuleInfoProvider {
|
|
21
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
22
|
+
moduleInfos[Map4dNavigationReactNativeModule.NAME] = ReactModuleInfo(
|
|
23
|
+
Map4dNavigationReactNativeModule.NAME,
|
|
24
|
+
Map4dNavigationReactNativeModule.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
false, // isCxxModule
|
|
28
|
+
true // isTurboModule
|
|
29
|
+
)
|
|
30
|
+
moduleInfos
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package com.map4dnavigationreactnative;
|
|
2
|
+
|
|
3
|
+
import java.util.ArrayList;
|
|
4
|
+
import java.util.List;
|
|
5
|
+
|
|
6
|
+
import vn.map4d.services.MFLocationComponent;
|
|
7
|
+
|
|
8
|
+
class PolylineUtils {
|
|
9
|
+
static List<MFLocationComponent> decodePolyline(String polyline) {
|
|
10
|
+
int len = polyline.length();
|
|
11
|
+
|
|
12
|
+
// For speed we preallocate to an upper bound on the final length, then
|
|
13
|
+
// truncate the array before returning.
|
|
14
|
+
List<MFLocationComponent> path = new ArrayList<>();
|
|
15
|
+
int index = 0;
|
|
16
|
+
int lat = 0;
|
|
17
|
+
int lng = 0;
|
|
18
|
+
|
|
19
|
+
while (index < len) {
|
|
20
|
+
int result = 1;
|
|
21
|
+
int shift = 0;
|
|
22
|
+
int b;
|
|
23
|
+
do {
|
|
24
|
+
b = polyline.charAt(index++) - 63 - 1;
|
|
25
|
+
result += b << shift;
|
|
26
|
+
shift += 5;
|
|
27
|
+
} while (b >= 0x1f);
|
|
28
|
+
|
|
29
|
+
if ((result & 1) != 0) {
|
|
30
|
+
lat += ~(result >> 1);
|
|
31
|
+
} else {
|
|
32
|
+
lat += result >> 1;
|
|
33
|
+
}
|
|
34
|
+
result = 1;
|
|
35
|
+
shift = 0;
|
|
36
|
+
|
|
37
|
+
do {
|
|
38
|
+
b = polyline.charAt(index++) - 63 - 1;
|
|
39
|
+
result += b << shift;
|
|
40
|
+
shift += 5;
|
|
41
|
+
} while (b >= 0x1f);
|
|
42
|
+
|
|
43
|
+
if ((result & 1) != 0) {
|
|
44
|
+
lng += ~(result >> 1);
|
|
45
|
+
} else {
|
|
46
|
+
lng += result >> 1;
|
|
47
|
+
}
|
|
48
|
+
path.add(new MFLocationComponent(1e-5 * lat, lng * 1e-5));
|
|
49
|
+
}
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package com.map4dnavigationreactnative;
|
|
2
|
+
|
|
3
|
+
import static com.map4dnavigationreactnative.Map4dNavigationReactNativeModule.DIRECTIONS_KEY;
|
|
4
|
+
import static com.map4dnavigationreactnative.Map4dNavigationReactNativeModule.PARAMS_KEY;
|
|
5
|
+
import static com.map4dnavigationreactnative.Map4dNavigationReactNativeModule.ROUTE_INDEX_KEY;
|
|
6
|
+
|
|
7
|
+
import android.os.Bundle;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
11
|
+
|
|
12
|
+
import vn.map4d.android.navigation.R;
|
|
13
|
+
import vn.map4d.android.navigation.ui.MFNavigationView;
|
|
14
|
+
import vn.map4d.android.navigation.ui.OnNavigationReadyCallback;
|
|
15
|
+
import vn.map4d.navigation.listeners.NavigationListener;
|
|
16
|
+
import vn.map4d.navigation.options.MFNavigationViewOptions;
|
|
17
|
+
|
|
18
|
+
public class RMFNavigationActivity extends AppCompatActivity implements OnNavigationReadyCallback, NavigationListener {
|
|
19
|
+
|
|
20
|
+
private MFNavigationView navigationView;
|
|
21
|
+
private String directions;
|
|
22
|
+
private double routeIndex;
|
|
23
|
+
private String params;
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public void onSaveInstanceState(Bundle outState) {
|
|
27
|
+
navigationView.onSaveInstanceState(outState);
|
|
28
|
+
super.onSaveInstanceState(outState);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
|
33
|
+
super.onRestoreInstanceState(savedInstanceState);
|
|
34
|
+
navigationView.onRestoreInstanceState(savedInstanceState);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
39
|
+
super.onCreate(savedInstanceState);
|
|
40
|
+
setContentView(R.layout.activity_navigation);
|
|
41
|
+
navigationView = findViewById(R.id.navigationView);
|
|
42
|
+
navigationView.onCreate(savedInstanceState);
|
|
43
|
+
initialize();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Override
|
|
47
|
+
protected void onDestroy() {
|
|
48
|
+
navigationView.onDestroy();
|
|
49
|
+
super.onDestroy();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Override
|
|
53
|
+
protected void onStart() {
|
|
54
|
+
super.onStart();
|
|
55
|
+
navigationView.onStart();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
protected void onPause() {
|
|
60
|
+
navigationView.onPause();
|
|
61
|
+
super.onPause();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Override
|
|
65
|
+
protected void onStop() {
|
|
66
|
+
navigationView.onStop();
|
|
67
|
+
super.onStop();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Override
|
|
71
|
+
protected void onResume() {
|
|
72
|
+
super.onResume();
|
|
73
|
+
navigationView.onResume();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private void initialize() {
|
|
77
|
+
navigationView.initialize(this);
|
|
78
|
+
directions = getIntent().getStringExtra(DIRECTIONS_KEY);
|
|
79
|
+
routeIndex = getIntent().getDoubleExtra(ROUTE_INDEX_KEY, 0.0);
|
|
80
|
+
params = getIntent().getStringExtra(PARAMS_KEY);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Override
|
|
84
|
+
public void onNavigationReady(boolean isRunning) {
|
|
85
|
+
MFNavigationViewOptions.Builder options = MFNavigationViewOptions.builder();
|
|
86
|
+
options.navigationListener(this);
|
|
87
|
+
options.directionOptions(JsonUtils.toDirectionOptions(params));
|
|
88
|
+
options.directionsRoute(JsonUtils.toDirectionsRoute(directions));
|
|
89
|
+
options.routeIndex((int) routeIndex);
|
|
90
|
+
options.shouldSimulateRoute(false);
|
|
91
|
+
navigationView.startNavigation(options.build());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Override
|
|
95
|
+
public void onCancelNavigation() {
|
|
96
|
+
finish();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Override
|
|
100
|
+
public void onNavigationStart() {
|
|
101
|
+
// Intentionally empty
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Override
|
|
105
|
+
public void onNavigationFinished() {
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Override
|
|
109
|
+
public void onNavigationRunning() {
|
|
110
|
+
// Intentionally empty
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "iPostMapNavigationReactNative"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/map4d/map4d-navigation-react-native.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
s.dependency "iPostMapNavigation", "~> 1.0"
|
|
20
|
+
|
|
21
|
+
install_modules_dependencies(s)
|
|
22
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#import "Map4dNavigationReactNative.h"
|
|
2
|
+
#import <Map4dServices/Map4dServices.h>
|
|
3
|
+
#import <Map4dNavigation/Map4dNavigation.h>
|
|
4
|
+
#import <React/RCTUtils.h>
|
|
5
|
+
#import <react-native-ipostmap-services/SParamConvert.h>
|
|
6
|
+
|
|
7
|
+
@interface MFDirectionsResult (Extension)
|
|
8
|
+
|
|
9
|
+
- (instancetype)initWithDictionary:(NSDictionary *)data;
|
|
10
|
+
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
@implementation Map4dNavigationReactNative
|
|
14
|
+
|
|
15
|
+
+ (NSString *)moduleName {
|
|
16
|
+
return @"Map4dNavigationReactNative";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
20
|
+
return std::make_shared<facebook::react::NativeMap4dNavigationReactNativeSpecJSI>(params);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void)startMapNavigation:(NSString *)resultJson routeIndex:(double)routeIndex params:(NSString *)paramsJson {
|
|
24
|
+
MFDirectionsResult *result = [self toDirectionsResult:resultJson];
|
|
25
|
+
MFDirectionsParams *params = [self toDirectionsParams:paramsJson];
|
|
26
|
+
NSInteger rIndex = routeIndex;
|
|
27
|
+
|
|
28
|
+
MFNavigationOptions *options = [[MFNavigationOptions alloc] init];
|
|
29
|
+
|
|
30
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
31
|
+
MFNavigationViewController *vc = [[MFNavigationViewController alloc] initWithDirectionsResult:result
|
|
32
|
+
routeIndex:rIndex
|
|
33
|
+
directionsParams:params
|
|
34
|
+
navigationOptions:options];
|
|
35
|
+
UIViewController *root = RCTPresentedViewController();
|
|
36
|
+
if (root.navigationController) {
|
|
37
|
+
[root.navigationController pushViewController:vc animated:YES];
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
vc.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
41
|
+
[root presentViewController:vc animated:YES completion:nil];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (MFDirectionsResult *)toDirectionsResult:(NSString *)json {
|
|
47
|
+
if (json == nil || [json isEqualToString:@""]) {
|
|
48
|
+
return nil;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
|
|
52
|
+
NSError *error = nil;
|
|
53
|
+
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
|
|
54
|
+
|
|
55
|
+
if (error || ![result isKindOfClass:[NSDictionary class]]) {
|
|
56
|
+
NSLog(@"Error parsing JSON params: %@", error.localizedDescription);
|
|
57
|
+
return nil;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return [[MFDirectionsResult alloc] initWithDictionary:result];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (MFDirectionsParams *)toDirectionsParams:(NSString *)json {
|
|
64
|
+
if (json == nil || [json isEqualToString:@""]) {
|
|
65
|
+
return nil;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
|
|
69
|
+
NSError *error = nil;
|
|
70
|
+
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
|
|
71
|
+
|
|
72
|
+
if (error || ![dict isKindOfClass:[NSDictionary class]]) {
|
|
73
|
+
NSLog(@"Error parsing JSON params: %@", error.localizedDescription);
|
|
74
|
+
return nil;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
MFLocationComponent *origin = [SParamConvert MFLocationComponent:dict[@"origin"]];
|
|
78
|
+
MFLocationComponent *destination = [SParamConvert MFLocationComponent:dict[@"destination"]];
|
|
79
|
+
MFDirectionsParams *params = [[MFDirectionsParams alloc] initWithOrigin:origin destination:destination];
|
|
80
|
+
params.mode = [SParamConvert MFTravelMode:dict[@"mode"] fallback:params.mode];
|
|
81
|
+
params.waypoints = [SParamConvert MFLocationComponentArray:dict[@"waypoints"]];
|
|
82
|
+
params.language = [SParamConvert MFLanguageResult:dict[@"language"] fallback:params.language];
|
|
83
|
+
params.weighting = [SParamConvert MFRouteWeighting:dict[@"weighting"] fallback:params.weighting];
|
|
84
|
+
params.restriction = [SParamConvert MFRouteRestriction:dict[@"restriction"]];
|
|
85
|
+
|
|
86
|
+
return params;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"..\\..\\src","sources":["NativeMap4dNavigationReactNative.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAMpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,4BAA4B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Map4dNavigationReactNative from "./NativeMap4dNavigationReactNative.js";
|
|
4
|
+
export function startMapNavigation(directions, routeIndex, params) {
|
|
5
|
+
const directionsJson = JSON.stringify(directions);
|
|
6
|
+
const paramsJson = JSON.stringify(params);
|
|
7
|
+
return Map4dNavigationReactNative.startMapNavigation(directionsJson, routeIndex, paramsJson);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Map4dNavigationReactNative","startMapNavigation","directions","routeIndex","params","directionsJson","JSON","stringify","paramsJson"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AACA,OAAOA,0BAA0B,MAAM,uCAAoC;AAE3E,OAAO,SAASC,kBAAkBA,CAACC,UAA8B,EAAEC,UAAkB,EAAEC,MAA0B,EAAQ;EACvH,MAAMC,cAAc,GAAGC,IAAI,CAACC,SAAS,CAACL,UAAU,CAAC;EACjD,MAAMM,UAAU,GAAGF,IAAI,CAACC,SAAS,CAACH,MAAM,CAAC;EACzC,OAAOJ,0BAA0B,CAACC,kBAAkB,CAACI,cAAc,EAAEF,UAAU,EAAEK,UAAU,CAAC;AAC9F","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
startMapNavigation(directions: string, routeIndex: number, params: string): void;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: Spec;
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=NativeMap4dNavigationReactNative.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeMap4dNavigationReactNative.d.ts","sourceRoot":"","sources":["../../../src/NativeMap4dNavigationReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAClF;;AAED,wBAAoF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAG7F,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAIvH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-ipostmap-navigation",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "iPostMap Navigation SDK for React Native",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace react-native-ipostmap-navigation-example",
|
|
36
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"release": "release-it --only-version"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android",
|
|
47
|
+
"map4d",
|
|
48
|
+
"navigation",
|
|
49
|
+
"ipostmap",
|
|
50
|
+
"vnpost",
|
|
51
|
+
"iotlink"
|
|
52
|
+
],
|
|
53
|
+
"author": "VNPost <cskh@vnpost.vn>",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"homepage": "https://ipostmap.vn",
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"registry": "https://registry.npmjs.org/"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"react-native-ipostmap-services": "^1.0.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@eslint/compat": "^1.3.2",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
65
|
+
"@eslint/js": "^9.35.0",
|
|
66
|
+
"@react-native/babel-preset": "0.83.0",
|
|
67
|
+
"@react-native/eslint-config": "0.83.0",
|
|
68
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
69
|
+
"@types/jest": "^29.5.14",
|
|
70
|
+
"@types/react": "^19.2.0",
|
|
71
|
+
"del-cli": "^6.0.0",
|
|
72
|
+
"eslint": "^9.35.0",
|
|
73
|
+
"eslint-config-prettier": "^10.1.8",
|
|
74
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
75
|
+
"jest": "^29.7.0",
|
|
76
|
+
"prettier": "^2.8.8",
|
|
77
|
+
"react": "19.2.0",
|
|
78
|
+
"react-native": "0.83.0",
|
|
79
|
+
"react-native-builder-bob": "^0.40.17",
|
|
80
|
+
"release-it": "^19.0.4",
|
|
81
|
+
"turbo": "^2.5.6",
|
|
82
|
+
"typescript": "^5.9.2"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"react": "*",
|
|
86
|
+
"react-native": "*"
|
|
87
|
+
},
|
|
88
|
+
"workspaces": [
|
|
89
|
+
"example"
|
|
90
|
+
],
|
|
91
|
+
"packageManager": "yarn@4.11.0",
|
|
92
|
+
"react-native-builder-bob": {
|
|
93
|
+
"source": "src",
|
|
94
|
+
"output": "lib",
|
|
95
|
+
"targets": [
|
|
96
|
+
[
|
|
97
|
+
"module",
|
|
98
|
+
{
|
|
99
|
+
"esm": true
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
"typescript",
|
|
104
|
+
{
|
|
105
|
+
"project": "tsconfig.build.json"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"codegenConfig": {
|
|
111
|
+
"name": "Map4dNavigationReactNativeSpec",
|
|
112
|
+
"type": "modules",
|
|
113
|
+
"jsSrcsDir": "src",
|
|
114
|
+
"android": {
|
|
115
|
+
"javaPackageName": "com.map4dnavigationreactnative"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"prettier": {
|
|
119
|
+
"quoteProps": "consistent",
|
|
120
|
+
"singleQuote": true,
|
|
121
|
+
"tabWidth": 2,
|
|
122
|
+
"trailingComma": "es5",
|
|
123
|
+
"useTabs": false
|
|
124
|
+
},
|
|
125
|
+
"jest": {
|
|
126
|
+
"preset": "react-native",
|
|
127
|
+
"modulePathIgnorePatterns": [
|
|
128
|
+
"<rootDir>/example/node_modules",
|
|
129
|
+
"<rootDir>/lib/"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"release-it": {
|
|
133
|
+
"git": {
|
|
134
|
+
"commitMessage": "chore: release ${version}",
|
|
135
|
+
"tagName": "v${version}"
|
|
136
|
+
},
|
|
137
|
+
"npm": {
|
|
138
|
+
"publish": true
|
|
139
|
+
},
|
|
140
|
+
"github": {
|
|
141
|
+
"release": true
|
|
142
|
+
},
|
|
143
|
+
"plugins": {
|
|
144
|
+
"@release-it/conventional-changelog": {
|
|
145
|
+
"preset": {
|
|
146
|
+
"name": "angular"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"create-react-native-library": {
|
|
152
|
+
"type": "turbo-module",
|
|
153
|
+
"languages": "kotlin-objc",
|
|
154
|
+
"tools": [
|
|
155
|
+
"eslint",
|
|
156
|
+
"jest",
|
|
157
|
+
"release-it"
|
|
158
|
+
],
|
|
159
|
+
"version": "0.56.1"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
startMapNavigation(directions: string, routeIndex: number, params: string): void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('Map4dNavigationReactNative');
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MFDirectionsParams, MFDirectionsResult } from 'react-native-ipostmap-services';
|
|
2
|
+
import Map4dNavigationReactNative from './NativeMap4dNavigationReactNative';
|
|
3
|
+
|
|
4
|
+
export function startMapNavigation(directions: MFDirectionsResult, routeIndex: number, params: MFDirectionsParams): void {
|
|
5
|
+
const directionsJson = JSON.stringify(directions)
|
|
6
|
+
const paramsJson = JSON.stringify(params)
|
|
7
|
+
return Map4dNavigationReactNative.startMapNavigation(directionsJson, routeIndex, paramsJson);
|
|
8
|
+
}
|