为什么我无法向 Vector 添加功能?此代码不起作用:
var features = [new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(-70.702451, 42.374473), {className: "latarnia"})]
vectors = new OpenLayers.Layer.Vector("warstwa", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
format: new OpenLayers.Format.OSM()
}),
features : features,
projection: new OpenLayers.Projection("EPSG:4326")});
map.addLayers([vectors]);
我的意思是向量根本没有特征。 我试过了
layer.addFeatures([feature]);
但它也失败了。
最佳答案
看来你的 map 和点的投影不一样。 map 投影是 EPSG:4326 ,但点投影似乎是 EPSG:3857 。
也许对你有帮助
conv_latlon = new OpenLayers.LonLat(-70.702451, 42.374473).transform('EPSG:3857', 'EPSG:4326')//transform point
var features = [new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(conv_latlon.lon, conv_latlon.lat), {className: "latarnia"})]
关于javascript - 开放层功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13431449/