Thi*_*IsJ 15 vector geojson openlayers-3
我试图从我的矢量图层获取功能.矢量图层由Geoserver加载的GeoJSON文档组成.我尝试过vector.features但是徒劳无功.任何人都可以帮忙吗?
小智 26
OL3的体系结构区分了一个层和它们的源.因此,要访问图层的功能,首先必须访问图层的源.这通过以下方式完成:
var source = layer.getSource();
Run Code Online (Sandbox Code Playgroud)
如果是矢量图层,您将得到一个ol.source.Vector对象.您可以通过以下对象访问您的功能:
var features = source.getFeatures();
Run Code Online (Sandbox Code Playgroud)
此外,您可以通过getFeatureById(id)或getFeaturesAtCoordinate(坐标)访问特殊功能.有关更多信息,请参阅api文档http://openlayers.org/en/v3.4.0/apidoc/ol.source.Vector.html