@rnmapbox/maps 10.0.8-rc.0 → 10.0.8-rc.1
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/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +13 -8
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +48 -43
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.kt +3 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/DownloadMapImageTask.kt +19 -14
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/ImageEntry.kt +17 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/ReadableMap.kt +11 -0
- package/package.json +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/ImageEntry.java +0 -25
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt
CHANGED
|
@@ -42,12 +42,15 @@ fun Style.addBitmapImage(imageId: String, bitmap: Bitmap, sdf: Boolean = false,
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
fun Style.addBitmapImage(nativeImage: NativeImage) : Expected<String, None> {
|
|
45
|
-
|
|
45
|
+
val info = nativeImage.info
|
|
46
|
+
return addBitmapImage(info.name, nativeImage.drawable.bitmap, info.sdf, info.stretchX, info.stretchY, info.content, info.scale)
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
data class
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
data class ImageInfo(val name: String, val scale: Double = 1.0, val sdf: Boolean = false, val stretchX: List<ImageStretches> = listOf(),
|
|
50
|
+
val stretchY: List<ImageStretches> = listOf(), val content: ImageContent? = null)
|
|
51
|
+
{}
|
|
52
|
+
|
|
53
|
+
data class NativeImage(val info: ImageInfo, val drawable: BitmapDrawable);
|
|
51
54
|
|
|
52
55
|
interface NativeImageUpdater {
|
|
53
56
|
fun updateImage(imageId: String, bitmap: Bitmap, sdf: Boolean = false, stretchX: List<ImageStretches> = listOf(), stretchY: List<ImageStretches> = listOf(), content: ImageContent? = null, scale: Double = 1.0)
|
|
@@ -77,9 +80,10 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
|
|
|
77
80
|
fun setNativeImages(nativeImages: List<NativeImage>) {
|
|
78
81
|
val newImages: MutableMap<String, NativeImage> = HashMap()
|
|
79
82
|
for (nativeImage in nativeImages) {
|
|
80
|
-
val
|
|
83
|
+
val name = nativeImage.info.name
|
|
84
|
+
val oldValue = mNativeImages.put(name, nativeImage)
|
|
81
85
|
if (oldValue == null) {
|
|
82
|
-
newImages[
|
|
86
|
+
newImages[name] = nativeImage
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
mMap?.let {
|
|
@@ -194,10 +198,11 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
|
|
|
194
198
|
val style = map.getStyle()
|
|
195
199
|
if (style == null) return
|
|
196
200
|
for (nativeImage in imageEntries) {
|
|
197
|
-
|
|
201
|
+
val name = nativeImage.info.name
|
|
202
|
+
if (!hasImage(name, map)) {
|
|
198
203
|
val bitmap = nativeImage.drawable
|
|
199
204
|
style.addBitmapImage(nativeImage)
|
|
200
|
-
mCurrentImages.add(
|
|
205
|
+
mCurrentImages.add(name)
|
|
201
206
|
}
|
|
202
207
|
}
|
|
203
208
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt
CHANGED
|
@@ -9,12 +9,11 @@ import com.facebook.react.uimanager.annotations.ReactProp
|
|
|
9
9
|
import com.mapbox.maps.ImageContent
|
|
10
10
|
import com.mapbox.maps.ImageStretches
|
|
11
11
|
import com.mapbox.rctmgl.components.AbstractEventEmitter
|
|
12
|
-
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
13
12
|
import com.mapbox.rctmgl.events.constants.EventKeys
|
|
14
|
-
import com.mapbox.rctmgl.modules.RCTMGLLogging
|
|
15
13
|
import com.mapbox.rctmgl.utils.ImageEntry
|
|
16
14
|
import com.mapbox.rctmgl.utils.Logger
|
|
17
15
|
import com.mapbox.rctmgl.utils.ResourceUtils
|
|
16
|
+
import com.mapbox.rctmgl.utils.extensions.forEach
|
|
18
17
|
import java.util.*
|
|
19
18
|
|
|
20
19
|
class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
|
|
@@ -29,24 +28,54 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
|
|
|
29
28
|
return RCTMGLImages(context, this)
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
fun imageInfo(name: String, map: ReadableMap): ImageInfo {
|
|
32
|
+
var sdf = false
|
|
33
|
+
var stretchX = listOf<ImageStretches>();
|
|
34
|
+
var stretchY = listOf<ImageStretches>();
|
|
35
|
+
var content : ImageContent? = null;
|
|
36
|
+
var scale : Double = ImageEntry.defaultScale
|
|
37
|
+
if (map.hasKey("sdf")) {
|
|
38
|
+
sdf = map.getBoolean("sdf");
|
|
39
|
+
}
|
|
40
|
+
if (map.hasKey("stretchX")) {
|
|
41
|
+
stretchX = convertStretch(map.getDynamic("stretchX")) ?: listOf()
|
|
42
|
+
}
|
|
43
|
+
if (map.hasKey("stretchY")) {
|
|
44
|
+
stretchY = convertStretch(map.getDynamic("stretchY")) ?: listOf()
|
|
45
|
+
}
|
|
46
|
+
if (map.hasKey("content")) {
|
|
47
|
+
content = convertContent(map.getDynamic("content")) ?: null
|
|
48
|
+
}
|
|
49
|
+
if (map.hasKey("scale")) {
|
|
50
|
+
if (map.getType("scale") != ReadableType.Number) {
|
|
51
|
+
Logger.e("RCTMGLImages", "scale should be a number found: $scale in $map")
|
|
52
|
+
}
|
|
53
|
+
scale = map.getDouble("scale")
|
|
54
|
+
}
|
|
55
|
+
return ImageInfo(name=name, sdf=sdf, scale=scale, content=content, stretchX = stretchX, stretchY = stretchY)
|
|
56
|
+
}
|
|
57
|
+
|
|
32
58
|
@ReactProp(name = "images")
|
|
33
59
|
fun setImages(images: RCTMGLImages, map: ReadableMap) {
|
|
34
|
-
val imagesList
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
val imagesList = mutableListOf<Map.Entry<String, ImageEntry>>()
|
|
61
|
+
map.forEach { imageName, imageInfo ->
|
|
62
|
+
when (imageInfo) {
|
|
63
|
+
is ReadableMap -> {
|
|
64
|
+
val uri = imageInfo.getString("uri") ?: imageInfo.getString("url")
|
|
65
|
+
if (uri != null) {
|
|
66
|
+
imagesList.add(AbstractMap.SimpleEntry(imageName, ImageEntry(uri, imageInfo(imageName, imageInfo))))
|
|
67
|
+
} else {
|
|
68
|
+
Logger.e("RCTMGLImagesManager", "Unexpected value for key: $imageName in images property, no uri/url found!")
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
is String -> {
|
|
72
|
+
val name = imageInfo
|
|
73
|
+
imagesList.add(AbstractMap.SimpleEntry(imageName, ImageEntry(name, ImageInfo(name=imageName))))
|
|
74
|
+
}
|
|
75
|
+
else -> {
|
|
76
|
+
Logger.e("RCTMGLImagesManager", "Unexpected value for key: $imageName in images property, only string/object is supported")
|
|
77
|
+
}
|
|
48
78
|
}
|
|
49
|
-
imagesList.add(AbstractMap.SimpleEntry(imageName, imageEntry))
|
|
50
79
|
}
|
|
51
80
|
images.setImages(imagesList)
|
|
52
81
|
}
|
|
@@ -63,7 +92,7 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
|
|
|
63
92
|
val drawable =
|
|
64
93
|
ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable?
|
|
65
94
|
if (drawable != null) {
|
|
66
|
-
return NativeImage(resourceName, drawable)
|
|
95
|
+
return NativeImage(ImageInfo(name=resourceName), drawable)
|
|
67
96
|
} else {
|
|
68
97
|
Logger.e("RCTMGLImages", "cound not get native drawable with name: $resourceName")
|
|
69
98
|
return null
|
|
@@ -72,34 +101,10 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
|
|
|
72
101
|
ReadableType.Map -> {
|
|
73
102
|
val map = dynamic.asMap()
|
|
74
103
|
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
104
|
val drawable =
|
|
100
105
|
ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable?
|
|
101
106
|
if (drawable != null && resourceName != null) {
|
|
102
|
-
return NativeImage(resourceName,
|
|
107
|
+
return NativeImage(imageInfo(resourceName, map), drawable)
|
|
103
108
|
} else {
|
|
104
109
|
Logger.e("RCTMGLImages", "cound not get native drawable with name: $resourceName")
|
|
105
110
|
return null
|
|
@@ -3,6 +3,7 @@ package com.mapbox.rctmgl.components.styles
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import com.facebook.react.bridge.ReadableMap
|
|
5
5
|
import com.mapbox.maps.MapboxMap
|
|
6
|
+
import com.mapbox.rctmgl.components.images.ImageInfo
|
|
6
7
|
import com.mapbox.rctmgl.utils.ImageEntry
|
|
7
8
|
import com.mapbox.rctmgl.utils.DownloadMapImageTask
|
|
8
9
|
import com.mapbox.rctmgl.utils.Logger
|
|
@@ -36,7 +37,7 @@ class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap?, map:
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
fun imageEntry(styleValue: RCTMGLStyleValue): ImageEntry {
|
|
39
|
-
return ImageEntry(styleValue.imageURI, styleValue.
|
|
40
|
+
return ImageEntry(styleValue.imageURI!!, ImageInfo(scale=styleValue.imageScale, name=styleValue.imageURI!!))
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
@JvmOverloads
|
|
@@ -46,7 +47,7 @@ class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap?, map:
|
|
|
46
47
|
return
|
|
47
48
|
}
|
|
48
49
|
Logger.w(LOG_TAG,"Deprecated: Image in style is deprecated, use images component instead. key: $styleKey [image-in-style-deprecated]")
|
|
49
|
-
val uriStr = styleValue.imageURI
|
|
50
|
+
val uriStr = styleValue.imageURI!!
|
|
50
51
|
val images = arrayOf<Map.Entry<String, ImageEntry>>(
|
|
51
52
|
AbstractMap.SimpleEntry<String, ImageEntry>(
|
|
52
53
|
uriStr,
|
|
@@ -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.ImageInfo
|
|
24
25
|
import com.mapbox.rctmgl.components.images.addBitmapImage
|
|
25
26
|
import java.io.File
|
|
26
27
|
import java.lang.ref.WeakReference
|
|
@@ -28,8 +29,10 @@ import java.util.AbstractMap
|
|
|
28
29
|
import java.util.ArrayList
|
|
29
30
|
import java.util.HashMap
|
|
30
31
|
|
|
32
|
+
data class DownloadedImage(val name: String, val bitmap: Bitmap, val info: ImageInfo)
|
|
33
|
+
|
|
31
34
|
class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImagesLoaded?) :
|
|
32
|
-
AsyncTask<Map.Entry<String, ImageEntry>, Void?, List<
|
|
35
|
+
AsyncTask<Map.Entry<String, ImageEntry>, Void?, List<DownloadedImage>>() {
|
|
33
36
|
private val mContext: WeakReference<Context>
|
|
34
37
|
private val mMap: WeakReference<MapboxMap>
|
|
35
38
|
private val mCallback: OnAllImagesLoaded?
|
|
@@ -40,8 +43,8 @@ class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImag
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
@SafeVarargs
|
|
43
|
-
protected override fun doInBackground(vararg objects: Map.Entry<String, ImageEntry>): List<
|
|
44
|
-
val images
|
|
46
|
+
protected override fun doInBackground(vararg objects: Map.Entry<String, ImageEntry>): List<DownloadedImage> {
|
|
47
|
+
val images = mutableListOf<DownloadedImage>()
|
|
45
48
|
val context = mContext.get() ?: return images
|
|
46
49
|
val resources = context.resources
|
|
47
50
|
val metrics = resources.displayMetrics
|
|
@@ -74,9 +77,7 @@ class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImag
|
|
|
74
77
|
1.0
|
|
75
78
|
)).toInt()
|
|
76
79
|
images.add(
|
|
77
|
-
|
|
78
|
-
key, bitmap
|
|
79
|
-
)
|
|
80
|
+
DownloadedImage(name=key, bitmap=bitmap, info=imageEntry.info)
|
|
80
81
|
)
|
|
81
82
|
} else {
|
|
82
83
|
FLog.e(LOG_TAG, "Failed to load bitmap from: $uri")
|
|
@@ -97,12 +98,14 @@ class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImag
|
|
|
97
98
|
val bitmap = BitmapUtils.getBitmapFromResource(
|
|
98
99
|
context,
|
|
99
100
|
uri,
|
|
100
|
-
getBitmapOptions(metrics, imageEntry.scale)
|
|
101
|
+
getBitmapOptions(metrics, imageEntry.info.scale)
|
|
101
102
|
)
|
|
102
103
|
if (bitmap != null) {
|
|
103
104
|
images.add(
|
|
104
|
-
|
|
105
|
-
key,
|
|
105
|
+
DownloadedImage(
|
|
106
|
+
name=key,
|
|
107
|
+
bitmap=bitmap,
|
|
108
|
+
info=imageEntry.info
|
|
106
109
|
)
|
|
107
110
|
)
|
|
108
111
|
} else {
|
|
@@ -113,17 +116,19 @@ class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImag
|
|
|
113
116
|
return images
|
|
114
117
|
}
|
|
115
118
|
|
|
116
|
-
override fun onPostExecute(images: List<
|
|
119
|
+
override fun onPostExecute(images: List<DownloadedImage>) {
|
|
117
120
|
val map = mMap.get()
|
|
118
121
|
if (map != null && images != null && images.size > 0) {
|
|
119
122
|
val style = map.getStyle()
|
|
120
123
|
if (style != null) {
|
|
121
124
|
val bitmapImages = HashMap<String, Bitmap>()
|
|
122
|
-
for (
|
|
123
|
-
bitmapImages[
|
|
124
|
-
|
|
125
|
+
for (image in images) {
|
|
126
|
+
bitmapImages[image.name] = image.bitmap
|
|
127
|
+
val info = image.info
|
|
128
|
+
style.addBitmapImage(image.name, image.bitmap,sdf = info.sdf, stretchX = info.stretchX, stretchY = info.stretchY,
|
|
129
|
+
content = info.content,scale = info.scale
|
|
130
|
+
)
|
|
125
131
|
}
|
|
126
|
-
// style.addImages(bitmapImages);
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
mCallback?.onAllImagesLoaded()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.utils
|
|
2
|
+
|
|
3
|
+
import com.mapbox.rctmgl.components.images.ImageInfo
|
|
4
|
+
|
|
5
|
+
data class ImageEntry(val uri: String, val info: ImageInfo) {
|
|
6
|
+
fun getScaleOr(v: Double): Double {
|
|
7
|
+
return if (info.scale == defaultScale) {
|
|
8
|
+
v
|
|
9
|
+
} else {
|
|
10
|
+
info.scale
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
companion object {
|
|
15
|
+
const val defaultScale = 0.0
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.utils.extensions
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableMap
|
|
4
|
+
|
|
5
|
+
fun ReadableMap.forEach(action: (String, Any) -> Unit) {
|
|
6
|
+
val iterator = this.entryIterator
|
|
7
|
+
while (iterator.hasNext()) {
|
|
8
|
+
val next = iterator.next()
|
|
9
|
+
action(next.key, next.value)
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package com.mapbox.rctmgl.utils;
|
|
2
|
-
|
|
3
|
-
public class ImageEntry {
|
|
4
|
-
public String uri;
|
|
5
|
-
public double scale = 1.0;
|
|
6
|
-
public static final double defaultScale = 0.0;
|
|
7
|
-
|
|
8
|
-
public ImageEntry(String _uri, Double _scale) {
|
|
9
|
-
uri = _uri;
|
|
10
|
-
scale = _scale;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public ImageEntry(String _uri) {
|
|
14
|
-
uri = _uri;
|
|
15
|
-
scale = ImageEntry.defaultScale;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public double getScaleOr(double v) {
|
|
19
|
-
if (scale == ImageEntry.defaultScale) {
|
|
20
|
-
return v;
|
|
21
|
-
} else {
|
|
22
|
-
return scale;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|