How can i create static marker in OpenLayers 3?

耗尽温柔 提交于 2019-12-25 02:48:07

问题


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.
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.


回答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);

This way you can load a GeoJSON file into your map.

If you want, say, a circle marker you add a style to ol.layer.Vector like:

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


来源:https://stackoverflow.com/questions/37941051/how-can-i-create-static-marker-in-openlayers-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!