@rnmapbox/maps 10.0.0-beta.75 → 10.0.0-beta.76

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 (134) hide show
  1. package/README.md +3 -3
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +5 -5
  3. package/ios/RCTMGL-v10/RCMTGLImage.swift +2 -1
  4. package/ios/RCTMGL-v10/RCTMGLImages.swift +57 -17
  5. package/ios/RCTMGL-v10/RCTMGLMapView.swift +11 -1
  6. package/ios/RCTMGL-v10/RCTMGLUtils.swift +14 -5
  7. package/javascript/MGLModule.ts +54 -0
  8. package/javascript/Mapbox.ts +97 -0
  9. package/javascript/classes/index.d.ts +20 -1
  10. package/javascript/components/Annotation.tsx +141 -0
  11. package/javascript/components/Callout.d.ts +35 -0
  12. package/javascript/components/ImageSource.tsx +1 -1
  13. package/javascript/components/Images.tsx +58 -6
  14. package/javascript/components/MapView.tsx +1 -1
  15. package/javascript/components/MarkerView.tsx +3 -2
  16. package/javascript/components/PointAnnotation.tsx +4 -3
  17. package/javascript/components/ShapeSource.tsx +1 -1
  18. package/javascript/components/{Style.js → Style.tsx} +117 -35
  19. package/javascript/components/Terrain.tsx +8 -7
  20. package/javascript/components/{UserLocation.js → UserLocation.tsx} +105 -94
  21. package/javascript/components/VectorSource.tsx +1 -1
  22. package/javascript/index.ts +4 -0
  23. package/javascript/modules/offline/offlineManager.ts +5 -1
  24. package/javascript/modules/snapshot/snapshotManager.ts +1 -0
  25. package/javascript/types/Position.ts +1 -0
  26. package/javascript/utils/Logger.ts +1 -1
  27. package/javascript/utils/geoUtils.ts +0 -35
  28. package/lib/commonjs/MGLModule.js +37 -0
  29. package/lib/commonjs/MGLModule.js.map +1 -0
  30. package/lib/commonjs/Mapbox.js +372 -0
  31. package/lib/commonjs/Mapbox.js.map +1 -0
  32. package/lib/commonjs/classes/index.d.js +2 -0
  33. package/lib/commonjs/classes/index.d.js.map +1 -1
  34. package/lib/commonjs/components/{annotations/Annotation.js → Annotation.js} +26 -27
  35. package/lib/commonjs/components/Annotation.js.map +1 -0
  36. package/lib/commonjs/components/Callout.d.js +9 -0
  37. package/lib/commonjs/components/Callout.d.js.map +1 -0
  38. package/lib/commonjs/components/Images.js +17 -1
  39. package/lib/commonjs/components/Images.js.map +1 -1
  40. package/lib/commonjs/components/MapView.js.map +1 -1
  41. package/lib/commonjs/components/MarkerView.js.map +1 -1
  42. package/lib/commonjs/components/PointAnnotation.js.map +1 -1
  43. package/lib/commonjs/components/Style.js +11 -15
  44. package/lib/commonjs/components/Style.js.map +1 -1
  45. package/lib/commonjs/components/Terrain.js.map +1 -1
  46. package/lib/commonjs/components/UserLocation.js +26 -77
  47. package/lib/commonjs/components/UserLocation.js.map +1 -1
  48. package/lib/commonjs/index.js +16 -339
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/modules/offline/offlineManager.js +6 -0
  51. package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
  52. package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
  53. package/lib/commonjs/types/Position.js +2 -0
  54. package/lib/commonjs/types/Position.js.map +1 -0
  55. package/lib/commonjs/utils/animated/Animated.js.map +1 -1
  56. package/lib/commonjs/utils/geoUtils.js +1 -19
  57. package/lib/commonjs/utils/geoUtils.js.map +1 -1
  58. package/lib/module/MGLModule.js +19 -0
  59. package/lib/module/MGLModule.js.map +1 -0
  60. package/lib/module/Mapbox.js +59 -0
  61. package/lib/module/Mapbox.js.map +1 -0
  62. package/lib/module/classes/index.d.js +2 -0
  63. package/lib/module/classes/index.d.js.map +1 -1
  64. package/lib/module/components/{annotations/Annotation.js → Annotation.js} +26 -27
  65. package/lib/module/components/Annotation.js.map +1 -0
  66. package/lib/module/components/Callout.d.js +2 -0
  67. package/lib/module/components/Callout.d.js.map +1 -0
  68. package/lib/module/components/Images.js +17 -1
  69. package/lib/module/components/Images.js.map +1 -1
  70. package/lib/module/components/MapView.js.map +1 -1
  71. package/lib/module/components/MarkerView.js.map +1 -1
  72. package/lib/module/components/PointAnnotation.js.map +1 -1
  73. package/lib/module/components/Style.js +11 -15
  74. package/lib/module/components/Style.js.map +1 -1
  75. package/lib/module/components/Terrain.js.map +1 -1
  76. package/lib/module/components/UserLocation.js +25 -76
  77. package/lib/module/components/UserLocation.js.map +1 -1
  78. package/lib/module/index.js +3 -108
  79. package/lib/module/index.js.map +1 -1
  80. package/lib/module/modules/offline/offlineManager.js +1 -0
  81. package/lib/module/modules/offline/offlineManager.js.map +1 -1
  82. package/lib/module/modules/snapshot/snapshotManager.js.map +1 -1
  83. package/lib/module/types/Position.js +2 -0
  84. package/lib/module/types/Position.js.map +1 -0
  85. package/lib/module/utils/animated/Animated.js.map +1 -1
  86. package/lib/module/utils/geoUtils.js +0 -16
  87. package/lib/module/utils/geoUtils.js.map +1 -1
  88. package/lib/typescript/MGLModule.d.ts +22 -0
  89. package/lib/typescript/MGLModule.d.ts.map +1 -0
  90. package/lib/typescript/Mapbox.d.ts +54 -0
  91. package/lib/typescript/Mapbox.d.ts.map +1 -0
  92. package/lib/typescript/components/Annotation.d.ts +34 -0
  93. package/lib/typescript/components/Annotation.d.ts.map +1 -0
  94. package/lib/typescript/components/ImageSource.d.ts +1 -1
  95. package/lib/typescript/components/ImageSource.d.ts.map +1 -1
  96. package/lib/typescript/components/Images.d.ts +24 -2
  97. package/lib/typescript/components/Images.d.ts.map +1 -1
  98. package/lib/typescript/components/MapView.d.ts +2 -5
  99. package/lib/typescript/components/MapView.d.ts.map +1 -1
  100. package/lib/typescript/components/MarkerView.d.ts +3 -2
  101. package/lib/typescript/components/MarkerView.d.ts.map +1 -1
  102. package/lib/typescript/components/PointAnnotation.d.ts +9 -3
  103. package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
  104. package/lib/typescript/components/ShapeSource.d.ts +1 -1
  105. package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
  106. package/lib/typescript/components/Style.d.ts +74 -0
  107. package/lib/typescript/components/Style.d.ts.map +1 -0
  108. package/lib/typescript/components/Terrain.d.ts +2 -2
  109. package/lib/typescript/components/Terrain.d.ts.map +1 -1
  110. package/lib/typescript/components/UserLocation.d.ts +102 -0
  111. package/lib/typescript/components/UserLocation.d.ts.map +1 -0
  112. package/lib/typescript/components/VectorSource.d.ts +1 -1
  113. package/lib/typescript/components/VectorSource.d.ts.map +1 -1
  114. package/lib/typescript/index.d.ts +4 -0
  115. package/lib/typescript/index.d.ts.map +1 -0
  116. package/lib/typescript/modules/offline/offlineManager.d.ts +2 -1
  117. package/lib/typescript/modules/offline/offlineManager.d.ts.map +1 -1
  118. package/lib/typescript/modules/snapshot/snapshotManager.d.ts +1 -0
  119. package/lib/typescript/modules/snapshot/snapshotManager.d.ts.map +1 -1
  120. package/lib/typescript/types/Position.d.ts +2 -0
  121. package/lib/typescript/types/Position.d.ts.map +1 -0
  122. package/lib/typescript/utils/Logger.d.ts +1 -1
  123. package/lib/typescript/utils/Logger.d.ts.map +1 -1
  124. package/lib/typescript/utils/animated/Animated.d.ts +23 -0
  125. package/lib/typescript/utils/animated/Animated.d.ts.map +1 -0
  126. package/lib/typescript/utils/geoUtils.d.ts +0 -8
  127. package/lib/typescript/utils/geoUtils.d.ts.map +1 -1
  128. package/package.json +3 -5
  129. package/index.d.ts +0 -516
  130. package/javascript/components/annotations/Annotation.js +0 -122
  131. package/javascript/index.js +0 -162
  132. package/lib/commonjs/components/annotations/Annotation.js.map +0 -1
  133. package/lib/module/components/annotations/Annotation.js.map +0 -1
  134. /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
package/README.md CHANGED
@@ -147,15 +147,15 @@ npm run android
147
147
  ```js
148
148
  import React from 'react';
149
149
  import { StyleSheet, View } from 'react-native';
150
- import MapboxGL from '@rnmapbox/maps';
150
+ import Mapbox from '@rnmapbox/maps';
151
151
 
152
- MapboxGL.setAccessToken('<YOUR_ACCESSTOKEN>');
152
+ Mapbox.setAccessToken('<YOUR_ACCESSTOKEN>');
153
153
 
154
154
  const App = () => {
155
155
  return (
156
156
  <View style={styles.page}>
157
157
  <View style={styles.container}>
158
- <MapboxGL.MapView style={styles.map} />
158
+ <Mapbox.MapView style={styles.map} />
159
159
  </View>
160
160
  </View>
161
161
  );
@@ -63,9 +63,9 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
63
63
  val drawable =
64
64
  ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable
65
65
  if (drawable != null) {
66
- return NativeImage(name, drawable)
66
+ return NativeImage(resourceName, drawable)
67
67
  } else {
68
- Logger.e("RCTMGLImages", "cound not get native drawable with name: $name")
68
+ Logger.e("RCTMGLImages", "cound not get native drawable with name: $resourceName")
69
69
  return null
70
70
  }
71
71
  }
@@ -98,10 +98,10 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
98
98
  }
99
99
  val drawable =
100
100
  ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable
101
- if (drawable != null) {
102
- return NativeImage(name, drawable, scale, sdf, stretchX, stretchY)
101
+ if (drawable != null && resourceName != null) {
102
+ return NativeImage(resourceName, drawable, scale, sdf, stretchX, stretchY)
103
103
  } else {
104
- Logger.e("RCTMGLImages", "cound not get native drawable with name: $name")
104
+ Logger.e("RCTMGLImages", "cound not get native drawable with name: $resourceName")
105
105
  return null
106
106
  }
107
107
  }
@@ -9,6 +9,7 @@ class RCTMGLImage : UIView {
9
9
  var sdf: Bool? = nil
10
10
  var stretchX: [[NSNumber]] = []
11
11
  var stretchY: [[NSNumber]] = []
12
+ var content: [NSNumber]? = nil
12
13
 
13
14
  weak var images: RCTMGLImageSetter? = nil {
14
15
  didSet {
@@ -42,7 +43,7 @@ class RCTMGLImage : UIView {
42
43
 
43
44
  func changeImage(_ image: UIImage, name: String) {
44
45
  if let images = images {
45
- let _ = images.addImage(name: name, image: image, sdf: sdf, stretchX:stretchX, stretchY:stretchY, log: "RCTMGLImage.addImage")
46
+ let _ = images.addImage(name: name, image: image, sdf: sdf, stretchX:stretchX, stretchY:stretchY, content:content, log: "RCTMGLImage.addImage")
46
47
  }
47
48
  }
48
49
 
@@ -1,7 +1,7 @@
1
1
  import MapboxMaps
2
2
 
3
3
  protocol RCTMGLImageSetter : AnyObject {
4
- func addImage(name: String, image: UIImage, sdf: Bool?, stretchX: [[NSNumber]], stretchY: [[NSNumber]], log: String) -> Bool
4
+ func addImage(name: String, image: UIImage, sdf: Bool?, stretchX: [[NSNumber]], stretchY: [[NSNumber]], content: [NSNumber]?, log: String) -> Bool
5
5
  }
6
6
 
7
7
  class RCTMGLImages : UIView, RCTMGLMapComponent {
@@ -26,7 +26,7 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
26
26
  }
27
27
  };
28
28
 
29
- typealias NativeImageInfo = (name:String, sdf: Bool, stretchX:[(from:Float, to:Float)], stretchY:[(from:Float, to:Float)]);
29
+ typealias NativeImageInfo = (name:String, sdf: Bool, stretchX:[(from:Float, to:Float)], stretchY:[(from:Float, to:Float)], content: (left:Float,top:Float,right:Float,bottom:Float)? );
30
30
  var nativeImageInfos: [NativeImageInfo] = []
31
31
 
32
32
  @objc open override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
@@ -80,14 +80,15 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
80
80
 
81
81
  for imageName in remoteImages.keys {
82
82
  if style.styleManager.getStyleImage(forImageId: imageName) == nil {
83
- try! style.addImage(placeholderImage, id: imageName, stretchX: [], stretchY: [])
84
- missingImages[imageName] = remoteImages[imageName]
83
+ logged("RCTMGLImages.addImagePlaceholder") {
84
+ try? style.addImage(placeholderImage, id: imageName, stretchX: [], stretchY: [])
85
+ missingImages[imageName] = remoteImages[imageName]
86
+ }
85
87
  }
86
88
  }
87
89
 
88
90
  if missingImages.count > 0 {
89
91
  RCTMGLUtils.fetchImages(bridge, style: style, objects: missingImages, forceUpdate: true, callback: { })
90
-
91
92
  }
92
93
  }
93
94
 
@@ -118,19 +119,51 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
118
119
  }
119
120
  }
120
121
 
121
- func convert(stretch: [[NSNumber]]) -> [(from: Float, to: Float)] {
122
+ static func convert(stretch: [[NSNumber]], scale: Float = 1.0) -> [(from: Float, to: Float)] {
122
123
  return stretch.map{ pair in
123
- return (from: pair[0].floatValue, to: pair[1].floatValue)
124
+ return (from: pair[0].floatValue * scale, to: pair[1].floatValue * scale)
124
125
  }
125
126
  }
126
127
 
127
- func convert(stretch: [(from: Float, to: Float)]) -> [ImageStretches] {
128
+ static func convert(stretch: [(from: Float, to: Float)]) -> [ImageStretches] {
128
129
  return stretch.map { v in ImageStretches(first: v.from, second: v.to) }
129
130
  }
130
131
 
132
+ static func convert(stretch: [[NSNumber]], scale: Float = 1.0) -> [ImageStretches] {
133
+ return convert(stretch: convert(stretch: stretch, scale: scale))
134
+ }
135
+
136
+ static func convert(content: (left:Float, top:Float, right:Float, bottom:Float)?) -> ImageContent? {
137
+ guard let content = content else {
138
+ return nil
139
+ }
140
+
141
+ return ImageContent(left:content.left, top:content.top, right:content.right, bottom:content.bottom)
142
+ }
143
+
144
+ static func convert(content: [NSNumber]?, scale: Float = 1.0) -> (left:Float,top:Float,right:Float,bottom:Float)? {
145
+ guard let content = content else {
146
+ return nil
147
+ }
148
+ guard content.count == 4 else {
149
+ Logger.log(level: .error, message: "Image content should have 4 elements got \(content)")
150
+ return nil
151
+ }
152
+ return (
153
+ left: content[0].floatValue*scale,
154
+ top: content[1].floatValue*scale,
155
+ right: content[2].floatValue*scale,
156
+ bottom: content[3].floatValue*scale
157
+ )
158
+ }
159
+
160
+ static func convert(content: [NSNumber]?, scale: Float = 1.0) -> ImageContent? {
161
+ return convert(content: convert(content: content, scale: scale))
162
+ }
163
+
131
164
  func decodeImage(_ imageNameOrInfo: Any) -> NativeImageInfo? {
132
165
  if let imageName = imageNameOrInfo as? String {
133
- return (name: imageName, sdf: false, stretchX:[],stretchY:[])
166
+ return (name: imageName, sdf: false, stretchX:[],stretchY:[],content:nil)
134
167
  } else if let imageInfo = imageNameOrInfo as? [String:Any] {
135
168
  guard let name = imageInfo["name"] as? String else {
136
169
  Logger.log(level: .warn, message: "NativeImage: \(imageInfo) has no name key")
@@ -144,14 +177,19 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
144
177
  }
145
178
 
146
179
  if let stretchXV = imageInfo["stretchX"] as? [[NSNumber]] {
147
- stretchX = convert(stretch: stretchXV)
180
+ stretchX = RCTMGLImages.convert(stretch: stretchXV)
148
181
  }
149
182
 
150
183
  if let stretchYV = imageInfo["stretchY"] as? [[NSNumber]] {
151
- stretchY = convert(stretch: stretchYV)
184
+ stretchY = RCTMGLImages.convert(stretch: stretchYV)
185
+ }
186
+
187
+ var content : (left:Float, top:Float, right:Float, bottom:Float)? = nil
188
+ if let contentV = imageInfo["content"] as? [NSNumber] {
189
+ content = RCTMGLImages.convert(content: contentV)
152
190
  }
153
191
 
154
- return (name: name, sdf: sdf, stretchX: stretchX, stretchY: stretchY)
192
+ return (name: name, sdf: sdf, stretchX: stretchX, stretchY: stretchY, content: content)
155
193
  } else {
156
194
  Logger.log(level: .warn, message: "RCTMGLImage.nativeImage, unexpected image: \(imageNameOrInfo)")
157
195
  return nil
@@ -165,8 +203,9 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
165
203
  if let image = UIImage(named: imageName) {
166
204
  logged("RCTMGLImage.addNativeImage: \(imageName)") {
167
205
  try style.addImage(image, id: imageName, sdf: imageInfo.sdf,
168
- stretchX: convert(stretch: imageInfo.stretchX),
169
- stretchY: convert(stretch: imageInfo.stretchY)
206
+ stretchX: RCTMGLImages.convert(stretch: imageInfo.stretchX),
207
+ stretchY: RCTMGLImages.convert(stretch: imageInfo.stretchY),
208
+ content: RCTMGLImages.convert(content: imageInfo.content)
170
209
  )
171
210
  }
172
211
  } else {
@@ -185,15 +224,16 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
185
224
  }
186
225
 
187
226
  extension RCTMGLImages : RCTMGLImageSetter {
188
- func addImage(name: String, image: UIImage, sdf: Bool?, stretchX: [[NSNumber]], stretchY: [[NSNumber]], log: String) -> Bool
227
+ func addImage(name: String, image: UIImage, sdf: Bool?, stretchX: [[NSNumber]], stretchY: [[NSNumber]], content: [NSNumber]?, log: String) -> Bool
189
228
  {
190
229
  return logged("\(log).addImage") {
191
230
  if let style = style {
192
231
  try style.addImage(image,
193
232
  id:name,
194
233
  sdf: sdf ?? false,
195
- stretchX: convert(stretch: convert(stretch: stretchX)),
196
- stretchY: convert(stretch: convert(stretch: stretchY))
234
+ stretchX: RCTMGLImages.convert(stretch: stretchX),
235
+ stretchY: RCTMGLImages.convert(stretch: stretchY),
236
+ content: RCTMGLImages.convert(content: content)
197
237
  )
198
238
  return true
199
239
  } else {
@@ -645,7 +645,17 @@ extension RCTMGLMapView: GestureManagerDelegate {
645
645
  }
646
646
 
647
647
  func highestZIndex(sources: [RCTMGLInteractiveElement]) -> RCTMGLInteractiveElement? {
648
- return sources.first
648
+ var layersToSource : [String:RCTMGLInteractiveElement] = [:]
649
+
650
+ sources.forEach { source in
651
+ source.getLayerIDs().forEach { layerId in
652
+ if layersToSource[layerId] == nil {
653
+ layersToSource[layerId] = source
654
+ }
655
+ }
656
+ }
657
+ let orderedLayers = mapboxMap.style.allLayerIdentifiers
658
+ return orderedLayers.lazy.reversed().compactMap { layersToSource[$0.id] }.first ?? sources.first
649
659
  }
650
660
 
651
661
  @objc
@@ -30,9 +30,15 @@ class RCTMGLUtils {
30
30
  if (forceUpdate || foundImage == nil) {
31
31
  let image = objects[imageName]
32
32
  if let image = image as? [String:Any] {
33
- let hasScale = image["scale"] != nil
34
- let scale = hasScale ? (image["scale"] as! NSNumber).doubleValue : 1.0
35
- RCTMGLImageQueue.sharedInstance.addImage(objects[imageName], scale: scale, bridge:bridge) {
33
+ let scale = (image["scale"] as? NSNumber)?.floatValue ?? 1.0
34
+ let sdf = (image["sdf"] as? NSNumber)?.boolValue ?? false
35
+ let imageStretchX = image["stretchX"] as? [[NSNumber]]
36
+ let stretchX: [ImageStretches] = imageStretchX != nil ? RCTMGLImages.convert(stretch: imageStretchX!, scale: scale) : []
37
+ let imageStretchY = image["stretchY"] as? [[NSNumber]]
38
+ let stretchY: [ImageStretches] = imageStretchY != nil ? RCTMGLImages.convert(stretch: imageStretchY!, scale: scale) : []
39
+ let content: ImageContent? = RCTMGLImages.convert(content: image["content"] as? [NSNumber], scale: scale)
40
+
41
+ RCTMGLImageQueue.sharedInstance.addImage(objects[imageName], scale: Double(scale), bridge:bridge) {
36
42
  (error,image) in
37
43
  if image == nil {
38
44
  RCTMGLLogWarn("Failed to fetch image: \(imageName) error:\(error)")
@@ -40,8 +46,11 @@ class RCTMGLUtils {
40
46
  else {
41
47
  DispatchQueue.main.async {
42
48
  if let image = image {
43
- try! style.addImage(image, id: imageName, stretchX: [], stretchY: [])
44
- imageLoadedBlock()
49
+ logged("RCTMGLUtils.fetchImage-\(imageName)") {
50
+ print("width=\(image.size.width) height=\(image.size.height) scale=\(image.scale) scale2=\(scale)")
51
+ try style.addImage(image, id: imageName, sdf:sdf, stretchX: stretchX, stretchY: stretchY, content: content)
52
+ imageLoadedBlock()
53
+ }
45
54
  }
46
55
  }
47
56
  }
@@ -0,0 +1,54 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ interface MGLModule {
4
+ StyleURL: {
5
+ Street: URL;
6
+ Outdoors: URL;
7
+ Light: URL;
8
+ Dark: URL;
9
+ Satellite: URL;
10
+ SatelliteStreet: URL;
11
+ };
12
+ OfflinePackDownloadState: {
13
+ Inactive: string | number;
14
+ Active: string | number;
15
+ Complete: string | number;
16
+ Unknown?: string | number;
17
+ };
18
+ LineJoin: {
19
+ Bevel: string | number;
20
+ Round: string | number;
21
+ Miter: string | number;
22
+ };
23
+ StyleSource: {
24
+ DefaultSourceID: string;
25
+ };
26
+ TileServers: {
27
+ Mapbox: string;
28
+ };
29
+
30
+ removeCustomHeader(headerName: string): void;
31
+ addCustomHeader(headerName: string, headerValue: string): void;
32
+ setAccessToken(accessToken: string | null): Promise<string | null>;
33
+ setWellKnownTileServer(tileServer: string): void;
34
+ getAccessToken(): Promise<string>;
35
+ setTelemetryEnabled(telemetryEnabled: boolean): void;
36
+ setConnected(connected: boolean): void;
37
+ }
38
+
39
+ const MGLModule: MGLModule = { ...NativeModules.MGLModule };
40
+
41
+ export const {
42
+ StyleURL,
43
+ OfflinePackDownloadState,
44
+ LineJoin,
45
+ StyleSource,
46
+ TileServers,
47
+ removeCustomHeader,
48
+ addCustomHeader,
49
+ setAccessToken,
50
+ setWellKnownTileServer,
51
+ getAccessToken,
52
+ setTelemetryEnabled,
53
+ setConnected,
54
+ } = MGLModule;
@@ -0,0 +1,97 @@
1
+ export * from './MGLModule';
2
+ export {
3
+ Camera,
4
+ UserTrackingMode,
5
+ type CameraPadding,
6
+ type CameraAnimationMode,
7
+ type CameraBounds,
8
+ } from './components/Camera';
9
+ export { Atmosphere } from './components/Atmosphere';
10
+ export { default as MapView, type MapState } from './components/MapView';
11
+ export { default as Light } from './components/Light';
12
+ export { default as PointAnnotation } from './components/PointAnnotation';
13
+ export { default as Annotation } from './components/Annotation';
14
+ export { default as Callout } from './components/Callout';
15
+ export { default as UserLocation } from './components/UserLocation';
16
+ export { default as VectorSource } from './components/VectorSource';
17
+ export { ShapeSource } from './components/ShapeSource';
18
+ export { default as RasterSource } from './components/RasterSource';
19
+ export { default as RasterDemSource } from './components/RasterDemSource';
20
+ export { default as ImageSource } from './components/ImageSource';
21
+ export { default as Images, type ImageEntry } from './components/Images';
22
+ export { default as Image } from './components/Image';
23
+ export { default as FillLayer } from './components/FillLayer';
24
+ export { default as FillExtrusionLayer } from './components/FillExtrusionLayer';
25
+ export { default as HeatmapLayer } from './components/HeatmapLayer';
26
+ export { default as LineLayer } from './components/LineLayer';
27
+ export { default as CircleLayer } from './components/CircleLayer';
28
+ export { default as SkyLayer } from './components/SkyLayer';
29
+ export { SymbolLayer } from './components/SymbolLayer';
30
+ export { default as RasterLayer } from './components/RasterLayer';
31
+ export { default as BackgroundLayer } from './components/BackgroundLayer';
32
+ export { Terrain } from './components/Terrain';
33
+ export {
34
+ default as locationManager,
35
+ type Location,
36
+ } from './modules/location/locationManager';
37
+ export {
38
+ default as offlineManager,
39
+ OfflineCreatePackOptions,
40
+ } from './modules/offline/offlineManager';
41
+ export {
42
+ default as snapshotManager,
43
+ type SnapshotOptions,
44
+ } from './modules/snapshot/snapshotManager';
45
+ export { default as MarkerView } from './components/MarkerView';
46
+ export { default as Animated } from './utils/animated/Animated';
47
+ export {
48
+ AnimatedCoordinatesArray,
49
+ AnimatedExtractCoordinateFromArray,
50
+ AnimatedPoint,
51
+ AnimatedRouteCoordinatesArray,
52
+ AnimatedShape,
53
+ } from './classes';
54
+ export { default as Style } from './components/Style';
55
+ export { default as Logger, type LogLevel } from './utils/Logger';
56
+ export { requestAndroidLocationPermissions } from './requestAndroidLocationPermissions';
57
+ export { getAnnotationsLayerID } from './utils/getAnnotationsLayerID';
58
+ export type {
59
+ FillLayerStyleProps as FillLayerStyle,
60
+ LineLayerStyleProps as LineLayerStyle,
61
+ SymbolLayerStyleProps as SymbolLayerStyle,
62
+ CircleLayerStyleProps as CircleLayerStyle,
63
+ HeatmapLayerStyleProps as HeatmapLayerStyle,
64
+ FillExtrusionLayerStyleProps as FillExtrusionLayerStyle,
65
+ RasterLayerStyleProps as RasterLayerStyle,
66
+ HillshadeLayerStyleProps as HillshadeLayerStyle,
67
+ BackgroundLayerStyleProps as BackgroundLayerStyle,
68
+ SkyLayerStyleProps as SkyLayerStyle,
69
+ LightLayerStyleProps as LightLayerStyle,
70
+ AtmosphereLayerStyleProps as AtmosphereLayerStyle,
71
+ TerrainLayerStyleProps as TerrainLayerStyle,
72
+ } from './utils/MapboxStyles';
73
+
74
+ import { deprecatedClass } from './utils/deprecation';
75
+ import { AnimatedPoint } from './classes';
76
+ import { UserTrackingMode } from './components/Camera';
77
+
78
+ /** @deprecated This will be removed in a future release. Use `AnimatedPoint` instead. */
79
+ export const AnimatedMapPoint = deprecatedClass(
80
+ AnimatedPoint,
81
+ 'AnimatedMapPoint is deprecated please use AnimatedPoint',
82
+ );
83
+
84
+ // types:
85
+ export enum StyleURL {
86
+ Street = 'mapbox://styles/mapbox/streets-v11',
87
+ Dark = 'mapbox://styles/mapbox/dark-v10',
88
+ Light = 'mapbox://styles/mapbox/light-v10',
89
+ Outdoors = 'mapbox://styles/mapbox/outdoors-v11',
90
+ Satellite = 'mapbox://styles/mapbox/satellite-v9',
91
+ SatelliteStreet = 'mapbox://styles/mapbox/satellite-streets-v11',
92
+ TrafficDay = 'mapbox://styles/mapbox/navigation-preview-day-v4',
93
+ TrafficNight = 'mapbox://styles/mapbox/navigation-preview-night-v4',
94
+ }
95
+
96
+ /** @deprecated UserTrackingModes is deprecated use UserTrackingMode */
97
+ export const UserTrackingModes = UserTrackingMode;
@@ -1,5 +1,24 @@
1
+ import { Point } from 'geojson';
2
+ import { Animated } from 'react-native';
3
+
4
+ import WithAnimatedObject = Animated.WithAnimatedObject;
5
+
1
6
  export class AnimatedCoordinatesArray {}
2
7
  export class AnimatedExtractCoordinateFromArray {}
3
- export class AnimatedPoint {}
8
+ export class AnimatedPoint implements WithAnimatedObject<Point> {
9
+ constructor(point: Point);
10
+
11
+ timing({
12
+ coordinates,
13
+ easing,
14
+ duration,
15
+ }: {
16
+ coordinates: number[];
17
+ easing?: (x: number) => number;
18
+ duration?: number;
19
+ });
20
+
21
+ stopAnimation();
22
+ }
4
23
  export class AnimatedRouteCoordinatesArray {}
5
24
  export class AnimatedShape {}
@@ -0,0 +1,141 @@
1
+ import React, { ReactElement } from 'react';
2
+ import { Animated as RNAnimated, Easing } from 'react-native';
3
+ import { Point } from 'geojson';
4
+
5
+ import Animated from '../utils/animated/Animated';
6
+ import { AnimatedPoint } from '../classes';
7
+ import { OnPressEvent } from '../types/OnPressEvent';
8
+ import { SymbolLayerStyle } from '../Mapbox';
9
+
10
+ import { SymbolLayer } from './SymbolLayer';
11
+
12
+ type Props = {
13
+ id: string;
14
+ animated?: boolean;
15
+ animationDuration?: number;
16
+ animationEasingFunction?: (x: number) => number;
17
+ coordinates: number[];
18
+ onPress?: (event: OnPressEvent) => void;
19
+ children: ReactElement | ReactElement[];
20
+ style?: object;
21
+ icon?: string | number | object;
22
+ };
23
+
24
+ type AnnotationState = {
25
+ shape: Point | AnimatedPoint | null;
26
+ };
27
+
28
+ class Annotation extends React.Component<Props, AnnotationState> {
29
+ static defaultProps = {
30
+ animated: false,
31
+ animationDuration: 1000,
32
+ animationEasingFunction: Easing.linear,
33
+ };
34
+
35
+ constructor(props: Props) {
36
+ super(props);
37
+
38
+ const shape = this._getShapeFromProps(props);
39
+
40
+ this.state = {
41
+ shape: props.animated ? new AnimatedPoint(shape) : shape,
42
+ };
43
+
44
+ this.onPress = this.onPress.bind(this);
45
+ }
46
+
47
+ componentDidUpdate(prevProps: Props) {
48
+ if (!Array.isArray(this.props.coordinates)) {
49
+ this.setState({ shape: null });
50
+ return;
51
+ }
52
+
53
+ const haveCoordinatesChanged =
54
+ prevProps.coordinates[0] !== this.props.coordinates[0] ||
55
+ prevProps.coordinates[1] !== this.props.coordinates[1];
56
+
57
+ if (
58
+ prevProps.animated !== this.props.animated ||
59
+ (haveCoordinatesChanged && (!this.state.shape || !this.props.animated))
60
+ ) {
61
+ const shape = this._getShapeFromProps(this.props);
62
+
63
+ this.setState({
64
+ shape: this.props.animated ? new AnimatedPoint(shape) : shape,
65
+ });
66
+ } else if (
67
+ haveCoordinatesChanged &&
68
+ this.props.animated &&
69
+ this.state.shape
70
+ ) {
71
+ // flush current animations
72
+ (this.state.shape as AnimatedPoint).stopAnimation();
73
+
74
+ (this.state.shape as AnimatedPoint)
75
+ .timing({
76
+ coordinates: this.props.coordinates,
77
+ easing: this.props.animationEasingFunction,
78
+ duration: this.props.animationDuration,
79
+ })
80
+ .start();
81
+ }
82
+ }
83
+
84
+ onPress(event: OnPressEvent) {
85
+ if (this.props.onPress) {
86
+ this.props.onPress(event);
87
+ }
88
+ }
89
+
90
+ _getShapeFromProps(props: Partial<Props> = {}): Point {
91
+ const lng = props.coordinates?.[0] || 0;
92
+ const lat = props.coordinates?.[1] || 0;
93
+ return { type: 'Point', coordinates: [lng, lat] };
94
+ }
95
+
96
+ get symbolStyle(): SymbolLayerStyle | undefined {
97
+ if (!this.props.icon) {
98
+ return undefined;
99
+ }
100
+ return Object.assign({}, this.props.style, {
101
+ iconImage: this.props.icon,
102
+ });
103
+ }
104
+
105
+ render() {
106
+ if (!this.props.coordinates) {
107
+ return null;
108
+ }
109
+
110
+ const children = [];
111
+
112
+ if (this.symbolStyle) {
113
+ children.push(
114
+ <SymbolLayer
115
+ id={`${this.props.id}-symbol`}
116
+ style={this.symbolStyle as SymbolLayerStyle}
117
+ />,
118
+ );
119
+ }
120
+
121
+ if (this.props.children) {
122
+ if (Array.isArray(this.props.children)) {
123
+ children.push(...this.props.children);
124
+ } else {
125
+ children.push(this.props.children);
126
+ }
127
+ }
128
+
129
+ return (
130
+ <Animated.ShapeSource
131
+ id={this.props.id}
132
+ onPress={this.onPress}
133
+ shape={this.state.shape as RNAnimated.WithAnimatedObject<Point>}
134
+ >
135
+ {children}
136
+ </Animated.ShapeSource>
137
+ );
138
+ }
139
+ }
140
+
141
+ export default Annotation;
@@ -0,0 +1,35 @@
1
+ import { ViewStyle } from 'react-native';
2
+
3
+ type Props = Omit<ViewProps, 'style'> & {
4
+ /**
5
+ * String that gets displayed in the default callout.
6
+ */
7
+ title: string;
8
+
9
+ /**
10
+ * Style property for the Animated.View wrapper, apply animations to this
11
+ */
12
+ style?: ViewStyle;
13
+
14
+ /**
15
+ * Style property for the native RCTMGLCallout container, set at your own risk.
16
+ */
17
+ containerStyle?: ViewStyle;
18
+
19
+ /**
20
+ * Style property for the content bubble.
21
+ */
22
+ contentStyle?: ViewStyle;
23
+
24
+ /**
25
+ * Style property for the triangle tip under the content.
26
+ */
27
+ tipStyle?: ViewStyle;
28
+
29
+ /**
30
+ * Style property for the title in the content bubble.
31
+ */
32
+ textStyle?: ViewStyle;
33
+ };
34
+
35
+ export default class Callout extends React.Component<Props> {}
@@ -29,7 +29,7 @@ type Props = BaseProps & {
29
29
  /**
30
30
  * The top left, top right, bottom right, and bottom left coordinates for the image.
31
31
  */
32
- coordinates: [Position, Position, Position, Position];
32
+ coordinates?: [Position, Position, Position, Position];
33
33
 
34
34
  children?: React.ReactElement | React.ReactElement[];
35
35
  };