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.
Files changed (40) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +24 -24
  3. package/android/build.gradle +60 -59
  4. package/android/src/main/AndroidManifest.xml +4 -4
  5. package/android/src/main/java/com/reactnativemap4dservices/Map4dServicesModule.java +91 -34
  6. package/android/src/main/java/com/reactnativemap4dservices/Map4dServicesPackage.java +28 -28
  7. package/android/src/main/java/com/reactnativemap4dservices/SClient.java +50 -0
  8. package/android/src/main/java/com/reactnativemap4dservices/SConverter.java +166 -0
  9. package/android/src/main/java/com/reactnativemap4dservices/SJsonUtils.java +130 -0
  10. package/android/src/main/java/com/reactnativemap4dservices/SRequest.java +376 -0
  11. package/ios/Map4dServices.h +5 -5
  12. package/ios/Map4dServices.m +81 -81
  13. package/ios/SClient.h +23 -23
  14. package/ios/SClient.m +47 -47
  15. package/ios/SParamConvert.h +44 -0
  16. package/ios/SParamConvert.m +229 -0
  17. package/ios/SRequest.h +40 -40
  18. package/ios/SRequest.m +142 -143
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/index.js.map +1 -1
  21. package/lib/typescript/index.d.ts +111 -111
  22. package/package.json +150 -150
  23. package/react-native-map4d-services.podspec +20 -20
  24. package/src/index.tsx +174 -174
  25. package/android/.gradle/7.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  26. package/android/.gradle/7.1.1/dependencies-accessors/gc.properties +0 -0
  27. package/android/.gradle/7.1.1/executionHistory/executionHistory.lock +0 -0
  28. package/android/.gradle/7.1.1/fileChanges/last-build.bin +0 -0
  29. package/android/.gradle/7.1.1/fileHashes/fileHashes.lock +0 -0
  30. package/android/.gradle/7.1.1/gc.properties +0 -0
  31. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  32. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  33. package/android/.gradle/checksums/checksums.lock +0 -0
  34. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  35. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  36. package/android/.gradle/vcs-1/gc.properties +0 -0
  37. package/ios/.DS_Store +0 -0
  38. package/ios/Map4dServices.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
  39. package/ios/RCTConvert+Services.h +0 -33
  40. package/ios/RCTConvert+Services.m +0 -146
package/ios/SClient.h CHANGED
@@ -1,23 +1,23 @@
1
- //
2
- // SClient.h
3
- // react-native-map4d-services
4
- //
5
- // Created by Huy Dang on 26/01/2022.
6
- //
7
-
8
- #ifndef SClient_h
9
- #define SClient_h
10
-
11
- #import <React/RCTBridgeModule.h>
12
- #import <Map4dServices/Map4dServices.h>
13
-
14
- @interface SClient : NSObject
15
-
16
- + (void)fireRequest:(MFServiceRequest *)request
17
- resolve:(RCTPromiseResolveBlock)resolve
18
- reject:(RCTPromiseRejectBlock)reject;
19
-
20
- @end
21
-
22
-
23
- #endif /* SClient_h */
1
+ //
2
+ // SClient.h
3
+ // react-native-map4d-services
4
+ //
5
+ // Created by Huy Dang on 26/01/2022.
6
+ //
7
+
8
+ #ifndef SClient_h
9
+ #define SClient_h
10
+
11
+ #import <React/RCTBridgeModule.h>
12
+ #import <Map4dServices/Map4dServices.h>
13
+
14
+ @interface SClient : NSObject
15
+
16
+ + (void)fireRequest:(MFServiceRequest *)request
17
+ resolve:(RCTPromiseResolveBlock)resolve
18
+ reject:(RCTPromiseRejectBlock)reject;
19
+
20
+ @end
21
+
22
+
23
+ #endif /* SClient_h */
package/ios/SClient.m CHANGED
@@ -1,47 +1,47 @@
1
- //
2
- // SClient.m
3
- // react-native-map4d-services
4
- //
5
- // Created by Huy Dang on 26/01/2022.
6
- //
7
-
8
- #import "SClient.h"
9
-
10
- @implementation SClient
11
-
12
- static MFServices *_services = nil;
13
-
14
- + (MFServices *)services {
15
- if (_services == nil) {
16
- _services = [[MFServices alloc] init];
17
- }
18
- return _services;
19
- }
20
-
21
- + (void)fireRequest:(MFServiceRequest *)request
22
- resolve:(RCTPromiseResolveBlock)resolve
23
- reject:(RCTPromiseRejectBlock)reject {
24
- [SClient.services dataTaskWithRequest:request
25
- completionHandler:^(NSData * _Nullable data, id<MFServiceError> _Nullable error) {
26
- if (error != nil) {
27
- resolve(@{
28
- @"code": error.code,
29
- @"message": error.message
30
- });
31
- }
32
-
33
- NSError *parseError = nil;
34
- NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&parseError];
35
-
36
- if (parseError != nil) {
37
- resolve(@{
38
- @"code": [NSString stringWithFormat:@"%ld", parseError.code],
39
- @"message": parseError.localizedDescription
40
- });
41
- }
42
-
43
- resolve(dictionary);
44
- }];
45
- }
46
-
47
- @end
1
+ //
2
+ // SClient.m
3
+ // react-native-map4d-services
4
+ //
5
+ // Created by Huy Dang on 26/01/2022.
6
+ //
7
+
8
+ #import "SClient.h"
9
+
10
+ @implementation SClient
11
+
12
+ static MFServices *_services = nil;
13
+
14
+ + (MFServices *)services {
15
+ if (_services == nil) {
16
+ _services = [[MFServices alloc] init];
17
+ }
18
+ return _services;
19
+ }
20
+
21
+ + (void)fireRequest:(MFServiceRequest *)request
22
+ resolve:(RCTPromiseResolveBlock)resolve
23
+ reject:(RCTPromiseRejectBlock)reject {
24
+ [SClient.services dataTaskWithRequest:request
25
+ completionHandler:^(NSData * _Nullable data, id<MFServiceError> _Nullable error) {
26
+ if (error != nil) {
27
+ resolve(@{
28
+ @"code": error.code,
29
+ @"message": error.message
30
+ });
31
+ }
32
+
33
+ NSError *parseError = nil;
34
+ NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&parseError];
35
+
36
+ if (parseError != nil) {
37
+ resolve(@{
38
+ @"code": [NSString stringWithFormat:@"%ld", parseError.code],
39
+ @"message": parseError.localizedDescription
40
+ });
41
+ }
42
+
43
+ resolve(dictionary);
44
+ }];
45
+ }
46
+
47
+ @end
@@ -0,0 +1,44 @@
1
+ //
2
+ // SParamConvert.h
3
+ // react-native-map4d-services
4
+ //
5
+ // Created by Huy Dang on 26/01/2022.
6
+ //
7
+
8
+ #ifndef SParamConvert_h
9
+ #define SParamConvert_h
10
+
11
+ #import <Map4dServices/Map4dServices.h>
12
+
13
+ @interface SParamConvert : NSObject
14
+
15
+ + (BOOL)BOOL:(id)json fallback:(BOOL)fallback;
16
+
17
+ + (NSUInteger)NSUInteger:(id)json;
18
+
19
+ + (NSUInteger)NSUInteger:(id)json fallback:(NSUInteger)fallback;
20
+
21
+ + (NSString *)NSString:(id)json;
22
+
23
+ + (NSArray<NSString *> *)NSStringArray:(id)json;
24
+
25
+ + (NSDate *)NSDate:(id)json;
26
+
27
+ + (MFLocationComponent *)MFLocationComponent:(id)json;
28
+
29
+ + (NSArray<MFLocationComponent *> *)MFLocationComponentArray:(id)json;
30
+
31
+ + (MFViewboxComponent *)MFViewboxComponent:(id)json;
32
+
33
+ + (MFRouteRestriction *)MFRouteRestriction:(id)json;
34
+
35
+ + (MFTravelMode)MFTravelMode:(id)json fallback:(MFTravelMode)fallback;
36
+
37
+ + (MFRouteWeighting)MFRouteWeighting:(id)json fallback:(MFRouteWeighting)fallback;
38
+
39
+ + (MFLanguageResult)MFLanguageResult:(id)json fallback:(MFLanguageResult)fallback;
40
+
41
+ @end
42
+
43
+
44
+ #endif /* SParamConvert_h */
@@ -0,0 +1,229 @@
1
+ //
2
+ // SParamConvert.m
3
+ // react-native-map4d-services
4
+ //
5
+ // Created by Huy Dang on 26/01/2022.
6
+ //
7
+
8
+ #import <React/RCTConvert.h>
9
+ #import <React/RCTConvert+CoreLocation.h>
10
+ #import "SParamConvert.h"
11
+
12
+ @interface SParamConvert (Private)
13
+ + (BOOL)isNull:(id)json;
14
+ + (BOOL)isMFRouteType:(NSString *)type;
15
+ + (MFRouteType)MFRouteType:(NSString *)type;
16
+ @end
17
+
18
+ #pragma mark - SParamConvert
19
+
20
+ @implementation SParamConvert
21
+
22
+ + (BOOL)BOOL:(id)json fallback:(BOOL)fallback {
23
+ return [self isNull:json] ? fallback : [RCTConvert BOOL:json];
24
+ }
25
+
26
+ + (NSUInteger)NSUInteger:(id)json {
27
+ return [self NSUInteger:json fallback:0];
28
+ }
29
+
30
+ + (NSUInteger)NSUInteger:(id)json fallback:(NSUInteger)fallback {
31
+ return [self isNull:json] ? fallback : [RCTConvert NSUInteger:json];
32
+ }
33
+
34
+ + (NSString *)NSString:(id)json {
35
+ return [self isNull:json] ? nil : [RCTConvert NSString:json];
36
+ }
37
+
38
+ + (NSArray<NSString *> *)NSStringArray:(id)json {
39
+ if ([self isNull:json]) {
40
+ return nil;
41
+ }
42
+
43
+ NSMutableArray *array = [NSMutableArray arrayWithCapacity:[json count]];
44
+ for (id e in json) {
45
+ NSString *str = [self NSString:e];
46
+ if (str != nil) {
47
+ [array addObject:str];
48
+ }
49
+ }
50
+ return array;
51
+ }
52
+
53
+ + (NSDate *)NSDate:(id)json {
54
+ return [self isNull:json] ? nil : [RCTConvert NSDate:json];
55
+ }
56
+
57
+ + (MFLocationComponent *)MFLocationComponent:(id)json {
58
+ if ([self isNull:json]) {
59
+ return nil;
60
+ }
61
+ CLLocationCoordinate2D coordinate = [RCTConvert CLLocationCoordinate2D:json];
62
+ return [[MFLocationComponent alloc] initWithCoordinate:coordinate alias:json[@"alias"]];
63
+ }
64
+
65
+ + (NSArray<MFLocationComponent *> *)MFLocationComponentArray:(id)json {
66
+ if ([self isNull:json]) {
67
+ return nil;
68
+ }
69
+
70
+ NSMutableArray<MFLocationComponent *> *array = [NSMutableArray arrayWithCapacity:[json count]];
71
+ for (id e in json) {
72
+ MFLocationComponent *location = [self MFLocationComponent:e];
73
+ if (location != nil) {
74
+ [array addObject:location];
75
+ }
76
+ }
77
+ return array;
78
+ }
79
+
80
+ + (MFViewboxComponent *)MFViewboxComponent:(id)json {
81
+ if ([self isNull:json]) {
82
+ return nil;
83
+ }
84
+
85
+ MFLocationComponent *southwest = [SParamConvert MFLocationComponent:json[@"southwest"]];
86
+ MFLocationComponent *northeast = [SParamConvert MFLocationComponent:json[@"northeast"]];
87
+ return [[MFViewboxComponent alloc] initWithSouthwest:southwest.coordinate northeast:northeast.coordinate];
88
+ }
89
+
90
+ + (MFRouteRestriction *)MFRouteRestriction:(id)json {
91
+ if ([self isNull:json]) {
92
+ return nil;
93
+ }
94
+
95
+ MFLocationComponent *location = [SParamConvert MFLocationComponent:json[@"location"]];
96
+ NSUInteger radius = json[@"radius"] != nil ? [RCTConvert NSUInteger:json[@"radius"]] : 0;
97
+ MFViewboxComponent *viewbox = [SParamConvert MFViewboxComponent:json[@"viewbox"]];
98
+ NSArray<MFLocationComponent *> *path = [SParamConvert MFLocationComponentArray:json[@"path"]];
99
+ NSArray<NSString *> *types = [RCTConvert NSStringArray:json[@"types"]];
100
+
101
+ MFRouteRestriction *result = nil;
102
+ if (location != nil) {
103
+ result = [[MFRouteRestriction alloc] initWithLocation:location radius:radius];
104
+ }
105
+ else if (viewbox != nil) {
106
+ result = [[MFRouteRestriction alloc] initWithViewbox:viewbox];
107
+ }
108
+ else if (path != nil) {
109
+ result = [[MFRouteRestriction alloc] initWithPath:path];
110
+ }
111
+
112
+ if (types != nil && types.count > 0) {
113
+ if (result != nil) {
114
+ for (NSUInteger i = 0; i < types.count; i++) {
115
+ if ([SParamConvert isMFRouteType:types[i]]) {
116
+ [result avoidRouteType:[SParamConvert MFRouteType:types[i]]];
117
+ }
118
+ }
119
+ }
120
+ else {
121
+ result = [[MFRouteRestriction alloc] initWithRouteType:[SParamConvert MFRouteType:types[0]]];
122
+ for (NSUInteger i = 1; i < types.count; i++) {
123
+ if ([SParamConvert isMFRouteType:types[i]]) {
124
+ [result avoidRouteType:[SParamConvert MFRouteType:types[i]]];
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ return result;
131
+
132
+ }
133
+
134
+ + (MFTravelMode)MFTravelMode:(id)json fallback:(MFTravelMode)fallback {
135
+ if ([self isNull:json]) {
136
+ return fallback;
137
+ }
138
+
139
+ NSString *mode = [RCTConvert NSString:json];
140
+ if ([@"motorcycle" isEqualToString:mode]) {
141
+ return MFTravelModeMotorcycle;
142
+ }
143
+ else if ([@"foot" isEqualToString:mode]) {
144
+ return MFTravelModeFoot;
145
+ }
146
+ else if ([@"bike" isEqualToString:mode]) {
147
+ return MFTravelModeBike;
148
+ }
149
+ else {
150
+ return MFTravelModeCar;
151
+ }
152
+ }
153
+
154
+ + (MFRouteWeighting)MFRouteWeighting:(id)json fallback:(MFRouteWeighting)fallback {
155
+ if ([self isNull:json]) {
156
+ return fallback;
157
+ }
158
+
159
+ NSString *weighting = [RCTConvert NSString:json];
160
+ if ([@"shortest" isEqualToString:weighting]) {
161
+ return MFRouteWeightingShortest;
162
+ }
163
+ else if ([@"balance" isEqualToString:weighting]) {
164
+ return MFRouteWeightingBalance;
165
+ }
166
+ else {
167
+ return MFRouteWeightingFastest;
168
+ }
169
+ }
170
+
171
+ + (MFLanguageResult)MFLanguageResult:(id)json fallback:(MFLanguageResult)fallback {
172
+ if ([self isNull:json]) {
173
+ return fallback;
174
+ }
175
+
176
+ NSString *language = [RCTConvert NSString:json];
177
+ if ([@"en" isEqualToString:language]) {
178
+ return MFLanguageResultEnglish;
179
+ }
180
+ else {
181
+ return MFLanguageResultVietnamese;
182
+ }
183
+ }
184
+
185
+ @end
186
+
187
+ #pragma mark - SParamConvert (Private)
188
+
189
+
190
+ @implementation SParamConvert (Private)
191
+
192
+ + (BOOL)isNull:(id)json {
193
+ if (json == nil || [json isKindOfClass:[NSNull class]]) {
194
+ return true;
195
+ }
196
+ return false;
197
+ }
198
+
199
+ + (BOOL)isMFRouteType:(NSString *)type {
200
+ if ([@"motorway" isEqualToString:type] ||
201
+ [@"trunk" isEqualToString:type] ||
202
+ [@"ferry" isEqualToString:type] ||
203
+ [@"bridge" isEqualToString:type] ||
204
+ [@"tunnel" isEqualToString:type]) {
205
+ return YES;
206
+ }
207
+ return NO;
208
+ }
209
+
210
+ + (MFRouteType)MFRouteType:(NSString *)type {
211
+ if ([@"motorway" isEqualToString:type]) {
212
+ return MFRouteTypeMotorway;
213
+ }
214
+ else if ([@"trunk" isEqualToString:type]) {
215
+ return MFRouteTypeTrunk;
216
+ }
217
+ else if ([@"ferry" isEqualToString:type]) {
218
+ return MFRouteTypeFerry;
219
+ }
220
+ else if ([@"bridge" isEqualToString:type]) {
221
+ return MFRouteTypeBridge;
222
+ }
223
+ else if ([@"tunnel" isEqualToString:type]) {
224
+ return MFRouteTypeTunnel;
225
+ }
226
+ return 0;
227
+ }
228
+
229
+ @end
package/ios/SRequest.h CHANGED
@@ -1,40 +1,40 @@
1
- //
2
- // SRequest.h
3
- // react-native-map4d-services
4
- //
5
- // Created by Huy Dang on 26/01/2022.
6
- //
7
-
8
- #ifndef SRequest_h
9
- #define SRequest_h
10
-
11
- #import <Foundation/Foundation.h>
12
-
13
- @class MFServiceRequest;
14
-
15
- @interface SRequest : NSObject
16
-
17
- + (MFServiceRequest *)buildGeocodingRequestWithData:(NSDictionary *)data;
18
-
19
- + (MFServiceRequest *)buildPlaceDetailRequestWithId:(NSString *)placeId;
20
-
21
- + (MFServiceRequest *)buildTextSearchRequestWithData:(NSDictionary *)data;
22
-
23
- + (MFServiceRequest *)buildNearbySearchRequestWithData:(NSDictionary *)data;
24
-
25
- + (MFServiceRequest *)buildViewboxSearchRequestWithData:(NSDictionary *)data;
26
-
27
- + (MFServiceRequest *)buildSuggestionsRequestWithData:(NSDictionary *)data;
28
-
29
- + (MFServiceRequest *)buildDirectionsRequestWithData:(NSDictionary *)data;
30
-
31
- + (MFServiceRequest *)buildRouteETARequestWithData:(NSDictionary *)data;
32
-
33
- + (MFServiceRequest *)buildDistanceMatrixRequestWithData:(NSDictionary *)data;
34
-
35
- + (MFServiceRequest *)buildGraphRouteRequestWithData:(NSDictionary *)data;
36
-
37
- @end
38
-
39
-
40
- #endif /* SRequest_h */
1
+ //
2
+ // SRequest.h
3
+ // react-native-map4d-services
4
+ //
5
+ // Created by Huy Dang on 26/01/2022.
6
+ //
7
+
8
+ #ifndef SRequest_h
9
+ #define SRequest_h
10
+
11
+ #import <Foundation/Foundation.h>
12
+
13
+ @class MFServiceRequest;
14
+
15
+ @interface SRequest : NSObject
16
+
17
+ + (MFServiceRequest *)buildGeocodingRequestWithData:(NSDictionary *)data;
18
+
19
+ + (MFServiceRequest *)buildPlaceDetailRequestWithId:(NSString *)placeId;
20
+
21
+ + (MFServiceRequest *)buildTextSearchRequestWithData:(NSDictionary *)data;
22
+
23
+ + (MFServiceRequest *)buildNearbySearchRequestWithData:(NSDictionary *)data;
24
+
25
+ + (MFServiceRequest *)buildViewboxSearchRequestWithData:(NSDictionary *)data;
26
+
27
+ + (MFServiceRequest *)buildSuggestionsRequestWithData:(NSDictionary *)data;
28
+
29
+ + (MFServiceRequest *)buildDirectionsRequestWithData:(NSDictionary *)data;
30
+
31
+ + (MFServiceRequest *)buildRouteETARequestWithData:(NSDictionary *)data;
32
+
33
+ + (MFServiceRequest *)buildDistanceMatrixRequestWithData:(NSDictionary *)data;
34
+
35
+ + (MFServiceRequest *)buildGraphRouteRequestWithData:(NSDictionary *)data;
36
+
37
+ @end
38
+
39
+
40
+ #endif /* SRequest_h */