如何在OpenLayers 3中创建静态标记? [英] How can i create static marker in OpenLayers 3?
问题描述
我对javascript和OpenLayers的掌握程度不高,我正在尝试实现一张带有静态标记的地图,该标记指向世界各地的机场.
好吧,我试图搜索我的答案,但我无法解决我的问题.
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?
非常感谢您.
推荐答案
(小提琴)>
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文件加载到地图中.
This way you can load a GeoJSON file into your map.
例如,如果您想要一个圆形标记,可以将样式添加到 ol.layer.Vector
喜欢:
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'
})
})
})
});
这篇关于如何在OpenLayers 3中创建静态标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!