简体   繁体   中英

How to edit/modify layer source in existing Leaflet map in React?

I have created Leaflet map using Carto and React, as it is described here https://github.com/IagoLast/cartojs-react-example , using:

const cartoSource = new carto.source.SQL(source);
const cartoStyle = new carto.style.CartoCSS(style);

this.layer = new carto.layer.Layer(cartoSource, cartoStyle);
client.getLeafletLayer().addTo(this.context.map);

Now i need to change this layer source dynamically somehow. Is it possible to change the layer source and how to do it? How to find specified layer from leaflet map? Or i need to delete this layer and create the new one?.

You would need to apply setQuery method on your cartoSource object. If necessary, you would need to change the style.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM