1

I need to add 60+ tile layers onto a map at once, each with a different XYZ source using MapGuide server.

I'm able to do it, as shown below, but the performance is not ideal, because the way Openlayers deals with this is making requests to the server along the way.

let layers = [];

for (var i = 0; i < 61; ++i) {
    var layer = new TileLayer({
        source: new XYZ({
            tileUrlFunction: testtileUrlFunction.bind(null, i % 99),
            tileGrid: new TileGrid({
                origin: [-5123200, 10002100],
                resolutions: scaleArr,
            }),
        }),
        zIndex: i,
    });

    layers.push(layer);
};

let map = new Map({
    target: 'map',
    maxTilesLoading: Infinity,
    view: new View({
        constrainResolution: true,
        maxZoom: 9,
        minZoom: 0,
        resolutions: scaleArr,
        zoom: 0
    }),
    layers: layers,
});

It seems that each time Openlayers renders a layer, it requests from the server only tiles of that particular layer, while in comparison Leaflet sends out all the requests from every layer at once up front, which improves the performance a lot.

I wonder if there's something I can do in Openlayers to achieve similar effects.

4
  • Do you really need them all to be loaded and visible at once? Commented May 24, 2021 at 10:28
  • @bugmenot123 Yes that is what I'm trying to do, and it actually takes only about 5 seconds for the whole thing to render on the initial load, but the problem is that each time the map is moved even the slightest, it usually takes another 5 seconds to render the new tiles, which is not really acceptable.
    – Zheng Fang
    Commented May 24, 2021 at 11:01
  • 1
    You write "It seems that each time Openlayers renders a layer, it requests from the server only tiles of that particular layer". I tested this with two XYZ layers and could not confirm this behavior. Order of tile requests was tested with the help of tileLoadFunction option, and requests for tiles from both layers were intermixed.
    – TomazicM
    Commented May 29, 2021 at 20:12
  • I have similar problem like this. My first layer is OSM layer, another is just multiple ImageLayer with custom tileLoadFunction on it. When tileLoadFunction is skipped/not get response, the OSM layer also 'dead' idk why. Commented Apr 27, 2023 at 5:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.