@maplibre/maplibre-react-native 11.0.3 → 11.1.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.
Files changed (52) hide show
  1. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +2 -0
  2. package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerView.kt +4 -13
  3. package/android/src/main/java/org/maplibre/reactnative/components/layer/MLRNLayer.kt +34 -25
  4. package/android/src/main/java/org/maplibre/reactnative/components/sources/tilesources/rasterdemsource/MLRNRasterDEMSource.kt +28 -0
  5. package/android/src/main/java/org/maplibre/reactnative/components/sources/tilesources/rasterdemsource/MLRNRasterDEMSourceManager.kt +34 -0
  6. package/ios/components/layer/MLRNLayer.h +14 -1
  7. package/ios/components/layer/MLRNLayer.m +52 -37
  8. package/ios/components/layer/MLRNLayerComponentView.mm +26 -1
  9. package/ios/components/sources/tile-sources/raster-dem-source/MLRNRasterDEMSource.h +10 -0
  10. package/ios/components/sources/tile-sources/raster-dem-source/MLRNRasterDEMSource.m +39 -0
  11. package/ios/components/sources/tile-sources/raster-dem-source/MLRNRasterDEMSourceComponentView.h +9 -0
  12. package/ios/components/sources/tile-sources/raster-dem-source/MLRNRasterDEMSourceComponentView.mm +131 -0
  13. package/lib/commonjs/components/layer/LayerNativeComponent.ts +13 -1
  14. package/lib/commonjs/components/sources/raster-dem-source/RasterDEMSource.js +31 -0
  15. package/lib/commonjs/components/sources/raster-dem-source/RasterDEMSource.js.map +1 -0
  16. package/lib/commonjs/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.ts +25 -0
  17. package/lib/commonjs/components/sources/raster-source/RasterSourceNativeComponent.ts +2 -2
  18. package/lib/commonjs/index.js +7 -0
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/components/layer/LayerNativeComponent.ts +13 -1
  21. package/lib/module/components/sources/raster-dem-source/RasterDEMSource.js +26 -0
  22. package/lib/module/components/sources/raster-dem-source/RasterDEMSource.js.map +1 -0
  23. package/lib/module/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.ts +25 -0
  24. package/lib/module/components/sources/raster-source/RasterSourceNativeComponent.ts +2 -2
  25. package/lib/module/index.js +1 -0
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/typescript/commonjs/components/layer/LayerNativeComponent.d.ts +1 -1
  28. package/lib/typescript/commonjs/components/layer/LayerNativeComponent.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/components/sources/raster-dem-source/RasterDEMSource.d.ts +58 -0
  30. package/lib/typescript/commonjs/components/sources/raster-dem-source/RasterDEMSource.d.ts.map +1 -0
  31. package/lib/typescript/commonjs/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.d.ts +15 -0
  32. package/lib/typescript/commonjs/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.d.ts.map +1 -0
  33. package/lib/typescript/commonjs/components/sources/raster-source/RasterSourceNativeComponent.d.ts +2 -2
  34. package/lib/typescript/commonjs/components/sources/raster-source/RasterSourceNativeComponent.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/index.d.ts +2 -1
  36. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  37. package/lib/typescript/module/components/layer/LayerNativeComponent.d.ts +1 -1
  38. package/lib/typescript/module/components/layer/LayerNativeComponent.d.ts.map +1 -1
  39. package/lib/typescript/module/components/sources/raster-dem-source/RasterDEMSource.d.ts +58 -0
  40. package/lib/typescript/module/components/sources/raster-dem-source/RasterDEMSource.d.ts.map +1 -0
  41. package/lib/typescript/module/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.d.ts +15 -0
  42. package/lib/typescript/module/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.d.ts.map +1 -0
  43. package/lib/typescript/module/components/sources/raster-source/RasterSourceNativeComponent.d.ts +2 -2
  44. package/lib/typescript/module/components/sources/raster-source/RasterSourceNativeComponent.d.ts.map +1 -1
  45. package/lib/typescript/module/index.d.ts +2 -1
  46. package/lib/typescript/module/index.d.ts.map +1 -1
  47. package/package.json +5 -4
  48. package/src/components/layer/LayerNativeComponent.ts +13 -1
  49. package/src/components/sources/raster-dem-source/RasterDEMSource.tsx +83 -0
  50. package/src/components/sources/raster-dem-source/RasterDEMSourceNativeComponent.ts +25 -0
  51. package/src/components/sources/raster-source/RasterSourceNativeComponent.ts +2 -2
  52. package/src/index.ts +14 -9
@@ -20,6 +20,7 @@ import org.maplibre.reactnative.components.mapview.MLRNMapViewModule
20
20
  import org.maplibre.reactnative.components.sources.geojsonsource.MLRNGeoJSONSourceManager
21
21
  import org.maplibre.reactnative.components.sources.geojsonsource.MLRNGeoJSONSourceModule
22
22
  import org.maplibre.reactnative.components.sources.imagesource.MLRNImageSourceManager
23
+ import org.maplibre.reactnative.components.sources.tilesources.rasterdemsource.MLRNRasterDEMSourceManager
23
24
  import org.maplibre.reactnative.components.sources.tilesources.rastersource.MLRNRasterSourceManager
24
25
  import org.maplibre.reactnative.components.sources.tilesources.vectorsource.MLRNVectorSourceManager
25
26
  import org.maplibre.reactnative.components.sources.tilesources.vectorsource.MLRNVectorSourceModule
@@ -196,6 +197,7 @@ class MLRNPackage : BaseReactPackage() {
196
197
  managers.add(MLRNImageSourceManager(reactContext))
197
198
  managers.add(MLRNGeoJSONSourceManager(reactContext))
198
199
  managers.add(MLRNRasterSourceManager(reactContext))
200
+ managers.add(MLRNRasterDEMSourceManager(reactContext))
199
201
  managers.add(MLRNVectorSourceManager(reactContext))
200
202
 
201
203
  // images
@@ -8,7 +8,6 @@ import android.view.ViewGroup
8
8
  import android.widget.FrameLayout
9
9
  import com.facebook.react.bridge.ReactContext
10
10
  import com.facebook.react.uimanager.UIManagerHelper
11
- import com.facebook.react.uimanager.ViewGroupManager
12
11
  import org.maplibre.android.geometry.LatLng
13
12
  import org.maplibre.geojson.Point
14
13
  import org.maplibre.reactnative.components.AbstractMapFeature
@@ -32,7 +31,7 @@ class MLRNMarkerView(
32
31
  private var mAddedToMap = false
33
32
  private var mLastWidth = 0
34
33
  private var mLastHeight = 0
35
- private var mLastZIndex: Int? = null
34
+ private var mLastZIndex: Float? = null
36
35
  private var markerId: String? = null
37
36
 
38
37
  private val surfaceId: Int
@@ -117,6 +116,7 @@ class MLRNMarkerView(
117
116
  }
118
117
 
119
118
  fun updateZIndex(zIndex: Float) {
119
+ mLastZIndex = zIndex
120
120
  mWrapperView?.translationZ = zIndex
121
121
  }
122
122
 
@@ -174,9 +174,8 @@ class MLRNMarkerView(
174
174
  }
175
175
  mWrapperView!!.setLayerType(LAYER_TYPE_HARDWARE, null)
176
176
 
177
- mLastZIndex = ViewGroupManager.getViewZIndex(this@MLRNMarkerView)
178
- if (mLastZIndex != null) {
179
- mWrapperView!!.translationZ = mLastZIndex!!.toFloat()
177
+ mLastZIndex?.let { zIndex ->
178
+ mWrapperView!!.translationZ = zIndex
180
179
  }
181
180
 
182
181
  val scale = resources.displayMetrics.density
@@ -233,14 +232,6 @@ class MLRNMarkerView(
233
232
  return
234
233
  }
235
234
 
236
- val currentZIndex = ViewGroupManager.getViewZIndex(this@MLRNMarkerView)
237
- if (currentZIndex != mLastZIndex) {
238
- mLastZIndex = currentZIndex
239
- if (currentZIndex != null) {
240
- mWrapperView?.translationZ = currentZIndex.toFloat()
241
- }
242
- }
243
-
244
235
  if (width == mLastWidth && height == mLastHeight) return
245
236
 
246
237
  mLastWidth = width
@@ -13,6 +13,7 @@ import org.maplibre.android.style.layers.CircleLayer
13
13
  import org.maplibre.android.style.layers.FillExtrusionLayer
14
14
  import org.maplibre.android.style.layers.FillLayer
15
15
  import org.maplibre.android.style.layers.HeatmapLayer
16
+ import org.maplibre.android.style.layers.HillshadeLayer
16
17
  import org.maplibre.android.style.layers.Layer
17
18
  import org.maplibre.android.style.layers.LineLayer
18
19
  import org.maplibre.android.style.layers.Property
@@ -146,26 +147,24 @@ class MLRNLayer(
146
147
 
147
148
  private fun makeLayer(): Layer? =
148
149
  when (mLayerType) {
149
- "fill" -> {
150
- val layer = FillLayer(mID, mSourceID)
151
- if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
152
- layer
150
+ "background" -> {
151
+ BackgroundLayer(mID)
153
152
  }
154
153
 
155
- "line" -> {
156
- val layer = LineLayer(mID, mSourceID)
154
+ "circle" -> {
155
+ val layer = CircleLayer(mID, mSourceID)
157
156
  if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
158
157
  layer
159
158
  }
160
159
 
161
- "symbol" -> {
162
- val layer = SymbolLayer(mID, mSourceID)
160
+ "fill" -> {
161
+ val layer = FillLayer(mID, mSourceID)
163
162
  if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
164
163
  layer
165
164
  }
166
165
 
167
- "circle" -> {
168
- val layer = CircleLayer(mID, mSourceID)
166
+ "fill-extrusion" -> {
167
+ val layer = FillExtrusionLayer(mID, mSourceID)
169
168
  if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
170
169
  layer
171
170
  }
@@ -176,8 +175,14 @@ class MLRNLayer(
176
175
  layer
177
176
  }
178
177
 
179
- "fill-extrusion" -> {
180
- val layer = FillExtrusionLayer(mID, mSourceID)
178
+ "hillshade" -> {
179
+ val layer = HillshadeLayer(mID, mSourceID)
180
+ if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
181
+ layer
182
+ }
183
+
184
+ "line" -> {
185
+ val layer = LineLayer(mID, mSourceID)
181
186
  if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
182
187
  layer
183
188
  }
@@ -186,8 +191,10 @@ class MLRNLayer(
186
191
  RasterLayer(mID, mSourceID)
187
192
  }
188
193
 
189
- "background" -> {
190
- BackgroundLayer(mID)
194
+ "symbol" -> {
195
+ val layer = SymbolLayer(mID, mSourceID)
196
+ if (mSourceLayerID != null) layer.setSourceLayer(mSourceLayerID)
197
+ layer
191
198
  }
192
199
 
193
200
  else -> {
@@ -201,36 +208,38 @@ class MLRNLayer(
201
208
  val map = mMap ?: return
202
209
  val style = MLRNStyle(context, reactStyle, map)
203
210
  when (mLayer) {
204
- is FillLayer -> MLRNStyleFactory.setFillLayerStyle(mLayer as FillLayer, style)
205
- is LineLayer -> MLRNStyleFactory.setLineLayerStyle(mLayer as LineLayer, style)
206
- is SymbolLayer -> MLRNStyleFactory.setSymbolLayerStyle(mLayer as SymbolLayer, style)
211
+ is BackgroundLayer -> MLRNStyleFactory.setBackgroundLayerStyle(mLayer as BackgroundLayer, style)
207
212
  is CircleLayer -> MLRNStyleFactory.setCircleLayerStyle(mLayer as CircleLayer, style)
208
- is HeatmapLayer -> MLRNStyleFactory.setHeatmapLayerStyle(mLayer as HeatmapLayer, style)
213
+ is FillLayer -> MLRNStyleFactory.setFillLayerStyle(mLayer as FillLayer, style)
209
214
  is FillExtrusionLayer -> MLRNStyleFactory.setFillExtrusionLayerStyle(mLayer as FillExtrusionLayer, style)
215
+ is HeatmapLayer -> MLRNStyleFactory.setHeatmapLayerStyle(mLayer as HeatmapLayer, style)
216
+ is HillshadeLayer -> MLRNStyleFactory.setHillshadeLayerStyle(mLayer as HillshadeLayer, style)
217
+ is LineLayer -> MLRNStyleFactory.setLineLayerStyle(mLayer as LineLayer, style)
210
218
  is RasterLayer -> MLRNStyleFactory.setRasterLayerStyle(mLayer as RasterLayer, style)
211
- is BackgroundLayer -> MLRNStyleFactory.setBackgroundLayerStyle(mLayer as BackgroundLayer, style)
219
+ is SymbolLayer -> MLRNStyleFactory.setSymbolLayerStyle(mLayer as SymbolLayer, style)
212
220
  }
213
221
  }
214
222
 
215
223
  private fun updateFilter(expression: Expression?) {
216
224
  when (mLayer) {
225
+ is CircleLayer -> (mLayer as CircleLayer).setFilter(expression!!)
217
226
  is FillLayer -> (mLayer as FillLayer).setFilter(expression!!)
227
+ is FillExtrusionLayer -> (mLayer as FillExtrusionLayer).setFilter(expression!!)
228
+ is HeatmapLayer -> (mLayer as HeatmapLayer).setFilter(expression!!)
218
229
  is LineLayer -> (mLayer as LineLayer).setFilter(expression!!)
219
230
  is SymbolLayer -> (mLayer as SymbolLayer).setFilter(expression!!)
220
- is CircleLayer -> (mLayer as CircleLayer).setFilter(expression!!)
221
- is HeatmapLayer -> (mLayer as HeatmapLayer).setFilter(expression!!)
222
- is FillExtrusionLayer -> (mLayer as FillExtrusionLayer).setFilter(expression!!)
223
231
  }
224
232
  }
225
233
 
226
234
  private fun applySourceLayer() {
227
235
  when (mLayer) {
236
+ is CircleLayer -> (mLayer as CircleLayer).setSourceLayer(mSourceLayerID)
228
237
  is FillLayer -> (mLayer as FillLayer).setSourceLayer(mSourceLayerID)
238
+ is FillExtrusionLayer -> (mLayer as FillExtrusionLayer).setSourceLayer(mSourceLayerID)
239
+ is HeatmapLayer -> (mLayer as HeatmapLayer).setSourceLayer(mSourceLayerID)
240
+ is HillshadeLayer -> (mLayer as HillshadeLayer).setSourceLayer(mSourceLayerID)
229
241
  is LineLayer -> (mLayer as LineLayer).setSourceLayer(mSourceLayerID)
230
242
  is SymbolLayer -> (mLayer as SymbolLayer).setSourceLayer(mSourceLayerID)
231
- is CircleLayer -> (mLayer as CircleLayer).setSourceLayer(mSourceLayerID)
232
- is HeatmapLayer -> (mLayer as HeatmapLayer).setSourceLayer(mSourceLayerID)
233
- is FillExtrusionLayer -> (mLayer as FillExtrusionLayer).setSourceLayer(mSourceLayerID)
234
243
  }
235
244
  }
236
245
 
@@ -0,0 +1,28 @@
1
+ package org.maplibre.reactnative.components.sources.tilesources.rasterdemsource
2
+
3
+ import android.content.Context
4
+ import org.maplibre.android.style.sources.RasterDemSource
5
+ import org.maplibre.reactnative.components.sources.tilesources.MLRNTileSource
6
+
7
+ class MLRNRasterDEMSource(
8
+ context: Context?,
9
+ ) : MLRNTileSource<RasterDemSource?>(context) {
10
+ var tileSize: Int? = null
11
+ var encoding: String? = null
12
+
13
+ override fun makeSource(): RasterDemSource {
14
+ val configurationUrl = url
15
+ val resolvedTileSize = (if (tileSize != null) tileSize else RasterDemSource.DEFAULT_TILE_SIZE)!!
16
+ if (configurationUrl != null) {
17
+ return RasterDemSource(mID, configurationUrl, resolvedTileSize)
18
+ }
19
+
20
+ return RasterDemSource(mID, buildTileset(), resolvedTileSize)
21
+ }
22
+
23
+ override fun buildTileset(): org.maplibre.android.style.sources.TileSet {
24
+ val tileSet = super.buildTileset()
25
+ encoding?.let { tileSet.encoding = it }
26
+ return tileSet
27
+ }
28
+ }
@@ -0,0 +1,34 @@
1
+ package org.maplibre.reactnative.components.sources.tilesources.rasterdemsource
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.annotations.ReactProp
6
+ import org.maplibre.reactnative.components.sources.tilesources.MLRNTileSourceManager
7
+
8
+ class MLRNRasterDEMSourceManager(
9
+ context: ReactApplicationContext,
10
+ ) : MLRNTileSourceManager<MLRNRasterDEMSource>(context) {
11
+ companion object {
12
+ const val REACT_CLASS: String = "MLRNRasterDEMSource"
13
+ }
14
+
15
+ override fun getName(): String = REACT_CLASS
16
+
17
+ override fun createViewInstance(themedReactContext: ThemedReactContext): MLRNRasterDEMSource = MLRNRasterDEMSource(themedReactContext)
18
+
19
+ @ReactProp(name = "tileSize")
20
+ fun setTileSize(
21
+ source: MLRNRasterDEMSource,
22
+ tileSize: Int,
23
+ ) {
24
+ source.tileSize = tileSize
25
+ }
26
+
27
+ @ReactProp(name = "encoding")
28
+ fun setEncoding(
29
+ source: MLRNRasterDEMSource,
30
+ encoding: String,
31
+ ) {
32
+ source.encoding = encoding
33
+ }
34
+ }
@@ -4,6 +4,19 @@
4
4
 
5
5
  #import <MapLibre/MapLibre.h>
6
6
 
7
+ typedef NS_ENUM(NSInteger, MLRNLayerType) {
8
+ MLRNLayerTypeBackground,
9
+ MLRNLayerTypeCircle,
10
+ MLRNLayerTypeColorRelief,
11
+ MLRNLayerTypeFill,
12
+ MLRNLayerTypeFillExtrusion,
13
+ MLRNLayerTypeHeatmap,
14
+ MLRNLayerTypeHillshade,
15
+ MLRNLayerTypeLine,
16
+ MLRNLayerTypeRaster,
17
+ MLRNLayerTypeSymbol,
18
+ };
19
+
7
20
  @interface MLRNLayer : UIView
8
21
 
9
22
  @property (nonatomic, strong, nullable) MLNStyleLayer *styleLayer;
@@ -13,7 +26,7 @@
13
26
  @property (nonatomic, strong, nullable) NSArray *filter;
14
27
 
15
28
  @property (nonatomic, copy, nullable) NSString *id;
16
- @property (nonatomic, copy, nullable) NSString *layerType;
29
+ @property (nonatomic, assign) MLRNLayerType layerType;
17
30
  @property (nonatomic, copy, nullable) NSString *sourceID;
18
31
  @property (nonatomic, copy, nullable) NSString *sourceLayerID;
19
32
 
@@ -166,13 +166,10 @@
166
166
  // MARK: - Layer factory (type-based dispatch)
167
167
 
168
168
  - (nullable MLNStyleLayer *)makeLayer:(MLNStyle *)style {
169
- NSString *type = _layerType;
170
-
171
- if ([type isEqualToString:@"background"]) {
169
+ if (_layerType == MLRNLayerTypeBackground) {
172
170
  return [[MLNBackgroundStyleLayer alloc] initWithIdentifier:_id];
173
171
  }
174
172
 
175
- // All other layer types need a source
176
173
  MLNSource *source = [self layerWithSourceIDInStyle:style];
177
174
  if (source == nil) {
178
175
  return nil;
@@ -180,23 +177,37 @@
180
177
 
181
178
  MLNStyleLayer *layer = nil;
182
179
 
183
- if ([type isEqualToString:@"fill"]) {
184
- layer = [[MLNFillStyleLayer alloc] initWithIdentifier:_id source:source];
185
- } else if ([type isEqualToString:@"line"]) {
186
- layer = [[MLNLineStyleLayer alloc] initWithIdentifier:_id source:source];
187
- } else if ([type isEqualToString:@"symbol"]) {
188
- layer = [[MLNSymbolStyleLayer alloc] initWithIdentifier:_id source:source];
189
- } else if ([type isEqualToString:@"circle"]) {
190
- layer = [[MLNCircleStyleLayer alloc] initWithIdentifier:_id source:source];
191
- } else if ([type isEqualToString:@"heatmap"]) {
192
- layer = [[MLNHeatmapStyleLayer alloc] initWithIdentifier:_id source:source];
193
- } else if ([type isEqualToString:@"fill-extrusion"]) {
194
- layer = [[MLNFillExtrusionStyleLayer alloc] initWithIdentifier:_id source:source];
195
- } else if ([type isEqualToString:@"raster"]) {
196
- layer = [[MLNRasterStyleLayer alloc] initWithIdentifier:_id source:source];
197
- } else {
198
- RCTLogError(@"Unknown layer type: %@", type);
199
- return nil;
180
+ switch (_layerType) {
181
+ case MLRNLayerTypeCircle:
182
+ layer = [[MLNCircleStyleLayer alloc] initWithIdentifier:_id source:source];
183
+ break;
184
+ case MLRNLayerTypeColorRelief:
185
+ RCTLogError(@"ColorRelief layer type is not supported on iOS");
186
+ return nil;
187
+ case MLRNLayerTypeFill:
188
+ layer = [[MLNFillStyleLayer alloc] initWithIdentifier:_id source:source];
189
+ break;
190
+ case MLRNLayerTypeFillExtrusion:
191
+ layer = [[MLNFillExtrusionStyleLayer alloc] initWithIdentifier:_id source:source];
192
+ break;
193
+ case MLRNLayerTypeHeatmap:
194
+ layer = [[MLNHeatmapStyleLayer alloc] initWithIdentifier:_id source:source];
195
+ break;
196
+ case MLRNLayerTypeHillshade:
197
+ layer = [[MLNHillshadeStyleLayer alloc] initWithIdentifier:_id source:source];
198
+ break;
199
+ case MLRNLayerTypeLine:
200
+ layer = [[MLNLineStyleLayer alloc] initWithIdentifier:_id source:source];
201
+ break;
202
+ case MLRNLayerTypeRaster:
203
+ layer = [[MLNRasterStyleLayer alloc] initWithIdentifier:_id source:source];
204
+ break;
205
+ case MLRNLayerTypeSymbol:
206
+ layer = [[MLNSymbolStyleLayer alloc] initWithIdentifier:_id source:source];
207
+ break;
208
+ default:
209
+ RCTLogError(@"Unknown layer type: %ld", (long)_layerType);
210
+ return nil;
200
211
  }
201
212
 
202
213
  // Set sourceLayerIdentifier for vector layers
@@ -216,34 +227,38 @@
216
227
  return [self isAddedToMap];
217
228
  };
218
229
 
219
- if ([_styleLayer isKindOfClass:[MLNFillStyleLayer class]]) {
220
- [style fillLayer:(MLNFillStyleLayer *)_styleLayer withReactStyle:_reactStyle isValid:isValid];
221
- } else if ([_styleLayer isKindOfClass:[MLNLineStyleLayer class]]) {
222
- [style lineLayer:(MLNLineStyleLayer *)_styleLayer withReactStyle:_reactStyle isValid:isValid];
223
- } else if ([_styleLayer isKindOfClass:[MLNSymbolStyleLayer class]]) {
224
- [style symbolLayer:(MLNSymbolStyleLayer *)_styleLayer
225
- withReactStyle:_reactStyle
226
- isValid:isValid];
230
+ if ([_styleLayer isKindOfClass:[MLNBackgroundStyleLayer class]]) {
231
+ [style backgroundLayer:(MLNBackgroundStyleLayer *)_styleLayer
232
+ withReactStyle:_reactStyle
233
+ isValid:isValid];
227
234
  } else if ([_styleLayer isKindOfClass:[MLNCircleStyleLayer class]]) {
228
235
  [style circleLayer:(MLNCircleStyleLayer *)_styleLayer
229
236
  withReactStyle:_reactStyle
230
237
  isValid:isValid];
231
- } else if ([_styleLayer isKindOfClass:[MLNHeatmapStyleLayer class]]) {
232
- [style heatmapLayer:(MLNHeatmapStyleLayer *)_styleLayer
233
- withReactStyle:_reactStyle
234
- isValid:isValid];
238
+ } else if ([_styleLayer isKindOfClass:[MLNFillStyleLayer class]]) {
239
+ [style fillLayer:(MLNFillStyleLayer *)_styleLayer withReactStyle:_reactStyle isValid:isValid];
235
240
  } else if ([_styleLayer isKindOfClass:[MLNFillExtrusionStyleLayer class]]) {
236
241
  [style fillExtrusionLayer:(MLNFillExtrusionStyleLayer *)_styleLayer
237
242
  withReactStyle:_reactStyle
238
243
  isValid:isValid];
244
+ } else if ([_styleLayer isKindOfClass:[MLNHeatmapStyleLayer class]]) {
245
+ [style heatmapLayer:(MLNHeatmapStyleLayer *)_styleLayer
246
+ withReactStyle:_reactStyle
247
+ isValid:isValid];
248
+ } else if ([_styleLayer isKindOfClass:[MLNHillshadeStyleLayer class]]) {
249
+ [style hillshadeLayer:(MLNHillshadeStyleLayer *)_styleLayer
250
+ withReactStyle:_reactStyle
251
+ isValid:isValid];
252
+ } else if ([_styleLayer isKindOfClass:[MLNLineStyleLayer class]]) {
253
+ [style lineLayer:(MLNLineStyleLayer *)_styleLayer withReactStyle:_reactStyle isValid:isValid];
239
254
  } else if ([_styleLayer isKindOfClass:[MLNRasterStyleLayer class]]) {
240
255
  [style rasterLayer:(MLNRasterStyleLayer *)_styleLayer
241
256
  withReactStyle:_reactStyle
242
257
  isValid:isValid];
243
- } else if ([_styleLayer isKindOfClass:[MLNBackgroundStyleLayer class]]) {
244
- [style backgroundLayer:(MLNBackgroundStyleLayer *)_styleLayer
245
- withReactStyle:_reactStyle
246
- isValid:isValid];
258
+ } else if ([_styleLayer isKindOfClass:[MLNSymbolStyleLayer class]]) {
259
+ [style symbolLayer:(MLNSymbolStyleLayer *)_styleLayer
260
+ withReactStyle:_reactStyle
261
+ isValid:isValid];
247
262
  }
248
263
  }
249
264
 
@@ -14,6 +14,31 @@
14
14
 
15
15
  using namespace facebook::react;
16
16
 
17
+ static MLRNLayerType MLRNLayerTypeFromCppEnum(MLRNLayerLayerType layerType) {
18
+ switch (layerType) {
19
+ case MLRNLayerLayerType::Background:
20
+ return MLRNLayerTypeBackground;
21
+ case MLRNLayerLayerType::Circle:
22
+ return MLRNLayerTypeCircle;
23
+ case MLRNLayerLayerType::ColorRelief:
24
+ return MLRNLayerTypeColorRelief;
25
+ case MLRNLayerLayerType::Fill:
26
+ return MLRNLayerTypeFill;
27
+ case MLRNLayerLayerType::FillExtrusion:
28
+ return MLRNLayerTypeFillExtrusion;
29
+ case MLRNLayerLayerType::Heatmap:
30
+ return MLRNLayerTypeHeatmap;
31
+ case MLRNLayerLayerType::Hillshade:
32
+ return MLRNLayerTypeHillshade;
33
+ case MLRNLayerLayerType::Line:
34
+ return MLRNLayerTypeLine;
35
+ case MLRNLayerLayerType::Raster:
36
+ return MLRNLayerTypeRaster;
37
+ case MLRNLayerLayerType::Symbol:
38
+ return MLRNLayerTypeSymbol;
39
+ }
40
+ }
41
+
17
42
  // MARK: - MLRNLayerComponentView
18
43
 
19
44
  @interface MLRNLayerComponentView () <RCTMLRNLayerViewProtocol>
@@ -64,7 +89,7 @@ using namespace facebook::react;
64
89
  }
65
90
 
66
91
  if (oldViewProps.layerType != newViewProps.layerType) {
67
- _view.layerType = RCTNSStringFromString(newViewProps.layerType);
92
+ _view.layerType = MLRNLayerTypeFromCppEnum(newViewProps.layerType);
68
93
  }
69
94
 
70
95
  if (oldViewProps.source != newViewProps.source) {
@@ -0,0 +1,10 @@
1
+ #import "MLRNTileSource.h"
2
+
3
+ #import <MapLibre/MapLibre.h>
4
+
5
+ @interface MLRNRasterDEMSource : MLRNTileSource
6
+
7
+ @property (nonatomic, strong) NSNumber *tileSize;
8
+ @property (nonatomic, copy) NSString *encoding;
9
+
10
+ @end
@@ -0,0 +1,39 @@
1
+ #import "MLRNRasterDEMSource.h"
2
+
3
+ @implementation MLRNRasterDEMSource
4
+
5
+ - (nullable MLNSource *)makeSource {
6
+ if (self.url != nil) {
7
+ NSURL *url = [NSURL URLWithString:self.url];
8
+ if (self.tileSize != nil) {
9
+ return [[MLNRasterDEMSource alloc] initWithIdentifier:self.id
10
+ configurationURL:url
11
+ tileSize:[self.tileSize floatValue]];
12
+ }
13
+ return [[MLNRasterDEMSource alloc] initWithIdentifier:self.id configurationURL:url];
14
+ }
15
+ return [[MLNRasterDEMSource alloc] initWithIdentifier:self.id
16
+ tileURLTemplates:self.tileUrlTemplates
17
+ options:[self getOptions]];
18
+ }
19
+
20
+ - (NSDictionary<MLNTileSourceOption, id> *)getOptions {
21
+ NSMutableDictionary<MLNTileSourceOption, id> *options =
22
+ [[NSMutableDictionary alloc] initWithDictionary:[super getOptions]];
23
+
24
+ if (self.tileSize != nil) {
25
+ options[MLNTileSourceOptionTileSize] = _tileSize;
26
+ }
27
+
28
+ if (self.encoding != nil) {
29
+ MLNDEMEncoding demEncoding = MLNDEMEncodingMapbox;
30
+ if ([self.encoding isEqualToString:@"terrarium"]) {
31
+ demEncoding = MLNDEMEncodingTerrarium;
32
+ }
33
+ options[MLNTileSourceOptionDEMEncoding] = @(demEncoding);
34
+ }
35
+
36
+ return options;
37
+ }
38
+
39
+ @end
@@ -0,0 +1,9 @@
1
+ #import <React/RCTViewComponentView.h>
2
+
3
+ @class MLRNRasterDEMSource;
4
+
5
+ @interface MLRNRasterDEMSourceComponentView : RCTViewComponentView
6
+
7
+ @property (nonatomic, readonly) MLRNRasterDEMSource *rasterDEMSource;
8
+
9
+ @end
@@ -0,0 +1,131 @@
1
+ #import "MLRNRasterDEMSourceComponentView.h"
2
+
3
+ #import <react/renderer/components/MapLibreReactNativeSpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/MapLibreReactNativeSpec/EventEmitters.h>
5
+ #import <react/renderer/components/MapLibreReactNativeSpec/Props.h>
6
+ #import <react/renderer/components/MapLibreReactNativeSpec/RCTComponentViewHelpers.h>
7
+
8
+ #import "RCTFabricComponentsPlugins.h"
9
+
10
+ #import <MapLibre/MapLibre.h>
11
+ #import <React/RCTConversions.h>
12
+ #import "MLRNRasterDEMSource.h"
13
+
14
+ using namespace facebook::react;
15
+
16
+ // MARK: - MLRNRasterDEMSourceComponentView
17
+
18
+ @interface MLRNRasterDEMSourceComponentView () <RCTMLRNRasterDEMSourceViewProtocol>
19
+
20
+ @end
21
+
22
+ @implementation MLRNRasterDEMSourceComponentView {
23
+ MLRNRasterDEMSource *_view;
24
+ }
25
+
26
+ - (instancetype)initWithFrame:(CGRect)frame {
27
+ if (self = [super initWithFrame:frame]) {
28
+ static const auto defaultProps = std::make_shared<const MLRNRasterDEMSourceProps>();
29
+ _props = defaultProps;
30
+ [self prepareView];
31
+ }
32
+
33
+ return self;
34
+ }
35
+
36
+ - (void)prepareView {
37
+ _view = [[MLRNRasterDEMSource alloc] init];
38
+ self.contentView = _view;
39
+ }
40
+
41
+ - (MLRNRasterDEMSource *)rasterDEMSource {
42
+ return _view;
43
+ }
44
+
45
+ #pragma mark - RCTComponentViewProtocol
46
+
47
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
48
+ return concreteComponentDescriptorProvider<MLRNRasterDEMSourceComponentDescriptor>();
49
+ }
50
+
51
+ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps {
52
+ const auto &oldViewProps = *std::static_pointer_cast<const MLRNRasterDEMSourceProps>(_props);
53
+ const auto &newViewProps = *std::static_pointer_cast<const MLRNRasterDEMSourceProps>(props);
54
+
55
+ if (oldViewProps.id != newViewProps.id) {
56
+ _view.id = RCTNSStringFromString(newViewProps.id);
57
+ }
58
+
59
+ if (oldViewProps.url != newViewProps.url) {
60
+ _view.url = RCTNSStringFromStringNilIfEmpty(newViewProps.url);
61
+ }
62
+
63
+ if (oldViewProps.tiles != newViewProps.tiles) {
64
+ if (newViewProps.tiles.size() > 0) {
65
+ NSMutableArray *tiles = [NSMutableArray arrayWithCapacity:newViewProps.tiles.size()];
66
+ for (const auto &tile : newViewProps.tiles) {
67
+ [tiles addObject:RCTNSStringFromString(tile)];
68
+ }
69
+ _view.tileUrlTemplates = tiles;
70
+ } else {
71
+ _view.tileUrlTemplates = nil;
72
+ }
73
+ }
74
+
75
+ if (oldViewProps.minzoom != newViewProps.minzoom) {
76
+ _view.minZoomLevel = newViewProps.minzoom >= 0 ? @(newViewProps.minzoom) : nil;
77
+ }
78
+
79
+ if (oldViewProps.maxzoom != newViewProps.maxzoom) {
80
+ _view.maxZoomLevel = newViewProps.maxzoom >= 0 ? @(newViewProps.maxzoom) : nil;
81
+ }
82
+
83
+ if (oldViewProps.attribution != newViewProps.attribution) {
84
+ _view.attribution = RCTNSStringFromStringNilIfEmpty(newViewProps.attribution);
85
+ }
86
+
87
+ if (oldViewProps.tileSize != newViewProps.tileSize) {
88
+ _view.tileSize = newViewProps.tileSize >= 0 ? @(newViewProps.tileSize) : nil;
89
+ }
90
+
91
+ if (oldViewProps.encoding != newViewProps.encoding) {
92
+ switch (newViewProps.encoding) {
93
+ case MLRNRasterDEMSourceEncoding::Terrarium:
94
+ _view.encoding = @"terrarium";
95
+ break;
96
+ case MLRNRasterDEMSourceEncoding::Mapbox:
97
+ default:
98
+ _view.encoding = @"mapbox";
99
+ break;
100
+ }
101
+ }
102
+
103
+ [super updateProps:props oldProps:oldProps];
104
+ }
105
+
106
+ - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView
107
+ index:(NSInteger)index {
108
+ if ([childComponentView isKindOfClass:[RCTViewComponentView class]] &&
109
+ ((RCTViewComponentView *)childComponentView).contentView) {
110
+ [_view insertReactSubview:(id<RCTComponent>)((RCTViewComponentView *)childComponentView)
111
+ .contentView
112
+ atIndex:index];
113
+ }
114
+ [super mountChildComponentView:childComponentView index:index];
115
+ }
116
+
117
+ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView
118
+ index:(NSInteger)index {
119
+ if ([childComponentView isKindOfClass:[RCTViewComponentView class]] &&
120
+ ((RCTViewComponentView *)childComponentView).contentView) {
121
+ [_view removeReactSubview:(id<RCTComponent>)((RCTViewComponentView *)childComponentView)
122
+ .contentView];
123
+ }
124
+ [super unmountChildComponentView:childComponentView index:index];
125
+ }
126
+
127
+ Class<RCTComponentViewProtocol> MLRNRasterDEMSourceCls(void) {
128
+ return MLRNRasterDEMSourceComponentView.class;
129
+ }
130
+
131
+ @end
@@ -10,7 +10,19 @@ import type { StyleValue } from "../../utils/StyleValue";
10
10
 
11
11
  export interface NativeProps extends ViewProps {
12
12
  id: string;
13
- layerType: string;
13
+ layerType?: CodegenTypes.WithDefault<
14
+ | "background"
15
+ | "circle"
16
+ | "color-relief"
17
+ | "fill"
18
+ | "fill-extrusion"
19
+ | "heatmap"
20
+ | "hillshade"
21
+ | "line"
22
+ | "raster"
23
+ | "symbol",
24
+ "background"
25
+ >;
14
26
 
15
27
  source?: string;
16
28
  sourceLayer?: string;