我已经尝试从以前在 SE 中提出的问题中解决问题,但无法通过阅读这些问题来解决问题,因此,作为单独的问题发布。
我正在marker使用以下代码创建一个图层
mLayer = new OpenLayers.Layer.Vector(layerName, {
projection: map.displayProjection,
extractAttributes: true,
styleMap: new OpenLayers.StyleMap({'default' : Lstyle}),
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: getURL,
format: new OpenLayers.Format.GeoJSON()
})
});
我的任务是计算marker坐标的平均值并将其设置为地图的中心,因为我想从mLayer对象中获取坐标。标记在地图上显示良好,但是当我mLayer.features.length在控制台中打印时它显示0但大小features为 10,我可以firebug console通过打印看到vLayer,这是我的 JSON 文件。