Search in sources :

Example 1 with GeometryComponent

use of com.revolsys.geometry.model.GeometryComponent in project com.revolsys.open by revolsys.

the class MapPanel method findCloseLocation.

public CloseLocation findCloseLocation(final GeometryFactory viewportGeometryFactory2d, final AbstractRecordLayer layer, final LayerRecord record, final Geometry geometry, final double x, final double y, final double maxDistance) {
    final Geometry convertedGeometry = geometry.convertGeometry(viewportGeometryFactory2d);
    final Pair<GeometryComponent, Double> closestGeometryComponent = convertedGeometry.findClosestGeometryComponent(x, y, maxDistance);
    if (!closestGeometryComponent.isEmpty()) {
        final GeometryComponent geometryComponent = closestGeometryComponent.getValue1();
        if (geometryComponent instanceof Vertex) {
            final Vertex convertedVertex = (Vertex) geometryComponent;
            final int[] vertexId = convertedVertex.getVertexId();
            // Get the vertex from the original geometry
            final Vertex vertex = geometry.getVertex(vertexId);
            return new CloseLocation(layer, record, vertex);
        } else if (geometryComponent instanceof Segment) {
            final Segment convertedSegment = (Segment) geometryComponent;
            final int[] segmentId = convertedSegment.getSegmentId();
            // Get the segment from the original geometry
            final Segment segment = geometry.getSegment(segmentId);
            final Point closePoint = convertedSegment.project(x, y);
            final Point sourcePoint = geometry.convertGeometry(closePoint);
            return new CloseLocation(layer, record, segment, closePoint, sourcePoint);
        }
    }
    return null;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) GeometryComponent(com.revolsys.geometry.model.GeometryComponent) Vertex(com.revolsys.geometry.model.vertex.Vertex) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)1 GeometryComponent (com.revolsys.geometry.model.GeometryComponent)1 Point (com.revolsys.geometry.model.Point)1 Segment (com.revolsys.geometry.model.segment.Segment)1 Vertex (com.revolsys.geometry.model.vertex.Vertex)1 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)1