Skip to content
目录

根据坐标点绘制面

js
import { Polygon } from 'ol/geom'
import { Fill, Style, Stroke } from 'ol/style.js'

createFill (pointData) {
  const feature = new Feature({
    geometry: new Polygon([pointData]),
    type: 'Polygon' // 指定type属性,用于匹配style,以及在feature点击事件中做出不同的操作
  })
  const lineStyle = new Style({
    stroke: new Stroke({
      color: '#ffc039',
      width: 2
    }),
    fill: new Fill({
      color: 'rgba(255, 255, 255, 0)'
    })
  })
  // 样式
  feature.setStyle(lineStyle)
  // 往地图实例中加入改层
  const source = this.mapLayers.track.getSource()
  // 清除图层
  source.refresh()
  // 添加图层
  source.addFeatures([feature])
}

Released under the MIT License.