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

How can i create static marker in OpenLayers 3?

我在javascript和OpenLayers方面的水平不高,我正在尝试实现一个带有指向世界各地机场的静态标记的地图。
好吧,我试图搜索我的答案,但我无法解决我的问题。

我已经尝试查找文档或示例,但每次都不起作用。

请问有人能告诉我如何根据数据列表创建标记吗?

非常感谢。

(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'
      })
    })
  })
});