【问题标题】:OpenLayers 6.5 - Change pixelRatio during runtimeOpenLayers 6.5 - 在运行时更改 pixelRatio
【发布时间】:2021-05-15 07:40:04
【问题描述】:

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

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

但是,在 OpenLayers 6.5 中,这仅影响矢量图层,而不是例如具有 XYZ 源的平铺层。

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

感谢您的任何建议,Vojtech

【问题讨论】:

    标签: javascript openlayers openlayers-6 pixel-ratio


    【解决方案1】:

    最终我们以这种方式解决了这个问题:

    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_
    • 刷新所有受影响的图层

    【讨论】:

      猜你喜欢
      • 2011-10-08
      • 1970-01-01
      • 2023-03-29
      • 2012-09-04
      • 2011-04-10
      • 2011-01-01
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多