获取openlayers矢量文件功能

获取openlayers矢量文件功能,openlayers,Openlayers,找到了以下问题的解决方案。只需使用显示每个功能的style属性即可 this.vec_layer = new ol.layer.VectorTile({ source: vectorTileSource, style: (feature: any, resolution: any) => { // access adn edit each feature here... } }); 原始问题: 如何获取openlayers矢量文件中的每个功能并对其

找到了以下问题的解决方案。只需使用显示每个功能的style属性即可

this.vec_layer = new ol.layer.VectorTile({
    source: vectorTileSource,
    style: (feature: any, resolution: any) => {
        // access adn edit each feature here...
    }
});
原始问题:

如何获取openlayers矢量文件中的每个功能并对其进行迭代。在我的json中返回的特性都有一个不同的“status”键,我需要根据这个键来设置它们的样式。api:

有一个forEachFeature()和getFeatures()方法,但是当我在“源”上调用其中一个时,我会得到未定义的

this.gisi_layer = new ol.layer.Tile({
    source: new ol.source.TileImage({
      url : 'https://tiles.gisinventory.net/raster/{z}/{x}/{y}.png',
      wrapX : true
    })
});
let myLonLat = [-104.036667, 36.895];
let myLonLatMercator = ol.proj.fromLonLat(myLonLat);
// note that the target cannot be set here!
this.map = new ol.Map({
    layers: [this.gisi_layer],
    view: new ol.View({
    center: myLonLatMercator,
    zoom: 4
    })
});
// the source I need access to
let vectorTileSource = new ol.source.VectorTile({
    format: new ol.format.GeoJSON(),
    tileGrid: ol.tilegrid.createXYZ({maxZoom: 22}),
    tilePixelRatio: 16,
    url: 'https://tiles.gisinventory.net/vector/layer_county_13/{z}/{x}/{y}.json'
});
this.vec_layer = new ol.layer.VectorTile({
    source: vectorTileSource,
    style: this.mapStyles.styleComplete
});

vectorTileSource.on('tileloadend', () => {
    this.setMapLoadingStatus('inactive');
});

this.map.addLayer(this.vec_layer);
调用获取源代码可以正常工作:

let vectorSource = this.vec_layer.getSource();

console.log(vectorSource.getFeatures()); // undefined
我花了两天的时间试图找出人们是如何在向量层中迭代特征的,但这些方法都不起作用。我检查了每个对象,没有看到文档大纲中公开的方法


非常感谢您在技术方面的帮助。

在您正在使用的代码中ol.source.vectorie但是api链接用于ol.source.Vector。如果您查看
ol.source.VectorTile
的文档,没有名为
getFeatures()
Yes的方法。确切地我正在尝试访问源代码,以便调用这些方法。您可以使用
getFeaturesInExtent()