javascript 使用 OpenLayers.Feature.Vector 在 openlayer 地图中添加标记?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6939946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add a marker in openlayer map using the OpenLayers.Feature.Vector?
提问by BoomirajP
I can add the marker on the openlayer map using Openlayers.Layer.markers
.
But i cannot do this using OpenLayers.Feature.Vector
? . Any one may help me..please...thanks in advance
我可以使用Openlayers.Layer.markers
. 但我不能用 OpenLayers.Feature.Vector
? . 任何人都可以帮助我...请...提前致谢
Regards, Boomiraj.P
问候, Boomiraj.P
回答by Ilia Choly
here's a simple example that should work.
这是一个应该有效的简单示例。
var point = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-111.04, 45.68));
var layer = new OpenLayers.Layer.Vector("My Layer", {
style: OpenLayers.Feature.Vector.style["default"]
});
map.addLayer(layer);
layer.addFeatures([point]);
回答by jlandercy
This also does the trick:
这也可以解决问题:
var point = new OpenLayers.LonLat( -0.1279688 ,51.5077286 ).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject());
var markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(point));