Esri / Esri/esri-leaflet-vector
Add hitTest function for vector tile layers
- Dominant language
- JavaScript
- Stars
- 72
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the problem
Querying the attributes of a vector tile layer is a popular workflow that is very clunky in Esri Leaflet Vector. You can currently query layer attributes, but you can *only* do so by manually accessing the `layer._maplibreGL._glMap` and using functions from MapLibre GL JS.
Not only is that confusing and unintuitive, it is also tricky to document and relies on developers having an understanding of a different, unrelated mapping library.
### Describe the proposed solution
I would like the ability to query the attributes of a vector tile layer using a new method specific to the layer.
The ArcGIS JS Maps SDK just added support for VTL hit tests as a method of the map object: https://developers.arcgis.com/javascript/latest/sample-code/layers-vectortilelayer-hittest/
MapLibre GL JS also supports this as a method of the map object: https://maplibre.org/maplibre-gl-js/docs/examples/queryrenderedfeatures/
^ this method in MapLibre is how I am currently querying vector tiles in Esri Leaflet, by calling `layer._maplibreGL._glMap.queryRenderedFeatures()`. I would like to add an exposed method to the vector tile layer class that invokes this MapLibre method under the hood.
Desired implementation: `const features = layer.hitTest() //features contains the returned maplibre features`
### Alternatives considered
_No response_
### Additional Information
Here's another example of using the underlying maplibre map for a different purpose (styling the layer): https://developers.arcgis.com/documentation/mapping-apis-and-services/maps/basemap-places/#filter-places-by-style-category
This is a similar workflow that has to access the same private data variable, definitely not best practice either. And unfortunately not resolved by this feature request :(
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the vector tile layer class and inspect how its private _maplibreGL._glMap is used. Compare that existing queryRenderedFeatures workflow with the referenced MapLibre and ArcGIS examples; done means the layer exposes hitTest() and returns the underlying MapLibre features.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100