use of org.activityinfo.shared.util.mapping.Tile in project activityinfo by bedatadriven.
the class AdminTileRenderer method render.
public byte[] render(int zoom, int x, int y) throws IOException {
Extents extents = TileMath.tileBounds(zoom, x, y);
mapPixelBounds = new Envelope(0, TileMath.TILE_SIZE, 0, TileMath.TILE_SIZE);
Envelope envelope = new Envelope(extents.getMinLon(), extents.getMaxLon(), extents.getMinLat(), extents.getMaxLat());
Geometry filter = gf.toGeometry(envelope);
LOGGER.info("Creating Buffered Image...");
BufferedImage image = new BufferedImage(TileMath.TILE_SIZE, TileMath.TILE_SIZE, ColorSpace.TYPE_RGB);
Graphics2D g2d = image.createGraphics();
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, TileMath.TILE_SIZE, TileMath.TILE_SIZE);
LOGGER.info("Querying geometry...");
Criteria criteria = session.createCriteria(AdminEntity.class);
criteria.add(SpatialRestrictions.filter("geometry", filter));
criteria.add(Restrictions.eq("level", level));
TiledMap map = new TiledMap(zoom, new Tile(x, y));
g2d.setColor(Color.BLACK);
g2d.setStroke(new BasicStroke(1));
g2d.setFont(new Font("Arial", 0, 10));
List<AdminEntity> entities = criteria.list();
/*
* Project Geometry onto this tile
*/
LOGGER.info("Projecting geometry...");
GeometryProjecter projector = new GeometryProjecter(map);
Map<Integer, Geometry> projected = Maps.newHashMap();
for (AdminEntity entity : entities) {
LOGGER.info(entity.getName());
Geometry transformed = projector.transform(entity.getGeometry());
Geometry simplified = DouglasPeuckerSimplifier.simplify(transformed, 1.25);
projected.put(entity.getId(), simplified);
}
/*
* Draw outlines
*/
LOGGER.info("Drawing geometry...");
for (AdminEntity entity : entities) {
Geometry geom = projected.get(entity.getId());
g2d.draw(toPath(geom));
}
/*
* Draw labels
*/
LOGGER.info("Drawing geometry...");
for (AdminEntity entity : entities) {
Geometry geom = projected.get(entity.getId());
// Polygon polygon = largestPolygon(geom);
//
// if (polygon != null) {
// labelPolygon(g2d, polygon, entity.getName());
// }
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
return baos.toByteArray();
}
Aggregations