Ya he mapeado mi mapa como se muestra a continuación. Después del mapeo, agregué algunas propiedades a las características de mi mapa. Entonces, ¿cómo podría actualizar este mapa? Probé este map.getSource('lines').setData(responseData) pero obtuve dos mapas superpuestos. Cualquier ayuda es apreciada.
map.on('load', function() { map.addSource('lines', { type: 'geojson', data: responseData }); map.addLayer({ 'id': 'lines', 'type': 'fill', 'source': 'lines', 'layout': {}, 'paint': { 'fill-color': '#4682B4', 'fill-opacity': 0.8, } }); map.setPaintProperty('lines', 'fill-color', ['get', 'color']) })Agregando algunas propiedades al mapa ya mapeado.
const links = await fetch(`http://127.0.0.1:8000/api/network/4/edges/`); const linksData = await links.json(); let ar = map.getSource('lines')._data.features.map((item, i) => { let currentLayer = linksData.find( element => element.edge_id === item.properties.edge_id) item.properties.name = currentLayer.name item.properties.length = currentLayer.length item.properties.speed = currentLayer.speed item.properties.lanes = currentLayer.lanes })Actualizar el mapa después de agregar propiedades
map.getSource('lines').setData(responseData) map.setPaintProperty('lines', 'fill-color', ['interpolate', ['linear'], ['get', 'lanes'], 0, 'rgb(255, 255, 255)', 5, 'rgb(255, 0, 0)'])Pero en lugar de actualizar el mapa, obtuve dos mapas superpuestos. ¿Cómo puedo arreglarlo por favor?