我的应用程序中有矢量图层如下:
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
crossOrigin:"Anonymous",
url: 'http://localhost:8080/geoserver/wfs?service=WFS&' +
'version=1.0.0&request=GetFeature&typename=genesis:Building_WGS&' +
'outputFormat=application/json&srsname=EPSG:4326'
});
var vector1 = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
Run Code Online (Sandbox Code Playgroud)
我运行时可以看到地图上的图层.但问题是当我使用警报消息检查我看到空的功能信息时.我这样感冒了:
alert(vectorSource.getFeatures());
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我在这里做错了什么?任何帮助都是相同的.
AJ
您已经达成了解决方案,因此请注册解决方案.
当你传递一个url参数时,ol.source.Vector异步(AJAX)加载,所以你必须等到它完全加载:
vectorSource.on('change', function(evt){
var source=evt.target;
if(source.getState() === 'ready'){
console.info(vectorSource.getFeatures());
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2328 次 |
| 最近记录: |