首页 > 解决方案 > 将叠加层添加到地图时如何将视图设置为叠加层?

问题描述

我正在将叠加层(下面代码中的“叠加层”)加载到传单底图(openstreetmap)上,并希望该叠加层在加载后完全填满显示窗口。

我认为我应该使用 getBounds 和 setView 使用通过 getBounds 获得的值,但没有设法使其工作。

// initialize the map
  var map = L.map('map').setView([48.85, -3], 15);

  // load a tile layer
    L.tileLayer('https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
        minZoom: 3,
        maxZoom: 18,
        subdomains: 'abcd',
        detectRetina : true
    }).addTo(map);    


    //Load overlay

    var overlayOptions = {
            attribution: '...',
            //minZoom: 3,
            maxZoom: 19,
            opacity: 1,
            format: 'image/png',
            detectRetina: true,
            //unloadInvisibleTiles: true,
        };
        overlay = L.tileLayer('https://www.laurentgontier.com/BrehatSHOM/{z}/{x}/{y}.png', overlayOptions).addTo(map);

        //fit map view to overlay bounds
map.fitBounds(overlay.getBounds());

到目前为止,应该将叠加层框入显示窗口的最后一行似乎不起作用。

标签: leafletfitbounds

解决方案


推荐阅读