首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >openlayers:使用MVT VectorTileSource集群是不可能的?

openlayers:使用MVT VectorTileSource集群是不可能的?
EN

Stack Overflow用户
提问于 2019-03-14 19:28:50
回答 2查看 804关注 0票数 2

我是openlayers的新手,我想对矢量数据使用cluster函数。

如果我在群集选项中指定一个MVT VectorTileSource作为source:,这似乎不起作用?!

下面的代码。它在没有集群的情况下工作良好。

它不受支持吗?谢谢你,彼得

代码语言:javascript
复制
var vectorTileSource = new VectorTileSource({
     format: new MVT(),
     url: 
         'http://xxxx/geoserver/gwc/service/tms/1.0.0/' + 'airports:airports' +
         '@EPSG%3A'+'900913'+
         '@pbf/{z}/{x}/{-y}.pbf'
});

var clusterSource = new Cluster({
     distance: 30, 
     source: vectorTileSource
});


var clusterLayer = new VectorTileLayer({
    source: vectorTileSource, //----> this works   
    source: clusterSource, // ---> does NOT work 
    style: clusterStyle 
  });
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-15 04:17:32

可能期望将MVT瓦片加载到向量源的代码不会产生任何功能和错误。请参阅https://gis.stackexchange.com/questions/225615/how-to-use-mapbox-vector-tiles-as-a-vector-source-in-ol3-so-that-labelling-will

然而,可以在法线矢量源中复制矢量瓦片图层中的要素,这可以用于聚类源(并在具有轮廓密度的测试中工作)

代码语言:javascript
复制
var vtLayer = new ol.layer.VectorTile({
    source: new ol.source.VectorTile({
        format new ol.format.MVT({
            featureClass: ol.Feature    // important
        }),
        ....
        ....
    }),
    style: []   // layer must be added to map to load features, use empty style to avoid display
});
map.addLayer(vtLayer);

var vSource = new ol.source.Vector();   // use this as the source for a cluster source
var featuresForZ = [];
var viewZ;

function vsRefresh() {
    vSource.clear();
    if (featuresForZ[viewZ]) {
        vSource.addFeatures(featuresForZ[viewZ]);
    }
}

vtLayer.getSource().on('tileloadend', function(evt) {
    var z = evt.tile.getTileCoord()[0];
    var features = evt.tile.getFeatures();
    features.forEach(function (feature) {
        // each vector tile has its own set of feature ids, but duplicates are not allowed in normal vector sources
        feature.setId(undefined);   
    });
    if (!Array.isArray(featuresForZ[z])) { featuresForZ[z] = []; }
    featuresForZ[z] = featuresForZ[z].concat(features);
    if (z === viewZ) {
        vsRefresh();
    }
});

map.getView().on('change:resolution', function() {
    // use VT features from the tile z level corresponding to view resolution
    var newZ = vtLayer.getSource().getTileGrid().getZForResolution(map.getView().getResolution());
    if (newZ !== viewZ) {
        viewZ = newZ;
        vsRefresh();
    }
});

// now create the cluster layer
var vLayer = new ol.layer.Vector({
    source: new ol.source.Cluster({
        source: vSource,
        geometryFunction: function(feature){
           // test data is linestrings
           return new ol.geom.Point(ol.extent.getCenter(feature.getGeometry().getExtent()));
        },
    }),
    style: function(feature) {
        return new ol.style.Style({
            image: new ol.style.Circle({
                radius: feature.get('features').length * 5,
                fill: new ol.style.Fill({ color: 'black' })
            })
       });
    }
});
map.addLayer(vLayer);
票数 1
EN

Stack Overflow用户

发布于 2019-03-14 19:58:23

(仍然没有足够的声誉来评论)根据文档,集群需要一个VectorSource。VectorTile源码和VectorTile源码的OpenLayers是不同的,因为它们可以是非常不同的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55161380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档