解决高德地图刷新页面后WMS图层消失问题


原代码:

let wms_forbidden_area = new AMap.TileLayer.WMS({
    map:map,
    url: wms_server + '/geoserver/ucloud/wms',
    blend: false,
    tileSize: 512,
    zIndex:20,
    params: {LAYERS: ['ucloud:forbidden_area'], VERSION: '1.1.1'}
});

当页面第一次加载的时候图层正确显示,但是当页面被刷新之后,图层就会消失
解决:

let wms_forbidden_area = new AMap.TileLayer.WMS({
    url: wms_server + '/geoserver/ucloud/wms',
    blend: false,
    tileSize: 512,
    zIndex:20,
    params: {LAYERS: ['ucloud:forbidden_area'], VERSION: '1.1.1'}
});
wms_forbidden_area.setMap(map);
wms_forbidden_area.show();

换成上面的写法就不会出现这样的问题,估计是因为缓存的问题,图层存在于缓存,但需要设置map属性

转载自:https://blog.csdn.net/weixin_44005989/article/details/88537968

You may also like...