如何更新OL4中的概述控件?

时间:2018-04-24 12:02:10

标签: javascript openlayers-3 wms mapserver

我是OpenLayers的新手。我正在使用WMS图层和自定义概述在地图上工作。我正在尝试根据用户选择更改概述中使用的图层。正确显示控件创建时设置的原始图层。我尝试使用render()和changed()但是尽管在'layers'参数中设置了新图层,但概述中没有显示任何内容。 这是我的代码:

/*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 ?
}

感谢您的时间。

0 个答案:

没有答案