OpenLayer 绘制在绘制结束后删除形状

问题描述 投票:0回答:1

使用基本示例无法在地图上添加元素 在drawend事件之后它消失 在drawend监听器元素中存在 使用默认示例页面中的代码给出相同的结果

private map: OlMap;
  private drawSource: VectorSource = new VectorSource({
    wrapX: false
  });
  private drawLayer: VectorLayer<VectorSource> = new VectorLayer({
    source: this.drawSource
  });
  private raster =  new TileLayer({
    source: new OSM()
  });    
  private drawAction: Draw;
  private snap: Snap;    
  constructor() {
  }    
  ngOnInit(): void {
    this.initMap();
    this.startDraw();
  }    
  private initMap(): void {

    const mapCentre: number[] =  fromLonLat(this.defaultMapCenter);

    this.map = new OlMap({
      layers: [
        this.drawLayer,
        this.raster
      ],
      target: 'map',
      view: new View({
        center: mapCentre,
        zoom: 8, maxZoom: 22,
      }),
      controls: [],
    });
    this.map.addLayer(basemapLayer);
    })
  }
private startDraw() {
    this.drawAction = new Draw({
      source: this.drawSource,
      type: 'Polygon'
    });

    this.map.addInteraction(this.drawAction);
    this.snap = new Snap({source: this.drawSource});
    this.map.addInteraction(this.snap)

}) }

提款前

之后

javascript openlayers
1个回答
0
投票

更改图层顺序,以便绘制的要素不会隐藏在栅格下方

  layers: [
    this.raster,
    this.drawLayer
  ],
© www.soinside.com 2019 - 2024. All rights reserved.