Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic example? #11

Open
ikmolbo opened this issue Nov 16, 2014 · 3 comments
Open

Basic example? #11

ikmolbo opened this issue Nov 16, 2014 · 3 comments

Comments

@ikmolbo
Copy link

ikmolbo commented Nov 16, 2014

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,

@oldo
Copy link

oldo commented May 15, 2015

I too would love a basic example as I'm having difficulty working out how to get abaculus to work. Cheers :-)

@poussinxt
Copy link

I am having the same difficulty building the getTile function! any luck?

@ssured
Copy link

ssured commented Sep 18, 2015

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');
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants