如何在OpenLayers 3中创建静态标记?

时间:2016-06-21 09:50:16

标签: javascript openlayers-3

我在javascript和OpenLayers中没有很好的水平,我正在努力实现一个带有静态标记的地图,指向全世界的机场。
好吧,我试着搜索我的答案,但我无法解决我的问题。

我已经尝试过查找文档或示例,但每次都无法正常工作。

如果有人可以通过告诉我如何根据数据列表创建标记来帮助我吗?

非常感谢你。

1 个答案:

答案 0 :(得分:1)

fiddle

var vectorLayer = new ol.layer.Vector({
  source: new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: 'url_of_your_file'
  })
});
map.addLayer(vectorLayer);

这样您就可以将GeoJSON文件加载到地图中。

如果你想要一个圆形标记,你可以添加样式到ol.layer.Vector,如:

var vectorLayer = new ol.layer.Vector({
  source: new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: 'url_of_your_file'
  }),
  style: new ol.style.Style({
    image: new ol.style.Circle({
      radius: 10,
      fill: new ol.style.Fill({
        color: '#ffff00'
      })
    })
  })
});