Search in sources :

Example 1 with ConstellationAbstractMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker in project constellation by constellation-app.

the class MapViewTileRenderer method addCustomMarker.

public ConstellationAbstractMarker addCustomMarker(final ConstellationAbstractFeature feature) {
    assert !SwingUtilities.isEventDispatchThread();
    if (map == null) {
        return null;
    }
    ConstellationAbstractMarker marker = null;
    try {
        marker = markerFactory.createMarker(feature);
        marker.setCustom(true);
        markerCache.add(marker, GraphElement.NON_ELEMENT);
        synchronized (LOCK) {
            map.addMarker(marker);
        }
    } catch (Exception ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return marker;
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker)

Example 2 with ConstellationAbstractMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker in project constellation by constellation-app.

the class MapViewTileRenderer method handleMouseZoom.

/**
 * Update the zoom level of the map based on the given set of markers.
 *
 * @param event the mouse event which caused the zoom
 * @param markers the markers to zoom to
 */
private void handleMouseZoom(final Set<ConstellationAbstractMarker> markers) {
    assert !SwingUtilities.isEventDispatchThread();
    if (markers == null) {
        return;
    }
    // the zoomAndPanToFit method is known to break for any of the following locations
    final List<Location> breakingLocations = new ArrayList<>();
    breakingLocations.add(new Location(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    breakingLocations.add(new Location(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY));
    breakingLocations.add(new Location(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY));
    breakingLocations.add(new Location(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
    final List<Location> locations = markers.stream().map(marker -> marker.getLocation()).filter(location -> !breakingLocations.contains(location)).collect(Collectors.toList());
    if (!locations.isEmpty()) {
        map.zoomAndPanToFit(locations);
    }
}
Also used : MarkerUtilities(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerUtilities) NewtCanvasAWT(com.jogamp.newt.awt.NewtCanvasAWT) URL(java.net.URL) MapProvider(au.gov.asd.tac.constellation.views.mapview.providers.MapProvider) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) MouseEvent(processing.event.MouseEvent) KeyEvent(processing.event.KeyEvent) Lookup(org.openide.util.Lookup) Collection(java.util.Collection) PApplet(processing.core.PApplet) Set(java.util.Set) ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) Logger(java.util.logging.Logger) Component(java.awt.Component) Collectors(java.util.stream.Collectors) PSurface(processing.core.PSurface) PConstants(processing.core.PConstants) List(java.util.List) ConstellationInstalledFileLocator(au.gov.asd.tac.constellation.utilities.file.ConstellationInstalledFileLocator) PanMapEvent(de.fhpotsdam.unfolding.events.PanMapEvent) Location(de.fhpotsdam.unfolding.geo.Location) ConstellationAbstractFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationAbstractFeature) ThreadUtils(org.apache.commons.lang3.ThreadUtils) UnfoldingMap(de.fhpotsdam.unfolding.UnfoldingMap) EventDispatcher(de.fhpotsdam.unfolding.events.EventDispatcher) BarScaleUI(de.fhpotsdam.unfolding.ui.BarScaleUI) MapOverlay(au.gov.asd.tac.constellation.views.mapview.overlays.MapOverlay) ConstellationClusterMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationClusterMarker) HashMap(java.util.HashMap) ConstellationMarkerFactory(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMarkerFactory) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Graph(au.gov.asd.tac.constellation.graph.Graph) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) Applet(java.applet.Applet) MarkerState(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerState) GLWindow(com.jogamp.newt.opengl.GLWindow) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) SharedDrawable(au.gov.asd.tac.constellation.visual.opengl.utilities.SharedDrawable) MapLayer(au.gov.asd.tac.constellation.views.mapview.layers.MapLayer) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) Field(java.lang.reflect.Field) File(java.io.File) MapUtils(de.fhpotsdam.unfolding.utils.MapUtils) ZoomMapEvent(de.fhpotsdam.unfolding.events.ZoomMapEvent) ArrayList(java.util.ArrayList) Location(de.fhpotsdam.unfolding.geo.Location)

Example 3 with ConstellationAbstractMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker 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 4 with ConstellationAbstractMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker 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 5 with ConstellationAbstractMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker in project constellation by constellation-app.

the class PointMarkerErrorLayer method update.

@Override
public PImage update() {
    if (map.getMarkers().isEmpty()) {
        return null;
    }
    markerCount = map.getMarkers().size();
    final int width = renderer.width - 5;
    final int height = renderer.height - 5;
    // get on screen markers
    final ScreenPosition topLeft = map.getScreenPosition(map.getTopLeftBorder());
    final ScreenPosition bottomRight = map.getScreenPosition(map.getBottomRightBorder());
    final List<ConstellationAbstractMarker> markers = renderer.getMarkerCache().getAllMarkers().stream().filter(marker -> {
        final ScreenPosition markerPosition = map.getScreenPosition(marker.getLocation());
        return markerPosition != null && markerPosition.x > topLeft.x && markerPosition.y > topLeft.y && markerPosition.x < bottomRight.x && markerPosition.y < bottomRight.y;
    }).collect(Collectors.toList());
    // create error region data from markers
    final PGraphics errorRegionImage = renderer.createGraphics(width, height, PConstants.JAVA2D);
    errorRegionImage.beginDraw();
    errorRegionImage.stroke(STROKE_COLOR);
    errorRegionImage.fill(ERROR_REGION_COLOR);
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int vertexPrecisionAttributeId = SpatialConcept.VertexAttribute.PRECISION.get(readableGraph);
            final int transactionPrecisionAttributeId = SpatialConcept.TransactionAttribute.PRECISION.get(readableGraph);
            for (final ConstellationAbstractMarker marker : markers) {
                if (!(marker instanceof ConstellationPointMarker)) {
                    continue;
                }
                float minimumPrecision = DEFAULT_PRECISION;
                final Set<GraphElement> elements = renderer.getMarkerCache().get(marker);
                for (final GraphElement element : elements) {
                    final float elementPrecision;
                    switch(element.getType()) {
                        case VERTEX:
                            if (vertexPrecisionAttributeId != Graph.NOT_FOUND) {
                                elementPrecision = readableGraph.getFloatValue(vertexPrecisionAttributeId, element.getId());
                                minimumPrecision = Math.max(elementPrecision, minimumPrecision);
                            } else {
                                elementPrecision = DEFAULT_PRECISION;
                                minimumPrecision = DEFAULT_PRECISION;
                            }
                            break;
                        case TRANSACTION:
                            elementPrecision = transactionPrecisionAttributeId != Graph.NOT_FOUND ? readableGraph.getFloatValue(transactionPrecisionAttributeId, element.getId()) : DEFAULT_PRECISION;
                            break;
                        default:
                            elementPrecision = DEFAULT_PRECISION;
                            break;
                    }
                    minimumPrecision = Math.max(elementPrecision, minimumPrecision);
                }
                // don't bother drawing if there isn't a precision
                if (minimumPrecision == 0) {
                    continue;
                }
                final Location errorRegionRadiusLocation = new Location(marker.getLocation().getLat() - Haversine.kilometersToDecimalDegrees(minimumPrecision), marker.getLocation().getLon() - Haversine.kilometersToDecimalDegrees(minimumPrecision));
                final List<Location> errorRegionLocations = MarkerUtilities.generateCircle(marker.getLocation(), errorRegionRadiusLocation);
                final List<MapPosition> errorRegionPositions = errorRegionLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
                errorRegionImage.beginShape();
                errorRegionPositions.forEach(position -> errorRegionImage.vertex(position.x, position.y));
                errorRegionImage.endShape(PConstants.CLOSE);
            }
        } finally {
            readableGraph.release();
        }
    }
    errorRegionImage.endDraw();
    return errorRegionImage;
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) MarkerUtilities(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerUtilities) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) Set(java.util.Set) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) PGraphics(processing.core.PGraphics) PImage(processing.core.PImage) ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) Collectors(java.util.stream.Collectors) Graph(au.gov.asd.tac.constellation.graph.Graph) PConstants(processing.core.PConstants) List(java.util.List) Location(de.fhpotsdam.unfolding.geo.Location) Haversine(au.gov.asd.tac.constellation.utilities.geospatial.Distance.Haversine) ServiceProvider(org.openide.util.lookup.ServiceProvider) ConstellationPointMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition) MapPosition(de.fhpotsdam.unfolding.utils.MapPosition) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PGraphics(processing.core.PGraphics) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) ConstellationPointMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker) MapPosition(de.fhpotsdam.unfolding.utils.MapPosition) Location(de.fhpotsdam.unfolding.geo.Location)

Aggregations

ConstellationAbstractMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker)10 ConstellationPointFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature)5 Location (de.fhpotsdam.unfolding.geo.Location)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)4 MarkerCache (au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 PConstants (processing.core.PConstants)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 SpatialConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept)2 ConstellationAbstractFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationAbstractFeature)2 ConstellationShapeFeature (au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature)2 ConstellationClusterMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationClusterMarker)2 GraphElement (au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement)2 MarkerUtilities (au.gov.asd.tac.constellation.views.mapview.utilities.MarkerUtilities)2 Set (java.util.Set)2 ServiceProvider (org.openide.util.lookup.ServiceProvider)2