为什么我不能给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]);
但它也失败了。
发布于 2014-07-15 21:43:03
看起来你的地图和点的投影不一样。地图投影是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"})]
发布于 2014-01-28 02:20:31
由于某些原因,在OpenLayers.Layer.Vector构造函数上初始化"features“属性不起作用。
但您应该能够在之后添加它们:
vectors.addFeatures(features);
然后您可以在浏览器控制台中进行测试:
vectors.features.length; //this should be 1 now
除此之外,代码看起来没问题。您还应该能够将地图上的要素显示为橙色圆圈(默认样式),但前提是点的坐标位于基本层的范围内。使用OpenLayers版本2.14进行了测试。
https://stackoverflow.com/questions/13431449
复制相似问题