I followed the Mapbox Android tutorial to draw Polygons with geoJSON: https://www.mapbox.com/android-docs/maps/overview/data-driven-styling/#geojson
It works, but I thought that I could not call "the Polygon's id" in geoJSON from a layer.
I want to call this for detecting that I stand on the Polygons with smartphone location.
How can I call "the Polygon's id" in geoJSON from a layer?
Here are my codes(I wrote in Kotlin, and I know Android Java):
// draw polygon from geoJSON
private fun drawPolygon(map: MapboxMap) {
val source = GeoJsonSource("sourceId", GEOJSON_STRING) //following
map.addSource(source)
val layer = FillLayer("layerId", "sourceId")
map.addLayer(layer)
findPolygonId(layer)
}
// find polygon id from layer
findPolygonId(layer: Layer) {
val id = layer.find(geoJSON.id) <--- unknown code
}
GEOJSON_STRING is following:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 1, <-----------------I want call this!
"properties": {
"stroke": "#000000",
"stroke-width": 3.3,
"stroke-opacity": 0,
"fill": "#000000",
"fill-opacity": 1
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
Lng1,
Lat1
],
[
Lng2,
Lat1
],
[
Lng2,
Lat3
],
[
Lng1,
Lat3
],
[
Lng1,
Lat1
]
]
]
}
},
{
"type": "Feature",
"id": 2, <-----------------I want call this!
"properties": {
"stroke": "#000000",
"stroke-width": 3.3,
"stroke-opacity": 0,
"fill": "#000000",
"fill-opacity": 1
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
[
Lng4,
Lat4
],
[
Lng5,
Lat4
],
[
Lng5,
Lat6
],
[
Lng4,
Lat6
],
[
Lng4,
Lat4
]
]
]
}
}
]
}