Closed dandev98 closed 4 years ago
For me, I miss something like this:
realtime.on('update', function() {
map.fitBounds(realtime.getBounds(), {maxZoom: 3});
....
update your feature (style, popup etc...) here
});
For the original question/issue by @dandev98, the issue is that you're using onEachFeature
incorrectly: the second argument is not a LatLng
, it's the layer created by Leaflet for this feature. Also, that function should not return a layer, it should work with the layer instance passed to it. So creating a layer and returning it will not accomplish anything. See the docs for onEachFeature
: https://leafletjs.com/reference-1.6.0.html#geojson-oneachfeature
If what you need is to update the polygon's styling, I suggest you instead look at the style
option.
Don't work, I tried with pointToLayer , the polygon but no change a simple color, only with polygon My code
const getShapesLayerGroupRealTime = (idCliente) => {
const shapesLayerGroup = new L.LayerGroup();
const realtimeReference = L.realtime(
{
url: ENDPOINT_DATA_GEOSERVICIOS,
method: 'POST',
body: JSON.stringify({
solicitud: 'shpCliente',
idCliente: idCliente,
}),
},
{
container: shapesLayerGroup,
interval: REALTIME_INTERVAL_SECONDS * 1000,
pointToLayer: (feature, latlng) => (
L.polygon(latlng,{
color: '#51F03B'
})
),
removeMissing: true,
updateFeature: (feature, oldLayer, newLayer) => {
console.log('feature', feature.properties.nivel )
console.log('nueva capa',newLayer)
return newLayer
},
}
);
return [shapesLayerGroup, realtimeReference];
}
Hi
I am trying to display a polygon from an external geojson file, the brochure loads the file but does not update the polygon in real time.
areas.json: