Hi
I am testing the Vector Tile API using this repo which is an excellent tool.
I would like to use the feature-id within the hits layer of a polygon, but get this: Error: The feature id parameter must be provided.
I do not find the id using:
map.on('click', () => {
// Find all features in one source layer in a vector source
const features = map.querySourceFeatures(sourceName, {
sourceLayer: renderMethod
})
console.log(JSON.stringify(features))
});
The Vector Tile API docs indicate that an id is contained in the response, but that does not appear to be the case or it is not being picked up on the client side.
@Joseph_Parish Thanks for bringing this up. I am seeing the same behavior.
For hits, feature.id is undefined, feature.properties._id contains the document id. For aggs, feature.id is undefined, feature.properties._key contains the bucket key.
Actually, vector tiles generated by the _mvt API do not use the id defined in the standard. This id is numeric but Elasticsearch ids are strings, therefore we are adding those identifiers as properties of the feature (hits later contains an _id property, aggs layer contains a _bucket _key property).
Thanks for the quick replies! Actually I started with queryRenderedFeatures and then added querySourceFeatures when not finding a feature id in the geoJson. I am a bit unclear on the resolution. Is it correct that the id will be added as a string value (and docs fixed) ? The Mapbox GL feature states docs state that the feature.id can be an integer or a string, but supports string values only when ... the string can be cast to an integer.
We use the feature state for a variety of data styling & joining configs starting with this ([simple example])(Create a hover effect | Mapbox GL JS | Mapbox). The Vector API is huge development for our app and we are in the process of changing out pre-generated tiles for tiles served from this API
As you noted, ids can have different data types as long as they are integers So no, we are not going to add values to those ids because our ids are not integers.
Unique identifiers are already added to the vector tiles as properties. In the hits layer you can find a property called _id and in the aggs layer you can find a property called _key.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.