Last active
June 14, 2021 11:13
-
-
Save tobrun/abeed323a5b1ba60d7046daaa3e7b1ea to your computer and use it in GitHub Desktop.
Filter a layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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