3

The ArcGIS Javascript API has a nice refresh interface for ArcGISDynamicMapServiceLayer:

    var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer");
    map.addLayer(dynamicMapServiceLayer);
    dynamicMapServiceLayer.setDisableClientCaching(true);

    if (dynamicMapServiceLayer.disableClientCaching) {
        aspect.after(dynamicMapServiceLayer, "onUpdateEnd", function () {
            $.delay(15000, "UpdateDynamicLayer", function () {
                dynamicMapServiceLayer.refresh();
            });
        });
    }

But this is not generalized across the other layer types. Anyone have a solution for refreshing layers of any type?

3
  • Can you outline a scenario where you'd need to refresh a tiled or feature layer? Would removing a layer then re-adding it suffice? Commented Aug 30, 2012 at 5:01
  • The code below does remove and re-add it and it does suffice to some degree...it's impossible to clone a layer so you need the constructor and it's not nearly as elegant as layer.refresh(). Regarding a scenario...updating weather radar. Not interested in tiles but in WMS.
    – ca0v
    Commented Aug 30, 2012 at 13:33
  • Cross-posted this to the ESRI forum at forums.arcgis.com/threads/65819-Refreshing-WMS-layers
    – ca0v
    Commented Aug 30, 2012 at 13:55

1 Answer 1

2

Replace getImageUrl and modify the url before passing it to the callback:

    layer = new esri.layers.WMSLayer("http://sampleserver1c.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer", {
        visibleLayers: ['1', '2']
    });

    function extendLayer(layer)
    {
        var getImageUrl, tick;

        tick = 0;
        getImageUrl = layer.getImageUrl;

        layer.setDisableClientCaching = layer.setDisableClientCaching || function(disable)
        {
            if (disable)
            {
                layer.getImageUrl = function (extent, width, height, callback) {
                    var result = getImageUrl.call(layer, extent, width, height, function (url) {
                        callback.call(layer, url + "&_c=" + tick++);
                    });
                    return result;
                };
            }
            else
            {
                layer.getImageUrl = getImageUrl;
            }
        };
        return layer;
    }

    extendLayer ( layer ).setDisableClientCaching ( true );

    setInterval(function () {
        layer.refresh();
    }, 5000);

    map.addLayer(layer);
1
  • Just a comment to say that this still fixed this for me with version 3.17.
    – Jon Lynch
    Commented Sep 11, 2016 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.