Search in sources :

Example 1 with ConstellationPointFeature

use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature in project constellation by constellation-app.

the class MapViewTileRenderer method mouseReleased.

@Override
public void mouseReleased(final MouseEvent event) {
    assert !SwingUtilities.isEventDispatchThread();
    if (event.getButton() == PConstants.CENTER) {
        // zoom to box
        if (boxZoomEnabled) {
            // update the box
            boxDeltaX = event.getX();
            boxDeltaY = event.getY();
            final Set<ConstellationAbstractMarker> markers = new HashSet<>();
            final float minX = Math.min(boxOriginX, boxDeltaX);
            final float minY = Math.min(boxOriginY, boxDeltaY);
            final float maxX = Math.max(boxOriginX, boxDeltaX);
            final float maxY = Math.max(boxOriginY, boxDeltaY);
            try {
                final ConstellationAbstractMarker topLeftMarker = markerFactory.createMarker(new ConstellationPointFeature(map.getLocation(minX, minY)));
                final ConstellationAbstractMarker topRightMarker = markerFactory.createMarker(new ConstellationPointFeature(map.getLocation(maxX, minY)));
                final ConstellationAbstractMarker bottomLeftMarker = markerFactory.createMarker(new ConstellationPointFeature(map.getLocation(minX, maxY)));
                final ConstellationAbstractMarker bottomRightMarker = markerFactory.createMarker(new ConstellationPointFeature(map.getLocation(maxX, maxY)));
                markers.add(topLeftMarker);
                markers.add(topRightMarker);
                markers.add(bottomLeftMarker);
                markers.add(bottomRightMarker);
            } catch (Exception ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
            }
            handleMouseZoom(markers);
            boxOriginX = -1;
            boxOriginY = -1;
            boxDeltaX = -1;
            boxDeltaY = -1;
            boxZoomEnabled = false;
        }
    } else if (event.getButton() == PConstants.LEFT && boxSelectionEnabled) {
        // select markers
        // update the box
        boxDeltaX = event.getX();
        boxDeltaY = event.getY();
        handleMouseSelection(event, calculateBoxSelection());
        boxOriginX = -1;
        boxOriginY = -1;
        boxDeltaX = -1;
        boxDeltaY = -1;
        boxSelectionEnabled = false;
    } else {
    // Do nothing
    }
    layers.forEach(layer -> layer.mouseReleased(event));
    overlays.forEach(overlay -> overlay.mouseReleased(event));
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) HashSet(java.util.HashSet)

Example 2 with ConstellationPointFeature

use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature in project constellation by constellation-app.

the class MapViewTopComponent method zoomLocationBasedOnGeoType.

private void zoomLocationBasedOnGeoType(final String geoType, final String location) throws AssertionError {
    final ConstellationAbstractMarker marker;
    switch(geoType) {
        case GEO_TYPE_COORDINATE:
            final String[] coordinate = location.split("[,\\s]+");
            if (coordinate.length != 2 && coordinate.length != 3) {
                NotifyDisplayer.display("Invalid coordinate syntax provided, should be comma or space separated", NotifyDescriptor.ERROR_MESSAGE);
                return;
            }
            final float latitude;
            final float longitude;
            final float radius;
            try {
                latitude = Float.parseFloat(coordinate[0]);
                longitude = Float.parseFloat(coordinate[1]);
                if (coordinate.length == 3) {
                    radius = Float.parseFloat(coordinate[2]);
                } else {
                    radius = 0;
                }
            } catch (final NumberFormatException ex) {
                NotifyDisplayer.display("Invalid coordinate data provided, latitude and longitude should be numbers", NotifyDescriptor.ERROR_MESSAGE);
                return;
            }
            if (latitude <= -90F || latitude >= 90F) {
                NotifyDisplayer.display("Invalid coordinate data provided, latitude should be in the range [-90. 90]", NotifyDescriptor.ERROR_MESSAGE);
                return;
            }
            if (longitude <= -180F || longitude >= 180F) {
                NotifyDisplayer.display("Invalid coordinate data provided, longitude should be in the range [-180, 180]", NotifyDescriptor.ERROR_MESSAGE);
                return;
            }
            if (radius < 0F) {
                NotifyDisplayer.display("Invalid coordinate data provided, radius should be greater than or equal to 0", NotifyDescriptor.ERROR_MESSAGE);
                return;
            }
            final Location coordinateLocation = new Location(latitude, longitude);
            if (radius > 0) {
                final float radiusDD = (float) Distance.Haversine.kilometersToDecimalDegrees(radius);
                final Location coordinateDelta = new Location(coordinateLocation.x + radiusDD, coordinateLocation.y + radiusDD);
                final List<Location> circleVertices = MarkerUtilities.generateCircle(coordinateLocation, coordinateDelta);
                final ConstellationShapeFeature coordinateFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON);
                circleVertices.forEach(vertex -> coordinateFeature.addLocation(vertex));
                marker = renderer.addCustomMarker(coordinateFeature);
            } else {
                final ConstellationPointFeature coordinateFeature = new ConstellationPointFeature(coordinateLocation);
                marker = renderer.addCustomMarker(coordinateFeature);
            }
            break;
        case GEO_TYPE_GEOHASH:
            final double[] geohashCoordinates = Geohash.decode(location, Geohash.Base.B16);
            final ConstellationShapeFeature geohashFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON);
            geohashFeature.addLocation(new Location(geohashCoordinates[0] - geohashCoordinates[2], geohashCoordinates[1] - geohashCoordinates[3]));
            geohashFeature.addLocation(new Location(geohashCoordinates[0] + geohashCoordinates[2], geohashCoordinates[1] - geohashCoordinates[3]));
            geohashFeature.addLocation(new Location(geohashCoordinates[0] + geohashCoordinates[2], geohashCoordinates[1] + geohashCoordinates[3]));
            geohashFeature.addLocation(new Location(geohashCoordinates[0] - geohashCoordinates[2], geohashCoordinates[1] + geohashCoordinates[3]));
            geohashFeature.addLocation(new Location(geohashCoordinates[0] - geohashCoordinates[2], geohashCoordinates[1] - geohashCoordinates[3]));
            marker = renderer.addCustomMarker(geohashFeature);
            break;
        case GEO_TYPE_MGRS:
            final double[] mgrsCoordinates = Mgrs.decode(location);
            final Location mgrsLocation = new Location(mgrsCoordinates[0], mgrsCoordinates[1]);
            final ConstellationPointFeature mgrsFeature = new ConstellationPointFeature(mgrsLocation);
            marker = renderer.addCustomMarker(mgrsFeature);
            break;
        default:
            marker = null;
            break;
    }
    renderer.zoomToLocation(marker == null ? null : marker.getLocation());
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) ConstellationShapeFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) Location(de.fhpotsdam.unfolding.geo.Location)

Example 3 with ConstellationPointFeature

use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature in project constellation by constellation-app.

the class MarkerCache method buildMarkers.

public Set<ConstellationAbstractMarker> buildMarkers(final Graph graph, final ConstellationMarkerFactory markerFactory) {
    assert !SwingUtilities.isEventDispatchThread();
    // clear cache (retaining custom markers)
    synchronized (lock) {
        final Set<ConstellationAbstractMarker> customMarkers = getCustomMarkers();
        clear();
        customMarkers.forEach(marker -> add(marker, GraphElement.NON_ELEMENT));
        if (graph != null && markerFactory != null) {
            // update cache (calculate graph markers)
            final GraphElementType[] elementTypes = new GraphElementType[] { GraphElementType.VERTEX, GraphElementType.TRANSACTION };
            final ReadableGraph readableGraph = graph.getReadableGraph();
            try {
                for (final GraphElementType graphElementType : elementTypes) {
                    final int elementLatitudeAttributeId;
                    final int elementLongitudeAttributeId;
                    final int elementShapeAttributeId;
                    final int elementCount;
                    switch(graphElementType) {
                        case VERTEX:
                            elementLatitudeAttributeId = SpatialConcept.VertexAttribute.LATITUDE.get(readableGraph);
                            elementLongitudeAttributeId = SpatialConcept.VertexAttribute.LONGITUDE.get(readableGraph);
                            elementShapeAttributeId = SpatialConcept.VertexAttribute.SHAPE.get(readableGraph);
                            elementCount = readableGraph.getVertexCount();
                            break;
                        case TRANSACTION:
                            elementLatitudeAttributeId = SpatialConcept.TransactionAttribute.LATITUDE.get(readableGraph);
                            elementLongitudeAttributeId = SpatialConcept.TransactionAttribute.LONGITUDE.get(readableGraph);
                            elementShapeAttributeId = SpatialConcept.TransactionAttribute.SHAPE.get(readableGraph);
                            elementCount = readableGraph.getTransactionCount();
                            break;
                        default:
                            continue;
                    }
                    for (int elementPosition = 0; elementPosition < elementCount; elementPosition++) {
                        final int elementId;
                        switch(graphElementType) {
                            case VERTEX:
                                elementId = readableGraph.getVertex(elementPosition);
                                break;
                            case TRANSACTION:
                                elementId = readableGraph.getTransaction(elementPosition);
                                break;
                            default:
                                elementId = GraphConstants.NOT_FOUND;
                                break;
                        }
                        boolean shapeAdded = false;
                        if (elementShapeAttributeId != GraphConstants.NOT_FOUND) {
                            final String elementShape = readableGraph.getStringValue(elementShapeAttributeId, elementId);
                            if (elementShape != null && Shape.isValidGeoJson(elementShape)) {
                                final List<ConstellationAbstractFeature> shapes = new ArrayList<>();
                                try {
                                    final List<ConstellationAbstractFeature> features = GeoJSONReader.loadDataFromJSON(null, elementShape).stream().map(FeatureUtilities::convert).collect(Collectors.toList());
                                    shapes.addAll(features);
                                    shapeAdded = true;
                                    markerFactory.createMarkers(shapes).forEach(marker -> {
                                        final GraphElement element = new GraphElement(elementId, graphElementType);
                                        add(marker, element);
                                    });
                                } catch (Exception ex) {
                                    LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                                }
                            }
                        }
                        if (!shapeAdded && elementLatitudeAttributeId != GraphConstants.NOT_FOUND && elementLongitudeAttributeId != GraphConstants.NOT_FOUND) {
                            final Float elementLatitude = readableGraph.getObjectValue(elementLatitudeAttributeId, elementId);
                            final Float elementLongitude = readableGraph.getObjectValue(elementLongitudeAttributeId, elementId);
                            if (elementLatitude != null && elementLongitude != null) {
                                final Location location = new Location(elementLatitude, elementLongitude);
                                final ConstellationAbstractFeature point = new ConstellationPointFeature(location);
                                try {
                                    final ConstellationAbstractMarker marker = markerFactory.createMarker(point);
                                    final GraphElement element = new GraphElement(elementId, graphElementType);
                                    add(marker, element);
                                } catch (Exception ex) {
                                    LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                                }
                            }
                        }
                    }
                }
            } finally {
                readableGraph.release();
            }
        }
    }
    return getAllMarkers();
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) ConstellationAbstractFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationAbstractFeature) Location(de.fhpotsdam.unfolding.geo.Location)

Example 4 with ConstellationPointFeature

use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature in project constellation by constellation-app.

the class ConstellationMarkerFactory method createMarker.

public ConstellationAbstractMarker createMarker(final ConstellationAbstractFeature feature) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
    final ConstellationAbstractMarker marker;
    final FeatureKey key = new FeatureKey(feature);
    if (featureCache.contains(key)) {
        marker = featureCache.getRandom(key);
    } else {
        switch(feature.getType()) {
            case POINT:
                marker = createPointMarker((ConstellationPointFeature) feature);
                break;
            case LINE:
                marker = createLineMarker((ConstellationShapeFeature) feature);
                break;
            case POLYGON:
                marker = createPolygonMarker((ConstellationShapeFeature) feature);
                break;
            case MULTI:
                marker = createMultiMarker((ConstellationMultiFeature) feature);
                break;
            case CLUSTER:
                marker = createClusterMarker((ConstellationMultiFeature) feature);
                break;
            default:
                return null;
        }
        featureCache.add(key, marker);
    }
    return marker;
}
Also used : ConstellationShapeFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) ConstellationMultiFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationMultiFeature) FeatureKey(au.gov.asd.tac.constellation.views.mapview.utilities.FeatureKey)

Example 5 with ConstellationPointFeature

use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature in project constellation by constellation-app.

the class ToolsOverlay method mouseClicked.

@Override
public void mouseClicked(final MouseEvent event) {
    if (event.getButton() == PConstants.LEFT) {
        // draw measure line
        if (mouseLeftMeasureToolRegion && measureActive) {
            if (measureOriginX == -1 && measureOriginY == -1) {
                if (event.isControlDown()) {
                    measurePath = true;
                    measureVertices.add(map.getLocation(event.getX(), event.getY()));
                } else if (event.isShiftDown()) {
                    measureCircle = true;
                } else {
                // Do nothing
                }
                measureFinished = false;
                measureOriginX = event.getX();
                measureOriginY = event.getY();
            } else {
                if (event.isControlDown()) {
                    measureVertices.add(map.getLocation(event.getX(), event.getY()));
                    measureOriginX = event.getX();
                    measureOriginY = event.getY();
                } else {
                    measureFinished = true;
                    measurePath = false;
                    measureVertices.clear();
                    measureCircle = false;
                    measureOriginX = -1;
                    measureOriginY = -1;
                    measureDeltaX = -1;
                    measureDeltaY = -1;
                }
            }
        }
        // draw markers
        final List<ConstellationAbstractMarker> hitMarkers;
        synchronized (LOCK) {
            hitMarkers = map.getHitMarkers(event.getX(), event.getY()).stream().map(ConstellationAbstractMarker.class::cast).collect(Collectors.toList());
        }
        if (mouseLeftDrawToolRegion && drawActive) {
            final MarkerCache markerCache = renderer.getMarkerCache();
            final Location clickLocation = map.getLocation(event.getX(), event.getY());
            if (hitMarkers.isEmpty()) {
                if (event.isControlDown()) {
                    drawPolygon = true;
                    drawVertices.add(clickLocation);
                    drawOriginX = event.getX();
                    drawOriginY = event.getY();
                } else if (event.isShiftDown() && !drawCircle) {
                    drawCircle = true;
                    drawOriginX = event.getX();
                    drawOriginY = event.getY();
                } else {
                    if (drawPolygon) {
                        final ConstellationShapeFeature clickFeature;
                        if (drawVertices.size() > 2) {
                            clickFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON);
                        } else if (drawVertices.size() == 2) {
                            clickFeature = new ConstellationShapeFeature(ConstellationFeatureType.LINE);
                        } else {
                            return;
                        }
                        drawVertices.forEach(clickFeature::addLocation);
                        renderer.addCustomMarker(clickFeature);
                        drawPolygon = false;
                        drawVertices.clear();
                        drawOriginX = -1;
                        drawOriginY = -1;
                        drawDeltaX = -1;
                        drawDeltaY = -1;
                    } else if (drawCircle) {
                        drawVertices.addAll(MarkerUtilities.generateCircle(map.getLocation(drawOriginX, drawOriginY), map.getLocation(drawDeltaX, drawDeltaY)));
                        final ConstellationShapeFeature clickFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON);
                        drawVertices.forEach(clickFeature::addLocation);
                        renderer.addCustomMarker(clickFeature);
                        drawCircle = false;
                        drawVertices.clear();
                        drawOriginX = -1;
                        drawOriginY = -1;
                        drawDeltaX = -1;
                        drawDeltaY = -1;
                    } else {
                        final ConstellationPointFeature clickFeature = new ConstellationPointFeature(clickLocation);
                        renderer.addCustomMarker(clickFeature);
                    }
                }
            } else {
                hitMarkers.forEach(hitMarker -> {
                    if (hitMarker.isCustom()) {
                        markerCache.get(hitMarker).remove(GraphElement.NON_ELEMENT);
                        if (markerCache.get(hitMarker).isEmpty()) {
                            map.getMarkers().remove(hitMarker);
                            markerCache.remove(hitMarker);
                        } else {
                            hitMarker.setCustom(false);
                        }
                    }
                });
            }
        }
    }
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) ConstellationShapeFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) Location(de.fhpotsdam.unfolding.geo.Location)

Aggregations

ConstellationPointFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature)6 ConstellationShapeFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature)4 ConstellationAbstractMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker)4 Location (de.fhpotsdam.unfolding.geo.Location)3 ConstellationAbstractFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationAbstractFeature)2 ConstellationMultiFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationMultiFeature)2 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 FeatureKey (au.gov.asd.tac.constellation.views.mapview.utilities.FeatureKey)1 MarkerCache (au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache)1 PointFeature (de.fhpotsdam.unfolding.data.PointFeature)1 ShapeFeature (de.fhpotsdam.unfolding.data.ShapeFeature)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DoublePoint (org.apache.commons.math3.ml.clustering.DoublePoint)1