context.getLayer().setStatus(ILayer.WORKING);
listenService(true);
// initialise the graphics handle
ViewportGraphics graphic = context.getGraphics();
if (graphic instanceof AWTGraphics) {
AWTGraphics awtG = (AWTGraphics) graphic;
Graphics2D g2D = awtG.g;
// setting rendering hints
@SuppressWarnings("unchecked")
RenderingHints hints = new RenderingHints(Collections.EMPTY_MAP);
hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
g2D.addRenderingHints(hints);
}
Dimension screen = context.getMapDisplay().getDisplaySize();
// get the AOI
IAOIService aOIService = PlatformGIS.getAOIService();
Geometry multiGeometry = aOIService.getGeometry();
if (multiGeometry != null) {
Geometry innerPolygons = null;
Polygon polygon = null;
// draw the rectangle around the active region green:143
//float[] rgba = style.backgroundColor.getColorComponents(null);
//g.setColor(new Color(rgba[0], rgba[1], rgba[2], style.bAlpha));
graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.5));
int screenWidth = screen.width;
int screenHeight = screen.height;
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
path.moveTo(0, 0);
path.lineTo(screenWidth, 0);
path.lineTo(screenWidth, screenHeight);
path.lineTo(0, screenHeight);
path.closePath();
// if multi geometry - loop through each geometry
for (int g=0; g<multiGeometry.getNumGeometries(); g++) {
Geometry geometry = multiGeometry.getGeometryN(g);
if (geometry.getGeometryType().equals("Polygon")){
polygon = (Polygon) geometry;
// get the exterior rings
LineString exterior = polygon.getExteriorRing();
// collects the internal holes if there are any
for (int i=0; i<polygon.getNumInteriorRing(); i++) {
if (innerPolygons == null) {
innerPolygons = polygon.getInteriorRingN(i);
}
else {
innerPolygons = innerPolygons.union(polygon.getInteriorRingN(i));
}
}
Coordinate[] coordinates = exterior.getCoordinates();
// move to the first point
Point point = null;
if (coordinates.length > 0) {
point = context.worldToPixel(coordinates[0]);
path.moveTo(point.x, point.y);
}
// draw all points
for (int c=0; c<coordinates.length; c++) {
point = context.worldToPixel(coordinates[c]);
path.lineTo(point.x, point.y);
}
path.closePath();
}
}
graphic.fill(path);
//rgba = style.foregroundColor.getColorComponents(null);
//g.setColor(new Color(rgba[0], rgba[1], rgba[2], style.fAlpha));
graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.75));
graphic.setStroke(ViewportGraphics.LINE_SOLID, 1);
graphic.draw(path);
// draw inner rings / holes
if (innerPolygons != null) {
for (int g=0; g<innerPolygons.getNumGeometries(); g++) {
path.reset();
Geometry geometry = innerPolygons.getGeometryN(g);
Coordinate[] coordinates = geometry.getCoordinates();
// move to the first point
Point point = null;
if (coordinates.length > 0) {
point = context.worldToPixel(coordinates[0]);
path.moveTo(point.x, point.y);
}
// draw all points
for (int c=0; c<coordinates.length; c++) {
point = context.worldToPixel(coordinates[c]);
path.lineTo(point.x, point.y);
}
path.closePath();
graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.5));
graphic.fill(path);
graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.75));
graphic.draw(path);
}
}
}
context.getLayer().setStatus(ILayer.DONE);