abaculus
abaculus copied to clipboard
Basic example?
Hi,
I'm trying to use Abaculus to generate a hi-res image. However, I haven't got the hang of the getTile function.
Could you give a simple example that, say, uses tiles from examples.map-zr0njcqy (from the developer docs: http://api.tiles.mapbox.com/v4/examples.map-zr0njcqy/0/0/0.png?access_token=pk.eyJ1Ijoid3JpZ2dsZXIiLCJhIjoiOXBUMjFERSJ9.jo2f0W7fTzbX-7lj_8pk7g) and saves an image to the local disk?
This is as far as I got, and the getTile function (at least) is clearly incorrect.
// Calculate image bounds from center lng,lat coordinates and
// pixel dimensions of final image (will be multipled by scale).
var params = {
zoom: 4,
scale: 4,
center: {
x: 20,
y: -10,
w: 100,
h: 100
},
//format: {format},
//quality: {quality},
getTile: function(z,x,y, callback){
// do something
return 'http://api.tiles.mapbox.com/v4/examples.map-zr0njcqy/' + z + '/' + x + '/' + y + '.png?access_token=pk.eyJ1Ijoid3JpZ2dsZXIiLCJhIjoiOXBUMjFERSJ9.jo2f0W7fTzbX-7lj_8pk7g';
//return callback(null, buffer, headers);
},
//limit: {limit}
};
abaculus(params, function(err, image){
if (err) return err;
console.log('File saved.');
// do something with image
});
I know that the Static Maps API exists, but this does not allow images large enough for my purposes.
Many thanks,
I too would love a basic example as I'm having difficulty working out how to get abaculus to work. Cheers :-)
I am having the same difficulty building the getTile function! any luck?
var request = require('request');
var abaculus = require('abaculus');
// Calculate image bounds from center lng,lat coordinates and
// pixel dimensions of final image (will be multipled by scale).
var params = {
zoom: 14,
scale: 1, // 1=72dpi, 4=288dpi
center: {
x: 6.6566667,
y: 53.216667,
w: 1000,
h: 1000
},
// format: {format}, // png
// quality: {quality},
getTile: function(z,x,y, callback){
var url = 'http://tile.openstreetmap.org/'+z+'/'+x+'/'+y+'.png';
request({
method: 'GET',
url: url,
encoding: null
}, function(err, response, body) {
if (err) {
return callback(err);
}
console.log('got url', url);
callback(null, body, response.headers);
});
}
// limit: {limit}
};
abaculus(params, function(err, image, headers){
if (err) return err;
require('fs').writeFile('image.png', image, function(err, res) {
console.log(err ? err : 'success');
});
});