diff --git a/leaflet.css b/Leaflet/leaflet.css similarity index 100% rename from leaflet.css rename to Leaflet/leaflet.css diff --git a/leaflet.js b/Leaflet/leaflet.js similarity index 100% rename from leaflet.js rename to Leaflet/leaflet.js diff --git a/README.rst b/README.rst index 7d4c6fc..7b91a0b 100644 --- a/README.rst +++ b/README.rst @@ -103,6 +103,13 @@ tilesize: a multiple of 16. The filenames will be created in the form __, where and are the tile numbers and is the name specified with -o. Skip empty tiles by also specifying --noemptyimage. +leaflet: + Together with --tilesize, output tiles in a leaflet-compaitble numbering and also output a html file to display the map. + Copy the files in the Leaflet subfolder to the same folder as your map. + +buildpyramid: + Together with --leaflet, build a zoom pyramid for faster zooming/loading of the generated map. + zoom: Apply zoom to drawn nodes by enlarging them to n*n squares, e.g. ``--zoom 4`` diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 239e65b..080ad79 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "TileGenerator.h" #include "config.h" @@ -81,6 +82,7 @@ TileGenerator::TileGenerator(): m_shading(true), m_leaflet(false), m_dontWriteEmpty(false), + m_buildPyramid(false), m_backend(""), m_xBorder(0), m_yBorder(0), @@ -185,6 +187,11 @@ void TileGenerator::setLeaflet(bool leaflet) m_leaflet = leaflet; } +void TileGenerator::setBuildPyramid(bool pyramid) +{ + m_buildPyramid = pyramid; +} + void TileGenerator::setBackend(std::string backend) { m_backend = backend; @@ -251,10 +258,6 @@ void TileGenerator::setDontWriteEmpty(bool f) void TileGenerator::generate(const std::string &input, const std::string &output) { - if (m_leaflet) - { - outputLeafletCode(output); - } string input_path = input; if (input_path[input.length() - 1] != PATH_SEPARATOR) { @@ -294,6 +297,22 @@ void TileGenerator::generate(const std::string &input, const std::string &output tilePositions(); + // round xMax/zMax tot integer number of tiles + m_xMax = m_xMin + m_numTilesX * m_tileW; + m_zMax = m_zMin + m_numTilesY * m_tileH; + + int maxZoomLevel = 0; + if (m_buildPyramid) + { + int maxDimX = m_xMax > -m_xMin ? m_xMax : -m_xMin; + int maxDimY = m_zMax > -m_zMin ? m_zMax : -m_zMin; + int maxDim = maxDimX > maxDimY ? maxDimX : maxDimY; + + maxZoomLevel = static_cast(log2(maxDim / m_tileW)) + 1; + } + + + int trueXMin = m_xMin; int trueZMin = m_zMin; @@ -322,8 +341,16 @@ void TileGenerator::generate(const std::string &input, const std::string &output renderPlayers(input_path); } ostringstream fn; + if (m_leaflet) + { + fn << maxZoomLevel << "_"; + } fn << x + minTileX << '_' << (flipY * (y + minTileZ)) << '_' << output; writeImage(fn.str()); + if (m_buildPyramid) + { + m_availableTiles.insert(Coords(x + minTileX,(flipY * (y + minTileZ)))); + } } } } @@ -334,6 +361,15 @@ void TileGenerator::generate(const std::string &input, const std::string &output m_image->fill(m_bgColor); writeImage(fn.str()); } + if (m_buildPyramid) + { + buildPyramid(output, maxZoomLevel); + } + if (m_leaflet) + { + outputLeafletCode(output, maxZoomLevel); + } + } else { @@ -843,12 +879,12 @@ static char const *leafletMapHtml = "