light map
minimal, lightweight, self contained XYZ tile map viewer with a 2d canvas renderer.
live example
- an example with the most common methods let's you set the lat/lon/zoom, change the width/height of the canvas and monitor the load progress.
- a basic example of controls you should be able to drag the map around.
- an example of retina support first I thought it wasn't much but it seems to be a big deal. it's based on the devicePixelRatio, ideally you should use a @2x provider but I did an internal nearest neighbour resize.
- an example with a vignette as the map output is a Canvas2D, this shows how to post process the output.
more info
basic example
<script src="light-map.min.js"></script> <script> var provider = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; var domains = "a,b,c"; var map = provider domains 512512018 ; documentbody; map;</script>
vignette example
<script src="light-map.min.js"></script> <script> // provider: URL of the tile map service // domains: URL of the domains used by the tile map service // you can choose from a list of *free* TMS providers: // http://leaflet-extras.github.io/leaflet-providers/preview/ // example: // // provider = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; // domains = [ "a", "b", "c" ]; // //alternately you can use .mbtiles var provider domains; provider = "http://ttiles{s}.mqcdn.com/tiles/1.0.0/vy/sat/{z}/{x}/{y}.png"; domains = "01" "02" "03" "04" ; // you may need to use a proxy to load images on local servers // check out this gist : https://gist.github.com/nicoptere/a23ffae9ed51a5ca9766 var proxy = "";//"./proxy.php?url="; var map = proxy + provider domains 512512 0 10 ; documentbody; //listening to the loading events { ifstatus==0 console; } //a new tile was loaded here { console; } //the canvas' context is returned here { console; } mapeventEmitter; mapeventEmitter; mapeventEmitter; //this would be where I live :) var lat = o_lat = 48854777; var lon = o_lon = 2317499; var zoom = 16; map; //it can be done in a loop { var t = Math ; lat = o_lat; lon = o_lon + t * 0025; map; } ; // as the result is a canvas, it's possible // to add post processing to map.ctx { //create a gradient var w2 = mapwidth / 2; var grd = ctx; // Add colors grd; grd; // Fill with gradient ctxfillStyle = grd; ctx; } mapeventEmitter; </script>
npm module installation
npm install light-map --save
related
Python library to perform Mercator conversions
npm globalMercator
License
This content is released under the MIT License.