Skip to content

Commit

Permalink
feat: add setFeatureState / getFeatureState / removeFeatureState
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnative committed Jul 5, 2023
1 parent eef0506 commit 7413f35
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,45 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
}
}

fun setFeatureState(
sourceId: String,
sourceLayerId: String?,
featureId: String,
state: Map<String, Any>
) {
if (mMap == null) {
Logger.e("MapView", "setFeatureState, map is null")
return
}
mMap.setFeatureState(sourceId, sourceLayerId, featureId, state)
}

fun getFeatureState(
callbackID: String?,
sourceId: String,
sourceLayerId: String?,
featureId: String
) {
val result = mMap?.getFeatureState(sourceId, sourceLayerId, featureId) { result ->
sendResponse(callbackID) { response ->
if (result != null) {
response.putString("data", "test")
} else {
response.putNull("data")
}
}
}
}

fun removeFeatureState(
sourceId: String,
sourceLayerId: String?,
featureId: String,
stateKey: String?
) {
mMap?.removeFeatureState(sourceId, sourceLayerId, featureId, stateKey)
}

// endregion

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,30 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext) :
args!!.getString(3)
);
}
"setFeatureState" -> {
mapView!!.setFeatureState(
args!!.getString(1),
args!!.getString(2),
args!!.getString(3),
args!!.getString(4),
);
}
"getFeatureState" -> {
mapView!!.getFeatureState(
args!!.getString(0),
args!!.getString(1),
args!!.getString(2),
args!!.getString(3),
);
}
"removeFeatureState" -> {
mapView!!.removeFeatureState(
args!!.getString(1),
args!!.getString(2),
args!!.getString(3),
args!!.getString(4)
);
}
"queryRenderedFeaturesAtPoint" -> {
mapView.queryRenderedFeaturesAtPoint(
args!!.getString(0),
Expand Down
56 changes: 56 additions & 0 deletions docs/MapView.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,62 @@ await this._map.setSourceVisibility(false, 'composite', 'building')
```


### setFeatureState(sourceId[, sourceLayerId], featureId, state)

Update the state map of a feature within a style source. Update entries in the state map of a given feature within a style source.<br/>Only entries listed in the state map will be updated. An entry in the feature state map that is not listed in state will retain its previous value.

#### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `sourceId` | `string` | `Yes` | Identifier of the target source (e.g. 'composite') |
| `sourceLayerId` | `String` | `No` | Identifier of the target source-layer (e.g. 'building') |
| `featureId` | `string` | `Yes` | Identifier of the feature whose state should be updated. |
| `state` | `{[key:string]:any}` | `Yes` | undefined |



```javascript
await this._map.setFeatureState('composite', 'building', 'id-01, { active: true })
```
### getFeatureState(sourceId[, sourceLayerId], featureId)
Get the state map of a feature within a style source.
#### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `sourceId` | `string` | `Yes` | Identifier of the target source (e.g. 'composite') |
| `sourceLayerId` | `String` | `No` | Identifier of the target source-layer (e.g. 'building') |
| `featureId` | `string` | `Yes` | Identifier of the feature whose state should be retrieved. |
```javascript
await this._map.getFeatureState('composite', 'building', 'id')
```
### removeFeatureState(sourceId[, sourceLayerId], featureId[, stateKey])
Removes entries from a feature state object.<br/><br/>Remove a specified property or all property from a feature’s state object, depending on the value of stateKey.
#### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `sourceId` | `string` | `Yes` | The style source identifier |
| `sourceLayerId` | `String` | `No` | Identifier of the target source-layer (e.g. 'building') |
| `featureId` | `string` | `Yes` | Identifier of the feature whose state should be updated. |
| `stateKey` | `String` | `No` | The key of the property to remove. If null, all feature’s state object properties are removed. Defaults to null. |
```javascript
this._map.removeFeatureState('composite', 'building', 'id', 'active')
```
### showAttribution()
Show the attribution and telemetry action sheet.<br/>If you implement a custom attribution button, you should add this action to the button.
Expand Down
150 changes: 150 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,156 @@
"\nawait this._map.setSourceVisibility(false, 'composite', 'building')\n\n"
]
},
{
"name": "setFeatureState",
"docblock": "Update the state map of a feature within a style source. Update entries in the state map of a given feature within a style source.\nOnly entries listed in the state map will be updated. An entry in the feature state map that is not listed in state will retain its previous value.\n\n@example\nawait this._map.setFeatureState('composite', 'building', 'id-01, { active: true })\n\n@param {String} sourceId - Identifier of the target source (e.g. 'composite')\n@param {String=} sourceLayerId - Identifier of the target source-layer (e.g. 'building')\n@param {String} featureId - Identifier of the feature whose state should be updated.\n@param",
"modifiers": [],
"params": [
{
"name": "sourceId",
"description": "Identifier of the target source (e.g. 'composite')",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "sourceLayerId",
"description": "Identifier of the target source-layer (e.g. 'building')",
"type": {
"name": "String"
},
"optional": true
},
{
"name": "featureId",
"description": "Identifier of the feature whose state should be updated.",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "state",
"optional": false,
"type": {
"name": "{[key:string]:any}"
}
}
],
"returns": null,
"description": "Update the state map of a feature within a style source. Update entries in the state map of a given feature within a style source.\nOnly entries listed in the state map will be updated. An entry in the feature state map that is not listed in state will retain its previous value.",
"examples": [
"\nawait this._map.setFeatureState('composite', 'building', 'id-01, { active: true })\n\n"
]
},
{
"name": "getFeatureState",
"docblock": "Get the state map of a feature within a style source.\n\n@example\nawait this._map.getFeatureState('composite', 'building', 'id')\n\n@param {String} sourceId - Identifier of the target source (e.g. 'composite')\n@param {String=} sourceLayerId - Identifier of the target source-layer (e.g. 'building')\n@param {String} featureId - Identifier of the feature whose state should be retrieved.\n@returns {Promise<{ [key: string]: any }>} Promise that resolves to the feature state object.",
"modifiers": [
"async"
],
"params": [
{
"name": "sourceId",
"description": "Identifier of the target source (e.g. 'composite')",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "sourceLayerId",
"description": "Identifier of the target source-layer (e.g. 'building')",
"type": {
"name": "String"
},
"optional": true
},
{
"name": "featureId",
"description": "Identifier of the feature whose state should be retrieved.",
"type": {
"name": "string"
},
"optional": false
}
],
"returns": {
"type": {
"name": "Promise",
"elements": [
{
"name": "signature",
"type": "object",
"raw": "{ [key: string]: any }",
"signature": {
"properties": [
{
"key": {
"name": "string"
},
"value": {
"name": "any",
"required": true
}
}
]
}
}
],
"raw": "Promise<{ [key: string]: any }>"
}
},
"description": "Get the state map of a feature within a style source.",
"examples": [
"\nawait this._map.getFeatureState('composite', 'building', 'id')\n\n"
]
},
{
"name": "removeFeatureState",
"docblock": "Removes entries from a feature state object.\n\nRemove a specified property or all property from a feature’s state object, depending on the value of stateKey.\n\n@example\nthis._map.removeFeatureState('composite', 'building', 'id', 'active')\n\n@param {String} sourceId - The style source identifier\n@param {String=} sourceLayerId - Identifier of the target source-layer (e.g. 'building')\n@param {String} featureId - Identifier of the feature whose state should be updated.\n@param {String} stateKey - The key of the property to remove. If null, all feature’s state object properties are removed. Defaults to null.",
"modifiers": [],
"params": [
{
"name": "sourceId",
"description": "The style source identifier",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "sourceLayerId",
"description": "Identifier of the target source-layer (e.g. 'building')",
"type": {
"name": "String"
},
"optional": true
},
{
"name": "featureId",
"description": "Identifier of the feature whose state should be updated.",
"type": {
"name": "string"
},
"optional": false
},
{
"name": "stateKey",
"description": "The key of the property to remove. If null, all feature’s state object properties are removed. Defaults to null.",
"type": {
"name": "String"
},
"optional": true
}
],
"returns": null,
"description": "Removes entries from a feature state object.\n\nRemove a specified property or all property from a feature’s state object, depending on the value of stateKey.",
"examples": [
"\nthis._map.removeFeatureState('composite', 'building', 'id', 'active')\n\n"
]
},
{
"name": "showAttribution",
"docblock": "Show the attribution and telemetry action sheet.\nIf you implement a custom attribution button, you should add this action to the button.",
Expand Down
Loading

0 comments on commit 7413f35

Please sign in to comment.