带有RasterSource的多个ImageLayer不可见

时间:2019-07-11 14:58:56

标签: openlayers openlayers-5

我正在尝试将具有不同范围的多个Openlayer图像层(使用栅格源)添加到单个Map中。如果添加单个图层,则显示该图层,但添加多个图层均不显示。

  1. 我认为zindex是我试图更改而没有用的问题。
  2. 我测试了添加后删除一个,然后第二个显示(一个未删除)

记录层数总是显示所有3层(我添加了2层,还有1个基本层,即地图)

this.raster = new RasterSource({
      sources: [this.layer.getSource()],
      operation: (pixels, data) => {
        let pixel = pixels[0];
        pixel[0] = 0;
        pixel[1] = 255;
        pixel[2] = 0;
        return pixel;
      }
    });

let previewColorLayer = new ImageLayer({
      opacity: 0.4,
      source: this.raster,
      extent: [972.145, 1948.98, 1270.395, 2082.48],
      zIndex: 1000
      // extent: ex
    });


    let previewColorLayer2 = new ImageLayer({
      opacity: 0.4,
      source: this.raster,
      extent: [952.145, 1756.98, 1270.395, 1890.48],
      zIndex: 2000
      // extent: ex
    });

    this.overviewMap.getOverviewMap().addLayer(previewColorLayer);
    this.overviewMap.getOverviewMap().addLayer(previewColorLayer2);

1 个答案:

答案 0 :(得分:1)

我尝试将栅格图层示例分为两个范围,并遇到相同的问题,看来构造的源不能用于多个图层。但是您可以重复使用用于构建它的选项

this.rasterOptions = {
  sources: [this.layer.getSource()],
  operation: (pixels, data) => {
    let pixel = pixels[0];
    pixel[0] = 0;
    pixel[1] = 255;
    pixel[2] = 0;
    return pixel;
  }
};

let previewColorLayer = new ImageLayer({
  opacity: 0.4,
  source: new RasterSource(this.rasterOptions},
  extent: [972.145, 1948.98, 1270.395, 2082.48],
  zIndex: 1000
  // extent: ex
});

let previewColorLayer2 = new ImageLayer({
  opacity: 0.4,
  source: new RasterSource(this.rasterOptions},
  extent: [952.145, 1756.98, 1270.395, 1890.48],
  zIndex: 2000
  // extent: ex
});