获取openlayers vectorTile功能

时间:2017-03-31 12:44:11

标签: openlayers

找到了以下解决方案。只需使用暴露每个特征的样式属性。

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

原始问题:

如何获取并迭代openlayers vectorTile中的每个要素。我的json中返回的功能都有不同的状态"键,我需要根据该键设置它们的样式。 api:

http://openlayers.org/en/latest/apidoc/ol.source.Vector.html

有一个方法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

我花了两天时间试图找出人们如何迭代矢量图层中的要素,但没有一种方法可行。我已经检查了每个对象,并且没有看到暴露文档大纲的方法。

对技术的任何帮助都非常感激。

0 个答案:

没有答案
相关问题