Skip to content

Instantly share code, notes, and snippets.

@hassaananjum
Created March 7, 2018 07:01
Show Gist options
  • Save hassaananjum/57c54c0a46c1b70169fd743b60605994 to your computer and use it in GitHub Desktop.
Save hassaananjum/57c54c0a46c1b70169fd743b60605994 to your computer and use it in GitHub Desktop.
// bing static map generator
var http = require('http');
var fs = require('fs');
var Jimp = require('jimp');
var uuid = require('uuid');
var url = require('url');
http.createServer(function(req, res){
console.log(req.url);
var url_parts = url.parse(req.url, true);
var centerPoint = url_parts.query.centerPoint;
var zoom = url_parts.query.zoom;
var mapSize = url_parts.query.mapSize;
var dpi = url_parts.query.dpi;
var key = url_parts.query.key
console.log(url_parts);
fileId = uuid.v4();
Jimp.read(`http://dev.virtualearth.net/REST/V1/Imagery/Map/Aerial/${centerPoint}/${zoom}?mapSize=${mapSize}&dpi=${dpi}&key=${key}`, function (err, bingMap) {
if (err) throw err;
console.log(bingMap.getMIME());
bingMap.crop( 320, 320, 640, 640 )
.scale( 2 )
.write(`/tmp/image_${fileId}.jpg`, function(){
res.setHeader("Content-Type", "image/jpeg");
fs.createReadStream(`/tmp/image_${fileId}.jpg`).pipe(res);
})
});
}).listen(3434, '0.0.0.0');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment