diff options
Diffstat (limited to 'platform/node/examples/load-from-fs.js')
-rwxr-xr-x | platform/node/examples/load-from-fs.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/platform/node/examples/load-from-fs.js b/platform/node/examples/load-from-fs.js new file mode 100755 index 0000000000..352b015573 --- /dev/null +++ b/platform/node/examples/load-from-fs.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node +/* jshint node: true, unused: false */ +'use strict'; + +var mbgl = require('..'); +var fs = require('fs'); +var path = require('path'); +var PNG = require('pngjs').PNG; + +var base = path.join(path.dirname(process.mainModule.filename), '../test'); + +var map = new mbgl.Map({ + request: function(req) { + fs.readFile(path.join(base, req.url), function(err, data) { + req.respond(err, { data: data }); + }); + } +}); + +map.load(require('../test/fixtures/style.json')); + +map.render({}, function(err, data) { + if (err) throw err; + + var png = new PNG({ + width: data.width, + height: data.height + }); + + png.data = data.pixels; + + png.pack() + .pipe(fs.createWriteStream('image.png')) + .on('finish', function() { + console.warn('Written image.png'); + }); +}); |