1

I am modifying features from layer and would like to use similar to "setData()" to a vector layer? From googling some places i read that its not possible to use that setData function to vectors and only to geojsons.

What i am doing is first i get the feature properties from layer

let features = this.map.queryRenderedFeatures({layers:["maakunta-fills"]}).map(item=>{
        const copied = {...item}
        copied.properties.modified = "some_modified_value"
        return copied;
    });

and then my wish is i can do something like : this.map.getSource("sourcename").setData(features) But mapbox will throw error by saying setData is not function (i assume because this "sourcename" is a vector tile. Which looks like this:

this.map.addSource("maakunta", {
            type: "vector",
            tiles: [tileServiceURL + "base.maakunta/{z}/{x}/{y}.pbf"],
            promoteId: "id"
        });
eko
  • 329
  • 2
  • 11

1 Answers1

0

The best way to do this is by using setFeatureState. It will not change the vector data but you can change the style and intercept any click events and push the updated data. This of course is limited to the current client session. Ideally you would be updating the source data in a database for example so that when a new user views a new db tile request they will have access to the new data.

malcolm
  • 455
  • 4
  • 13