From 3ef98d5060833f480c0c6deca6127f68d893303c Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Thu, 29 Sep 2016 16:14:48 +0200 Subject: [PATCH 1/2] #206 - calculate label point in map --- .../rendering/r2d/GeometryClipper.java | 31 ++++++- .../rendering/r2d/Java2DLabelRenderer.java | 91 +++++++++++-------- 2 files changed, 81 insertions(+), 41 deletions(-) diff --git a/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/GeometryClipper.java b/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/GeometryClipper.java index fbbc50cea3..af9bb7bf76 100644 --- a/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/GeometryClipper.java +++ b/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/GeometryClipper.java @@ -44,18 +44,25 @@ Occam Labs UG (haftungsbeschränkt) import static org.deegree.commons.utils.math.MathUtils.isZero; import static org.deegree.rendering.r2d.OrientationFixer.fixOrientation; +import org.deegree.commons.tom.TypedObjectNode; import org.deegree.geometry.Envelope; import org.deegree.geometry.Geometries; import org.deegree.geometry.Geometry; +import org.deegree.geometry.GeometryFactory; +import org.deegree.geometry.multi.MultiPolygon; import org.deegree.geometry.primitive.Point; import org.deegree.geometry.primitive.Polygon; import org.deegree.geometry.standard.AbstractDefaultGeometry; import org.deegree.geometry.standard.DefaultEnvelope; import org.deegree.geometry.standard.primitive.DefaultPoint; +import org.deegree.geometry.standard.primitive.DefaultSurface; import org.deegree.style.styling.LineStyling; import org.deegree.style.styling.PolygonStyling; import org.deegree.style.styling.components.Stroke; +import java.util.ArrayList; +import java.util.List; + /** * Responsible for clipping geometries to the area of the viewport. * @@ -115,7 +122,29 @@ Geometry clipGeometry( final Geometry geom ) { } return geom; } - + + Geometry calculateInteriorPoints( final Geometry geom ) { + if( geom == null ) + return null; + try { + List points = new ArrayList(); + if ( geom != null && geom instanceof DefaultSurface ) { + points.add( ( (DefaultSurface) geom ).getInteriorPoint() ); + } + if ( geom != null && geom instanceof MultiPolygon ) { + for ( Polygon p : ( (MultiPolygon) geom ) ) { + if ( p instanceof DefaultSurface ) { + points.add( ( (DefaultSurface) p ).getInteriorPoint() ); + } + } + } + return new GeometryFactory().createMultiPoint( null, geom.getCoordinateSystem(), points ); + } catch ( UnsupportedOperationException e ) { + // use original geometry if intersection not supported by JTS + return geom; + } + } + /** * Check if the passed Geometry is a Polygon (or the first Geometry of a Collection) and the exterior Ring has CW orientation * diff --git a/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/Java2DLabelRenderer.java b/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/Java2DLabelRenderer.java index 5c6bd62bf4..88fc892ccf 100644 --- a/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/Java2DLabelRenderer.java +++ b/deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/Java2DLabelRenderer.java @@ -65,10 +65,7 @@ Occam Labs UG (haftungsbeschränkt) import org.deegree.geometry.multi.MultiGeometry; import org.deegree.geometry.multi.MultiLineString; import org.deegree.geometry.multi.MultiPoint; -import org.deegree.geometry.primitive.Curve; -import org.deegree.geometry.primitive.GeometricPrimitive; -import org.deegree.geometry.primitive.Point; -import org.deegree.geometry.primitive.Surface; +import org.deegree.geometry.primitive.*; import org.deegree.rendering.r2d.strokes.OffsetStroke; import org.deegree.rendering.r2d.strokes.TextStroke; import org.deegree.style.styling.TextStyling; @@ -76,22 +73,21 @@ Occam Labs UG (haftungsbeschränkt) /** * Responsible for creating and rendering of labels. Based on Java2DTextRenderer - * + * * @author Florian Bingel * @author last edited by: $Author: stranger $ - * * @version $Revision: $, $Date: $ */ public class Java2DLabelRenderer implements LabelRenderer { static final Logger LOG = getLogger( Java2DLabelRenderer.class ); - + private Java2DRenderer renderer; private RendererContext context; - + private Java2DTextRenderer textRenderer; - + private ArrayList