I'm new to OpenLayers. I'm working on a map with WMS layers and a custom overview. I'm trying to change the layer used in the overview based on the user choice. The original layer set at the control's creation is correctly displayed. I've tried to use render() and changed() but despite the fact that the new layer is set in the 'layers' parameter, nothing is displayed in the overview. Here is my code:
/*add wms layers to map */
for (var i = 0; i < couchesToutes.length; i++) {
var WMSlayer = new ol.layer.Image({
name: couchesToutes[i].Name,
extent: maxextent,
isBaseLayer: couchesToutes[i].IsBaselayer,
isVisible: couchesToutes[i].Visible,
source: new ol.source.ImageWMS({
url: url,
params: { 'LAYERS': couchesToutes[i].Name },
ratio: 1,
serverType: 'mapserver'
}),
minResolution: minRes,
maxResolution: couchesToutes[i].IsBaselayer === 1 ? 1000 : maxRes
});
if (WMSlayer.get('isBaseLayer') === 1 && currentBaseLayer == null)
currentBaseLayer = WMSlayer;
arrayLayerTous[i] = WMSlayer;
map.addLayer(WMSlayer);
}
/*Overview*/
ctrlOverview = new ol.control.OverviewMap({
className: 'ol-overviewmap ol-custom-overviewmap',
collapsible: false,
target: 'overview',
view: viewOverview,
maxResolution: maxRes,
layers: [currentBaseLayer]
});
/* redraw map */
refreshOLMap = function () {
arrayLayerTous.forEach(function (el) {
el.setVisible(el.get('isVisible') == 1 ? true : false);
})
map.renderSync();
}
/* change the overview layer */
setFondDePlan = function (layername) {
arrayLayerTous.forEach(function (el) {
if (el.get('isBaseLayer') == 1) {
if (el.get('name') === layername) {
el.set('isVisible', 1); //show the layer
currentBaseLayer = el;
ctrlOverview.set('layers', [currentBaseLayer]); //new layer is set
}
else {
el.set('isVisible', 0); //hide the other layers
}
}
})
refreshOLMap();
ctrlOverview.render(); //doesn't work, how to update the overview ?
}
Thanks for your time.