Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ class NativeMapViewModule(context: ReactApplicationContext, val viewTagResolver:
}
}

override fun setStyleLayerProperty(
viewRef: ViewRefTag?,
layerId: String,
propertyName: String,
propertyValue: String,
promise: Promise
) {
withMapViewOnUIThread(viewRef, promise) {
it.setStyleLayerProperty(layerId, propertyName, propertyValue)

promise.resolve(null)
}
}

override fun getCenter(viewRef: ViewRefTag?, promise: Promise) {
withMapViewOnUIThread(viewRef, promise) {
it.getCenter(createCommandResponse(promise))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,41 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
}
}
}

fun setStyleLayerProperty(
layerId: String,
propertyName: String,
propertyValue: String
): Boolean {
if (mMap == null) {
Logger.e("MapView", "setStyleLayerProperty, map is null")
return false
}

val style = mMap.getStyle()
if (style == null) {
Logger.e("MapView", "setStyleLayerProperty, style is null")
return false
}

try {
val result = style.setStyleLayerProperty(
layerId,
propertyName,
Value.valueOf(propertyValue)
)

if (result.isError) {
Logger.e("MapView", "setStyleLayerProperty error: ${result.error}")
return false
}

return true
} catch (e: Exception) {
Logger.e("MapView", "setStyleLayerProperty exception: ${e.message}")
return false
}
}
// endregion

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public NativeMapViewModuleSpec(ReactApplicationContext reactContext) {
@DoNotStrip
public abstract void setSourceVisibility(@Nullable Double viewRef, boolean visible, String sourceId, String sourceLayerId, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void setStyleLayerProperty(@Nullable Double viewRef, String layerId, String propertyName, String propertyValue, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void getCenter(@Nullable Double viewRef, Promise promise);
Expand Down
18 changes: 18 additions & 0 deletions docs/MapView.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,22 @@ await this._map.setSourceVisibility(false, 'composite', 'building')
```


### setStyleLayerProperty(layerId, propertyName, propertyValue)

Sets the value of a property for a specific layer referencing the specified `layerId`

#### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `layerId` | `string` | `Yes` | layerId |
| `propertyName` | `string` | `Yes` | propertyName |
| `propertyValue` | `string` | `Yes` | propertyValue |



```javascript
await this._map.setStyleLayerProperty('my-layer', 'visibility', 'none')
```



36 changes: 36 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3726,6 +3726,42 @@
"examples": [
"\nawait this._map.setSourceVisibility(false, 'composite', 'building')\n\n"
]
},
{
"name": "setStyleLayerProperty",
"docblock": "Sets the value of a property for a specific layer referencing the specified `layerId`\n\n@example\nawait this._map.setStyleLayerProperty('my-layer', 'visibility', 'none')\n\n@param {String} layerId - layerId\n@param {String} propertyName - propertyName\n@param {String} propertyValue - propertyValue",
"modifiers": [],
"params": [
{
"name": "layerId",
"description": "layerId",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "propertyName",
"description": "propertyName",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "propertyValue",
"description": "propertyValue",
"type": {
"name": "string"
},
"optional": false
}
],
"returns": null,
"description": "Sets the value of a property for a specific layer referencing the specified `layerId`",
"examples": [
"\nawait this._map.setStyleLayerProperty('my-layer', 'visibility', 'none')\n\n"
]
}
],
"props": [
Expand Down
12 changes: 12 additions & 0 deletions ios/RNMBX/RNMBXMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,18 @@ extension RNMBXMapView {
}
}

extension RNMBXMapView {
func setStyleLayerProperty(layerId: String, propertyName: String, propertyValue: Any) -> Void {
let style = self.mapboxMap.style

do {
try style.setLayerProperty(for: layerId, property: propertyName, value: propertyValue)
} catch {
Logger.log(level: .error, message: "Cannot set property \(propertyName) on layer: \(layerId)")
}
}
}

class RNMBXPointAnnotationManager : AnnotationInteractionDelegate {
weak var selected : RNMBXPointAnnotation? = nil
private var draggedAnnotation: PointAnnotation?
Expand Down
10 changes: 10 additions & 0 deletions ios/RNMBX/RNMBXMapViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ extension RNMBXMapViewManager {
view.setSourceVisibility(visible, sourceId: sourceId, sourceLayerId:sourceLayerId)
resolver(nil)
}

@objc public static func setStyleLayerProperty(_ view: RNMBXMapView,
layerId: String,
propertyName: String,
propertyValue: String,
resolver: @escaping RCTPromiseResolveBlock,
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
view.setStyleLayerProperty(layerId: layerId, propertyName: propertyName, propertyValue: propertyValue)
resolver(nil)
}

@objc public static func getCenter(_ view: RNMBXMapView, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
view.withMapboxMap { map in
Expand Down
11 changes: 11 additions & 0 deletions ios/RNMBX/RNMBXMapViewModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ - (void)withMapView:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXMapView *))b
} reject:reject methodName:@"setSourceVisibility"];
}

RCT_EXPORT_METHOD(setStyleLayerProperty:(nonnull NSNumber*)viewRef
layerId:(NSString *)layerId
propertyName:(NSString *)propertyName
propertyValue:(id)propertyValue
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self withMapView:viewRef block:^(RNMBXMapView *view) {
[RNMBXMapViewManager setStyleLayerProperty:view layerId:layerId propertyName:propertyName propertyValue:propertyValue resolver:resolve rejecter:reject];
} reject:reject methodName:@"setStyleLayerProperty"];
}

RCT_EXPORT_METHOD(querySourceFeatures:(nonnull NSNumber*)viewRef sourceId:(NSString*)sourceId withFilter:(NSArray<id>*)withFilter withSourceLayerIDs:(NSArray<NSString*>*)withSourceLayerIDs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
[self withMapView:viewRef block:^(RNMBXMapView *view) {
[RNMBXMapViewManager querySourceFeatures:view withSourceId:sourceId withFilter:withFilter withSourceLayerIds:withSourceLayerIDs resolver:resolve rejecter:reject];
Expand Down
1 change: 1 addition & 0 deletions setup-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ NativeModules.RNMBXMapViewModule = {
takeSnap: jest.fn(),
queryTerrainElevation: jest.fn(),
setSourceVisibility: jest.fn(),
setStyleLayerProperty: jest.fn(),
getCenter: jest.fn(),
getCoordinateFromView: jest.fn(),
getPointInView: jest.fn(),
Expand Down
22 changes: 22 additions & 0 deletions src/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,28 @@ class MapView extends NativeBridgeComponent(
]);
}

/**
* Sets the value of a property for a specific layer referencing the specified `layerId`
*
* @example
* await this._map.setStyleLayerProperty('my-layer', 'visibility', 'none')
*
* @param {String} layerId - layerId
* @param {String} propertyName - propertyName
* @param {String} propertyValue - propertyValue
*/
setStyleLayerProperty(
layerId: string,
propertyName: string,
propertyValue: string,
) {
this._runNative<void>('setStyleLayerProperty', [
layerId,
propertyName,
propertyValue,
]);
}

_decodePayload<T>(payload: T | string): T {
if (typeof payload === 'string') {
return JSON.parse(payload);
Expand Down
6 changes: 6 additions & 0 deletions src/specs/NativeMapViewModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export interface Spec extends TurboModule {
sourceId: string,
sourceLayerId: string,
) => Promise<Object>;
setStyleLayerProperty: (
viewRef: Int32 | null,
layerId: string,
propertyName: string,
propertyValue: string,
) => Promise<Object>;
getCenter: (viewRef: Int32 | null) => Promise<Object>;
getCoordinateFromView: (
viewRef: Int32 | null,
Expand Down
Loading