martin icon indicating copy to clipboard operation
martin copied to clipboard

Set id to feature

Open korywka opened this issue 4 years ago • 3 comments

Is there a way to set id to feature (last param of ST_AsMVT function)?

id from table is not passed to feature id.

image

Or int value:

image

korywka avatar Mar 16 '20 10:03 korywka

Hi! You can do it in your frontend as well (Mapbox GL JS). Call your id (int or string) on the function source and then:

map.addSource('counties', {
  "type": "vector",
  "url" || "tiles": "your url / tiles",
  "promoteId": "your id"
});

AdriSolid avatar Mar 28 '20 08:03 AdriSolid

@AdriSolid For now I do it with custom function and ST_AsMVT (https://postgis.net/docs/ST_AsMVT.html) takes last param as feature_id_name, but your advice is very helpful too. Thanks! Will leave doc link here for the community: https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId

korywka avatar Mar 28 '20 16:03 korywka

great idea @AdriSolid but that is a very Mapbox GL specific feature. I do, think this feature is very valuable to have in API itself that way it's available agnostic of which client is being used to render the tiles.

shaunakv1 avatar Sep 30 '21 02:09 shaunakv1

This is partially already implemented, and will be cleaned up and fixed in #380

nyurik avatar Dec 04 '22 14:12 nyurik