ol加载多面、多点、多线、并隐藏或删除图层

// 加载多面
export function addMultiPolygon1(map,id,data){
  const layers = map.getLayers().getArray()
  let layer = layers.find((item) => item.values_.id === id)
  if (layer) {
    layer.getSource().clear()
    layer.setVisible(true)
  }else {
    layer = new VectorLayer({
      source: new VectorSource(),
      properties: {
        id: id
      }
    })
    map.addLayer(layer)
  }
  data.forEach(item => {
    item.valueName = id
    let polygonData = JSON.parse(item.geojson);
    let polygon = null;
    if (polygonData.type === "Polygon") {
        polygon = new Polygon(polygonData.coordinates);
    } else if (polygonData.type === "MultiPolygon") {
        polygon = new MultiPolygon(polygonData.coordinates);
    }
    let feature = new Feature({
      type: 'polygon',
      properties: item, // 传递数据,点击面展示可用
      geometry: polygon,
      id
    });
    feature.setStyle(
      new Style({
        fill: new Fill({
          color: 'rgba(0, 255, 0, 0.4)'
        }),
        stroke: new Stroke({
          color: '#0000FF',
          width: 1,
        }),
      })
    )
    // 添加到之前的创建的layer中去
    layer.getSource().addFeature(feature)
  });
  layer.setZIndex(10)
}


// 添加多点
export function addMarkerMore(map,id,graphics,icon){
  const layers = map.getLayers().getArray()
  let layer = layers.find((item) => item.values_.id === id)
  console.log(layer,'layer',layers);
  if (layer) {
    layer.getSource().clear()
    layer.setVisible(true)
  } else {
    layer = new VectorLayer({
      source: new VectorSource(),
      properties: {
        id: id
      }
    })
    map.addLayer(layer)
  }
  let jdwd
  let rotation
  
  graphics.forEach((item) => {
    item.valueName = id
    if(id === 'shuiwen' || id === 'yuliang' || id === 'xingbian' || id === 'shenya' || id === 'shipin'){
      jdwd = {
        coordinates:[item.lgtd,item.lttd]
      }
    }else {
      jdwd = JSON.parse(item.geojson)
    }
    if(id === 'shuiwen'){
      rotation = item.angle ? item.angle : 0
    }
    // 创建一个Feature,并设置好在地图上的位置
    const feature = new Feature({
      geometry: new Point(jdwd.coordinates),
      properties: item
    })
    // 设置样式,在样式中就可以设置图标
    feature.setStyle(
      new Style({
        image: new Icon({
          anchor: [16, 32],
          anchorXUnits: 'pixels',
          anchorYUnits: 'pixels',
          src: icon,
          rotation: rotation,
        })
      })
    )
    // 添加到之前的创建的layer中去
    layer.getSource().addFeature(feature)
  })
  layer.setZIndex(10)
}

// 添加单个标记图层
 export function addMarker(lonlat,map,id) {
  let feature = new Feature({
    id:id,
    geometry: new Point(lonlat)
  });
  feature.setStyle(
    new Style({
      image: new CircleStyle({
        radius: 3,
        fill: new Fill({
          color: '#00AAFF',
        }),
        stroke: new Stroke({
          color: '#00AAFF',
          width: 16
        })
      })
    })
  );
  let source = new VectorSource()
  source.addFeature(feature)
  let layer = new VectorLayer({
    opacity: 1,
    properties: {
      layerId: id
    },
    zIndex:9999
  })
  layer.setSource(source)
  // 添加到之前的创建的layer中去
  map.addLayer(layer)
}

// 添加多线段
export function addMultiLineString(map,id,graphics){
  const layers = map.getLayers().getArray()
  let layer = layers.find((item) => item.values_.id === id)
  if (layer) {
    layer.getSource().clear()
    layer.setVisible(true)
  } else {
    layer = new VectorLayer({
      source: new VectorSource(),
      properties: {
        id: id
      }
    })
    map.addLayer(layer)
  }
  graphics.forEach((item) => {
    item.valueName = id
    let jdwd = JSON.parse(item.geojson)
    const feature = new Feature({
      geometry: new MultiLineString(jdwd.coordinates),
      properties: item
    })
    feature.setStyle(
      new Style({
        // 线样式
        stroke: new Stroke({
          color: '#f00',
          width: 4,
        }),
      })
    )
    layer.getSource().addFeature(feature)

  })
  layer.setZIndex(10)
}

// 根据id隐藏图层
export function hideLayerById(map,layerId) {
  const layers = map.getLayers().getArray()
  const layer = layers.find((item) => item.values_.id === layerId)
  if (layer) {
    layer.setVisible(false)
  }
}


// 根据id删除图层
export function removeMarker(map,id){
  const layers = map.getLayers().getArray()
  const layer = layers.find((item) => item.values_.layerId === id)
  map.removeLayer(layer)
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
函数名称 描述 PL_3d? 如果多段线的检查是3D或不 PL_AddPoint 入一个新的多段线点之前指定的顶点数量VxNum PL_Arced? 如果检查多段线有至少一个弧段 PL_ArcPl2LinearPl 重建更换指定的距离直线段只有所有弧段的多段线列表。 PL_BoundPoly 创建直线,多段线和/或圆周围的边界多边形 PL_BreakX 在这一点上打断多段线 PL_DelPoint 从多段线删除点 PL_DividedPoints 返回除以给定的多段线(无论是在“实体”的形式或列表的形式)所获得的点 PL_DrawLeaders 沿线各段多段线绘制的领袖,从而呈现出多段线的流动方向。 PL_DrawLeaders2 沿线各段多段线绘制两端箭头。 PL_facelist 返回从一个多面对象的面部定义列表 PL_Fitted? 检查是否有多段线在选集中 PL_FlipArcedPolyline 翻转(反转)的圆弧(2D)多段线使用特殊技巧 PL_Get2dPolyElev 找到一个二维多段线的标高 PL_GetBulgeLst 返回凸出圆弧多段线列表 PL_GetMiddlePoint 查找行的中间点,多段线,圆弧或样条线对象 PL_GetSlope @点 在某一时间点的斜率的曲线对象 PL_GetVxEntl 返回完整的实体,包括多段线顶点实体的实体列表的列表, PL_GetWidths 返回一个列表的开始和结束段多段线宽度 PL_MapMask 创建出多段线和/或圆形的不透明的面具,变成区实体。 PL_MeasuredPoints 返回通过测量给定的多段线(无论是在“实体”的形式或列表的形式)获得的分 PL_Mesh? 如果一个多段线对象的检查是一个三维网格对象或否 PL_mk_pl 给个列表,绘制多段线或LWPOLYLINE的entmake功能 PL_mk_pl_feed 给个列表,绘制多段线或LWPOLYLINE的,使用命令行坐标传输; PL_NewPoint 在指定的顶点更新多段线点 PL_Open? 判断多段线的检查是打开“或”不 PL_plist 返回一个LWPOLYLINE或多段线点表 PL_PlJoin 连接选择集中多段线线段。 PL_plpick 多段线挑毛,挑个毛,看里面。 PL_PolyFace? 检查多段线对象是否是一个多面网格 PL_ReconstructPoly 重建炸开的多段线对象 PL_SeekMain 寻求从顶点名主要实体名称 PL_Spl2Pl_Int 转换到一个正常的多段线样条或ELLISPE对象的插值方法 PL_Splined? 检查是否拟合多段线 PL_SplitPoly 拟合多条多段线。 PL_SplPl2Pl 拟合多段线转换到正常的多段线 PL_UpdateLine 更新与两个新端点的线对象。保持所有行属性,包括句柄 PL_UpdatePoly 更新一个新的顶点列表的多段线实体。保留所有多段线特性:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值