简体   繁体   English

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

[英]How can i create static marker in OpenLayers 3?

I don't have a great level in javascript and OpenLayers, and i am trying to realize a map with static markers pointing airports in all the world. 我在javascript和OpenLayers方面的水平不高,我正在尝试实现一张带有静态标记的地图,该标记指向世界各地的机场。
Well i tried to search my answer but i can't resolve my problem. 好吧,我试图搜索我的答案,但我无法解决我的问题。

I already tried to find docs or examples, but every time it doesn't work. 我已经尝试找到文档或示例,但是每次都行不通。

Please if anybody can help me by telling me how to create markers based on a list of data? 请问有人可以通过告诉我如何根据数据列表创建标记来帮助我吗?

Thank you a lot. 非常感谢。

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

This way you can load a GeoJSON file into your map. 这样,您可以将GeoJSON文件加载到地图中。

If you want, say, a circle marker you add a style to ol.layer.Vector like: 例如,如果您想要一个圆形标记,则可以向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'
      })
    })
  })
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM