How can i create static marker in OpenLayers 3?

2019-09-06 07:03发布

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条回答
太酷不给撩
2楼-- · 2019-09-06 07:31

(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'
      })
    })
  })
});
查看更多
登录 后发表回答