json数据没问题
加载geojson后无法显示图形
解决:发现少加了个策略
equipmentDatasLayer = new OpenLayers.Layer.Vector('数据图层', {
projection: new OpenLayers.Projection('EPSG:4326'),
protocol: new OpenLayers.Protocol.HTTP({
url: 'map.json',
format: new OpenLayers.Format.GeoJSON({
read: function(json,type,filter){
var geojson = new OpenLayers.Format.GeoJSON();
var features =geojson.read(json,"FeatureCollection");//FeatureConllection与json数据中type对应
refreshData(features);
}
})
}),
strategies: [new OpenLayers.Strategy.Fixed()],
styleMap: equipmentDatas_style
});
本文解决了在使用OpenLayers加载GeoJSON数据时图形无法显示的问题。通过增加Fixed策略,确保了矢量图层能正确读取并展示GeoJSON格式的数据。
382





