美文网首页
layers + features

layers + features

作者: xueyueshuai | 来源:发表于2023-06-27 20:13 被阅读0次

获取所有图层


      this.map.getLayers().forEach(layer=>{
        console.log(layer)
      })

获取所有矢量图层的所有要素

          layer.getSource().getFeatures().forEach(feature=>{
            console.log(feature)
            console.log(feature.getId())
            console.log(feature.get('xxx'))
          })

要素的获取 添加 删除

          let feature = layer.getSource().getFeatureById('base-old.2')
          console.log(feature)

          layer.getSource().removeFeature(feature);
          
          setTimeout(()=>{
            layer.getSource().addFeatures([feature]);
          },2000)
      let getLayerByK = (map, k = 'name', v = 'oldBaseLayer') => {
        let findLayer = null
        this.map.getLayers().forEach(layer => {
          if (layer.get(k) === v) {
            findLayer = layer
          }
        })
        return findLayer
      }
      
      let oldBaseLayer = getLayerByK(this.map, 'name', 'oldBaseLayer')
      console.log(oldBaseLayer)
      if(oldBaseLayer){
        let feature = oldBaseLayer.getSource().getFeatureById('base-old.2')
        console.log(feature)
        if(feature) {
          oldBaseLayer.getSource().removeFeature(feature);
          setTimeout(()=>{
            oldBaseLayer.getSource().addFeatures([feature]);
          },2000)
        }
      }

相关文章

网友评论

      本文标题:layers + features

      本文链接:https://www.haomeiwen.com/subject/comnydtx.html