react-native-ipostmap-navigation 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/Map4dNavigationReactNative.mm +1 -1
- package/ios/SParamConvert.h +44 -0
- package/ios/SParamConvert.m +229 -0
- package/package.json +1 -1
|
@@ -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
|