简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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