@rnmapbox/maps 10.0.0-beta.72 → 10.0.0-beta.74

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 (121) hide show
  1. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +2 -0
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +0 -1
  3. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImage.kt +74 -0
  4. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImageManager.kt +67 -0
  5. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +62 -35
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +216 -0
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/LocationComponentManager.kt +4 -2
  8. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +9 -3
  9. package/index.d.ts +22 -74
  10. package/javascript/components/AbstractLayer.tsx +2 -1
  11. package/javascript/components/AbstractSource.tsx +3 -1
  12. package/javascript/components/Atmosphere.tsx +2 -1
  13. package/javascript/components/Camera.tsx +6 -4
  14. package/javascript/components/Image.tsx +12 -4
  15. package/javascript/components/Images.tsx +1 -1
  16. package/javascript/components/Light.tsx +60 -0
  17. package/javascript/components/PointAnnotation.tsx +2 -1
  18. package/javascript/components/ShapeSource.tsx +1 -11
  19. package/javascript/components/Terrain.tsx +2 -1
  20. package/javascript/components/VectorSource.tsx +209 -0
  21. package/javascript/components/annotations/Annotation.js +9 -10
  22. package/javascript/modules/location/locationManager.ts +2 -2
  23. package/javascript/types/BaseProps.ts +3 -0
  24. package/javascript/types/OnPressEvent.ts +11 -0
  25. package/javascript/utils/{Logger.js → Logger.ts} +32 -14
  26. package/javascript/utils/MapboxStyles.d.ts +1 -1
  27. package/javascript/utils/deprecation.ts +3 -3
  28. package/javascript/utils/nativeRef.ts +28 -0
  29. package/lib/commonjs/components/AbstractLayer.js.map +1 -1
  30. package/lib/commonjs/components/AbstractSource.js.map +1 -1
  31. package/lib/commonjs/components/Atmosphere.js.map +1 -1
  32. package/lib/commonjs/components/Camera.js +4 -4
  33. package/lib/commonjs/components/Camera.js.map +1 -1
  34. package/lib/commonjs/components/Image.js.map +1 -1
  35. package/lib/commonjs/components/Images.js +1 -1
  36. package/lib/commonjs/components/Images.js.map +1 -1
  37. package/lib/commonjs/components/Light.js +32 -33
  38. package/lib/commonjs/components/Light.js.map +1 -1
  39. package/lib/commonjs/components/PointAnnotation.js.map +1 -1
  40. package/lib/commonjs/components/ShapeSource.js.map +1 -1
  41. package/lib/commonjs/components/Terrain.js.map +1 -1
  42. package/lib/commonjs/components/VectorSource.js +15 -74
  43. package/lib/commonjs/components/VectorSource.js.map +1 -1
  44. package/lib/commonjs/components/annotations/Annotation.js +6 -9
  45. package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
  46. package/lib/commonjs/modules/location/locationManager.js +2 -1
  47. package/lib/commonjs/modules/location/locationManager.js.map +1 -1
  48. package/lib/commonjs/types/BaseProps.js +2 -0
  49. package/lib/commonjs/types/BaseProps.js.map +1 -0
  50. package/lib/commonjs/types/OnPressEvent.js +2 -0
  51. package/lib/commonjs/types/OnPressEvent.js.map +1 -0
  52. package/lib/commonjs/utils/Logger.js +7 -7
  53. package/lib/commonjs/utils/Logger.js.map +1 -1
  54. package/lib/commonjs/utils/deprecation.js +2 -2
  55. package/lib/commonjs/utils/nativeRef.js +27 -0
  56. package/lib/commonjs/utils/nativeRef.js.map +1 -0
  57. package/lib/module/components/AbstractLayer.js.map +1 -1
  58. package/lib/module/components/AbstractSource.js.map +1 -1
  59. package/lib/module/components/Atmosphere.js.map +1 -1
  60. package/lib/module/components/Camera.js +4 -4
  61. package/lib/module/components/Camera.js.map +1 -1
  62. package/lib/module/components/Image.js.map +1 -1
  63. package/lib/module/components/Images.js +1 -1
  64. package/lib/module/components/Images.js.map +1 -1
  65. package/lib/module/components/Light.js +29 -32
  66. package/lib/module/components/Light.js.map +1 -1
  67. package/lib/module/components/PointAnnotation.js.map +1 -1
  68. package/lib/module/components/ShapeSource.js.map +1 -1
  69. package/lib/module/components/Terrain.js.map +1 -1
  70. package/lib/module/components/VectorSource.js +15 -74
  71. package/lib/module/components/VectorSource.js.map +1 -1
  72. package/lib/module/components/annotations/Annotation.js +6 -9
  73. package/lib/module/components/annotations/Annotation.js.map +1 -1
  74. package/lib/module/modules/location/locationManager.js +1 -1
  75. package/lib/module/modules/location/locationManager.js.map +1 -1
  76. package/lib/module/types/BaseProps.js +2 -0
  77. package/lib/module/types/BaseProps.js.map +1 -0
  78. package/lib/module/types/OnPressEvent.js +2 -0
  79. package/lib/module/types/OnPressEvent.js.map +1 -0
  80. package/lib/module/utils/Logger.js +7 -7
  81. package/lib/module/utils/Logger.js.map +1 -1
  82. package/lib/module/utils/deprecation.js +2 -2
  83. package/lib/module/utils/nativeRef.js +21 -0
  84. package/lib/module/utils/nativeRef.js.map +1 -0
  85. package/lib/typescript/components/AbstractLayer.d.ts +2 -1
  86. package/lib/typescript/components/AbstractLayer.d.ts.map +1 -1
  87. package/lib/typescript/components/AbstractSource.d.ts +2 -1
  88. package/lib/typescript/components/AbstractSource.d.ts.map +1 -1
  89. package/lib/typescript/components/Atmosphere.d.ts +2 -1
  90. package/lib/typescript/components/Atmosphere.d.ts.map +1 -1
  91. package/lib/typescript/components/Camera.d.ts.map +1 -1
  92. package/lib/typescript/components/Image.d.ts +10 -4
  93. package/lib/typescript/components/Image.d.ts.map +1 -1
  94. package/lib/typescript/components/Images.d.ts +1 -1
  95. package/lib/typescript/components/Images.d.ts.map +1 -1
  96. package/lib/typescript/components/Light.d.ts +17 -0
  97. package/lib/typescript/components/Light.d.ts.map +1 -0
  98. package/lib/typescript/components/PointAnnotation.d.ts +2 -1
  99. package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
  100. package/lib/typescript/components/ShapeSource.d.ts +3 -13
  101. package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
  102. package/lib/typescript/components/Terrain.d.ts +2 -1
  103. package/lib/typescript/components/Terrain.d.ts.map +1 -1
  104. package/lib/typescript/components/VectorSource.d.ts +144 -0
  105. package/lib/typescript/components/VectorSource.d.ts.map +1 -0
  106. package/lib/typescript/modules/location/locationManager.d.ts +2 -2
  107. package/lib/typescript/modules/location/locationManager.d.ts.map +1 -1
  108. package/lib/typescript/types/BaseProps.d.ts +4 -0
  109. package/lib/typescript/types/BaseProps.d.ts.map +1 -0
  110. package/lib/typescript/types/OnPressEvent.d.ts +12 -0
  111. package/lib/typescript/types/OnPressEvent.d.ts.map +1 -0
  112. package/lib/typescript/utils/Logger.d.ts +53 -0
  113. package/lib/typescript/utils/Logger.d.ts.map +1 -0
  114. package/lib/typescript/utils/deprecation.d.ts +4 -3
  115. package/lib/typescript/utils/deprecation.d.ts.map +1 -1
  116. package/lib/typescript/utils/nativeRef.d.ts +21 -0
  117. package/lib/typescript/utils/nativeRef.d.ts.map +1 -0
  118. package/package.json +1 -1
  119. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.java +0 -103
  120. package/javascript/components/Light.js +0 -47
  121. package/javascript/components/VectorSource.js +0 -203
@@ -15,6 +15,7 @@ import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager;
15
15
  import com.mapbox.rctmgl.components.annotation.RCTMGLCalloutManager;
16
16
  import com.mapbox.rctmgl.components.annotation.RCTMGLPointAnnotationManager;
17
17
  import com.mapbox.rctmgl.components.annotation.RCTMGLMarkerViewManager;
18
+ import com.mapbox.rctmgl.components.images.RCTMGLImageManager;
18
19
  import com.mapbox.rctmgl.components.images.RCTMGLImagesManager;
19
20
  import com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocationManager;
20
21
  import com.mapbox.rctmgl.components.mapview.RCTMGLMapViewManager;
@@ -94,6 +95,7 @@ public class RCTMGLPackage implements ReactPackage {
94
95
 
95
96
  // images
96
97
  managers.add(new RCTMGLImagesManager(reactApplicationContext));
98
+ managers.add(new RCTMGLImageManager(reactApplicationContext));
97
99
 
98
100
  // layers
99
101
  managers.add(new RCTMGLFillLayerManager());
@@ -53,7 +53,6 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
53
53
  childView.addOnLayoutChangeListener(this)
54
54
 
55
55
  mMapView?.offscreenAnnotationViewContainer?.addView(childView)
56
-
57
56
  }
58
57
 
59
58
  override fun removeView(childView: View) {
@@ -0,0 +1,74 @@
1
+ package com.mapbox.rctmgl.components.images
2
+
3
+ import android.graphics.Bitmap
4
+ import android.view.View
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.annotations.ReactProp
7
+ import com.facebook.react.views.view.ReactViewGroup
8
+ import com.mapbox.maps.ImageContent
9
+ import com.mapbox.maps.ImageStretches
10
+ import com.mapbox.rctmgl.components.annotation.RCTMGLCallout
11
+ import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
12
+ import com.mapbox.rctmgl.utils.BitmapUtils
13
+ import com.mapbox.rctmgl.utils.Logger
14
+
15
+ class RCTMGLImage(private val mContext: ReactApplicationContext, private val mManager: RCTMGLImageManager): ReactViewGroup(mContext), View.OnLayoutChangeListener {
16
+ var name: String? = null
17
+ var sdf: Boolean = false
18
+ var scale: Double = 1.0
19
+ var stretchX = listOf<ImageStretches>();
20
+ var stretchY = listOf<ImageStretches>();
21
+ var content: ImageContent? = null;
22
+
23
+ var mChildView: View? = null;
24
+
25
+ var mMapView: RCTMGLMapView? = null;
26
+
27
+ var nativeImageUpdater: NativeImageUpdater? = null;
28
+
29
+ var mBitmap : Bitmap? = null
30
+
31
+ override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int,
32
+ oldRight: Int, oldBottom: Int) {
33
+ if (left == 0 && top == 0 && right == 0 && bottom == 0) {
34
+ return
35
+ }
36
+ if (left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom) {
37
+ refreshBitmap(v, left, top, right, bottom)
38
+ }
39
+ }
40
+
41
+ private fun refreshBitmap(v: View, left: Int = v.left, top: Int = v.top, right: Int = v.right, bottom: Int = v.bottom) {
42
+ val name = this.name
43
+ if (name == null) {
44
+ Logger.e("RCTMGLImage", "Image component has no name")
45
+ return
46
+ }
47
+ val bitmap = BitmapUtils.viewToBitmap(v, left, top, right, bottom)
48
+ nativeImageUpdater?.let {
49
+ it.updateImage(name, bitmap, sdf, stretchX, stretchY, content, scale)
50
+ mBitmap = null;
51
+ }
52
+ }
53
+
54
+ fun refresh() {
55
+ mChildView?.let {
56
+ refreshBitmap(it)
57
+ }
58
+ }
59
+
60
+ override fun addView(childView: View, childPosition: Int) {
61
+ if (childPosition != 0) {
62
+ Logger.e("RCTMGLImage", "expected a single subview got childView:$childView position:$childPosition")
63
+ }
64
+ mMapView?.offscreenAnnotationViewContainer?.addView(childView)
65
+ mChildView = childView
66
+ childView.addOnLayoutChangeListener(this)
67
+ }
68
+
69
+ // region add/remove to Map
70
+ fun addToMap(mapView: RCTMGLMapView) {
71
+ mMapView = mapView
72
+ }
73
+ // endregion
74
+ }
@@ -0,0 +1,67 @@
1
+ package com.mapbox.rctmgl.components.images
2
+
3
+ import com.facebook.react.bridge.Dynamic
4
+ import com.facebook.react.bridge.DynamicFromArray
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReadableArray
7
+ import com.facebook.react.common.MapBuilder
8
+ import com.facebook.react.uimanager.ThemedReactContext
9
+ import com.facebook.react.uimanager.annotations.ReactProp
10
+ import com.mapbox.rctmgl.components.AbstractEventEmitter
11
+ import com.mapbox.rctmgl.events.constants.EventKeys
12
+
13
+ class RCTMGLImageManager(private val mContext: ReactApplicationContext) : AbstractEventEmitter<RCTMGLImage>(
14
+ mContext
15
+ ) {
16
+ override fun getName(): String {
17
+ return "RCTMGLImage"
18
+ }
19
+
20
+ override fun createViewInstance(p0: ThemedReactContext): RCTMGLImage {
21
+ return RCTMGLImage(mContext, this)
22
+ }
23
+
24
+ override fun customEvents(): MutableMap<String, String>? {
25
+ return mutableMapOf();
26
+ }
27
+
28
+ // region React properties
29
+ @ReactProp(name="name")
30
+ fun setName(image: RCTMGLImage, value: String) {
31
+ image.name = value
32
+ }
33
+
34
+ @ReactProp(name="sdf")
35
+ fun setSdf(image: RCTMGLImage, value: Boolean) {
36
+ image.sdf = value
37
+ }
38
+
39
+ @ReactProp(name="stretchX")
40
+ fun setStretchX(image: RCTMGLImage, value: Dynamic) {
41
+ image.stretchX = RCTMGLImagesManager.convertStretch(value) ?: listOf()
42
+ }
43
+
44
+ @ReactProp(name="stretchY")
45
+ fun setStretchY(image: RCTMGLImage, value: Dynamic) {
46
+ image.stretchY = RCTMGLImagesManager.convertStretch(value) ?: listOf()
47
+ }
48
+
49
+ @ReactProp(name="content")
50
+ fun setContent(image: RCTMGLImage, value: Dynamic) {
51
+ image.content = RCTMGLImagesManager.convertContent(value)
52
+ }
53
+
54
+ @ReactProp(name="scale")
55
+ fun setScale(image: RCTMGLImage, value: Double) {
56
+ image.scale = value
57
+ }
58
+ // endregion
59
+
60
+ // region React methods
61
+ override fun receiveCommand(root: RCTMGLImage, commandId: String?, args: ReadableArray?) {
62
+ if (commandId == "refresh") {
63
+ root.refresh()
64
+ }
65
+ }
66
+ // endregion
67
+ }
@@ -10,6 +10,8 @@ import androidx.core.content.res.ResourcesCompat
10
10
  import com.mapbox.bindgen.Expected
11
11
  import com.mapbox.bindgen.None
12
12
  import com.mapbox.maps.Image
13
+ import com.mapbox.maps.ImageContent
14
+ import com.mapbox.maps.ImageStretches
13
15
  import com.mapbox.maps.MapboxMap
14
16
  import com.mapbox.maps.Style
15
17
  import com.mapbox.rctmgl.R
@@ -24,28 +26,40 @@ import java.util.ArrayList
24
26
  import java.util.HashMap
25
27
  import java.util.HashSet
26
28
 
27
- fun Style.addBitmapImage(imageId: String, bitmap: Bitmap) : Expected<String, None> {
29
+ fun Style.addBitmapImage(imageId: String, bitmap: Bitmap, sdf: Boolean = false, stretchX: List<ImageStretches> = listOf(), stretchY: List<ImageStretches> = listOf(), content: ImageContent? = null, scale: Double = 1.0) : Expected<String, None> {
28
30
  val byteBuffer = ByteBuffer.allocate(bitmap.byteCount)
29
31
  bitmap.copyPixelsToBuffer(byteBuffer)
30
- val sdf = false
31
32
  return this.addStyleImage(
32
33
  imageId,
33
- (1.0/((160.0/bitmap.density))).toFloat(),
34
+ (1.0/((160.0/bitmap.density)) * scale).toFloat() ,
34
35
  Image(bitmap.width, bitmap.height, byteBuffer.array()),
35
36
  sdf,
36
- listOf(),
37
- listOf(),
38
- null
37
+ stretchX,
38
+ stretchY,
39
+ content,
39
40
  )
40
41
  }
41
42
 
42
- class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager) : AbstractMapFeature(context) {
43
+ fun Style.addBitmapImage(nativeImage: NativeImage) : Expected<String, None> {
44
+ return addBitmapImage(nativeImage.name, nativeImage.drawable.bitmap, nativeImage.sdf, nativeImage.stretchX, nativeImage.stretchY, nativeImage.content, nativeImage.scale)
45
+ }
46
+
47
+ data class NativeImage(val name: String, val drawable: BitmapDrawable, val scale: Double = 1.0, val sdf: Boolean = false, val stretchX: List<ImageStretches> = listOf(),
48
+ val stretchY: List<ImageStretches> = listOf(), val content: ImageContent? = null
49
+ );
50
+
51
+ interface NativeImageUpdater {
52
+ fun updateImage(imageId: String, bitmap: Bitmap, sdf: Boolean = false, stretchX: List<ImageStretches> = listOf(), stretchY: List<ImageStretches> = listOf(), content: ImageContent? = null, scale: Double = 1.0)
53
+ }
54
+
55
+ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager) : AbstractMapFeature(context), NativeImageUpdater {
43
56
  var mCurrentImages: MutableSet<String?>
57
+ var mImageViews = mutableListOf<RCTMGLImage>();
44
58
  private var mImages: MutableMap<String, ImageEntry>?
45
- private var mNativeImages: MutableMap<String?, BitmapDrawable?>?
59
+ private var mNativeImages = mutableMapOf<String, NativeImage>()
46
60
  private var mSendMissingImageEvents = false
47
61
  private var mMap: MapboxMap? = null
48
- var iD: String? = null
62
+
49
63
  fun setImages(images: List<Map.Entry<String, ImageEntry>>) {
50
64
  val newImages: MutableMap<String, ImageEntry> = HashMap()
51
65
  for ((key, value) in images) {
@@ -59,16 +73,18 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
59
73
  }
60
74
  }
61
75
 
62
- fun setNativeImages(nativeImages: List<Map.Entry<String, BitmapDrawable>>) {
63
- val newImages: MutableMap<String?, BitmapDrawable?> = HashMap()
64
- for ((key, value) in nativeImages) {
65
- val oldValue = mNativeImages?.put(key, value)
76
+ fun setNativeImages(nativeImages: List<NativeImage>) {
77
+ val newImages: MutableMap<String, NativeImage> = HashMap()
78
+ for (nativeImage in nativeImages) {
79
+ val oldValue = mNativeImages.put(nativeImage.name, nativeImage)
66
80
  if (oldValue == null) {
67
- newImages[key] = value
81
+ newImages[nativeImage.name] = nativeImage
68
82
  }
69
83
  }
70
- if (mMap != null && mMap?.getStyle() != null) {
71
- addNativeImagesToStyle(newImages, mMap!!)
84
+ mMap?.let {
85
+ if (it.getStyle() != null) {
86
+ addNativeImagesToStyle(newImages, it)
87
+ }
72
88
  }
73
89
  }
74
90
 
@@ -79,7 +95,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
79
95
  override fun removeFromMap(mapView: RCTMGLMapView) {
80
96
  removeImages(mapView)
81
97
  mMap = null
82
- mNativeImages = HashMap()
98
+ mNativeImages = mutableMapOf()
83
99
  mImages = HashMap()
84
100
  mCurrentImages = HashSet()
85
101
  super.removeFromMap(mapView)
@@ -111,12 +127,10 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
111
127
  }
112
128
 
113
129
  fun addMissingImageToStyle(id: String, map: MapboxMap): Boolean {
114
- if (mNativeImages != null) {
115
- val drawable = mNativeImages!![id]
116
- if (drawable != null) {
117
- addNativeImages(entry<String?, BitmapDrawable?>(id, drawable), map)
118
- return true
119
- }
130
+ val nativeImage = mNativeImages.get(id)
131
+ if (nativeImage != null) {
132
+ addNativeImages(listOf(nativeImage), map)
133
+ return true
120
134
  }
121
135
  if (mImages != null) {
122
136
  val entry = mImages!![id]
@@ -134,10 +148,8 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
134
148
  }
135
149
  }
136
150
 
137
- fun addNativeImagesToStyle(images: Map<String?, BitmapDrawable?>?, map: MapboxMap) {
138
- if (images != null) {
139
- addNativeImages(ArrayList(images.entries), map)
140
- }
151
+ fun addNativeImagesToStyle(images: Map<String, NativeImage>, map: MapboxMap) {
152
+ addNativeImages(images.values.toList(), map)
141
153
  }
142
154
 
143
155
  fun sendImageMissingEvent(id: String, map: MapboxMap) {
@@ -153,6 +165,10 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
153
165
 
154
166
  override fun addToMap(mapView: RCTMGLMapView) {
155
167
  super.addToMap(mapView)
168
+
169
+ mImageViews.forEach {
170
+ it.addToMap(mapView)
171
+ }
156
172
  // Wait for style before adding the source to the map
157
173
  // only then we can pre-load required images / placeholders into the style
158
174
  // before we add the ShapeSource to the map
@@ -163,18 +179,22 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
163
179
  addNativeImagesToStyle(mNativeImages, map)
164
180
  addImagesToStyle(mImages, map)
165
181
  // super.addToMap(mapView);
182
+
183
+ mImageViews.forEach {
184
+ it.refresh()
185
+ }
166
186
  }
167
187
  })
168
188
  }
169
189
 
170
- private fun addNativeImages(imageEntries: List<Map.Entry<String?, BitmapDrawable?>>?, map: MapboxMap) {
190
+ private fun addNativeImages(imageEntries: List<NativeImage>, map: MapboxMap) {
171
191
  val style = map.getStyle()
172
- if (style == null || imageEntries == null) return
173
- for ((key, value) in imageEntries) {
174
- if (key != null && !hasImage(key, map)) {
175
- val bitmap = value!!.bitmap
176
- style.addBitmapImage(key, bitmap)
177
- mCurrentImages.add(key)
192
+ if (style == null) return
193
+ for (nativeImage in imageEntries) {
194
+ if (!hasImage(nativeImage.name, map)) {
195
+ val bitmap = nativeImage.drawable
196
+ style.addBitmapImage(nativeImage)
197
+ mCurrentImages.add(nativeImage.name)
178
198
  }
179
199
  }
180
200
  }
@@ -193,7 +213,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
193
213
  // See also: https://github.com/mapbox/mapbox-gl-native/pull/14253#issuecomment-478827792
194
214
  for (imageEntry in imageEntries) {
195
215
  if (!hasImage(imageEntry.key, map)) {
196
- mImagePlaceholder?.let { style.addBitmapImage(imageEntry.key, it) }
216
+ mImagePlaceholder?.let { style.addBitmapImage(imageEntry.key, it, false, listOf(), listOf(), null,1.0) }
197
217
  missingImages.add(imageEntry)
198
218
  mCurrentImages.add(imageEntry.key)
199
219
  }
@@ -220,4 +240,11 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
220
240
  mImagePlaceholder = BitmapUtils.getBitmapFromDrawable(ResourcesCompat.getDrawable(context.resources, R.drawable.empty_drawable, null))
221
241
  }
222
242
  }
243
+
244
+ override fun updateImage(imageId: String, bitmap: Bitmap, sdf: Boolean, stretchX: List<ImageStretches>, stretchY: List<ImageStretches>, content: ImageContent?, scale: Double)
245
+ {
246
+ mMap?.getStyle()?.let {
247
+ it.addBitmapImage(imageId, bitmap, sdf, stretchX, stretchY, content, scale);
248
+ }
249
+ }
223
250
  }
@@ -0,0 +1,216 @@
1
+ package com.mapbox.rctmgl.components.images
2
+
3
+ import android.graphics.drawable.BitmapDrawable
4
+ import android.view.View
5
+ import com.facebook.react.bridge.*
6
+ import com.facebook.react.common.MapBuilder
7
+ import com.facebook.react.uimanager.ThemedReactContext
8
+ import com.facebook.react.uimanager.annotations.ReactProp
9
+ import com.mapbox.maps.ImageContent
10
+ import com.mapbox.maps.ImageStretches
11
+ import com.mapbox.rctmgl.components.AbstractEventEmitter
12
+ import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
13
+ import com.mapbox.rctmgl.events.constants.EventKeys
14
+ import com.mapbox.rctmgl.modules.RCTMGLLogging
15
+ import com.mapbox.rctmgl.utils.ImageEntry
16
+ import com.mapbox.rctmgl.utils.Logger
17
+ import com.mapbox.rctmgl.utils.ResourceUtils
18
+ import java.util.*
19
+
20
+ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
21
+ AbstractEventEmitter<RCTMGLImages?>(
22
+ mContext
23
+ ) {
24
+ override fun getName(): String {
25
+ return "RCTMGLImages"
26
+ }
27
+
28
+ public override fun createViewInstance(context: ThemedReactContext): RCTMGLImages {
29
+ return RCTMGLImages(context, this)
30
+ }
31
+
32
+ @ReactProp(name = "images")
33
+ fun setImages(images: RCTMGLImages, map: ReadableMap) {
34
+ val imagesList: MutableList<Map.Entry<String, ImageEntry>> = ArrayList()
35
+ val iterator = map.keySetIterator()
36
+ while (iterator.hasNextKey()) {
37
+ val imageName = iterator.nextKey()
38
+ var imageEntry: ImageEntry? = null
39
+ imageEntry = if (map.getType(imageName) == ReadableType.Map) {
40
+ val imageMap = map.getMap(imageName)
41
+ val uri = imageMap!!.getString("uri")
42
+ val hasScale =
43
+ imageMap.hasKey("scale") && imageMap.getType("scale") == ReadableType.Number
44
+ val scale = if (hasScale) imageMap.getDouble("scale") else ImageEntry.defaultScale
45
+ ImageEntry(uri, scale)
46
+ } else {
47
+ ImageEntry(map.getString(imageName))
48
+ }
49
+ imagesList.add(AbstractMap.SimpleEntry(imageName, imageEntry))
50
+ }
51
+ images.setImages(imagesList)
52
+ }
53
+
54
+ @ReactProp(name = "hasOnImageMissing")
55
+ fun setHasOnImageMissing(images: RCTMGLImages, value: Boolean?) {
56
+ images.setHasOnImageMissing(value!!)
57
+ }
58
+
59
+ fun toNativeImage(dynamic: Dynamic): NativeImage? {
60
+ when (dynamic.type) {
61
+ ReadableType.String -> {
62
+ val resourceName = dynamic.asString();
63
+ val drawable =
64
+ ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable
65
+ if (drawable != null) {
66
+ return NativeImage(name, drawable)
67
+ } else {
68
+ Logger.e("RCTMGLImages", "cound not get native drawable with name: $name")
69
+ return null
70
+ }
71
+ }
72
+ ReadableType.Map -> {
73
+ val map = dynamic.asMap()
74
+ val resourceName = map.getString("name")
75
+ var sdf = false
76
+ var stretchX = listOf<ImageStretches>();
77
+ var stretchY = listOf<ImageStretches>();
78
+ var content : ImageContent? = null;
79
+ var scale : Double = 1.0;
80
+ if (map.hasKey("sdf")) {
81
+ sdf = map.getBoolean("sdf");
82
+ }
83
+ if (map.hasKey("stretchX")) {
84
+ stretchX = convertStretch(map.getDynamic("stretchX")) ?: listOf()
85
+ }
86
+ if (map.hasKey("stretchY")) {
87
+ stretchY = convertStretch(map.getDynamic("stretchY")) ?: listOf()
88
+ }
89
+ if (map.hasKey("content")) {
90
+ content = convertContent(map.getDynamic("content")) ?: null
91
+ }
92
+ if (map.hasKey("scale")) {
93
+ if (map.getType("scale") != ReadableType.Number) {
94
+ Logger.e("RCTMGLImages", "scale should be a number found: $scale in $dynamic")
95
+ return null
96
+ }
97
+ scale = map.getDouble("scale")
98
+ }
99
+ val drawable =
100
+ ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable
101
+ if (drawable != null) {
102
+ return NativeImage(name, drawable, scale, sdf, stretchX, stretchY)
103
+ } else {
104
+ Logger.e("RCTMGLImages", "cound not get native drawable with name: $name")
105
+ return null
106
+ }
107
+ }
108
+ else -> {
109
+ Logger.e("RCTMGLImages", "nativeImages element should be a string or a object, but was: $dynamic")
110
+ return null
111
+ }
112
+ }
113
+ }
114
+
115
+ @ReactProp(name = "nativeImages")
116
+ fun setNativeImages(images: RCTMGLImages, arr: ReadableArray) {
117
+ val nativeImages = mutableListOf<NativeImage>();
118
+ for (i in 0 until arr.size()) {
119
+ val nativeImage = toNativeImage(arr.getDynamic(i))
120
+ if (nativeImage != null) {
121
+ nativeImages.add(nativeImage)
122
+ }
123
+ }
124
+ images.setNativeImages(nativeImages)
125
+ }
126
+
127
+ override fun customEvents(): Map<String, String>? {
128
+ return MapBuilder.builder<String, String>()
129
+ .put(EventKeys.IMAGES_MISSING, "onImageMissing")
130
+ .build()
131
+ }
132
+
133
+ // region RCTMGLImage children
134
+
135
+ override fun addView(parent: RCTMGLImages?, childView: View?, childPosition: Int) {
136
+ if (parent == null || childView == null) {
137
+ Logger.e("RCTMGLImages", "addView: parent or childView is null")
138
+ return
139
+ }
140
+
141
+ if (childView !is RCTMGLImage) {
142
+ Logger.e("RCTMGLImages", "child view should be RCTMGLImage")
143
+ return
144
+ }
145
+
146
+ parent.mImageViews.add(childPosition, childView)
147
+ childView.nativeImageUpdater = parent
148
+ }
149
+
150
+ override fun removeView(parent: RCTMGLImages?, view: View?) {
151
+ if (parent == null || view == null) {
152
+ Logger.e("RCTMGLImages", "removeView: parent or view is null")
153
+ return
154
+ }
155
+
156
+ parent.mImageViews.remove(view)
157
+ }
158
+
159
+ override fun removeAllViews(parent: RCTMGLImages?) {
160
+ if (parent == null) {
161
+ Logger.e("RCTMGLImages", "removeAllViews parent is null")
162
+ return
163
+ }
164
+
165
+ parent.mImageViews.clear()
166
+ }
167
+
168
+ // endregion
169
+
170
+ companion object {
171
+ const val REACT_CLASS = "RCTMGLImages"
172
+
173
+ fun convertStretch(stretch: Dynamic) : List<ImageStretches>? {
174
+ if (stretch.type != ReadableType.Array) {
175
+ Logger.e("RCTMGLImages", "stretch should be an array, got $stretch")
176
+ return null
177
+ }
178
+ val array = stretch.asArray()
179
+ var result = mutableListOf<ImageStretches>();
180
+ for (i in 0 until array.size()) {
181
+ if (array.getType(i) != ReadableType.Array) {
182
+ Logger.e("RTMGLImages", "each element of strech should be an array but was: ${array.getDynamic(i)}")
183
+ } else {
184
+ val pair = array.getArray(i)
185
+ if (pair.size() != 2 || pair.getType(0) != ReadableType.Number || pair.getType(1) != ReadableType.Number) {
186
+ Logger.e("RCTMGLImages", "each element of stretch should be pair of 2 integers but was ${pair}")
187
+ }
188
+ result.add(ImageStretches(pair.getDouble(0).toFloat(), pair.getDouble(1).toFloat()))
189
+ }
190
+ }
191
+ return result;
192
+ }
193
+
194
+ fun convertContent(content: Dynamic) : ImageContent? {
195
+ if (content.type != ReadableType.Array) {
196
+ Logger.e("RCTMGLImages", "content should be an array, got $content")
197
+ return null
198
+ }
199
+ val array = content.asArray()
200
+ if (array.size() != 4) {
201
+ Logger.e("RCTMGLImages", "content should be an array of 4 numbers, got $content")
202
+ return null
203
+ }
204
+ val result = arrayOf(0.0, 0.0, 0.0, 0.0, 0.0)
205
+ for (i in 0 until array.size()) {
206
+ if (array.getType(i) != ReadableType.Number) {
207
+ Logger.e("RTMGLImages", "each element of content should be an number but was : ${array}")
208
+ return null
209
+ } else {
210
+ result[i] = array.getDouble(i)
211
+ }
212
+ }
213
+ return ImageContent(result[0].toFloat(), result[1].toFloat() ,result[2].toFloat(), result[3].toFloat())
214
+ }
215
+ }
216
+ }
@@ -23,7 +23,7 @@ import com.mapbox.rctmgl.location.LocationManager
23
23
  class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
24
24
  var mMapView = mapView
25
25
  var mContext = context
26
- private var mState = State(showUserLocation=false, followUserLocation=false, hidden=false, tintColor= null, bearingImage = null, puckBearingSource =null)
26
+ private var mState = State(showUserLocation=false, followUserLocation=false, tintColor= null, bearingImage = null, puckBearingSource =null)
27
27
 
28
28
  private var mLocationManager: LocationManager = LocationManager.getInstance(context)
29
29
 
@@ -34,13 +34,15 @@ class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
34
34
  data class State(
35
35
  val showUserLocation: Boolean,
36
36
  val followUserLocation: Boolean,
37
- val hidden: Boolean, // in case it isn't native
38
37
  val tintColor: Int?, // tint of location puck
39
38
  var bearingImage: Drawable?, // bearing image (background)
40
39
  var puckBearingSource: PuckBearingSource? // bearing source
41
40
  ) {
42
41
  val enabled: Boolean
43
42
  get() = showUserLocation || followUserLocation
43
+
44
+ val hidden: Boolean
45
+ get() = followUserLocation && !showUserLocation
44
46
  }
45
47
 
46
48
  fun update(newStateCallback: (currentState: State) -> State) {
@@ -11,6 +11,7 @@ import com.mapbox.maps.MapboxMap
11
11
  import com.facebook.react.bridge.ReadableArray
12
12
  import com.mapbox.rctmgl.components.mapview.RCTMGLMapView.FoundLayerCallback
13
13
  import com.facebook.common.logging.FLog
14
+ import com.mapbox.maps.extension.style.expressions.dsl.generated.all
14
15
  import com.mapbox.maps.extension.style.expressions.dsl.generated.literal
15
16
  import com.mapbox.maps.extension.style.expressions.generated.Expression
16
17
  import com.mapbox.maps.extension.style.layers.*
@@ -115,7 +116,7 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
115
116
  mHadFilter = true
116
117
  updateFilter(mFilter)
117
118
  } else if (mHadFilter) {
118
- updateFilter(literal(true))
119
+ updateFilter(/* literal(true)*/all {} )
119
120
  }
120
121
  }
121
122
  }
@@ -245,8 +246,13 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
245
246
  }
246
247
 
247
248
  override fun removeFromMap(mapView: RCTMGLMapView) {
248
- if (style != null) {
249
- style!!.removeStyleLayer(mLayer!!.layerId)
249
+ style?.let {
250
+ val layer = mLayer
251
+ if (layer != null) {
252
+ it.removeStyleLayer(layer.layerId)
253
+ } else {
254
+ Logger.e("RCTLayer","mLayer is null on removal layer from map")
255
+ }
250
256
  }
251
257
  super.removeFromMap(mapView)
252
258
  }