简体   繁体   English

使用多层的OpenLayers 4.6.5的性能限制

[英]Performance limitations with OpenLayers 4.6.5 using several layers

I am currently working on a GIS holding a large amount of layers (up to 20 / 30). 我目前正在处理包含大量图层(最多20/30)的GIS。 The map is rendering tiles in a really slow way. 地图以非常慢的方式渲染图块。

It was previously written with OpenLayers 2.x, and we didn't face this performance bottleneck. 它以前是用OpenLayers 2.x编写的,我们并没有遇到这个性能瓶颈。

Our layers are using WMS sources & tiles, which are declared as follow 我们的图层使用WMS源和图块,声明如下

function createTileLayer(options){
    let source = new ol.source.TileWMS({
        url: serverURL, // Our GeoServer instance
        params: {
            'LAYERS': options.id
            'BGCOLOR': options.backgroundColor,
            'TRANSPARENT': options.transparent,
            'VERSION': options.version,
            'FORMAT': 'image/png'
        },
        serverType: 'geoserver',
        projection: 'EPSG:2100', // Managed by Proj4J
        transition: 0
    });

    let layerTile = new ol.layer.Tile({
        source: source,
        visible: options.visible,
    });

    return layerTile;
}

The map declaration in itself is quite simple: map声明本身非常简单:

let map = new ol.Map({
        target: document.getElementById('app'),
        layers: Layers, // All the layers we created before
        view: new ol.View({
            center: ol.proj.fromLonLat([5.497853028599662, 34.82203273834541]),
            zoom: 18,
            projection: 'EPSG:2100'
        }),
        loadTilesWhileAnimating: true,
        loadTilesWhileInteracting: true,
        renderer: 'canvas'
    });
}

Problem with this approach is that the browser seems to spend far too much time in drawing every layer. 这种方法的问题在于,浏览器似乎在绘制每个图层上花费了太多时间。 Here is the profile of some tests on Chrome: 以下是在Chrome上进行的一些测试的配置文件:

Chrome设定档画面

Results are an almost unusable map. 结果是几乎无法使用的地图。 I am aware that the amount of layers is high, but the issue was not in OpenLayers 2.x (or at least, performances were better). 我知道层数很多,但是问题不在OpenLayers 2.x中(或者至少性能更好)。

One possible workaround is using only one TileWMS source and pass it the list of all our layers in its 'LAYERS' param. 一种可能的解决方法是仅使用一个TileWMS源并将其所有图层的列表传递给其“图层”参数。 This dramatically improve the speed because GeoServer does all the rendering work, but we lose some possibilities such as managing each layer transparency. 由于GeoServer可以完成所有渲染工作,因此极大地提高了速度,但是我们却失去了诸如管理每一层透明度的功能。

I might be doing something wrong in querying / rendering tiles this way, that I am not aware of. 我以这种方式在查询/渲染图块时可能做错了我不知道的事情。 Thanks for any help. 谢谢你的帮助。

The most likely issue is that you are not hitting the tile boundaries that GeoWebCache (which is what GeoServer) uses to render the tiles. 最可能的问题是您没有达到GeoWebCache(这是GeoServer)用来渲染图块的图块边界。 See this page in the manual which lists the criteria that must be met for this to work. 请参阅手册中的此页面 ,该页面列出了必须满足的标准才能起作用。

A better way to do this is to use a WMTS request (where the tile grids etc are agreed on between the client and server rather than guessed at). 更好的方法是使用WMTS请求 (在客户端和服务器之间商定切片网格等,而不用猜测)。 You can even get OpenLayers to do the negotiation for you by asking for the getCapabilities document . 您甚至可以通过要求getCapabilities文档来使OpenLayers进行协商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM