コード例 #1
0
ファイル: renderer.hpp プロジェクト: mapycz/mapnik
 image_type render(mapnik::Map & map, double scale_factor, map_size const & tiles) const
 {
     mapnik::box2d<double> box = map.get_current_extent();
     image_type image(map.width(), map.height());
     map.resize(image.width() / tiles.width, image.height() / tiles.height);
     double tile_box_width = box.width() / tiles.width;
     double tile_box_height = box.height() / tiles.height;
     for (std::size_t tile_y = 0; tile_y < tiles.height; tile_y++)
     {
         for (std::size_t tile_x = 0; tile_x < tiles.width; tile_x++)
         {
             mapnik::box2d<double> tile_box(
                 box.minx() + tile_x * tile_box_width,
                 box.miny() + tile_y * tile_box_height,
                 box.minx() + (tile_x + 1) * tile_box_width,
                 box.miny() + (tile_y + 1) * tile_box_height);
             map.zoom_to_box(tile_box);
             image_type tile(ren.render(map, scale_factor));
             set_rectangle(tile, image, tile_x * tile.width(), (tiles.height - 1 - tile_y) * tile.height());
         }
     }
     return image;
 }
コード例 #2
0
//------------------------------------------------------------------------------
void TileRenderer::RenderTile(std::string tile_uri, mapnik::Map m, int x, int y, int zoom, GoogleProjection tileproj, mapnik::projection prj, bool verbose, bool overrideTile, bool lockEnabled, std::string compositionLayerPath, std::string compositionMode, double compositionAlpha)
{
   if(!overrideTile && FileSystem::FileExists(tile_uri))
   {
      return;
   }
   else
   {
	   
       
      // Calculate pixel positions of bottom-left & top-right
      ituple p0(x * 256, (y + 1) * 256);
      ituple p1((x + 1) * 256, y * 256);

      // Convert to LatLong (EPSG:4326)
      dtuple l0 = tileproj.pixel2GeoCoord(p0, zoom);
      dtuple l1 = tileproj.pixel2GeoCoord(p1, zoom);

	  

      // Convert to map projection (e.g. mercator co-ords EPSG:900913)
      dtuple c0(l0.a,l0.b);
      dtuple c1(l1.a,l1.b);
      prj.forward(c0.a, c0.b);
      prj.forward(c1.a, c1.b);

      // Bounding box for the tile
#ifndef MAPNIK_2
      mapnik::Envelope<double> bbox = mapnik::Envelope<double>(c0.a,c0.b,c1.a,c1.b);
      m.resize(256,256);
      m.zoomToBox(bbox);
#else
      mapnik::box2d<double> bbox(c0.a,c0.b,c1.a,c1.b);
      m.resize(256,256);
      m.zoom_to_box(bbox);
#endif
      m.set_buffer_size(128);

      // Render image with default Agg renderer

#ifndef MAPNIK_2
      mapnik::Image32 buf(m.getWidth(),m.getHeight());
      mapnik::agg_renderer<mapnik::Image32> ren(m,buf);
#else
      mapnik::image_32 buf(m.width(), m.height());
      mapnik::agg_renderer<mapnik::image_32> ren(m,buf);
#endif
      ren.apply();
      if(lockEnabled)
      {
         int lockhandle = FileSystem::Lock(tile_uri);
#ifndef MAPNIK_2
		 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.getWidth(),m.getHeight(),&buf, zoom, x,y);
         mapnik::save_to_file<mapnik::ImageData32>(buf.data(),tile_uri,"png");
#else
	 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.width(),m.height(),&buf, zoom, x,y);
	 mapnik::save_to_file<mapnik::image_data_32>(buf.data(),tile_uri,"png");
#endif
         FileSystem::Unlock(tile_uri, lockhandle);
      }
      else
      {
#ifndef MAPNIK_2
		 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.getWidth(),m.getHeight(),&buf, zoom, x,y);
         mapnik::save_to_file<mapnik::ImageData32>(buf.data(),tile_uri,"png");
#else
		Compose(compositionLayerPath, compositionMode, compositionAlpha, m.width(),m.height(),&buf, zoom, x,y);
		mapnik::save_to_file<mapnik::image_data_32>(buf.data(),tile_uri,"png");
#endif
      }
   }
}