Hi,
I'm trying to refresh a featureLayer in Esri Leaflet 3.0.3 (but this also happens in previous versions) that calls an AGOL FeatureServer service, with the refresh() method and setInterval, but it does not work as expected.
The implementation is very simple:
var testIcons = {
'A': L.icon({
iconUrl: 'A.png',
iconSize: [35, 35],
iconAnchor: [6, 6],
popupAnchor: [-3, -5],
}),
'B': L.icon({
iconUrl: 'B.png',
iconSize: [35, 35],
iconAnchor: [6, 6],
popupAnchor: [-3, -5],
}),
};
var testLayer = L.esri.featureLayer({
url: 'https://services5.arcgis.com/xxxxx/ArcGIS/rest/services/NAME/FeatureServer/0',
pointToLayer: function (geojson, latlng) {
return L.marker(latlng, {
icon: testIcons[geojson.properties.Status]
});
}
}).addTo(map);
testLayer.bindPopup(function (layer) {
return L.Util.template('<b>Name:</b> {Name}</br><b>Status:</b> {Status}', layer.feature.properties);
});
setInterval(function() {
testLayer.refresh();
}, 120000);//2min
Looking at the browser console, the layer refreshes at the given interval, but it loads the same data again. Sometimes, after a long period with the same data on map, it changes, but very outdated when compared with the service.
I've some other layers working fine and configured exactly the same way, but they are MapServer services.
So, my question is, refresh() method does not work well with FeatureServer services in featureLayers? The implementation needs to be different than with MapServer services? Or this should work and it can be a bug?
Thank you very much!
Solved! Go to Solution.
Hi Pedro,
We began doing more investigation on our side and trying out manual edits and the refresh() method, and I've a follow up question for you.
Is the point feature in question on your FeatureServer layer being added and deleted, or is it being updated with new attributes and/or geometry?
Thanks
Hi @Anonymous User
Thanks again for taking a look on this!
There are just attribute and geometry updates. For instance, a new point is added with it's attributes, then it is regularly updated until it is deleted / hidded (in this case I don't know if it's permanently deleted or just hidded). Anyway, once a new point is added, at least the "EstadoAgrupado" field evolves from "Em Curso", to "Em Resolução" and finally to "Em Conclusão". The point position can also change slightly in the process.
The FeatureServer layer exists and is static, what changes is the content, both geometries and attributes.
Thanks!
Thanks for the clarifying info! We may have a fix brewing and ready soon. Look for an update early in the week. https://github.com/Esri/esri-leaflet/pull/1304