Bounding view of a Leaflet image map to a landscap

2019-08-15 02:43发布

问题:

I have a square image 16384x16384 that has been sliced into tiles using MapTiler to create 6 levels of zoom in Leaflet.

I have set up the image in Leaflet as follows:

var map = L.map('map', {
      maxZoom: 6,
      minZoom: 0,
    }).setView([0, 0],1);

var tilesURL = "_server/tiles/{z}/{x}/{y}.jpg";

L.tileLayer(tilesURL, {
    maxZoom: 6,
    continuousWorld: 'false',
    tms: true
}).addTo(map);

How would I either:

  1. Restrict the view of this large square image to just the middle (landscape rectangle) area?
  2. Produce a non-square rectangular set of tiles?

Additionally, can Leaflet auto-fit the bounded area to the Map container?

回答1:

  1. Yes. Use the maxBounds option.
  2. No idea, but why do you want to do such a thing?
  3. Yes: the method fitBounds does that.