use of de.fhg.igd.mapviewer.marker.area.PolygonArea in project hale by halestudio.
the class InstanceMarker method paintPolygon.
/**
* Paint a polygon geometry.
*
* @param geometry the polygon
* @param g the graphics object to paint on
* @param crsDefinition the CRS definition associated to the geometry
* @param context the context
* @param converter the pixel converter
* @param zoom the zoom level
* @param mapCRS the map coordinate reference system
* @param calculateArea if the area representing the marker should be
* calculated, if <code>false</code> is given here the return
* value is ignored and should be <code>null</code>
* @return the polygon area or <code>null</code> if painting failed
*/
protected Area paintPolygon(Polygon geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
try {
// get CRS converter
CRSConverter conv = CRSConverter.getConverter(crsDefinition.getCRS(), mapCRS);
// exterior
Coordinate[] coordinates = geometry.getExteriorRing().getCoordinates();
java.awt.Polygon outerPolygon = createPolygon(coordinates, conv, converter, zoom);
if (geometry.getNumInteriorRing() > 0) {
// polygon has interior geometries
java.awt.geom.Area drawArea = new java.awt.geom.Area(outerPolygon);
// interior
for (int i = 0; i < geometry.getNumInteriorRing(); i++) {
LineString interior = geometry.getInteriorRingN(i);
java.awt.Polygon innerPolygon = createPolygon(interior.getCoordinates(), conv, converter, zoom);
drawArea.subtract(new java.awt.geom.Area(innerPolygon));
}
if (applyFill(g, context)) {
g.fill(drawArea);
}
if (applyStroke(g, context)) {
g.draw(drawArea);
}
if (calculateArea) {
return new AdvancedPolygonArea(drawArea, outerPolygon);
}
} else {
// visible)
if (applyFill(g, context)) {
g.fill(outerPolygon);
}
if (applyStroke(g, context)) {
g.draw(outerPolygon);
}
if (calculateArea) {
return new PolygonArea(outerPolygon);
}
}
// no calculateArea set
return null;
} catch (Exception e) {
log.error("Error painting instance polygon geometry", e);
return null;
}
}
use of de.fhg.igd.mapviewer.marker.area.PolygonArea in project hale by halestudio.
the class CircleMarker method paintMarker.
/**
* @see SimpleMarker#paintMarker(Object)
*/
@Override
protected Area paintMarker(T context) {
int maxSize = Math.max(2 * 11, size + 2);
Graphics2D g = beginPainting(maxSize, maxSize, maxSize / 2, maxSize / 2);
try {
g.setPaint(getPaintColor(context));
g.fillOval(-size / 2, -size / 2, size, size);
g.setColor(getBorderColor(context));
g.drawOval(-size / 2 - 1, -size / 2 - 1, size + 1, size + 1);
if (showMarker(context)) {
g.setPaint(getMarkerColor(context));
Polygon triangle = new Polygon();
triangle.addPoint(0, 0);
triangle.addPoint(-11, -11);
triangle.addPoint(11, -11);
g.fill(triangle);
return new PolygonArea(new Polygon(new int[] { -11, 11 + 1, size / 2 + 1, -size / 2 - 1 }, new int[] { -11, -11, size / 2 + 1, size / 2 + 1 }, 4));
} else
return new PolygonArea(new Polygon(new int[] { -size / 2 - 1, size / 2 + 1, size / 2 + 1, -size / 2 - 1 }, new int[] { -size / 2 - 1, -size / 2 - 1, size / 2 + 1, size / 2 + 1 }, 4));
} finally {
endPainting(g);
}
}
use of de.fhg.igd.mapviewer.marker.area.PolygonArea in project hale by halestudio.
the class LabelMarker method paintMarker.
/**
* @see SimpleMarker#paintMarker(java.lang.Object)
*/
@Override
protected Area paintMarker(T context) {
String name = getName(context);
Graphics2D dummy = getGraphicsDummy();
int width = (int) dummy.getFontMetrics().getStringBounds(name, dummy).getWidth();
Graphics2D g = beginPainting(width + 10, 30, width / 2 + 5, 0);
try {
g.setPaint(getPaintColor(context));
Polygon triangle = new Polygon();
triangle.addPoint(0, 0);
triangle.addPoint(11, 11);
triangle.addPoint(-11, 11);
g.fill(triangle);
g.fillRoundRect(-width / 2 - 5, 10, width + 10, 20, 10, 10);
// g.setColor(borderColor);
// g.drawRoundRect(-width/2 -5, 10, width+10, 20, 10, 10);
// bounding polygon
// (0,0), (11,11), (width/2 + 5, 10), (width/2 + 5, 30),
// (-width/2 - 5, 30), (-width/2 - 5, 10), (-11, 11)
Polygon bounds = new Polygon(new int[] { 0, 11, width / 2 + 5, width / 2 + 5, -width / 2 - 5, -width / 2 - 5, -11 }, new int[] { 0, 11, 10, 30, 30, 10, 11 }, 7);
// draw text w/ shadow
g.setPaint(Color.BLACK);
// shadow
g.drawString(name, -width / 2 - 1, 26 - 1);
// g.drawString(name, -width/2-1, 26-1); //shadow
g.setPaint(Color.WHITE);
// text
g.drawString(name, -width / 2, 26);
return new PolygonArea(bounds);
} finally {
endPainting(g);
}
}
use of de.fhg.igd.mapviewer.marker.area.PolygonArea in project hale by halestudio.
the class InstanceMarker method paintLine.
/**
* Paint a line string geometry.
*
* @param geometry the line string
* @param g the graphics object to paint on
* @param crsDefinition the CRS definition associated to the geometry
* @param context the context
* @param converter the pixel converter
* @param zoom the zoom level
* @param mapCRS the map coordinate reference system
* @param calculateArea if the area representing the marker should be
* calculated, if <code>false</code> is given here the return
* value is ignored and should be <code>null</code>
* @return the polygon area or <code>null</code> if painting failed
*/
protected Area paintLine(LineString geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
Coordinate[] coordinates = geometry.getCoordinates();
if (coordinates.length <= 0) {
return null;
}
if (coordinates.length == 1) {
// fall back to point drawing
Point point = getGeometryFactory().createPoint(coordinates[0]);
return paintPoint(point, g, crsDefinition, context, converter, zoom, mapCRS, calculateArea);
}
try {
// get CRS converter
CRSConverter conv = CRSConverter.getConverter(crsDefinition.getCRS(), mapCRS);
List<Point2D> mapPoints = new ArrayList<Point2D>(coordinates.length);
for (Coordinate coord : coordinates) {
// manually convert to map CRS
Point3D mapPoint = conv.convert(coord.x, coord.y, 0);
GeoPosition pos = new GeoPosition(mapPoint.getX(), mapPoint.getY(), converter.getMapEpsg());
Point2D point = converter.geoToPixel(pos, zoom);
mapPoints.add(point);
}
if (applyStroke(g, context)) {
for (int i = 0; i < mapPoints.size() - 1; i++) {
// draw each connecting line
Point2D p1 = mapPoints.get(i);
Point2D p2 = mapPoints.get(i + 1);
g.drawLine((int) p1.getX(), (int) p1.getY(), (int) p2.getX(), (int) p2.getY());
}
} else {
log.warn("Stroke disabled in style, LineString is not rendered");
}
if (!calculateArea) {
return null;
}
// use a buffer around the line as area
// XXX
java.awt.Polygon[] buffer = createBufferPolygon(mapPoints, 3);
// ok?
if (buffer.length == 0) {
return null;
} else if (buffer.length == 1) {
return new PolygonArea(buffer[0]);
} else {
Collection<Area> areas = new ArrayList<Area>();
for (java.awt.Polygon bufferPoly : buffer) {
areas.add(new PolygonArea(bufferPoly));
}
return new MultiArea(areas);
}
} catch (Exception e) {
log.error("Error painting instance polygon geometry", e);
return null;
}
}
use of de.fhg.igd.mapviewer.marker.area.PolygonArea in project hale by halestudio.
the class InstanceMarker method paintPoint.
/**
* Paint a point geometry.
*
* @param geometry the point
* @param g the graphics object to paint on
* @param crsDefinition the CRS definition associated to the geometry
* @param context the context
* @param converter the pixel converter
* @param zoom the zoom level
* @param mapCRS the map coordinate reference system
* @param calculateArea if the area representing the marker should be
* calculated, if <code>false</code> is given here the return
* value is ignored and should be <code>null</code>
* @return the point marker area or <code>null</code> if painting failed
*/
protected Area paintPoint(Point geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
try {
/*
* Conversion to map pixel coordinates: Though most of the time the
* result will be the origin (0,0), e.g. for way-points representing
* a single point, the coordinates may also be different, e.g. for
* MultiPoint way-points.
*/
// get CRS converter
CRSConverter conv = CRSConverter.getConverter(crsDefinition.getCRS(), mapCRS);
// manually convert to map CRS
Point3D mapPoint = conv.convert(geometry.getX(), geometry.getY(), 0);
GeoPosition pos = new GeoPosition(mapPoint.getX(), mapPoint.getY(), converter.getMapEpsg());
// determine pixel coordinates
Point2D point = converter.geoToPixel(pos, zoom);
int x = (int) point.getX();
int y = (int) point.getY();
// fall-back: circle
if (applyFill(g, context)) {
g.fillOval(x - defaultPointSize / 2, y - defaultPointSize / 2, defaultPointSize, defaultPointSize);
}
if (applyStroke(g, context)) {
// TODO respect stroke width?
g.drawOval(x - defaultPointSize / 2 - 1, y - defaultPointSize / 2 - 1, defaultPointSize + 1, defaultPointSize + 1);
}
if (calculateArea) {
return new PolygonArea(new java.awt.Polygon(new int[] { x - defaultPointSize / 2 - 1, x + defaultPointSize / 2 + 1, x + defaultPointSize / 2 + 1, x - defaultPointSize / 2 - 1 }, new int[] { y - defaultPointSize / 2 - 1, y - defaultPointSize / 2 - 1, y + defaultPointSize / 2 + 1, y + defaultPointSize / 2 + 1 }, 4));
} else {
return null;
}
} catch (Exception e) {
log.error("Error painting instance point geometry", e);
return null;
}
}
Aggregations