简体   繁体   English

OpenLayers 6.5 - 在运行时更改 pixelRatio

[英]OpenLayers 6.5 - Change pixelRatio during runtime

in OpenLayers 5.3 we used to do this to change pixelRatio of all the layers in map:在 OpenLayers 5.3 中,我们曾经这样做来改变 map 中所有层的 pixelRatio:

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

However, in OpenLayers 6.5 this effects only vector layers and not for example tile layers with XYZ source.但是,在 OpenLayers 6.5 中,这仅影响矢量图层,而不影响例如具有 XYZ 源的平铺层。

Is there a new way of achieving this?有没有实现这一目标的新方法?

Thanks for any advice, Vojtech感谢您的任何建议,Vojtech

In the end we managed to solve the issue this way:最后我们设法以这种方式解决了这个问题:

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();

Basically there is necessary to:基本上有必要:

  • update property pixelRatio_ of map (for vector layers)更新 map 的属性pixelRatio_ (用于矢量图层)
  • update also the property tilePixelRatio_ of layer sources other than vector还更新除矢量以外的图层源的属性tilePixelRatio_
  • refresh all the affected layers刷新所有受影响的图层

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM