@rnmapbox/maps 10.0.0-beta.44 → 10.0.0-beta.46

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 (37) hide show
  1. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +0 -2
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt +162 -51
  3. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewManager.kt +10 -0
  4. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +6 -6
  5. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +5 -1
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +22 -2
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +17 -19
  8. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.kt +1 -1
  9. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/CustomHttpHeaders.kt +38 -0
  10. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLModule.kt +12 -1
  11. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/DownloadMapImageTask.kt +2 -1
  12. package/docs/MapboxGL.md +1 -1
  13. package/docs/MarkerView.md +17 -10
  14. package/docs/PointAnnotation.md +1 -1
  15. package/docs/SymbolLayer.md +1 -1
  16. package/docs/docs.json +116 -102
  17. package/index.d.ts +1 -0
  18. package/ios/RCTMGL-v10/RCTLog.swift +5 -5
  19. package/ios/RCTMGL-v10/RCTMGLMapView.swift +70 -9
  20. package/ios/RCTMGL-v10/RCTMGLMapViewManager.swift +2 -2
  21. package/ios/RCTMGL-v10/RCTMGLMarkerView.swift +186 -105
  22. package/ios/RCTMGL-v10/RCTMGLMarkerViewManager.m +2 -1
  23. package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.swift +1 -1
  24. package/ios/RCTMGL-v10/RCTMGLUtils.swift +1 -1
  25. package/ios/RCTMGL-v10/RCTMGLVectorLayer.swift +1 -1
  26. package/javascript/components/AbstractLayer.tsx +6 -3
  27. package/javascript/components/MarkerView.tsx +81 -77
  28. package/javascript/components/PointAnnotation.tsx +1 -1
  29. package/javascript/components/SymbolLayer.tsx +2 -2
  30. package/javascript/utils/index.d.ts +3 -3
  31. package/package.json +1 -1
  32. package/scripts/autogenHelpers/DocJSONBuilder.js +17 -1
  33. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewWrapper.kt +0 -8
  34. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewWrapperManager.kt +0 -21
  35. package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapper.swift +0 -24
  36. package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapperManager.m +0 -8
  37. package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapperManager.swift +0 -14
@@ -10,7 +10,6 @@ import java.util.ArrayList;
10
10
  import java.util.Collections;
11
11
  import java.util.List;
12
12
 
13
- import com.mapbox.rctmgl.components.annotation.RCTMGLMarkerViewWrapperManager;
14
13
  import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager;
15
14
 
16
15
  import com.mapbox.rctmgl.components.annotation.RCTMGLCalloutManager;
@@ -81,7 +80,6 @@ public class RCTMGLPackage implements ReactPackage {
81
80
 
82
81
  // annotations
83
82
  managers.add(new RCTMGLMarkerViewManager(reactApplicationContext));
84
- managers.add(new RCTMGLMarkerViewWrapperManager(reactApplicationContext));
85
83
  managers.add(new RCTMGLPointAnnotationManager(reactApplicationContext));
86
84
  managers.add(new RCTMGLCalloutManager());
87
85
 
@@ -1,85 +1,196 @@
1
1
  package com.mapbox.rctmgl.components.annotation
2
2
 
3
3
  import android.content.Context
4
+ import android.os.Handler
5
+ import android.os.Looper
6
+ import android.util.Log
4
7
  import android.view.View
8
+ import android.widget.FrameLayout
5
9
  import com.mapbox.geojson.Point
10
+ import com.mapbox.maps.ViewAnnotationAnchor
6
11
  import com.mapbox.maps.ViewAnnotationOptions
12
+ import com.mapbox.maps.viewannotation.viewAnnotationOptions
7
13
  import com.mapbox.rctmgl.components.AbstractMapFeature
8
14
  import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
15
+ import com.mapbox.rctmgl.modules.RCTMGLLogging
16
+ import com.mapbox.rctmgl.utils.Logger
17
+ import java.util.Vector
18
+
19
+ private data class Vec2(val dx: Double, val dy: Double)
20
+
21
+ class RCTMGLMarkerView(context: Context?, private val mManager: RCTMGLMarkerViewManager):
22
+ AbstractMapFeature(context),
23
+ View.OnLayoutChangeListener
24
+ {
25
+ // region Instance variables
9
26
 
10
- class RCTMGLMarkerView(context: Context?, private val mManager: RCTMGLMarkerViewManager) : AbstractMapFeature(context), View.OnLayoutChangeListener {
11
27
  private var mMapView: RCTMGLMapView? = null
12
- private var mChildView: View? = null
13
- private var mCoordinate: Point? = null
14
- private lateinit var mAnchor: Array<Float>
28
+ private var mView: View? = null
29
+ private var didAddToMap = false
15
30
 
16
- override fun addView(childView: View, childPosition: Int) {
17
- mChildView = childView
18
- }
31
+ private var mCoordinate: Point? = null
32
+ private var mAnchor: Vec2 = Vec2(0.5, 0.5)
33
+ private var mAllowOverlap = false
34
+ private var mIsSelected = false
19
35
 
20
36
  fun setCoordinate(point: Point?) {
21
37
  mCoordinate = point
22
- if (mChildView != null) {
23
- val options = ViewAnnotationOptions.Builder().geometry(mCoordinate).build()
24
- mMapView?.viewAnnotationManager?.updateViewAnnotation(mChildView!!, options)
25
- }
38
+ update()
26
39
  }
27
40
 
28
41
  fun setAnchor(x: Float, y: Float) {
29
- mAnchor = arrayOf(x, y)
30
- refresh()
42
+ mAnchor = Vec2(x.toDouble(), y.toDouble())
43
+ update()
31
44
  }
32
45
 
33
- fun refresh() {
34
- // this will cause position to be recalculated
35
- if (mChildView != null) {
36
- val width = mChildView!!.width
37
- val height = mChildView!!.height
38
- val options = ViewAnnotationOptions.Builder().geometry(mCoordinate).width(width).height(height).offsetX(((mAnchor[0] - 0.5) * width).toInt()).offsetY(((mAnchor[1] - 0.5) * height).toInt()).build()
39
- mMapView?.viewAnnotationManager?.updateViewAnnotation(mChildView!!, options)
40
- }
46
+ fun setAllowOverlap(allowOverlap: Boolean) {
47
+ mAllowOverlap = allowOverlap
48
+ update()
49
+ }
50
+
51
+ fun setIsSelected(isSelected: Boolean) {
52
+ mIsSelected = isSelected
53
+ update()
54
+ }
55
+
56
+ // endregion
57
+
58
+ // region View methods
59
+
60
+ override fun addView(childView: View, childPosition: Int) {
61
+ mView = childView
62
+ // Note: Do not call this method on `super`. The view is added manually.
63
+ }
64
+
65
+ override fun onLayoutChange(
66
+ v: View,
67
+ left: Int, top: Int, right: Int, bottom: Int,
68
+ oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int
69
+ ) {
70
+ addOrUpdate()
41
71
  }
42
72
 
73
+ // endregion
74
+
75
+ // region RCTMGLMapComponent methods
76
+
43
77
  override fun addToMap(mapView: RCTMGLMapView) {
44
78
  mMapView = mapView
45
- val rctmglMarkerView = this
46
- mMapView?.getMapAsync {
47
- if (mChildView != null) {
48
- val width = mChildView!!.width
49
- val height = mChildView!!.height
50
- val options = ViewAnnotationOptions.Builder().geometry(mCoordinate).width(width).height(height).offsetX(((mAnchor[0] - 0.5) * width).toInt()).offsetY(((mAnchor[1] - 0.5) * height).toInt()).build()
51
- mChildView!!.addOnLayoutChangeListener(rctmglMarkerView)
52
- if (mChildView!!.layoutParams == null && !mChildView!!.isAttachedToWindow) {
53
- mMapView?.offscreenAnnotationViewContainer()?.addView(mChildView)
54
- mMapView?.offscreenAnnotationViewContainer()?.removeView(mChildView)
55
- }
56
- mMapView?.viewAnnotationManager?.addViewAnnotation(mChildView!!, options)
57
- }
58
- }
79
+ add()
59
80
  }
60
81
 
61
82
  override fun removeFromMap(mapView: RCTMGLMapView) {
62
- val childView = mChildView
63
- if (childView != null) {
64
- childView.removeOnLayoutChangeListener(this)
65
- childView.visibility = INVISIBLE;
66
- mMapView?.viewAnnotationManager?.removeViewAnnotation(childView)
83
+ remove(mapView)
84
+ }
85
+
86
+ // endregion
87
+
88
+ // region Create, update, and remove methods
89
+
90
+ private fun addOrUpdate() {
91
+ if (didAddToMap) {
92
+ update()
93
+ } else {
94
+ add()
95
+ }
96
+ }
97
+
98
+ private fun add() {
99
+ if (didAddToMap) {
100
+ return
67
101
  }
102
+
103
+ if (mView == null || mCoordinate == null) {
104
+ return
105
+ }
106
+ val view = mView!!
107
+
108
+ view.addOnLayoutChangeListener(this)
109
+
110
+ if (view.layoutParams == null && !view.isAttachedToWindow) {
111
+ mMapView?.offscreenAnnotationViewContainer?.addView(view)
112
+ mMapView?.offscreenAnnotationViewContainer?.removeView(view)
113
+ }
114
+
115
+ val options = getOptions()
116
+
117
+ val annotation = mMapView?.viewAnnotationManager?.addViewAnnotation(
118
+ view,
119
+ options
120
+ )
121
+ didAddToMap = true
122
+ }
123
+
124
+ fun update() {
125
+ if (!didAddToMap) {
126
+ return
127
+ }
128
+
129
+ if (mView == null || mCoordinate == null) {
130
+ return
131
+ }
132
+ val view = mView!!
133
+
134
+ val options = getOptions()
135
+
136
+ val annotation = mMapView?.viewAnnotationManager?.updateViewAnnotation(
137
+ view,
138
+ options
139
+ )
68
140
  }
69
141
 
70
- override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int,
71
- oldRight: Int, oldBottom: Int) {
72
- if (left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom) {
73
- val centerX = oldLeft + (oldRight-oldLeft)*mAnchor[0];
74
- val centerY = oldTop + (oldBottom-oldTop)*mAnchor[1];
142
+ private fun remove(mapView: RCTMGLMapView) {
143
+ this.removeOnLayoutChangeListener(this)
75
144
 
76
- val newLeft = (centerX - (mAnchor[0] * (right - left))).toInt();
77
- val newTop = (centerY - (mAnchor[1] * (bottom - top))).toInt();
145
+ mView?.let { view ->
146
+ mapView.endViewTransition(view) // https://github.com/mapbox/mapbox-maps-android/issues/1723
147
+ val removed = mapView.viewAnnotationManager?.removeViewAnnotation(view)
148
+ if (removed == false) {
149
+ Logger.w("RCTMGLMarkerView", "Unable to remove view")
150
+ }
151
+ }
152
+ }
153
+
154
+ // endregion
155
+
156
+ // region Helper functions
157
+
158
+ private fun getOptions(): ViewAnnotationOptions {
159
+ val view = mView!!
160
+ val width = view.width
161
+ val height = view.height
162
+ val coordinate = mCoordinate
163
+
164
+ val offset = getOffset()
78
165
 
79
- val childView = mChildView!!
80
- childView.x = (newLeft - oldLeft) + childView.x;
81
- childView.y = (newTop-oldTop) + childView.y;
82
- refresh()
166
+ val options = viewAnnotationOptions {
167
+ geometry(coordinate)
168
+ width(width)
169
+ height(height)
170
+ allowOverlap(mAllowOverlap)
171
+ offsetX(offset.dx.toInt())
172
+ offsetY(offset.dy.toInt())
173
+ selected(mIsSelected)
83
174
  }
175
+ return options
84
176
  }
177
+
178
+ private fun getOffset(): Vec2 {
179
+ if (mView == null) {
180
+ return Vec2(0.0, 0.0)
181
+ }
182
+ val view = mView!!
183
+
184
+ val width = view.width
185
+ val height = view.height
186
+
187
+ // Create a modified offset, normalized from 0..1 to -1..1 and scaled to
188
+ // the view size.
189
+ val offsetX = (mAnchor.dx * 2 - 1) * (width / 2) * -1
190
+ val offsetY = (mAnchor.dy * 2 - 1) * (height / 2)
191
+
192
+ return Vec2(offsetX, offsetY)
193
+ }
194
+
195
+ // endregion
85
196
  }
@@ -25,6 +25,16 @@ class RCTMGLMarkerViewManager(reactApplicationContext: ReactApplicationContext?)
25
25
  markerView.setAnchor(map.getDouble("x").toFloat(), map.getDouble("y").toFloat())
26
26
  }
27
27
 
28
+ @ReactProp(name = "allowOverlap")
29
+ fun setAllowOverlap(markerView: RCTMGLMarkerView, allowOverlap: Boolean) {
30
+ markerView.setAllowOverlap(allowOverlap)
31
+ }
32
+
33
+ @ReactProp(name = "isSelected")
34
+ fun setIsSelected(markerView: RCTMGLMarkerView, isSelected: Boolean) {
35
+ markerView.setIsSelected(isSelected)
36
+ }
37
+
28
38
  override fun createViewInstance(reactContext: ThemedReactContext): RCTMGLMarkerView {
29
39
  return RCTMGLMarkerView(reactContext, this)
30
40
  }
@@ -53,7 +53,7 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
53
53
  }
54
54
  childView.addOnLayoutChangeListener(this)
55
55
 
56
- mMapView?.offscreenAnnotationViewContainer()?.addView(childView)
56
+ mMapView?.offscreenAnnotationViewContainer?.addView(childView)
57
57
 
58
58
  }
59
59
 
@@ -70,7 +70,7 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
70
70
  }
71
71
  })
72
72
  }
73
- mMapView?.offscreenAnnotationViewContainer()?.removeView(childView)
73
+ mMapView?.offscreenAnnotationViewContainer?.removeView(childView)
74
74
  }
75
75
 
76
76
  override fun addToMap(mapView: RCTMGLMapView) {
@@ -79,14 +79,14 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
79
79
  makeMarker()
80
80
  if (mChildView != null) {
81
81
  if (!mChildView!!.isAttachedToWindow) {
82
- mMapView!!.offscreenAnnotationViewContainer().addView(mChildView)
82
+ mMapView!!.offscreenAnnotationViewContainer?.addView(mChildView)
83
83
  }
84
84
  addBitmapToStyle(mChildBitmap, mChildBitmapId)
85
85
  updateOptions()
86
86
  }
87
87
  if (calloutView != null) {
88
88
  if (!calloutView!!.isAttachedToWindow && mMapView != null) {
89
- mMapView!!.offscreenAnnotationViewContainer().addView(calloutView)
89
+ mMapView!!.offscreenAnnotationViewContainer?.addView(calloutView)
90
90
  }
91
91
  addBitmapToStyle(mCalloutBitmap, mCalloutBitmapId)
92
92
  }
@@ -98,10 +98,10 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
98
98
  map.pointAnnotationManager?.delete(marker!!)
99
99
  }
100
100
  if (mChildView != null) {
101
- map.offscreenAnnotationViewContainer().removeView(mChildView)
101
+ map.offscreenAnnotationViewContainer?.removeView(mChildView)
102
102
  }
103
103
  if (calloutView != null) {
104
- map.offscreenAnnotationViewContainer().removeView(calloutView)
104
+ map.offscreenAnnotationViewContainer?.removeView(calloutView)
105
105
  }
106
106
  }
107
107
 
@@ -84,8 +84,12 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
84
84
  }
85
85
 
86
86
  fun convert(value: IntArray): EdgeInsets {
87
+ val left = value[0].toDouble();
88
+ val top = value[1].toDouble();
89
+ val right = value[2].toDouble();
90
+ val bottom = value[3].toDouble();
87
91
  return EdgeInsets(
88
- value[0].toDouble(), value[1].toDouble(), value[2].toDouble(), value[3].toDouble()
92
+ top, left, bottom, right
89
93
  )
90
94
  }
91
95
 
@@ -7,6 +7,9 @@ import com.mapbox.rctmgl.components.AbstractMapFeature
7
7
  import com.mapbox.rctmgl.utils.ImageEntry
8
8
  import android.graphics.drawable.BitmapDrawable
9
9
  import androidx.core.content.res.ResourcesCompat
10
+ import com.mapbox.bindgen.Expected
11
+ import com.mapbox.bindgen.None
12
+ import com.mapbox.maps.Image
10
13
  import com.mapbox.maps.MapboxMap
11
14
  import com.mapbox.maps.Style
12
15
  import com.mapbox.rctmgl.R
@@ -15,11 +18,27 @@ import com.mapbox.rctmgl.components.images.RCTMGLImages
15
18
  import com.mapbox.rctmgl.events.ImageMissingEvent
16
19
  import com.mapbox.rctmgl.utils.BitmapUtils
17
20
  import com.mapbox.rctmgl.utils.DownloadMapImageTask
21
+ import java.nio.ByteBuffer
18
22
  import java.util.AbstractMap
19
23
  import java.util.ArrayList
20
24
  import java.util.HashMap
21
25
  import java.util.HashSet
22
26
 
27
+ fun Style.addBitmapImage(imageId: String, bitmap: Bitmap) : Expected<String, None> {
28
+ val byteBuffer = ByteBuffer.allocate(bitmap.byteCount)
29
+ bitmap.copyPixelsToBuffer(byteBuffer)
30
+ val sdf = false
31
+ return this.addStyleImage(
32
+ imageId,
33
+ (1.0/((160.0/bitmap.density))).toFloat(),
34
+ Image(bitmap.width, bitmap.height, byteBuffer.array()),
35
+ sdf,
36
+ listOf(),
37
+ listOf(),
38
+ null
39
+ )
40
+ }
41
+
23
42
  class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager) : AbstractMapFeature(context) {
24
43
  var mCurrentImages: MutableSet<String?>
25
44
  private var mImages: MutableMap<String, ImageEntry>?
@@ -151,7 +170,8 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
151
170
  if (style == null || imageEntries == null) return
152
171
  for ((key, value) in imageEntries) {
153
172
  if (key != null && !hasImage(key, map)) {
154
- style.addImage(key, BitmapUtils.toImage(value))
173
+ val bitmap = value!!.bitmap
174
+ style.addBitmapImage(key, bitmap)
155
175
  mCurrentImages.add(key)
156
176
  }
157
177
  }
@@ -171,7 +191,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
171
191
  // See also: https://github.com/mapbox/mapbox-gl-native/pull/14253#issuecomment-478827792
172
192
  for (imageEntry in imageEntries) {
173
193
  if (!hasImage(imageEntry.key, map)) {
174
- mImagePlaceholder?.let { style.addImage(imageEntry.key, it) }
194
+ mImagePlaceholder?.let { style.addBitmapImage(imageEntry.key, it) }
175
195
  missingImages.add(imageEntry)
176
196
  mCurrentImages.add(imageEntry.key)
177
197
  }
@@ -38,6 +38,7 @@ import com.mapbox.maps.plugin.delegates.listeners.*
38
38
  import com.mapbox.maps.plugin.gestures.*
39
39
  import com.mapbox.maps.plugin.logo.generated.LogoSettings
40
40
  import com.mapbox.maps.plugin.logo.logo
41
+ import com.mapbox.maps.viewannotation.ViewAnnotationManager
41
42
  import com.mapbox.rctmgl.R
42
43
  import com.mapbox.rctmgl.components.AbstractMapFeature
43
44
  import com.mapbox.rctmgl.components.annotation.RCTMGLMarkerView
@@ -70,6 +71,14 @@ interface RCTMGLMapViewLifecycleOwner : LifecycleOwner {
70
71
  }
71
72
 
72
73
  open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapViewManager /*, MapboxMapOptions options*/) : MapView(mContext), OnMapClickListener, OnMapLongClickListener {
74
+ /**
75
+ * `PointAnnotations` are rendered to a canvas, but the React Native `Image` component is
76
+ * implemented on top of Fresco (https://frescolib.org), which does not load images for
77
+ * views not attached to the window. This provides an offscreen view where views can
78
+ * be rendered to the canvas before being added as annotations.
79
+ */
80
+ public var offscreenAnnotationViewContainer: ViewGroup? = null
81
+
73
82
  private val mSources: MutableMap<String, RCTSource<*>>
74
83
  private val mImages: MutableList<RCTMGLImages>
75
84
  private var mPointAnnotationManager: PointAnnotationManager? = null
@@ -87,7 +96,6 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
87
96
  var savedStyle: Style? = null
88
97
  private set
89
98
  private val mHandledMapChangedEvents: HashSet<String>? = null
90
- private var mOffscreenAnnotationViewContainer: ViewGroup? = null
91
99
  private var mAnnotationClicked = false
92
100
  private var mAnnotationDragged = false
93
101
  private var mLocationComponentManager: LocationComponentManager? = null
@@ -229,7 +237,6 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
229
237
  mPointAnnotations[annotation.iD.toString()] = annotation
230
238
  feature = childView
231
239
  } else if (childView is RCTMGLMarkerView) {
232
- val marker = childView
233
240
  feature = childView
234
241
  } else if (childView is RCTMGLCamera) {
235
242
  mCamera = childView
@@ -630,23 +637,6 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
630
637
  )
631
638
  }
632
639
 
633
- /**
634
- * PointAnnotations are rendered to a canvas, but react native Image component is
635
- * implemented on top of Fresco, and fresco will not load images when their view is
636
- * not attached to the window. So we'll have an offscreen view where we add those views
637
- * so they can rendered full to canvas.
638
- */
639
- fun offscreenAnnotationViewContainer(): ViewGroup {
640
- if (mOffscreenAnnotationViewContainer == null) {
641
- mOffscreenAnnotationViewContainer = FrameLayout(context)
642
- val flParams = LayoutParams(0, 0)
643
- flParams.setMargins(-10000, -10000, -10000, -10000)
644
- (mOffscreenAnnotationViewContainer as FrameLayout).setLayoutParams(flParams)
645
- addView(mOffscreenAnnotationViewContainer)
646
- }
647
- return mOffscreenAnnotationViewContainer!!
648
- }
649
-
650
640
  val locationComponentManager: LocationComponentManager
651
641
  get() {
652
642
  if (mLocationComponentManager == null) {
@@ -839,11 +829,19 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
839
829
  }
840
830
 
841
831
  init {
832
+ offscreenAnnotationViewContainer = FrameLayout(getContext())
833
+ val p = FrameLayout.LayoutParams(0, 0)
834
+ p.setMargins(-10000, -10000, -10000, -10000)
835
+ offscreenAnnotationViewContainer?.setLayoutParams(p)
836
+ addView(offscreenAnnotationViewContainer)
837
+
842
838
  mMap = getMapboxMap()
843
839
  mSources = HashMap()
844
840
  mImages = ArrayList()
845
841
  mPointAnnotations = HashMap()
842
+
846
843
  onMapReady(mMap)
844
+
847
845
  val _this = this
848
846
  mMap.addOnMapLoadedListener(OnMapLoadedListener { (begin, end) -> _this.handleMapChangedEvent(EventTypes.DID_FINISH_LOADING_MAP) })
849
847
  mMap.addOnStyleImageMissingListener(OnStyleImageMissingListener { (begin, end, id) ->
@@ -8,7 +8,7 @@ import com.mapbox.rctmgl.utils.DownloadMapImageTask
8
8
  import java.util.AbstractMap
9
9
  import java.util.ArrayList
10
10
 
11
- class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap, map: MapboxMap) {
11
+ class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap?, map: MapboxMap) {
12
12
  private val mReactStyle: ReadableMap?
13
13
  private val mMap: MapboxMap
14
14
  val allStyleKeys: List<String>
@@ -0,0 +1,38 @@
1
+ package com.mapbox.rctmgl.modules
2
+
3
+ import com.mapbox.common.*
4
+
5
+ object CustomHttpHeaders : HttpServiceInterceptorInterface {
6
+ init {}
7
+
8
+ val map = mutableMapOf<String, String>()
9
+
10
+ fun addCustomHeader(headerName: String, headerValue: String) {
11
+ HttpServiceFactory.getInstance().setInterceptor(
12
+ this
13
+ )
14
+ }
15
+
16
+ fun removeCustomHeader(headerName: String) {
17
+ map.remove(headerName)
18
+ }
19
+
20
+ override fun onRequest(request: HttpRequest): HttpRequest {
21
+ for (entry in map.entries.iterator()) {
22
+ request.headers[entry.key] = entry.value
23
+ }
24
+ return request
25
+ }
26
+
27
+ override fun onDownload(download: DownloadOptions): DownloadOptions {
28
+ for (entry in map.entries.iterator()) {
29
+ download.request.headers[entry.key] = entry.value
30
+ }
31
+ return download
32
+ }
33
+
34
+ override fun onResponse(response: HttpResponse): HttpResponse {
35
+ return response
36
+ }
37
+ }
38
+
@@ -12,6 +12,7 @@ import com.mapbox.rctmgl.modules.RCTMGLOfflineModule
12
12
  import com.mapbox.rctmgl.modules.RCTMGLLocationModule
13
13
  import com.facebook.react.bridge.ReactMethod
14
14
  import com.facebook.react.common.MapBuilder
15
+ import com.mapbox.common.*
15
16
  import com.mapbox.maps.Style
16
17
  import com.mapbox.rctmgl.components.camera.constants.CameraMode
17
18
  import java.util.HashMap
@@ -124,6 +125,16 @@ class RCTMGLModule(private val mReactContext: ReactApplicationContext) : ReactCo
124
125
  // NO-OP
125
126
  }
126
127
 
128
+ @ReactMethod
129
+ fun addCustomHeader(headerName: String, headerValue: String) {
130
+ CustomHttpHeaders.addCustomHeader(headerName, headerValue)
131
+ }
132
+
133
+ @ReactMethod
134
+ fun removeCustomHeader(headerName: String) {
135
+ CustomHttpHeaders.removeCustomHeader(headerName)
136
+ }
137
+
127
138
  companion object {
128
139
  const val REACT_CLASS = "RCTMGLModule"
129
140
  private val customHeaderInterceptorAdded = false
@@ -132,4 +143,4 @@ class RCTMGLModule(private val mReactContext: ReactApplicationContext) : ReactCo
132
143
  return getDefault((reactContext)!!, null).resourceOptions.accessToken
133
144
  }
134
145
  }
135
- }
146
+ }
@@ -21,6 +21,7 @@ import com.facebook.imagepipeline.image.CloseableImage
21
21
  import com.facebook.imagepipeline.image.CloseableStaticBitmap
22
22
  import com.facebook.imagepipeline.request.ImageRequestBuilder
23
23
  import com.facebook.react.views.imagehelper.ImageSource
24
+ import com.mapbox.rctmgl.components.images.addBitmapImage
24
25
  import java.io.File
25
26
  import java.lang.ref.WeakReference
26
27
  import java.util.AbstractMap
@@ -120,7 +121,7 @@ class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImag
120
121
  val bitmapImages = HashMap<String, Bitmap>()
121
122
  for ((key, value) in images) {
122
123
  bitmapImages[key] = value
123
- style.addImage(key, value)
124
+ style.addBitmapImage(key, value)
124
125
  }
125
126
  // style.addImages(bitmapImages);
126
127
  }
package/docs/MapboxGL.md CHANGED
@@ -20,7 +20,7 @@ not required when using other tiles
20
20
  | `tileServer` | `String` | `Yes` | tile server |
21
21
 
22
22
  #### Description
23
- No-op on non MapLibre implemntations. Use MapboxGL.TileServer.Mapbox to consume mapbox tiles with maplibre. *Note*: Consuming mapbox with MapLibre has different pricing than with the official SDK. Other values: MapboxGL.TileServer.MapLibre, MapboxGL.TileServer.MapTiler
23
+ No-op on non MapLibre implemntations. Use MapboxGL.TileServers.Mapbox to consume mapbox tiles with maplibre. *Note*: Consuming mapbox with MapLibre has different pricing than with the official SDK. Other values: MapboxGL.TileServers.MapLibre, MapboxGL.TileServers.MapTiler
24
24
 
25
25
  ### getAccessToken()
26
26
 
@@ -1,19 +1,26 @@
1
1
  <!-- This file was autogenerated from MarkerView.tsx do not modify -->
2
2
  # <MapboxGL.MarkerView />
3
- MarkerView allows you to place a interactive react native marker to the map.
3
+ MarkerView represents an interactive React Native marker on the map.
4
4
 
5
- If you have static view consider using PointAnnotation or SymbolLayer they'll offer much better performance
6
- .
7
- This is based on [MakerView plugin](https://docs.mapbox.com/android/plugins/overview/markerview/) on Android
8
- and PointAnnotation on iOS.
5
+ If you have static views, consider using PointAnnotation or SymbolLayer to display
6
+ an image, as they'll offer much better performance. Mapbox suggests using this
7
+ component for a maximum of around 100 views displayed at one time.
8
+
9
+ This is implemented with view annotations on [Android](https://docs.mapbox.com/android/maps/guides/annotations/view-annotations/)
10
+ and [iOS](https://docs.mapbox.com/ios/maps/guides/annotations/view-annotations).
11
+
12
+ This component has no dedicated `onPress` method. Instead, you should handle gestures
13
+ with the React views passed in as `children`.
9
14
 
10
15
  ## props
11
16
  | Prop | Type | Default | Required | Description |
12
17
  | ---- | :-- | :----- | :------ | :---------- |
13
- | coordinate | `tuple` | `none` | `true` | The center point (specified as a map coordinate) of the marker.<br/>See also #anchor. |
14
- | anchor | `shape` | `{ x: 0.5, y: 0.5 }` | `false` | Specifies the anchor being set on a particular point of the annotation.<br/>The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],<br/>where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.<br/>Note this is only for custom annotations not the default pin view.<br/>Defaults to the center of the view. |
15
- | &nbsp;&nbsp;x | `number` | `none` | `true` | `x` of anchor |
16
- | &nbsp;&nbsp;y | `number` | `none` | `true` | `y` of anchor |
17
- | children | `ReactReactElement` | `none` | `true` | Expects one child - can be container with multiple elements |
18
+ | coordinate | `tuple` | `none` | `true` | The center point (specified as a map coordinate) of the marker. |
19
+ | anchor | `shape` | `{ x: 0.5, y: 0.5 }` | `false` | Any coordinate between (0, 0) and (1, 1), where (0, 0) is the top-left corner of<br/>the view, and (1, 1) is the bottom-right corner. Defaults to the center at (0.5, 0.5). |
20
+ | &nbsp;&nbsp;x | `number` | `none` | `true` | FIX ME NO DESCRIPTION |
21
+ | &nbsp;&nbsp;y | `number` | `none` | `true` | FIX ME NO DESCRIPTION |
22
+ | allowOverlap | `boolean` | `false` | `false` | @v10<br/><br/>Whether or not nearby markers on the map should all be displayed. If false, adjacent<br/>markers will 'collapse' and only one will be shown. Defaults to false. |
23
+ | isSelected | `boolean` | `false` | `false` | FIX ME NO DESCRIPTION |
24
+ | children | `ReactReactElement` | `none` | `true` | One or more valid React Native views. |
18
25
 
19
26
 
@@ -6,7 +6,7 @@ Consider using ShapeSource and SymbolLayer instead, if you have many points and
6
6
  they'll offer much better performance.
7
7
 
8
8
  If you need interactive views please use MarkerView,
9
- as with PointAnnotation on Android child views are rendered onto a bitmap for better performance.
9
+ as with PointAnnotation child views are rendered onto a bitmap
10
10
 
11
11
  ## props
12
12
  | Prop | Type | Default | Required | Description |
@@ -11,7 +11,7 @@ SymbolLayer is a style layer that renders icon and text labels at points or alon
11
11
  | aboveLayerID | `string` | `none` | `false` | Inserts a layer above aboveLayerID. |
12
12
  | belowLayerID | `string` | `none` | `false` | Inserts a layer below belowLayerID |
13
13
  | layerIndex | `number` | `none` | `false` | Inserts a layer at a specified index |
14
- | filter | `Array` | `none` | `false` | Filter only the features in the source layer that satisfy a condition that you define |
14
+ | filter | `Expression` | `none` | `false` | Filter only the features in the source layer that satisfy a condition that you define |
15
15
  | minZoomLevel | `number` | `none` | `false` | The minimum zoom level at which the layer gets parsed and appears. |
16
16
  | maxZoomLevel | `number` | `none` | `false` | The maximum zoom level at which the layer gets parsed and appears. |
17
17
  | style | `SymbolLayerStyleProps` | `none` | `true` | FIX ME NO DESCRIPTION |