Skip to content
目录

添加图标(图片)

  • 构建Feature,构建Source,构建Layer,最后添加Layer到map即可
  • 相关变量在data中申明即可,

js
// point: [118.339408, 32.261271]
addIcon (point) {
  const vectorSource = new VectorSource()
  this.iconLayer = new VectorLayer({
    source: vectorSource
  })
  // 添加图层
  this.map.addLayer(this.iconLayer)
  // 设置图片位置
  const iconFeature = new Feature({
    geometry: new Point(point)
  })
  // 设置样式,这里使用图片
  iconFeature.setStyle(new Style({
    image: new Icon({
      src: require('@/assets/logo.png')
    })
  }))
  // 将图片Feature添加到Source
  this.iconLayer.getSource().addFeature(iconFeature)
},

Released under the MIT License.