Skip to content

Instantly share code, notes, and snippets.

@tobrun
Last active June 14, 2021 11:13
Show Gist options
  • Save tobrun/abeed323a5b1ba60d7046daaa3e7b1ea to your computer and use it in GitHub Desktop.
Save tobrun/abeed323a5b1ba60d7046daaa3e7b1ea to your computer and use it in GitHub Desktop.
Filter a layer
mapView.getMapboxMap().addOnMapClickListener { point ->
val queryRenderOptions = RenderedQueryOptions(arrayListOf("country-label"), null)
mapView.getMapboxMap().queryRenderedFeatures(
mapView.getMapboxMap().pixelForCoordinate(point),
queryRenderOptions
) {
val feature: Feature = it.getValueOrElse {
throw IllegalStateException()
}[0].feature
val layer = mapView.getMapboxMap().getStyle()!!.getLayer("country-label") as SymbolLayer
layer.filter(
Expression.match(
get("name_en"),
literal(feature.getStringProperty("name_en")), literal(true),
literal(false)
)
)
}
true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment