简体   繁体   中英

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:

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.

Is there a new way of achieving this?

Thanks for any advice, 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)
  • update also the property tilePixelRatio_ of layer sources other than vector
  • refresh all the affected layers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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