Skip to content
目录

根据坐标点绘制线

js
import { Feature } from 'ol'
import { LineString } from 'ol/geom'
import { Style } from 'ol/style.js'


creatLine (pointData) {
  // 根据经纬度点位创建线
  const routeFeature = new Feature({
    type: 'route',
    geometry: new LineString(pointData)
  })
  const lineStyle = new Style({
    stroke: new Stroke({
      color: '#00eaff',
      width: 5
    })
  })
  // 添加样式
  routeFeature.setStyle(lineStyle)
  // 往地图实例中加入改层
  const source = this.mapLayers.track.getSource()
  // 清除图层
  source.refresh()
  // 添加图层
  source.addFeatures([routeFeature])
},

Released under the MIT License.