Openlayers:矢量特征而不是标记
我想在地图上放置一个符号。例如
到目前为止,我已经将 OpenLayers 与 OpenLayers.Layer.Markers
一起使用。代码如下所示:
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
map.addLayer(layer);
map.setCenter(
new OpenLayers.LonLat({{ location.lon }}, {{ location.lat }}).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 15);
var lonLat = new OpenLayers.LonLat({{ location.lon }}, {{ location.lat }})
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonLat));
这可以正常工作并显示上面的地图。但我无法让它与 Vectors 一起使用,将最后 3 行替换为:
vectors = new OpenLayers.Layer.Vector("Vector Layer");
vectors.addFeatures([new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonLat))]);
map.addLayer(vectors);
使用 OpenLayers.Feature.Vector
是否需要任何特殊的魔法?
I want to place a symbol o a Map. E.g.
So far I have used OpenLayers with OpenLayers.Layer.Markers
. The code looks like this:
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
map.addLayer(layer);
map.setCenter(
new OpenLayers.LonLat({{ location.lon }}, {{ location.lat }}).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 15);
var lonLat = new OpenLayers.LonLat({{ location.lon }}, {{ location.lat }})
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonLat));
This works as excepted and shows the map above. But I can't get it to work with Vectors replacing the last 3 lines with:
vectors = new OpenLayers.Layer.Vector("Vector Layer");
vectors.addFeatures([new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonLat))]);
map.addLayer(vectors);
Is there any special magic needed to use OpenLayers.Feature.Vector
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenLayers.Geometry.Point
在其构造函数中接收两个坐标,而不是OpenLayers.LonLat
。OpenLayers.Geometry.Point
receives two coordinates in its constructor and not anOpenLayers.LonLat
.