use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature 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.features.ConstellationShapeFeature 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;
}
use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature 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);
}
}
});
}
}
}
}
use of au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature in project constellation by constellation-app.
the class FeatureUtilities method convert.
public static ConstellationAbstractFeature convert(final Feature feature) {
final ConstellationAbstractFeature constellationFeature;
switch(feature.getType()) {
case POINT:
constellationFeature = new ConstellationPointFeature(((PointFeature) feature).getLocation());
break;
case LINES:
constellationFeature = new ConstellationShapeFeature(ConstellationFeatureType.LINE, ((ShapeFeature) feature).getLocations());
break;
case POLYGON:
constellationFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON, ((ShapeFeature) feature).getLocations());
break;
case MULTI:
final List<ConstellationAbstractFeature> constellationFeatures = ((MultiFeature) feature).getFeatures().stream().map(FeatureUtilities::convert).collect(Collectors.toList());
constellationFeature = new ConstellationMultiFeature(ConstellationFeatureType.MULTI, constellationFeatures);
break;
default:
return null;
}
return constellationFeature;
}
Aggregations