Select to view content in your preferred language

Esri Leaflet refresh() method not working

3936
12
Jump to solution
11-16-2021 04:52 AM
PedroVenancio
Occasional Contributor

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!

0 Kudos
12 Replies
by Anonymous User
Not applicable

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

0 Kudos
PedroVenancio
Occasional Contributor

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!

0 Kudos
by Anonymous User
Not applicable

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