maptiler-js

1.1.3 • Public • Published

maptiler-js

Calculate tiles required for a given geographic extent. The coordinates are based on Global Mercator EPSG:3857 and made to work with existing web mapping libraries like Openlayers, Leaflet, MapboxGL, d3 etc..

Pass a geographic extent and zoom level (0-30). Coordinates must be Latitudes and Longitudes.

var tiles = maptiler.getTiles(177.13846,-38.03898,177.26629,-37.99240,12);

Think of extent as the left, bottom, right and top sides of a box.

An object is returned representing an array of all tiles making up the extent at that particular zoom level. The extent arrays can be used to clip the source dataset. The tms/google arrays are how you save the file within the directory structure... And how the files are located by most mapping frameworks.

[0:
  extent3857: [19714638.33531266, -4588667.6820157, 19724422.274933163, -4578883.742395198],
  extent4326: [177.09960937500003, -38.06539235133247, 177.1875, -37.996162679728116],
  google: [12, 4063, 2516],
  tms: [12, 4063, 1579]]
1: ...
2: ...
3: ...
 

The rest is up to you. ☺

Redis Support

Node/io has a hard limit for memory usage. Which can be exceeded when calculating millions of tiles. I personally found anything over 800,000 caused a core dump. This can be overcome by using a memory cache store like Redis. Just make sure you have it installed. Along with a node client like node-redis.

redis = require("redis");
maptiler = require("maptiler-js");
 
maptiler.redis.turnOn(); // Use Redis
 
printFirstTile = function (tiles) {
  redis.lpop(tiles, function (tile) {
    console.log(tile);
  });
}
The variable *tiles* is just the object store name in Redis that was allocated by maptiler.
 
maptiler.getTiles(177.13846,-38.03898,177.26629,-37.99240,12,printFirstTile);

Or if you have a small amout of tiles you can allow them to be stored in a regular javascript array.

printAllTiles = function (tiles) {
  console.log(tiles);
}
 
maptiler.getTiles(177.13846,-38.03898,177.26629,-37.99240,12,printAllTiles);

Most logic was ported from the maptiler python module. Adapted for node/io or the browser. Redis functionality is limited to server side.

Readme

Keywords

none

Package Sidebar

Install

npm i maptiler-js

Weekly Downloads

1

Version

1.1.3

License

ISC

Unpacked Size

31.8 kB

Total Files

10

Last publish

Collaborators

  • popkinj