react-native-maps 1.21.0-alpha.99 → 1.21.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.
Files changed (230) hide show
  1. package/README.md +9 -4
  2. package/android/build.gradle +65 -72
  3. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  4. package/android/src/main/RCTAppDependencyProvider.h +25 -0
  5. package/android/src/main/RCTAppDependencyProvider.mm +55 -0
  6. package/android/src/main/RCTModulesConformingToProtocolsProvider.h +18 -0
  7. package/android/src/main/RCTModulesConformingToProtocolsProvider.mm +33 -0
  8. package/android/src/main/RCTThirdPartyComponentsProvider.h +16 -0
  9. package/android/src/main/RCTThirdPartyComponentsProvider.mm +28 -0
  10. package/android/src/main/ReactAppDependencyProvider.podspec +34 -0
  11. package/android/src/main/java/com/facebook/fbreact/specs/NativeAirMapsModuleSpec.java +63 -0
  12. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerDelegate.java +35 -0
  13. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerInterface.java +17 -0
  14. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCircleManagerDelegate.java +49 -0
  15. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsCircleManagerInterface.java +23 -0
  16. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerDelegate.java +49 -0
  17. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerInterface.java +23 -0
  18. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerDelegate.java +209 -0
  19. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerInterface.java +74 -0
  20. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerDelegate.java +104 -0
  21. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerInterface.java +39 -0
  22. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerDelegate.java +45 -0
  23. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerInterface.java +22 -0
  24. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerDelegate.java +58 -0
  25. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerInterface.java +26 -0
  26. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsUrlTileManagerDelegate.java +62 -0
  27. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsUrlTileManagerInterface.java +27 -0
  28. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsWMSTileManagerDelegate.java +56 -0
  29. package/android/src/main/java/com/facebook/react/viewmanagers/RNMapsWMSTileManagerInterface.java +25 -0
  30. package/android/src/main/java/com/rnmaps/fabric/MapViewManager.java +5 -1
  31. package/android/src/main/java/com/rnmaps/fabric/NativeAirMapsModule.java +1 -1
  32. package/android/src/main/java/com/rnmaps/fabric/OverlayManager.java +9 -3
  33. package/android/src/main/java/com/rnmaps/fabric/UrlTileManager.java +124 -0
  34. package/android/src/main/java/com/rnmaps/fabric/WMSTileManager.java +114 -0
  35. package/android/src/main/java/com/rnmaps/maps/MapAirModulePackage.java +19 -3
  36. package/android/src/main/java/com/rnmaps/maps/MapMarker.java +608 -603
  37. package/android/src/main/java/com/rnmaps/maps/MapMarkerManager.java +3 -3
  38. package/android/src/main/java/com/rnmaps/maps/MapOverlay.java +2 -22
  39. package/android/src/main/java/com/rnmaps/maps/MapOverlayManager.java +23 -1
  40. package/android/src/main/java/com/rnmaps/maps/MapUrlTile.java +18 -18
  41. package/android/src/main/java/com/rnmaps/maps/MapUrlTileManager.java +10 -14
  42. package/android/src/main/java/com/rnmaps/maps/MapView.java +58 -49
  43. package/android/src/main/java/com/rnmaps/maps/MapWMSTile.java +3 -3
  44. package/android/src/main/java/com/rnmaps/maps/MapWMSTileManager.java +10 -10
  45. package/android/src/main/jni/CMakeLists.txt +36 -0
  46. package/android/src/main/jni/RNMapsSpecs-generated.cpp +68 -0
  47. package/android/src/main/jni/RNMapsSpecs.h +31 -0
  48. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.cpp +31 -0
  49. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.h +33 -0
  50. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/EventEmitters.cpp +979 -0
  51. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/EventEmitters.h +860 -0
  52. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/Props.cpp +227 -0
  53. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/Props.h +1297 -0
  54. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI-generated.cpp +74 -0
  55. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI.h +268 -0
  56. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.cpp +26 -0
  57. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.h +131 -0
  58. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/States.cpp +16 -0
  59. package/android/src/main/jni/react/renderer/components/RNMapsSpecs/States.h +137 -0
  60. package/ios/AirGoogleMaps/AIRGoogleMap.h +13 -13
  61. package/ios/AirGoogleMaps/{AIRGoogleMap.m → AIRGoogleMap.mm} +32 -34
  62. package/ios/AirGoogleMaps/AIRGoogleMapManager.h +1 -0
  63. package/ios/AirGoogleMaps/AIRGoogleMapManager.mm +543 -0
  64. package/ios/AirGoogleMaps/AIRGoogleMapMarker.m +3 -3
  65. package/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m +1 -1
  66. package/ios/AirGoogleMaps/AIRGoogleMapUrlTile.m +2 -2
  67. package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.m +2 -2
  68. package/ios/AirGoogleMaps/RNMapsGoogleMapView.h +5 -2
  69. package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +41 -33
  70. package/ios/AirGoogleMaps/RNMapsGoogleMapViewManager.mm +16 -1
  71. package/ios/AirGoogleMaps/RNMapsGooglePolygonView.mm +23 -14
  72. package/ios/AirGoogleMaps/RNMapsGooglePolygonViewManager.mm +1 -0
  73. package/ios/AirMaps/AIRMap.h +8 -9
  74. package/ios/AirMaps/{AIRMap.m → AIRMap.mm} +18 -14
  75. package/ios/AirMaps/AIRMapManager.m +8 -19
  76. package/ios/AirMaps/AIRMapMarker.m +57 -44
  77. package/ios/AirMaps/AIRMapOverlay.m +2 -2
  78. package/ios/AirMaps/AIRMapWMSTile.m +8 -8
  79. package/ios/AirMaps/FabricPlaceholders/PlaceHolderGoogleMapView.h +25 -0
  80. package/ios/AirMaps/FabricPlaceholders/PlaceHolderGoogleMapView.mm +77 -0
  81. package/ios/AirMaps/FabricPlaceholders/PlaceHolderPolygonView.h +25 -0
  82. package/ios/AirMaps/FabricPlaceholders/PlaceHolderPolygonView.mm +51 -0
  83. package/ios/AirMaps/RNMapsAirModule.h +2 -3
  84. package/ios/AirMaps/RNMapsAirModule.mm +14 -0
  85. package/ios/AirMaps/RNMapsDefines.h +1 -0
  86. package/ios/AirMaps/RNMapsMapView.h +5 -2
  87. package/ios/AirMaps/RNMapsMapView.mm +16 -6
  88. package/ios/AirMaps/RNMapsMapViewManager.mm +19 -1
  89. package/ios/AirMaps/RNMapsMarkerView.mm +12 -4
  90. package/ios/AirMaps/RNMapsMarkerViewManager.mm +7 -0
  91. package/ios/AirMaps/module.modulemap +6 -0
  92. package/ios/AirMaps.xcodeproj/project.pbxproj +15 -55
  93. package/ios/generated/RCTAppDependencyProvider.h +25 -0
  94. package/ios/generated/RCTAppDependencyProvider.mm +55 -0
  95. package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
  96. package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
  97. package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
  98. package/ios/generated/RCTThirdPartyComponentsProvider.mm +26 -0
  99. package/ios/{AirMaps → generated}/RNMapsAirModuleDelegate.h +1 -1
  100. package/ios/generated/RNMapsSpecs/ComponentDescriptors.cpp +29 -0
  101. package/ios/generated/RNMapsSpecs/ComponentDescriptors.h +31 -0
  102. package/ios/generated/RNMapsSpecs/EventEmitters.cpp +977 -0
  103. package/ios/generated/RNMapsSpecs/EventEmitters.h +846 -0
  104. package/ios/generated/RNMapsSpecs/Props.cpp +194 -0
  105. package/ios/generated/RNMapsSpecs/Props.h +1224 -0
  106. package/ios/generated/RNMapsSpecs/RCTComponentViewHelpers.h +591 -0
  107. package/ios/generated/RNMapsSpecs/RNMapsSpecs-generated.mm +92 -0
  108. package/ios/generated/RNMapsSpecs/RNMapsSpecs.h +137 -0
  109. package/ios/generated/RNMapsSpecs/ShadowNodes.cpp +24 -0
  110. package/ios/generated/RNMapsSpecs/ShadowNodes.h +109 -0
  111. package/ios/generated/RNMapsSpecs/States.cpp +16 -0
  112. package/ios/generated/RNMapsSpecs/States.h +113 -0
  113. package/ios/generated/RNMapsSpecsJSI-generated.cpp +74 -0
  114. package/ios/generated/RNMapsSpecsJSI.h +268 -0
  115. package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
  116. package/ios/generated/module.modulemap +15 -0
  117. package/package.json +30 -26
  118. package/react-native-google-maps.podspec +27 -0
  119. package/react-native-maps-generated.podspec +31 -0
  120. package/react-native-maps.podspec +52 -46
  121. package/react-native.config.js +16 -0
  122. package/src/AnimatedRegion.ts +169 -0
  123. package/src/Geojson.tsx +541 -0
  124. package/src/MapCallout.tsx +77 -0
  125. package/src/MapCalloutSubview.tsx +64 -0
  126. package/src/MapCircle.tsx +162 -0
  127. package/src/MapHeatmap.tsx +125 -0
  128. package/src/MapLocalTile.tsx +60 -0
  129. package/src/MapMarker.tsx +531 -0
  130. package/src/MapMarkerNativeComponent.ts +51 -0
  131. package/src/MapOverlay.tsx +178 -0
  132. package/src/MapPolygon.tsx +188 -0
  133. package/src/MapPolygon.types.ts +25 -0
  134. package/src/MapPolyline.tsx +215 -0
  135. package/src/MapUrlTile.tsx +169 -0
  136. package/src/MapView.tsx +1230 -0
  137. package/src/MapView.types.ts +212 -0
  138. package/src/MapView.web.ts +2 -0
  139. package/src/MapViewNativeComponent.ts +86 -0
  140. package/src/MapWMSTile.tsx +148 -0
  141. package/src/ProviderConstants.ts +2 -0
  142. package/src/createFabricMap.tsx +253 -0
  143. package/src/decorateMapComponent.ts +227 -0
  144. package/src/fixImageProp.ts +17 -0
  145. package/src/index.ts +52 -0
  146. package/src/sharedTypes.ts +101 -0
  147. package/{specs → src/specs}/NativeComponentCircle.ts +3 -4
  148. package/{specs → src/specs}/NativeComponentGoogleMapView.ts +15 -9
  149. package/{specs → src/specs}/NativeComponentMapView.ts +61 -32
  150. package/{specs → src/specs}/NativeComponentOverlay.ts +11 -2
  151. package/{specs → src/specs}/NativeComponentPolyline.ts +1 -1
  152. package/src/specs/NativeComponentUrlTile.ts +128 -0
  153. package/src/specs/NativeComponentWMSTile.ts +107 -0
  154. package/ios/AirGoogleMaps/AIRGoogleMapManager.m +0 -533
  155. package/lib/AnimatedRegion.d.ts +0 -19
  156. package/lib/AnimatedRegion.js +0 -134
  157. package/lib/Geojson.d.ts +0 -204
  158. package/lib/Geojson.js +0 -166
  159. package/lib/MapCallout.d.ts +0 -40
  160. package/lib/MapCallout.js +0 -51
  161. package/lib/MapCalloutSubview.d.ts +0 -34
  162. package/lib/MapCalloutSubview.js +0 -48
  163. package/lib/MapCircle.d.ts +0 -117
  164. package/lib/MapCircle.js +0 -53
  165. package/lib/MapHeatmap.d.ts +0 -78
  166. package/lib/MapHeatmap.js +0 -59
  167. package/lib/MapLocalTile.d.ts +0 -35
  168. package/lib/MapLocalTile.js +0 -44
  169. package/lib/MapMarker.d.ts +0 -322
  170. package/lib/MapMarker.js +0 -158
  171. package/lib/MapMarkerNativeComponent.d.ts +0 -15
  172. package/lib/MapMarkerNativeComponent.js +0 -15
  173. package/lib/MapOverlay.d.ts +0 -88
  174. package/lib/MapOverlay.js +0 -65
  175. package/lib/MapPolygon.d.ts +0 -140
  176. package/lib/MapPolygon.js +0 -53
  177. package/lib/MapPolygon.types.d.ts +0 -18
  178. package/lib/MapPolygon.types.js +0 -2
  179. package/lib/MapPolyline.d.ts +0 -156
  180. package/lib/MapPolyline.js +0 -53
  181. package/lib/MapUrlTile.d.ts +0 -134
  182. package/lib/MapUrlTile.js +0 -44
  183. package/lib/MapView.d.ts +0 -703
  184. package/lib/MapView.js +0 -427
  185. package/lib/MapView.types.d.ts +0 -161
  186. package/lib/MapView.types.js +0 -2
  187. package/lib/MapView.web.d.ts +0 -1
  188. package/lib/MapView.web.js +0 -9
  189. package/lib/MapViewNativeComponent.d.ts +0 -18
  190. package/lib/MapViewNativeComponent.js +0 -19
  191. package/lib/MapWMSTile.d.ts +0 -116
  192. package/lib/MapWMSTile.js +0 -44
  193. package/lib/ProviderConstants.d.ts +0 -2
  194. package/lib/ProviderConstants.js +0 -5
  195. package/lib/createFabricMap.d.ts +0 -24
  196. package/lib/createFabricMap.js +0 -188
  197. package/lib/decorateMapComponent.d.ts +0 -36
  198. package/lib/decorateMapComponent.js +0 -120
  199. package/lib/fixImageProp.d.ts +0 -4
  200. package/lib/fixImageProp.js +0 -16
  201. package/lib/index.d.ts +0 -38
  202. package/lib/index.js +0 -81
  203. package/lib/sharedTypes.d.ts +0 -81
  204. package/lib/sharedTypes.js +0 -2
  205. package/lib/sharedTypesInternal.js +0 -2
  206. package/lib/specs/NativeAirMapsModule.d.ts +0 -31
  207. package/lib/specs/NativeAirMapsModule.js +0 -4
  208. package/lib/specs/NativeComponentCallout.d.ts +0 -46
  209. package/lib/specs/NativeComponentCallout.js +0 -9
  210. package/lib/specs/NativeComponentCircle.d.ts +0 -74
  211. package/lib/specs/NativeComponentCircle.js +0 -7
  212. package/lib/specs/NativeComponentGoogleMapView.d.ts +0 -713
  213. package/lib/specs/NativeComponentGoogleMapView.js +0 -22
  214. package/lib/specs/NativeComponentGooglePolygon.d.ts +0 -75
  215. package/lib/specs/NativeComponentGooglePolygon.js +0 -7
  216. package/lib/specs/NativeComponentMapView.d.ts +0 -847
  217. package/lib/specs/NativeComponentMapView.js +0 -20
  218. package/lib/specs/NativeComponentMarker.d.ts +0 -258
  219. package/lib/specs/NativeComponentMarker.js +0 -19
  220. package/lib/specs/NativeComponentOverlay.d.ts +0 -67
  221. package/lib/specs/NativeComponentOverlay.js +0 -7
  222. package/lib/specs/NativeComponentPolyline.d.ts +0 -101
  223. package/lib/specs/NativeComponentPolyline.js +0 -7
  224. /package/ios/AirMaps/{UIView +AirMap.m → UIView+AirMap.m} +0 -0
  225. /package/ios/{AirMaps → generated}/RNMapsHostVewDelegate.h +0 -0
  226. /package/{lib/sharedTypesInternal.d.ts → src/sharedTypesInternal.ts} +0 -0
  227. /package/{specs → src/specs}/NativeAirMapsModule.ts +0 -0
  228. /package/{specs → src/specs}/NativeComponentCallout.ts +0 -0
  229. /package/{specs → src/specs}/NativeComponentGooglePolygon.ts +0 -0
  230. /package/{specs → src/specs}/NativeComponentMarker.ts +0 -0
@@ -0,0 +1,169 @@
1
+ import {Animated} from 'react-native';
2
+ import {Region} from './sharedTypes';
3
+
4
+ const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
5
+ if (__DEV__) {
6
+ if (AnimatedWithChildren.name !== 'AnimatedWithChildren') {
7
+ console.error(
8
+ 'AnimatedRegion could not obtain AnimatedWithChildren base class',
9
+ );
10
+ }
11
+ }
12
+
13
+ const configTypes: (keyof Region)[] = [
14
+ 'latitude',
15
+ 'longitude',
16
+ 'latitudeDelta',
17
+ 'longitudeDelta',
18
+ ];
19
+
20
+ const defaultValues = {
21
+ // probably want to come up with better defaults
22
+ latitude: 0,
23
+ longitude: 0,
24
+ latitudeDelta: 0,
25
+ longitudeDelta: 0,
26
+ };
27
+
28
+ let _uniqueId = 1;
29
+
30
+ type TValueIn = number | Animated.Value | undefined;
31
+
32
+ type Props = Partial<Region> | undefined;
33
+
34
+ const getAnimatedValue = (valueIn: TValueIn, fallback: number) => {
35
+ if (valueIn instanceof Animated.Value) {
36
+ return valueIn;
37
+ } else if (typeof valueIn === 'number') {
38
+ return new Animated.Value(valueIn);
39
+ }
40
+ return new Animated.Value(fallback);
41
+ };
42
+
43
+ export default class AnimatedMapRegion extends AnimatedWithChildren {
44
+ constructor(valueIn: Props = {}) {
45
+ super();
46
+ this.latitude = getAnimatedValue(valueIn.latitude, defaultValues.latitude);
47
+ this.longitude = getAnimatedValue(
48
+ valueIn.longitude,
49
+ defaultValues.longitude,
50
+ );
51
+ this.latitudeDelta = getAnimatedValue(
52
+ valueIn.latitudeDelta,
53
+ defaultValues.latitudeDelta,
54
+ );
55
+ this.longitudeDelta = getAnimatedValue(
56
+ valueIn.longitudeDelta,
57
+ defaultValues.longitudeDelta,
58
+ );
59
+ this._regionListeners = {};
60
+ }
61
+
62
+ setValue(value: Region) {
63
+ this.latitude._value = value.latitude;
64
+ this.longitude._value = value.longitude;
65
+ this.latitudeDelta._value = value.latitudeDelta;
66
+ this.longitudeDelta._value = value.longitudeDelta;
67
+ }
68
+
69
+ setOffset(offset: Region) {
70
+ this.latitude.setOffset(offset.latitude);
71
+ this.longitude.setOffset(offset.longitude);
72
+ this.latitudeDelta.setOffset(offset.latitudeDelta);
73
+ this.longitudeDelta.setOffset(offset.longitudeDelta);
74
+ }
75
+
76
+ flattenOffset() {
77
+ this.latitude.flattenOffset();
78
+ this.longitude.flattenOffset();
79
+ this.latitudeDelta.flattenOffset();
80
+ this.longitudeDelta.flattenOffset();
81
+ }
82
+
83
+ private __getValue() {
84
+ return {
85
+ latitude: this.latitude.__getValue(),
86
+ longitude: this.longitude.__getValue(),
87
+ latitudeDelta: this.latitudeDelta.__getValue(),
88
+ longitudeDelta: this.longitudeDelta.__getValue(),
89
+ };
90
+ }
91
+
92
+ private __attach() {
93
+ this.latitude.__addChild(this);
94
+ this.longitude.__addChild(this);
95
+ this.latitudeDelta.__addChild(this);
96
+ this.longitudeDelta.__addChild(this);
97
+ }
98
+
99
+ private __detach() {
100
+ this.latitude.__removeChild(this);
101
+ this.longitude.__removeChild(this);
102
+ this.latitudeDelta.__removeChild(this);
103
+ this.longitudeDelta.__removeChild(this);
104
+ }
105
+
106
+ stopAnimation(callback: (region: Region) => void) {
107
+ this.latitude.stopAnimation();
108
+ this.longitude.stopAnimation();
109
+ this.latitudeDelta.stopAnimation();
110
+ this.longitudeDelta.stopAnimation();
111
+ callback && callback(this.__getValue());
112
+ }
113
+
114
+ addListener(callback: (region: Region) => void) {
115
+ const id = String(_uniqueId++);
116
+ const jointCallback = () => /*{value}*/ callback(this.__getValue());
117
+ this._regionListeners[id] = {
118
+ latitude: this.latitude.addListener(jointCallback),
119
+ longitude: this.longitude.addListener(jointCallback),
120
+ latitudeDelta: this.latitudeDelta.addListener(jointCallback),
121
+ longitudeDelta: this.longitudeDelta.addListener(jointCallback),
122
+ };
123
+ return id;
124
+ }
125
+
126
+ removeListener(id: string) {
127
+ this.latitude.removeListener(this._regionListeners[id].latitude);
128
+ this.longitude.removeListener(this._regionListeners[id].longitude);
129
+ this.latitudeDelta.removeListener(this._regionListeners[id].latitudeDelta);
130
+ this.longitudeDelta.removeListener(
131
+ this._regionListeners[id].longitudeDelta,
132
+ );
133
+ delete this._regionListeners[id];
134
+ }
135
+
136
+ spring(config: Animated.SpringAnimationConfig & Region) {
137
+ const animations = [];
138
+ for (const type of configTypes) {
139
+ if (config.hasOwnProperty(type)) {
140
+ animations.push(
141
+ Animated.spring(this[type], {
142
+ ...config,
143
+ toValue: config[type],
144
+ // may help to eliminate some dev warnings and perf issues
145
+ useNativeDriver: !!config?.useNativeDriver,
146
+ }),
147
+ );
148
+ }
149
+ }
150
+ return Animated.parallel(animations);
151
+ }
152
+
153
+ timing(config: Animated.TimingAnimationConfig & Region) {
154
+ const animations = [];
155
+ for (const type of configTypes) {
156
+ if (config.hasOwnProperty(type)) {
157
+ animations.push(
158
+ Animated.timing(this[type], {
159
+ ...config,
160
+ toValue: config[type],
161
+ // may help to eliminate some dev warnings and perf issues
162
+ useNativeDriver: !!config?.useNativeDriver,
163
+ }),
164
+ );
165
+ }
166
+ }
167
+ return Animated.parallel(animations);
168
+ }
169
+ }
@@ -0,0 +1,541 @@
1
+ import * as React from 'react';
2
+ import {
3
+ Feature,
4
+ FeatureCollection,
5
+ Point,
6
+ Position,
7
+ MultiPoint,
8
+ LineString,
9
+ MultiLineString,
10
+ Polygon,
11
+ MultiPolygon,
12
+ } from 'geojson';
13
+ import Marker, {MapMarkerProps as MarkerProps} from './MapMarker';
14
+ import {MapPolygonProps as PolygonProps} from './MapPolygon';
15
+ import {MapPolylineProps as PolylineProps} from './MapPolyline';
16
+ import Polyline from './MapPolyline';
17
+ import MapPolygon from './MapPolygon';
18
+ import {LatLng} from './sharedTypes';
19
+
20
+ export type GeojsonProps = {
21
+ /**
22
+ * Sets the anchor point for the marker.
23
+ * The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.
24
+ *
25
+ * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
26
+ * where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
27
+ *
28
+ * The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding.
29
+ * For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).
30
+ *
31
+ * @default {x: 0.5, y: 1.0}
32
+ * @platform iOS: Google Maps only. For Apple Maps, see the `centerOffset` prop
33
+ * @platform Android: Supported
34
+ */
35
+ anchor?: MarkerProps['anchor'];
36
+
37
+ /**
38
+ * The offset (in points) at which to display the annotation view.
39
+ *
40
+ * By default, the center point of an annotation view is placed at the coordinate point of the associated annotation.
41
+ *
42
+ * Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.
43
+ *
44
+ * @default {x: 0.0, y: 0.0}
45
+ * @platform iOS: Apple Maps only. For Google Maps, see the `anchor` prop
46
+ * @platform Android: Not supported. See see the `anchor` prop
47
+ */
48
+ centerOffset?: MarkerProps['centerOffset'];
49
+
50
+ /**
51
+ * The pincolor used on markers
52
+ *
53
+ * @platform iOS: Supported
54
+ * @platform Android: Supported
55
+ */
56
+ color?: MarkerProps['pinColor'];
57
+
58
+ /**
59
+ * The fill color to use for the path.
60
+ *
61
+ * @platform iOS: Supported
62
+ * @platform Android: Supported
63
+ */
64
+ fillColor?: PolygonProps['fillColor'];
65
+
66
+ /**
67
+ * [Geojson](https://geojson.org/) description of object.
68
+ *
69
+ * @platform iOS: Supported
70
+ * @platform Android: Supported
71
+ */
72
+ geojson: FeatureCollection;
73
+
74
+ /**
75
+ * A custom image to be used as the marker's icon. Only local image resources are allowed to be
76
+ * used.
77
+ *
78
+ * @platform iOS: Supported
79
+ * @platform Android: Supported
80
+ */
81
+ image?: MarkerProps['image'];
82
+
83
+ /**
84
+ * The line cap style to apply to the open ends of the path.
85
+ * The default style is `round`.
86
+ *
87
+ * @platform iOS: Apple Maps only
88
+ * @platform Android: Supported
89
+ */
90
+ lineCap?: PolylineProps['lineCap'];
91
+
92
+ /**
93
+ * An array of numbers specifying the dash pattern to use for the path.
94
+ *
95
+ * The array contains one or more numbers that indicate the lengths (measured in points) of the
96
+ * line segments and gaps in the pattern. The values in the array alternate, starting with the
97
+ * first line segment length, followed by the first gap length, followed by the second line
98
+ * segment length, and so on.
99
+ *
100
+ * This property is set to `null` by default, which indicates no line dash pattern.
101
+ *
102
+ * @platform iOS: Supported
103
+ * @platform Android: Supported
104
+ */
105
+ lineDashPattern?:
106
+ | PolygonProps['lineDashPattern']
107
+ | PolylineProps['lineDashPattern'];
108
+
109
+ /**
110
+ * The offset (in points) at which to start drawing the dash pattern.
111
+ *
112
+ * Use this property to start drawing a dashed line partway through a segment or gap. For
113
+ * example, a phase value of 6 for the patter 5-2-3-2 would cause drawing to begin in the
114
+ * middle of the first gap.
115
+ *
116
+ * The default value of this property is 0.
117
+ *
118
+ * @platform iOS: Apple Maps only
119
+ * @platform Android: Not supported
120
+ */
121
+ lineDashPhase?: PolylineProps['lineDashPhase'];
122
+
123
+ /**
124
+ * The line join style to apply to corners of the path.
125
+ * The default style is `round`.
126
+ *
127
+ * @platform iOS: Apple Maps only
128
+ * @platform Android: Not supported
129
+ */
130
+ lineJoin?: PolylineProps['lineJoin'];
131
+
132
+ /**
133
+ * Component to render in place of the default marker when the overlay type is a `point`
134
+ *
135
+ * @platform iOS: Supported
136
+ * @platform Android: Supported
137
+ */
138
+ markerComponent?: MarkerProps['children'];
139
+
140
+ /**
141
+ * The limiting value that helps avoid spikes at junctions between connected line segments.
142
+ * The miter limit helps you avoid spikes in paths that use the `miter` `lineJoin` style. If
143
+ * the ratio of the miter length—that is, the diagonal length of the miter join—to the line
144
+ * thickness exceeds the miter limit, the joint is converted to a bevel join. The default
145
+ * miter limit is 10, which results in the conversion of miters whose angle at the joint
146
+ * is less than 11 degrees.
147
+ *
148
+ * @platform iOS: Apple Maps only
149
+ * @platform Android: Not supported
150
+ */
151
+ miterLimit?: PolylineProps['miterLimit'];
152
+
153
+ /**
154
+ * Callback that is called when the user presses any of the overlays
155
+ */
156
+ onPress?: (event: OverlayPressEvent) => void;
157
+
158
+ /**
159
+ * The stroke color to use for the path.
160
+ *
161
+ * @platform — iOS: Supported
162
+ * @platform — Android: Supported
163
+ */
164
+ strokeColor?: PolygonProps['strokeColor'] | PolylineProps['strokeColor'];
165
+
166
+ /**
167
+ * The stroke width to use for the path.
168
+ *
169
+ * @platform — iOS: Supported
170
+ * @platform — Android: Supported
171
+ */
172
+ strokeWidth?: PolygonProps['strokeWidth'] | PolylineProps['strokeWidth'];
173
+
174
+ /**
175
+ * Make the `Polygon` or `Polyline` tappable
176
+ *
177
+ * @platform — iOS: Google Maps only
178
+ * @platform — Android: Supported
179
+ */
180
+ tappable?: PolygonProps['tappable'] | PolylineProps['tappable'];
181
+
182
+ /**
183
+ * The title of the marker. This is only used if the <Marker /> component has no children that
184
+ * are a `<Callout />`, in which case the default callout behavior will be used, which
185
+ * will show both the `title` and the `description`, if provided.
186
+ *
187
+ * @platform — iOS: Supported
188
+ * @platform — Android: Supported
189
+ */
190
+ title?: MarkerProps['title'];
191
+
192
+ /**
193
+ * Sets whether this marker should track view changes.
194
+ * It's recommended to turn it off whenever it's possible to improve custom marker performance.
195
+ * This is the default value for all point markers in your geojson data. It can be overriden
196
+ * on a per point basis by adding a `trackViewChanges` property to the `properties` object on the point.
197
+ *
198
+ * @default true
199
+ * @platform iOS: Google Maps only
200
+ * @platform Android: Supported
201
+ */
202
+ tracksViewChanges?: boolean;
203
+
204
+ /**
205
+ * The order in which this tile overlay is drawn with respect to other overlays. An overlay
206
+ * with a larger z-index is drawn over overlays with smaller z-indices. The order of overlays
207
+ * with the same z-index is arbitrary. The default zIndex is 0.
208
+ *
209
+ * @platform iOS: Apple Maps: [Marker], Google Maps: [Marker, Polygon, Polyline]
210
+ * @platform Android: Supported
211
+ */
212
+ zIndex?:
213
+ | MarkerProps['zIndex']
214
+ | PolygonProps['zIndex']
215
+ | PolylineProps['zIndex'];
216
+ };
217
+
218
+ const Geojson = (props: GeojsonProps) => {
219
+ const {
220
+ anchor,
221
+ centerOffset,
222
+ geojson,
223
+ strokeColor,
224
+ fillColor,
225
+ strokeWidth,
226
+ color,
227
+ title,
228
+ image,
229
+ zIndex,
230
+ onPress,
231
+ lineCap,
232
+ lineJoin,
233
+ tappable,
234
+ tracksViewChanges,
235
+ miterLimit,
236
+ lineDashPhase,
237
+ lineDashPattern,
238
+ markerComponent,
239
+ } = props;
240
+ const pointOverlays = makePointOverlays(geojson.features);
241
+ const lineOverlays = makeLineOverlays(geojson.features);
242
+ const polygonOverlays = makePolygonOverlays(geojson.features);
243
+ return (
244
+ <React.Fragment>
245
+ {pointOverlays.map((overlay, index) => {
246
+ const markerColor = getColor(color, overlay, 'marker-color');
247
+ const pointOverlayTracksViewChanges =
248
+ overlay.feature.properties?.tracksViewChanges || tracksViewChanges;
249
+ return (
250
+ <Marker
251
+ key={index}
252
+ coordinate={overlay.coordinates}
253
+ tracksViewChanges={pointOverlayTracksViewChanges}
254
+ image={image}
255
+ title={title}
256
+ pinColor={markerColor}
257
+ zIndex={zIndex}
258
+ anchor={anchor}
259
+ centerOffset={centerOffset}
260
+ onPress={() => onPress && onPress(overlay)}>
261
+ {markerComponent}
262
+ </Marker>
263
+ );
264
+ })}
265
+ {lineOverlays.map((overlay, index) => {
266
+ const lineStrokeColor = getColor(strokeColor, overlay, 'stroke');
267
+ const lineStrokeWidth = getStrokeWidth(strokeWidth, overlay);
268
+
269
+ return (
270
+ <Polyline
271
+ key={index}
272
+ coordinates={overlay.coordinates}
273
+ strokeColor={lineStrokeColor}
274
+ strokeWidth={lineStrokeWidth}
275
+ lineDashPhase={lineDashPhase}
276
+ lineDashPattern={lineDashPattern}
277
+ lineCap={lineCap}
278
+ lineJoin={lineJoin}
279
+ miterLimit={miterLimit}
280
+ zIndex={zIndex}
281
+ tappable={tappable}
282
+ onPress={() => onPress && onPress(overlay)}
283
+ />
284
+ );
285
+ })}
286
+ {polygonOverlays.map((overlay, index) => {
287
+ const polygonFillColor = getColor(fillColor, overlay, 'fill');
288
+ const lineStrokeColor = getColor(strokeColor, overlay, 'stroke');
289
+ const lineStrokeWidth = getStrokeWidth(strokeWidth, overlay);
290
+
291
+ return (
292
+ <MapPolygon
293
+ key={index}
294
+ coordinates={overlay.coordinates}
295
+ holes={overlay.holes}
296
+ strokeColor={lineStrokeColor}
297
+ fillColor={polygonFillColor}
298
+ strokeWidth={lineStrokeWidth}
299
+ lineDashPhase={lineDashPhase}
300
+ lineDashPattern={lineDashPattern}
301
+ lineCap={lineCap}
302
+ lineJoin={lineJoin}
303
+ miterLimit={miterLimit}
304
+ tappable={tappable}
305
+ onPress={() => onPress && onPress(overlay)}
306
+ zIndex={zIndex}
307
+ />
308
+ );
309
+ })}
310
+ </React.Fragment>
311
+ );
312
+ };
313
+
314
+ export default Geojson;
315
+
316
+ const makePointOverlays = (features: Feature[]): AnyPointOverlay[] => {
317
+ return features
318
+ .filter(isAnyPointFeature)
319
+ .map(feature =>
320
+ makeCoordinatesForAnyPoint(feature.geometry).map(coordinates =>
321
+ makeOverlayForAnyPoint(coordinates, feature),
322
+ ),
323
+ )
324
+ .reduce((prev, curr) => prev.concat(curr), [])
325
+ .map(overlay => ({...overlay, type: 'point'}));
326
+ };
327
+
328
+ const makeLineOverlays = (features: Feature[]): AnyLineStringOverlay[] => {
329
+ return features
330
+ .filter(isAnyLineStringFeature)
331
+ .map(feature =>
332
+ makeCoordinatesForAnyLine(feature.geometry).map(coordinates =>
333
+ makeOverlayForAnyLine(coordinates, feature),
334
+ ),
335
+ )
336
+ .reduce((prev, curr) => prev.concat(curr), [])
337
+ .map(overlay => ({...overlay, type: 'polyline'}));
338
+ };
339
+
340
+ const makePolygonOverlays = (features: Feature[]): AnyPolygonOverlay[] => {
341
+ const multipolygons: AnyPolygonOverlay[] = features
342
+ .filter(isMultiPolygonFeature)
343
+ .map(feature =>
344
+ makeCoordinatesForMultiPolygon(feature.geometry).map(coordinates =>
345
+ makeOverlayForAnyPolygon(coordinates, feature),
346
+ ),
347
+ )
348
+ .reduce((prev, curr) => prev.concat(curr), [])
349
+ .map(overlay => ({...overlay, type: 'polygon'}));
350
+
351
+ const polygons: AnyPolygonOverlay[] = features
352
+ .filter(isPolygonFeature)
353
+ .map(feature =>
354
+ makeOverlayForAnyPolygon(
355
+ makeCoordinatesForPolygon(feature.geometry),
356
+ feature,
357
+ ),
358
+ )
359
+ .reduce<Omit<AnyPolygonOverlay, 'type'>[]>(
360
+ (prev, curr) => prev.concat(curr),
361
+ [],
362
+ )
363
+ .map(overlay => ({...overlay, type: 'polygon'}));
364
+
365
+ return polygons.concat(multipolygons);
366
+ };
367
+
368
+ const makeOverlayForAnyPoint = (
369
+ coordinates: LatLng,
370
+ feature: Feature<Point | MultiPoint>,
371
+ ): Omit<AnyPointOverlay, 'type'> => {
372
+ return {feature, coordinates};
373
+ };
374
+
375
+ const makeOverlayForAnyLine = (
376
+ coordinates: LatLng[],
377
+ feature: Feature<LineString | MultiLineString>,
378
+ ): Omit<AnyLineStringOverlay, 'type'> => {
379
+ return {feature, coordinates};
380
+ };
381
+
382
+ const makeOverlayForAnyPolygon = (
383
+ coordinates: LatLng[][],
384
+ feature: Feature<Polygon | MultiPolygon>,
385
+ ): Omit<AnyPolygonOverlay, 'type'> => {
386
+ return {
387
+ feature,
388
+ coordinates: coordinates[0],
389
+ holes: coordinates.length > 1 ? coordinates.slice(1) : undefined,
390
+ };
391
+ };
392
+
393
+ const makePoint = (c: Position): LatLng => ({
394
+ latitude: c[1],
395
+ longitude: c[0],
396
+ });
397
+
398
+ const makeLine = (l: Position[]) => l.map(makePoint);
399
+
400
+ const makeCoordinatesForAnyPoint = (geometry: Point | MultiPoint) => {
401
+ if (geometry.type === 'Point') {
402
+ return [makePoint(geometry.coordinates)];
403
+ }
404
+ return geometry.coordinates.map(makePoint);
405
+ };
406
+
407
+ const makeCoordinatesForAnyLine = (geometry: LineString | MultiLineString) => {
408
+ if (geometry.type === 'LineString') {
409
+ return [makeLine(geometry.coordinates)];
410
+ }
411
+ return geometry.coordinates.map(makeLine);
412
+ };
413
+
414
+ const makeCoordinatesForPolygon = (geometry: Polygon) => {
415
+ return geometry.coordinates.map(makeLine);
416
+ };
417
+
418
+ const makeCoordinatesForMultiPolygon = (geometry: MultiPolygon) => {
419
+ return geometry.coordinates.map(p => p.map(makeLine));
420
+ };
421
+
422
+ const getRgbaFromHex = (hex: string, alpha: number = 1) => {
423
+ const matchArray = hex.match(/\w\w/g);
424
+ if (!matchArray || matchArray.length < 3) {
425
+ throw new Error('Invalid hex string');
426
+ }
427
+ const [r, g, b] = matchArray.map(x => {
428
+ const subColor = parseInt(x, 16);
429
+ if (Number.isNaN(subColor)) {
430
+ throw new Error('Invalid hex string');
431
+ }
432
+ return subColor;
433
+ });
434
+ return `rgba(${r},${g},${b},${alpha})`;
435
+ };
436
+
437
+ const getColor = (
438
+ prop: string | undefined,
439
+ overlay: Overlay,
440
+ colorType: string,
441
+ ) => {
442
+ if (prop) {
443
+ return prop;
444
+ }
445
+ let color = overlay.feature.properties?.[colorType];
446
+ if (color) {
447
+ const opacityProperty = colorType + '-opacity';
448
+ const alpha = overlay.feature.properties?.[opacityProperty];
449
+ if (alpha && alpha !== '0' && color[0] === '#') {
450
+ color = getRgbaFromHex(color, alpha);
451
+ }
452
+ return color;
453
+ }
454
+ return undefined;
455
+ };
456
+
457
+ const getStrokeWidth = (
458
+ prop: GeojsonProps['strokeWidth'],
459
+ overlay: Overlay,
460
+ ) => {
461
+ if (prop) {
462
+ return prop;
463
+ }
464
+ return overlay.feature.properties?.['stroke-width'];
465
+ };
466
+
467
+ // GeoJSON.Feature type-guards
468
+ const isPointFeature = (feature: Feature): feature is Feature<Point> =>
469
+ feature.geometry.type === 'Point';
470
+
471
+ const isMultiPointFeature = (
472
+ feature: Feature,
473
+ ): feature is Feature<MultiPoint> => feature.geometry.type === 'MultiPoint';
474
+
475
+ const isAnyPointFeature = (
476
+ feature: Feature,
477
+ ): feature is Feature<Point> | Feature<MultiPoint> =>
478
+ isPointFeature(feature) || isMultiPointFeature(feature);
479
+
480
+ const isLineStringFeature = (
481
+ feature: Feature,
482
+ ): feature is Feature<LineString> => feature.geometry.type === 'LineString';
483
+
484
+ const isMultiLineStringFeature = (
485
+ feature: Feature,
486
+ ): feature is Feature<MultiLineString> =>
487
+ feature.geometry.type === 'MultiLineString';
488
+
489
+ const isAnyLineStringFeature = (
490
+ feature: Feature,
491
+ ): feature is Feature<LineString> | Feature<MultiLineString> =>
492
+ isLineStringFeature(feature) || isMultiLineStringFeature(feature);
493
+
494
+ const isPolygonFeature = (feature: Feature): feature is Feature<Polygon> =>
495
+ feature.geometry.type === 'Polygon';
496
+
497
+ const isMultiPolygonFeature = (
498
+ feature: Feature,
499
+ ): feature is Feature<MultiPolygon> => feature.geometry.type === 'MultiPolygon';
500
+
501
+ type OverlayPressEvent = {
502
+ type:
503
+ | AnyPointOverlay['type']
504
+ | AnyLineStringOverlay['type']
505
+ | AnyPolygonOverlay['type'];
506
+ feature:
507
+ | AnyPointOverlay['feature']
508
+ | AnyLineStringOverlay['feature']
509
+ | AnyPolygonOverlay['feature'];
510
+ coordinates:
511
+ | AnyPointOverlay['coordinates']
512
+ | AnyLineStringOverlay['coordinates']
513
+ | AnyPolygonOverlay['coordinates'];
514
+ holes?: AnyPolygonOverlay['holes'];
515
+ };
516
+
517
+ type AnyPointOverlay = {
518
+ type: 'point';
519
+ feature: Feature<Point | MultiPoint>;
520
+ coordinates: LatLng;
521
+ };
522
+
523
+ type AnyLineStringOverlay = {
524
+ type: 'polyline';
525
+ feature: Feature<LineString | MultiLineString>;
526
+ coordinates: LatLng[];
527
+ };
528
+
529
+ type AnyPolygonOverlay = {
530
+ type: 'polygon';
531
+ feature: Feature<Polygon | MultiPolygon>;
532
+ coordinates: LatLng[];
533
+ holes?: LatLng[][];
534
+ };
535
+
536
+ type Overlay = {
537
+ type: 'point' | 'polyline' | 'polygon';
538
+ feature: Feature;
539
+ coordinates: LatLng | LatLng[];
540
+ holes?: LatLng[][];
541
+ };