OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.94k stars 2.57k forks source link

gdal2tiles.py option --webviewer=leaflet does nothing for profile != mercator #2030

Open sebastic opened 5 years ago

sebastic commented 5 years ago

As reported by Witold Baryluk in Debian Bug #944974:

I did run gdal2tiles.py on big PNG input in raster mode and gdal2tiles generated only tilemapresource.xml , no leaflet viewer skeleton when I used --webviewer=leaflet.

There are no HTML / JS / CSS files in the current working directory or in the directory with tiles.

Looking at the source code it looks like the included leaflet viewer only supports mercator profile, not raster. I know leaflet does support raster / cartesian layers, so this simply looks like a bit of missing code (actually way less than the one for the mercator) to add, but maybe there is some other reason behind it.

This might be a good start:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>{title}</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css"
    integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
    crossorigin=""/>
  <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"
   integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
   crossorigin=""></script>
</haad>
<body>
<div id="mapid" style="width: 1600px; height: 1000px;"></div>
<script>
var yx = L.latLng;

// Helper function to conver to leaflet coventions.
var xy = function(x, y) {
  if (L.Util.isArray(x)) {    // When doing xy([x, y]);
    return yx(x[1], x[0]);
  }
  return yx(y, x);  // When doing xy(x, y);
};

document.addEventListener('DOMContentLoaded', (event) => {
  // In a CRS.Simple, one horizontal map unit is mapped to one horizontal
  // pixel, and idem with vertical. This means that the whole map is about
  // 1000x1000 pixels big and won’t fit in our HTML container. Luckily, we
  // can set minZoom to values lower than zero.

  var map = L.map('mapid', {zoomSnap: 0.25, zoomDelta: 0.5, crs: L.CRS.Simple, minZoom: -5, maxZoom: 10});  // Square cartesian grid for coordinate reference system.

  map.setView([30000, 30000], 0);  // [y, x]

  L.tileLayer('{outputdir}/{z}/{x}/{y}.png', {
    attribution: '{copyright}',
    maxZoom: {maxzoom},
  }).addTo(map);
});
</script>
</body>
</html>

Operating system

Debian unstable

GDAL version and provenance

2.4.3

rouault commented 5 years ago

I don't think there's a particular reason this is not supported (perhaps it wasn't when gdal2tiles was initially written). In any cse, a pull request to add support would be welcome

baryluk commented 5 years ago

Hi I am original issue reporter. I will try to come with a patch. I am polishing the leaflet code a bit, as there are some minor issues when using tileLayer with CRS.Simple, that require some workarounds (i.e. inverted y axis, and simply flipping it does make tiles be rendered correctly but makes zooming not work fully correct). Setting map bounds and initial view / zoom level is also tricky or buggy in leaflet. Once I figure it out I will send updated skeleton.