react-native-ipostmap-navigation 1.0.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.
@@ -2,7 +2,7 @@
2
2
  #import <Map4dServices/Map4dServices.h>
3
3
  #import <Map4dNavigation/Map4dNavigation.h>
4
4
  #import <React/RCTUtils.h>
5
- #import <react-native-ipostmap-services/SParamConvert.h>
5
+ #import "NParamConvert.h"
6
6
 
7
7
  @interface MFDirectionsResult (Extension)
8
8
 
@@ -74,14 +74,14 @@
74
74
  return nil;
75
75
  }
76
76
 
77
- MFLocationComponent *origin = [SParamConvert MFLocationComponent:dict[@"origin"]];
78
- MFLocationComponent *destination = [SParamConvert MFLocationComponent:dict[@"destination"]];
77
+ MFLocationComponent *origin = [NParamConvert MFLocationComponent:dict[@"origin"]];
78
+ MFLocationComponent *destination = [NParamConvert MFLocationComponent:dict[@"destination"]];
79
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"]];
80
+ params.mode = [NParamConvert MFTravelMode:dict[@"mode"] fallback:params.mode];
81
+ params.waypoints = [NParamConvert MFLocationComponentArray:dict[@"waypoints"]];
82
+ params.language = [NParamConvert MFLanguageResult:dict[@"language"] fallback:params.language];
83
+ params.weighting = [NParamConvert MFRouteWeighting:dict[@"weighting"] fallback:params.weighting];
84
+ params.restriction = [NParamConvert MFRouteRestriction:dict[@"restriction"]];
85
85
 
86
86
  return params;
87
87
  }
@@ -0,0 +1,44 @@
1
+ //
2
+ // NParamConvert.h
3
+ // react-native-map4d-services
4
+ //
5
+ // Created by Huy Dang on 26/01/2022.
6
+ //
7
+
8
+ #ifndef NParamConvert_h
9
+ #define NParamConvert_h
10
+
11
+ #import <Map4dServices/Map4dServices.h>
12
+
13
+ @interface NParamConvert : 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 /* NParamConvert_h */
@@ -0,0 +1,229 @@
1
+ //
2
+ // NParamConvert.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 "NParamConvert.h"
11
+
12
+ @interface NParamConvert (Private)
13
+ + (BOOL)isNull:(id)json;
14
+ + (BOOL)isMFRouteType:(NSString *)type;
15
+ + (MFRouteType)MFRouteType:(NSString *)type;
16
+ @end
17
+
18
+ #pragma mark - NParamConvert
19
+
20
+ @implementation NParamConvert
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 = [NParamConvert MFLocationComponent:json[@"southwest"]];
86
+ MFLocationComponent *northeast = [NParamConvert 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 = [NParamConvert MFLocationComponent:json[@"location"]];
96
+ NSUInteger radius = json[@"radius"] != nil ? [RCTConvert NSUInteger:json[@"radius"]] : 0;
97
+ MFViewboxComponent *viewbox = [NParamConvert MFViewboxComponent:json[@"viewbox"]];
98
+ NSArray<MFLocationComponent *> *path = [NParamConvert 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 ([NParamConvert isMFRouteType:types[i]]) {
116
+ [result avoidRouteType:[NParamConvert MFRouteType:types[i]]];
117
+ }
118
+ }
119
+ }
120
+ else {
121
+ result = [[MFRouteRestriction alloc] initWithRouteType:[NParamConvert MFRouteType:types[0]]];
122
+ for (NSUInteger i = 1; i < types.count; i++) {
123
+ if ([NParamConvert isMFRouteType:types[i]]) {
124
+ [result avoidRouteType:[NParamConvert 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 - NParamConvert (Private)
188
+
189
+
190
+ @implementation NParamConvert (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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ipostmap-navigation",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "iPostMap Navigation SDK for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",