vue3 + openlayers---使用GeoJSON的方式加载点线面

const layer = new VectorLayer({
  source: new VectorSource({
    features: new GeoJSON().readFeatures(
      {
        type: 'FeatureCollection',
        features: [
          {
            type: 'Feature',
            geometry: {
              type: 'MultiPoint',
              coordinates: [
                [117.283042, 31.86119],
                [121.687899486, 31.24916171]
                ...............
                ...............
              ]
            }
          }
        ]
      },
      {
        dataProjection: 'EPSG:4326', // 原始数据坐标系
        featureProjection: 'EPSG:3857' // 需要显示的坐标系
      }
    )
  }),
  style: new Style({
    image: new StyleCircle({
      radius: 6,
      fill: new Fill({
        color: '#f00'
      }),
      stroke: new Stroke({
        color: '#ff0',
        width: 2
      })
    })
  })
})
window.olMap.addLayer(layer)

线

const layer = new VectorLayer({
  source: new VectorSource({
    features: new GeoJSON().readFeatures(
      {
        type: 'FeatureCollection',
        features: [
          {
            type: 'Feature',
            geometry: {
              type: 'LineString',
              coordinates: [
                [117.283042, 31.86119],
                [121.687899486, 31.24916171],
                ...............
                ...............
              ]
            }
          }
        ]
      },
      {
        dataProjection: 'EPSG:4490',
        featureProjection: 'EPSG:3857'
      }
    )
  }),
  style: new Style({
    stroke: new Stroke({
      color: '#f00',
      width: 3
    })
  })
})
window.olMap.addLayer(layer)

const layer = new VectorLayer({
  source: new VectorSource({
    // anHui 是安徽省 GeoJSON 面数据  大家可以网上自行下载导入
    features: new GeoJSON().readFeatures(anHui, {
      dataProjection: 'EPSG:4490', // 原数据的投影坐标
      featureProjection: 'EPSG:3857' // 规定要素以哪种坐标显示
    })
  }),
  style: new Style({
    fill: new Fill({
      //矢量图层填充颜色,以及透明度
      color: 'rgba(33,194,219,0.5)'
    }),
    stroke: new Stroke({
      //边界样式
      color: 'rgba(100, 90, 209, 0.6)',
      width: 3
    }),
    text: new Text({
      //文本样式
      font: '12px Calibri,sans-serif',
      fill: new Fill({
        color: '#000'
      }),
      stroke: new Stroke({
        color: '#fff',
        width: 3
      })
    })
  })
})
window.olMap.addLayer(layer)
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值