コード例 #1
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
      }
   }
}