javascriptopenlayersopenlayers-6pixel-ratio

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


Solution

  • 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: