0

I'm looking to create XYZ tiles for use in leafletjs with nodejs. Previously I've been creating my tiles using this python library (gdal2tiles).

I was wondering if anyone had yet written a nodejs equivalent?

I'm looking to take a single png image and specify the zoom range for the tiles to generated at, min zoom probably defined by log2(max(width, height)/tilesize)

Ideally each zoom range could be created by an independent process as I'd like to spin up a separate AWS lambda instance for each zoom level and upload the tiles to an S3 bucket in parallel.

How do I generate these tiles in JS rather than Python where I lack the knowledge to edit?

  • I am looking for something similar. Did you ever get around to solving this? – Shaunak Oct 16 '17 at 2:35
  • Unfortunately not, I resorted to modifying my previous gdal2tiles script in python – Titan Oct 16 '17 at 6:39
1

I was able to create this in PHP using the following pseudo code

load source image

for each zoom level (0-maxZoom) as zoomLevel
    resize source image based on current zoomLevel pow(2, 8 + zoomLevel)

    while xCoordPointer < resized image size

        while yCoordPointer <= resized image size

            crop resized image at current xCoordPointer, yCoordPointer at 256 x 256

            save in path format /zoomLevel/xCount/yCount.png

            increment yCoordPointer + 256
            increment yCount + 1

        reset yCoordPonter = 0
        reset yCount = 0

        increment xCoordPointer + 256
        increment xCount + 1

maxZoom calculated by

ceil(log(max(originalImageWidth, originalImageHeight) / 256, 2))

I attempted it in Node.js but unfortunately every library I tried choked on the very large image source (~80MB)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.