OpenLayers 6.5 -在运行时更改pixelRatio



在OpenLayers 5.3中,我们曾经这样做来改变所有图层的pixelRatio:

this.map.pixelRatio_ = newRatio;
this.map.updateSize();

然而,在OpenLayers 6.5中,这只影响矢量层,而不是例如XYZ源的平铺层。

是否有新的方法来实现这一点?

谢谢你的建议,Vojtech

最后我们这样解决了这个问题:

this.map.pixelRatio_ = pixelRatio;
this.map.getLayers().forEach((layer) => {
if(layer.getVisible()) {
if (layer.getSource().tilePixelRatio_ !== undefined) {
layer.getSource().tilePixelRatio_ = pixelRatio;
layer.getSource().refresh();
}
else {
if (layer instanceof layerVector) {
let source = layer.getSource();
if (source instanceof Cluster) {
source.getSource().changed();
}
else {
source.changed();
}
}
else {
let source = layer.getSource();
if(source instanceof ImageWMS || source instanceof TileWMS) {
let params = source.getParams();
params["XX"] = getNextRefreshCounter(); // this method generates unique number each time it is called
source.updateParams(params);
}
}
}
});
this.map.refs.layer.map.updateSize();

基本上有必要:

  • 更新属性pixelRatio_地图(矢量图层)
  • 也更新属性tilePixelRatio_除矢量
  • 以外的图层源
  • 刷新所有受影响的图层

最新更新