@rnmapbox/maps 10.0.0-beta.71 → 10.0.0-beta.73
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.
- package/README.md +1 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +2 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +0 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImage.kt +74 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImageManager.kt +67 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +62 -35
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +216 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +2 -1
- package/index.d.ts +13 -3
- package/ios/RCTMGL-v10/RCMTGLImage.swift +93 -0
- package/ios/RCTMGL-v10/RCMTGLImageManager.m +9 -0
- package/ios/RCTMGL-v10/RCMTGLImageManager.swift +14 -0
- package/ios/RCTMGL-v10/RCTMGLImages.swift +68 -9
- package/javascript/components/Image.tsx +63 -0
- package/javascript/components/Images.tsx +29 -6
- package/javascript/components/annotations/Annotation.js +9 -10
- package/javascript/index.js +3 -0
- package/javascript/modules/location/locationManager.ts +1 -1
- package/lib/commonjs/components/Image.js +34 -0
- package/lib/commonjs/components/Image.js.map +1 -0
- package/lib/commonjs/components/Images.js +13 -0
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/annotations/Annotation.js +6 -9
- package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/Image.js +24 -0
- package/lib/module/components/Image.js.map +1 -0
- package/lib/module/components/Images.js +15 -2
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/annotations/Annotation.js +6 -9
- package/lib/module/components/annotations/Annotation.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/Image.d.ts +26 -0
- package/lib/typescript/components/Image.d.ts.map +1 -0
- package/lib/typescript/components/Images.d.ts +6 -4
- package/lib/typescript/components/Images.d.ts.map +1 -1
- package/lib/typescript/modules/location/locationManager.d.ts +1 -1
- package/lib/typescript/modules/location/locationManager.d.ts.map +1 -1
- package/package.json +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.java +0 -103
package/README.md
CHANGED
|
@@ -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());
|
|
@@ -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
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImageManager.kt
ADDED
|
@@ -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
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt
CHANGED
|
@@ -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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
stretchX,
|
|
38
|
+
stretchY,
|
|
39
|
+
content,
|
|
39
40
|
)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
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
|
|
59
|
+
private var mNativeImages = mutableMapOf<String, NativeImage>()
|
|
46
60
|
private var mSendMissingImageEvents = false
|
|
47
61
|
private var mMap: MapboxMap? = null
|
|
48
|
-
|
|
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<
|
|
63
|
-
val newImages: MutableMap<String
|
|
64
|
-
for (
|
|
65
|
-
val oldValue = mNativeImages
|
|
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[
|
|
81
|
+
newImages[nativeImage.name] = nativeImage
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
|
-
|
|
71
|
-
|
|
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 =
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
|
138
|
-
|
|
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<
|
|
190
|
+
private fun addNativeImages(imageEntries: List<NativeImage>, map: MapboxMap) {
|
|
171
191
|
val style = map.getStyle()
|
|
172
|
-
if (style == null
|
|
173
|
-
for (
|
|
174
|
-
if (
|
|
175
|
-
val bitmap =
|
|
176
|
-
style.addBitmapImage(
|
|
177
|
-
mCurrentImages.add(
|
|
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
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt
ADDED
|
@@ -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
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt
CHANGED
|
@@ -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
|
}
|
package/index.d.ts
CHANGED
|
@@ -47,7 +47,8 @@ import {
|
|
|
47
47
|
type UserTrackingMode as _UserTrackingMode,
|
|
48
48
|
type UserTrackingModeChangeCallback as _UserTrackingModeChangeCallback,
|
|
49
49
|
} from './javascript/components/Camera';
|
|
50
|
-
import
|
|
50
|
+
import _Images from './javascript/components/Images';
|
|
51
|
+
import _Image from './javascript/components/Image';
|
|
51
52
|
import { MarkerView as _MarkerView } from './javascript/components/MarkerView';
|
|
52
53
|
import { PointAnnotation as _PointAnnotation } from './javascript/components/PointAnnotation';
|
|
53
54
|
import { Atmosphere as _Atmosphere } from './javascript/components/Atmosphere';
|
|
@@ -78,7 +79,7 @@ import type { requestAndroidLocationPermissions as _requestAndroidLocationPermis
|
|
|
78
79
|
import type {
|
|
79
80
|
Location as _Location,
|
|
80
81
|
LocationManager,
|
|
81
|
-
} from './javascript/locationManager';
|
|
82
|
+
} from './javascript/modules/location/locationManager';
|
|
82
83
|
|
|
83
84
|
// prettier-ignore
|
|
84
85
|
type ExpressionName =
|
|
@@ -179,6 +180,9 @@ declare namespace MapboxGL {
|
|
|
179
180
|
type UserTrackingModeChangeCallback = _UserTrackingModeChangeCallback;
|
|
180
181
|
type Location = _Location;
|
|
181
182
|
|
|
183
|
+
/** @deprecated This will be removed in a future release. Use `Location['coords']` instead. */
|
|
184
|
+
type Coordinates = Location['coords'];
|
|
185
|
+
|
|
182
186
|
const offlineManager: OfflineManager;
|
|
183
187
|
const snapshotManager: SnapshotManager;
|
|
184
188
|
const locationManager: LocationManager;
|
|
@@ -355,9 +359,10 @@ declare namespace MapboxGL {
|
|
|
355
359
|
class ImageSource extends Component<ImageSourceProps> {}
|
|
356
360
|
class SkyLayer extends Component<_SkyLayerProps> {}
|
|
357
361
|
|
|
358
|
-
type Location = _Location;
|
|
359
362
|
type Images = _Images;
|
|
360
363
|
const Images = _Images;
|
|
364
|
+
type Image = _Image;
|
|
365
|
+
const Image = _Image;
|
|
361
366
|
|
|
362
367
|
/**
|
|
363
368
|
* Offline
|
|
@@ -772,6 +777,10 @@ export import MarkerView = MapboxGL.MarkerView;
|
|
|
772
777
|
export import PointAnnotation = MapboxGL.PointAnnotation;
|
|
773
778
|
export import Callout = MapboxGL.Callout;
|
|
774
779
|
|
|
780
|
+
export import Location = MapboxGL.Location;
|
|
781
|
+
/** @deprecated This will be removed in a future release. Use `Location['coords']` instead. */
|
|
782
|
+
export import Coordinates = MapboxGL.Coordinates;
|
|
783
|
+
|
|
775
784
|
export import MapboxGLEvent = MapboxGL.MapboxGLEvent;
|
|
776
785
|
export import UserTrackingMode = MapboxGL.UserTrackingMode;
|
|
777
786
|
export import UserTrackingModeChangeCallback = MapboxGL.UserTrackingModeChangeCallback;
|
|
@@ -780,6 +789,7 @@ export import AnimatedPoint = MapboxGL.AnimatedPoint;
|
|
|
780
789
|
export import AnimatedMapPoint = MapboxGL.AnimatedPoint;
|
|
781
790
|
export import AnimatedShape = MapboxGL.AnimatedShape;
|
|
782
791
|
export import Images = MapboxGL.Images;
|
|
792
|
+
export import Image = MapboxGL.Image;
|
|
783
793
|
|
|
784
794
|
export const { offlineManager } = MapboxGL;
|
|
785
795
|
|