2016-06-21 150 views
0

我在JavaScript和OpenLayers中的表现并不是很好,我试图实现一个静态标记指向全球所有机场的地图。
嗯,我试图搜索我的答案,但我无法解决我的问题。如何在OpenLayers 3中创建静态标记?

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

如果有人能告诉我如何基于数据列表创建标记,请帮助我吗?

非常感谢。

+0

你有数据的这个名单? –

+0

是的,我愿意。感谢您的回答。 –

+0

它是什么格式? GeoJSON,TopoJSON,KML ... –

回答

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

这样你可以一个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' 
     }) 
    }) 
    }) 
}); 
+0

工作!非常感谢你的回复:) –

+0

@InèsZarka欢迎您,如果这是您的预期,请将答案标记为正确并完成。 –