Snippets

Piotr Szrajber Geospatial Portal - Force WMS Layer to reload

Created by Piotr Szrajber
/**
* Force particular WMS layer to refresh.
* This code snippet is using internal API and private variables and should not be considered as a part of the Portal API.
* Use at your own risk.
* 2016-12-09 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
*/

// find the topmost layer - replace it with the code that actually finds your WMS layer
// TODO: make sure that it is a WMS layer
var ml = $mapStateManager.findMapState("map").get_mapControl().get_mapLayers().slice(-1)[0];

// preparation on a selected WMS layer
// the actual image reload would be prevented by browser cache, so I am appending some garbage to the URL. Some WMS services don't handle it
var orig = ml.getURL;
ml.getURL = function(bounds) {
    return orig.call(this, bounds) + this._forceRedraw ? "&foo=" + (new Date()).getTime() : ""
};

// call it when you need to refresh the layer
function reloadMyWmsLayer() {
    ml._isDirty = ml._forceRedraw = true;
    ml._render();
}

// actual execution in your code
reloadMyWmsLayer();

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.