Skip to content

Commit 5d89372

Browse files
authored
chore(ios,v10): various fixes, warn if below/aboveLayerID doesn't exi… (#2694)
* chore(ios,v10): various fixes, warn if below/aboveLayerID doesn't exists. * chore(android,v10): kotlin, added and require existing when referring to existing layers/sources
1 parent 87266c2 commit 5d89372

File tree

98 files changed

+1955
-1927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1955
-1927
lines changed

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.facebook.react.bridge.ReadableMap
55
import com.mapbox.maps.MapboxMap
66
import com.mapbox.rctmgl.utils.ImageEntry
77
import com.mapbox.rctmgl.utils.DownloadMapImageTask
8+
import com.mapbox.rctmgl.utils.Logger
89
import java.util.AbstractMap
910
import java.util.ArrayList
1011

@@ -39,11 +40,12 @@ class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap?, map:
3940
}
4041

4142
@JvmOverloads
42-
fun addImage(styleValue: RCTMGLStyleValue, callback: DownloadMapImageTask.OnAllImagesLoaded? = null) {
43+
fun addImage(styleValue: RCTMGLStyleValue, styleKey: String, callback: DownloadMapImageTask.OnAllImagesLoaded? = null) {
4344
if (!styleValue.shouldAddImage()) {
4445
callback?.onAllImagesLoaded()
4546
return
4647
}
48+
Logger.w(LOG_TAG,"Deprecated: Image in style is deprecated, use images component instead. key: $styleKey [image-in-style-deprecated]")
4749
val uriStr = styleValue.imageURI
4850
val images = arrayOf<Map.Entry<String, ImageEntry>>(
4951
AbstractMap.SimpleEntry<String, ImageEntry>(
@@ -59,4 +61,8 @@ class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap?, map:
5961
mReactStyle = reactStyle
6062
mMap = map
6163
}
64+
65+
companion object {
66+
const val LOG_TAG = "RCTMGLStyle"
67+
}
6268
}

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyleFactory.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static void setFillLayerStyle(final FillLayer layer, RCTMGLStyle style) {
8080
RCTMGLStyleFactory.setFillTranslateAnchor(layer, styleValue);
8181
break;
8282
case "fillPattern":
83-
style.addImage(styleValue, new DownloadMapImageTask.OnAllImagesLoaded() {
83+
style.addImage(styleValue, styleKey, new DownloadMapImageTask.OnAllImagesLoaded() {
8484
@Override
8585
public void onAllImagesLoaded() {
8686
try {
@@ -172,7 +172,7 @@ public static void setLineLayerStyle(final LineLayer layer, RCTMGLStyle style) {
172172
RCTMGLStyleFactory.setLineDasharray(layer, styleValue);
173173
break;
174174
case "linePattern":
175-
style.addImage(styleValue, new DownloadMapImageTask.OnAllImagesLoaded() {
175+
style.addImage(styleValue, styleKey, new DownloadMapImageTask.OnAllImagesLoaded() {
176176
@Override
177177
public void onAllImagesLoaded() {
178178
try {
@@ -240,7 +240,7 @@ public static void setSymbolLayerStyle(final SymbolLayer layer, RCTMGLStyle styl
240240
RCTMGLStyleFactory.setIconTextFitPadding(layer, styleValue);
241241
break;
242242
case "iconImage":
243-
style.addImage(styleValue, new DownloadMapImageTask.OnAllImagesLoaded() {
243+
style.addImage(styleValue, styleKey, new DownloadMapImageTask.OnAllImagesLoaded() {
244244
@Override
245245
public void onAllImagesLoaded() {
246246
try {
@@ -573,7 +573,7 @@ public static void setFillExtrusionLayerStyle(final FillExtrusionLayer layer, RC
573573
RCTMGLStyleFactory.setFillExtrusionTranslateAnchor(layer, styleValue);
574574
break;
575575
case "fillExtrusionPattern":
576-
style.addImage(styleValue, new DownloadMapImageTask.OnAllImagesLoaded() {
576+
style.addImage(styleValue, styleKey, new DownloadMapImageTask.OnAllImagesLoaded() {
577577
@Override
578578
public void onAllImagesLoaded() {
579579
try {
@@ -729,7 +729,7 @@ public static void setBackgroundLayerStyle(final BackgroundLayer layer, RCTMGLSt
729729
RCTMGLStyleFactory.setBackgroundColorTransition(layer, styleValue);
730730
break;
731731
case "backgroundPattern":
732-
style.addImage(styleValue, new DownloadMapImageTask.OnAllImagesLoaded() {
732+
style.addImage(styleValue, styleKey, new DownloadMapImageTask.OnAllImagesLoaded() {
733733
@Override
734734
public void onAllImagesLoaded() {
735735
try {

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt

+37-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.mapbox.maps.extension.style.expressions.generated.Expression
1717
import com.mapbox.maps.extension.style.layers.*
1818
import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
1919
import com.mapbox.rctmgl.components.styles.layers.RCTLayer
20+
import com.mapbox.rctmgl.components.styles.sources.RCTSource
2021
import com.mapbox.rctmgl.modules.RCTMGLLogging
2122
import com.mapbox.rctmgl.utils.ExpressionParser
2223
import java.lang.ClassCastException
@@ -43,10 +44,19 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
4344
protected var mLayer: T? = null
4445
protected var mHadFilter = false
4546

47+
protected var mExisting : Boolean? = null
48+
4649
fun setSourceID(sourceID: String?) {
4750
mSourceID = sourceID
4851
}
4952

53+
fun checkID(): String? {
54+
if (iD == null) {
55+
Logger.w(LOG_TAG, "iD is null in layer")
56+
}
57+
return iD;
58+
}
59+
5060
fun setAboveLayerID(aboveLayerID: String?) {
5161
if (mAboveLayerID != null && mAboveLayerID == aboveLayerID) {
5262
return
@@ -76,7 +86,7 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
7686
mLayerIndex = layerIndex
7787
if (mLayer != null) {
7888
removeFromMap(mMapView!!)
79-
addAtIndex(mLayerIndex!!)
89+
addAtIndex(layerIndex)
8090
}
8191
}
8292

@@ -121,6 +131,10 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
121131
}
122132
}
123133

134+
fun setExisting(existing: Boolean) {
135+
mExisting = existing
136+
}
137+
124138
fun add() {
125139
if (!hasInitialized()) {
126140
return
@@ -175,7 +189,7 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
175189
if (!hasInitialized()) {
176190
return
177191
}
178-
if (style == null) return
192+
val style = this.style ?: return
179193
val layerSize = style!!.styleLayers.size
180194
if (index >= layerSize) {
181195
FLog.e(
@@ -184,13 +198,16 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
184198
)
185199
index = layerSize - 1
186200
}
187-
style!!.addLayerAt(mLayer!!, index)
188-
mMapView!!.layerAdded(mLayer!!)
201+
val layer = mLayer ?: return
202+
val mapView = mMapView ?: return
203+
style.addLayerAt(layer, index)
204+
mapView.layerAdded(layer)
189205
}
190206

191207
protected fun insertLayer() {
192-
if (style == null) return
193-
if (style!!.getLayer(iD!!) != null) {
208+
val style = this.style ?: return
209+
val id = checkID() ?: return
210+
if (style.styleLayerExists(id)) {
194211
return // prevent adding a layer twice
195212
}
196213
if (mAboveLayerID != null) {
@@ -218,8 +235,8 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
218235
// override if you want to update the filter
219236
}
220237

221-
private fun getLayerAs(style: Style?, id: String?): T? {
222-
val result = style!!.getLayer(iD!!)
238+
private fun getLayerAs(style: Style, id: String?): T? {
239+
val result = style.getLayer(iD!!)
223240
return try {
224241
result as T?
225242
} catch (exception: ClassCastException) {
@@ -230,14 +247,24 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
230247
override fun addToMap(mapView: RCTMGLMapView) {
231248
super.addToMap(mapView)
232249
mMap = mapView.getMapboxMap()
233-
if (style == null) return
234-
val existingLayer = getLayerAs(style, iD)
250+
val style = style ?: return
251+
val id = checkID() ?: return
252+
253+
val exists = style.styleLayerExists(id)
254+
var existingLayer: T? = null;
255+
if (exists) {
256+
if (mExisting == null) {
257+
Logger.e(LOG_TAG, "Layer $id seems to refer to an existing layer but existing flag is not specified, this is deprecated")
258+
}
259+
existingLayer = getLayerAs(style, id)
260+
}
235261
if (existingLayer != null) {
236262
mLayer = existingLayer
237263
} else {
238264
mLayer = makeLayer()
239265
insertLayer()
240266
}
267+
241268
addStyles()
242269
if (mFilter != null) {
243270
mHadFilter = true

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLBackgroundLayer.java

-23
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.mapbox.rctmgl.components.styles.layers
2+
3+
import android.content.Context
4+
import com.mapbox.maps.extension.style.layers.generated.BackgroundLayer
5+
import com.mapbox.rctmgl.components.styles.RCTMGLStyle
6+
import com.mapbox.rctmgl.components.styles.RCTMGLStyleFactory
7+
8+
class RCTMGLBackgroundLayer(context: Context?) : RCTLayer<BackgroundLayer?>(
9+
context!!
10+
) {
11+
override fun makeLayer(): BackgroundLayer {
12+
return BackgroundLayer(iD!!)
13+
}
14+
15+
override fun addStyles() {
16+
RCTMGLStyleFactory.setBackgroundLayerStyle(
17+
mLayer,
18+
RCTMGLStyle(context, mReactStyle, mMap!!)
19+
)
20+
}
21+
}

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLBackgroundLayerManager.java

-60
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.mapbox.rctmgl.components.styles.layers
2+
3+
import com.facebook.react.bridge.ReadableMap
4+
import com.facebook.react.uimanager.ThemedReactContext
5+
import com.facebook.react.uimanager.ViewGroupManager
6+
import com.facebook.react.uimanager.annotations.ReactProp
7+
8+
class RCTMGLBackgroundLayerManager : ViewGroupManager<RCTMGLBackgroundLayer>() {
9+
override fun getName(): String {
10+
return REACT_CLASS
11+
}
12+
13+
override fun createViewInstance(reactContext: ThemedReactContext): RCTMGLBackgroundLayer {
14+
return RCTMGLBackgroundLayer(reactContext)
15+
}
16+
17+
@ReactProp(name = "id")
18+
fun setId(layer: RCTMGLBackgroundLayer, id: String?) {
19+
layer.iD = id
20+
}
21+
22+
@ReactProp(name = "existing")
23+
fun setExisting(layer: RCTMGLBackgroundLayer, existing: Boolean) {
24+
layer.setExisting(existing)
25+
}
26+
27+
@ReactProp(name = "sourceID")
28+
fun setSourceID(layer: RCTMGLBackgroundLayer, sourceID: String?) {
29+
layer.setSourceID(sourceID)
30+
}
31+
32+
@ReactProp(name = "aboveLayerID")
33+
fun setAboveLayerID(layer: RCTMGLBackgroundLayer, aboveLayerID: String?) {
34+
layer.setAboveLayerID(aboveLayerID)
35+
}
36+
37+
@ReactProp(name = "belowLayerID")
38+
fun setBelowLayerID(layer: RCTMGLBackgroundLayer, belowLayerID: String?) {
39+
layer.setBelowLayerID(belowLayerID)
40+
}
41+
42+
@ReactProp(name = "layerIndex")
43+
fun setLayerIndex(layer: RCTMGLBackgroundLayer, layerIndex: Int) {
44+
layer.setLayerIndex(layerIndex)
45+
}
46+
47+
@ReactProp(name = "minZoomLevel")
48+
fun setMinZoomLevel(layer: RCTMGLBackgroundLayer, minZoomLevel: Double) {
49+
layer.setMinZoomLevel(minZoomLevel)
50+
}
51+
52+
@ReactProp(name = "maxZoomLevel")
53+
fun setMaxZoomLevel(layer: RCTMGLBackgroundLayer, maxZoomLevel: Double) {
54+
layer.setMaxZoomLevel(maxZoomLevel)
55+
}
56+
57+
@ReactProp(name = "reactStyle")
58+
fun setReactStyle(layer: RCTMGLBackgroundLayer, style: ReadableMap?) {
59+
layer.setReactStyle(style)
60+
}
61+
62+
companion object {
63+
const val REACT_CLASS = "RCTMGLBackgroundLayer"
64+
}
65+
}

0 commit comments

Comments
 (0)