How to use the mapnik/sphericalmercator.xyz_to_envelope function in mapnik

To help you get started, we’ve selected a few mapnik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapnik / node-mapnik / examples / tile / database / app.js View on Github external
util.parseXYZ(req, TMS_SCHEME, function(err,params) {
    if (err) {
      res.writeHead(500, {'Content-Type': 'text/plain'});
      res.end(err.message);
    } else {
      try {        
        var map     = new mapnik.Map(256, 256, mercator.proj4);                
        var layer   = new mapnik.Layer('tile', mercator.proj4);
        var postgis = new mapnik.Datasource(postgis_settings);
        var bbox    = mercator.xyz_to_envelope(parseInt(params.x),
                                               parseInt(params.y),
                                               parseInt(params.z), false);    

        layer.datasource = postgis;
        layer.styles     = ['point'];
        
        map.bufferSize = 64;
        map.load(path.join(__dirname,'point_vector.xml'), {strict:true}, function(err,map) {
            if (err) throw err;
            map.add_layer(layer);
    
            // console.log(map.toXML()); // Debug settings
            
            map.extent = bbox;
            var im = new mapnik.Image(map.width,map.height);
            map.render(im, function(err, im) {
github mapnik / node-mapnik / examples / tile / simple / app.js View on Github external
app.get('/:x/:y/:z', function(req, res, next){      

      try {
        // calculate the bounding box for each tile
        var bbox = mercator.xyz_to_envelope(parseInt(req.params.x),
                                            parseInt(req.params.y),
                                            parseInt(req.params.z), false);
      
        // create map
        var map = new mapnik.Map(256, 256, mercator.srs);
        map.load(path.join(__dirname, '../../stylesheet.xml'));
        map.zoom_all();
                  
        // render map
        map.render(bbox, 'png', function(err, buffer) {
          if (err) {
            throw err;
          } else {
            res.statusCode = 200;
            res.setHeader('Content-Type', 'image/png');        
            res.end(buffer);
github springmeyer / coalition / server / app.js View on Github external
res.end(fs.readFileSync('./public/' + req.url));      
        }
      } catch (err) {
            res.end('Not found: ' + req.url);      
      }
  } else {
        
      if (query &&
          query.x !== undefined &&
          query.y !== undefined &&
          query.z !== undefined &&
          query.sql !== undefined &&
          query.style !== undefined
          ) {
    
          var bbox = mercator.xyz_to_envelope(parseInt(query.x),
                                              parseInt(query.y),
                                              parseInt(query.z), false);
          var map = new mapnik.Map(256, 256, mercator.srs);
          map.buffer_size(50);
          var layer = new mapnik.Layer('tile', mercator.srs);
          try {
              settings.postgis.table = unescape(query.sql);
              var postgis = new mapnik.Datasource(settings.postgis);
              layer.datasource = postgis;
              styles = [query.style];
              map.load(path.join(settings.styles, query.style + '.xml'));
              // labels
              styles.push('text');
              map.load(path.join(settings.styles, 'text.xml'));
              layer.styles = styles;
              map.add_layer(layer);
github mapnik / node-mapnik / examples / tile / dynamic / app.js View on Github external
http.createServer(function(req, res) {

  var query = url.parse(req.url, true).query;

  if (query &&
      query.x !== undefined &&
      query.y !== undefined &&
      query.z !== undefined
      ) {

      var map = new mapnik.Map(tile, tile);

      res.writeHead(200, {'Content-Type': 'image/png'});

      var bbox = mercator.xyz_to_envelope(parseInt(query.x), parseInt(query.y), parseInt(query.z), false);

      map.from_string(s, path.join(__dirname, './'));
      //map.load('../../examples/stylesheet.xml')
      //console.log(map.to_string());

      if (async_render) {
          map.render(bbox, 'png', function(err, image) {
              if (err) {
                  res.writeHead(500, {
                    'Content-Type': 'text/plain'
                  });
                  res.end(err.message);
              } else {
                  res.end(image);
              }
          });
github mapnik / node-mapnik / examples / tile / elastic / app.js View on Github external
http.createServer(function(req, res) {

  var query = url.parse(req.url, true).query;

  if (query &&
      query.x !== undefined &&
      query.y !== undefined &&
      query.z !== undefined
      ) {

      var map = new mapnik.Map(tile, tile);

      res.writeHead(200, {'Content-Type': 'image/png'});

      var bbox = mercator.xyz_to_envelope(parseInt(query.x), parseInt(query.y), parseInt(query.z), false);
      map.fromString(s,
          {strict:true,base:'./'},
          function (err, map) {
              if (err) {
                  res.writeHead(500, {
                    'Content-Type': 'text/plain'
                  });
                  res.end(err.message);
              }

              var options = {
                  extent: '-20037508.342789,-8283343.693883,20037508.342789,18365151.363070',
              };
        
              var mem_ds = new mapnik.MemoryDatasource(options);