Skip to content

Instantly share code, notes, and snippets.

@YenTheFirst
Created February 23, 2013 01:21
Show Gist options
  • Save YenTheFirst/5017847 to your computer and use it in GitHub Desktop.
Save YenTheFirst/5017847 to your computer and use it in GitHub Desktop.
rendering tile based on XML file with node-mapnik
options = {z:7,x:35,y:54, metatile:1, tileSize:256,format:'png'}
calculateMetatile = require('tilelive-mapnik/lib/render')['calculateMetatile']
meta = calculateMetatile({z:7,x:35,y:54, metatile:1, tileSize:256,format:'png'})
var mapnik = require('mapnik')
options.headers = { 'Content-Type': 'image/png' };
var image = new mapnik.Image(meta.width, meta.height);
var map = new mapnik.Map(256,256);
map.bufferSize=0
map.fromString(path_to_Xml, {strict: false, base: path_to_base}, function(err,map) {console.log('done')})
map.loadSync(<path_to_xml>)
map.resize(meta.width, meta.height);
map.extent = meta.bbox;
map.render(image, options, function(err,image) {console.log("done!",err,image)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment