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;
}
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);
}
}
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));
}
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());
}
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;
}
Aggregations