Openlayers Pbf矢量瓷砖性能不佳

问题描述

因此,在渲染完成后,在进行所有操作后,我会使用pbf矢量图块来执行性能问题,同时平移/放大和缩小直到渲染图块(例如,如果您尝试放大和平移渲染图块时屏幕将冻结)运行顺利。 我正在为Android / IOS实现离线地图功能,并在设备上存储了pbf切片,这可能很重要。所以这是我目前正在做的事情:

// create vector tile layer
const layer = new VectorTileLayer({
  source: new VectorTileSource({
    format: new MVT(),url: 'offline-pbfs/{z}/{x}/{y}.pbf',// Url on device
    tileLoadFunction: this.tileload,maxZoom: 14
  })
});

// custom load tiles function for loading tiles from device storage
private tileload = (tile,url) => {
  tile.setLoader((extent,resolution,projection) => {
    this.file.readAsArrayBuffer(this.file.dataDirectory,url)
      .then(data => {
        const format: any = tile.getFormat();
        tile.setFeatures(format.readFeatures(data,{extent}));
    })
    .catch(err => logger.error(err,'Error loading tile',url));
  });
}

// obtain and apply osm-bright-style.json
this.offlineMapService.getofflineMapStyle().subscribe(styleData => {
  applyStyle(layer,styleData,'openmaptiles').then((_: any) => {
    this.map.addLayer(layer);
  });
})

我尝试过使用renderOrder,renderBuffer,renderMode,declutter选项,但是它没有帮助。另外,我here可以看到在缩放/平移地图口吃期间,它并不平滑。任何帮助将不胜感激

解决方法

每次缩放、平移等都会对功能进行重新设计,如果每次都重新定义样式,则速度会很慢。如果您可以将样式保存为每个特征一次的变量,那么在后续缩放时会从变量中获取样式,而不是再次创建样式。