use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.
the class ExtendedMapKit method saveState.
/**
* @see IPersistable#saveState(IMemento)
*/
@Override
public void saveState(IMemento memento) {
GeoPosition min = getMainMap().convertPointToGeoPosition(new Point((int) Math.round(getMainMap().getWidth() * 0.1), (int) Math.round(getMainMap().getHeight() * 0.1)));
GeoPosition max = getMainMap().convertPointToGeoPosition(new Point((int) Math.round(getMainMap().getWidth() * 0.9), (int) Math.round(getMainMap().getHeight() * 0.9)));
// GeoPosition min = getMainMap().convertPointToGeoPosition(new Point(0,
// 0));
// GeoPosition max = getMainMap().convertPointToGeoPosition(new
// Point(getMainMap().getWidth(), getMainMap().getHeight()));
int epsg = min.getEpsgCode();
try {
if (epsg != max.getEpsgCode())
max = GeotoolsConverter.getInstance().convert(max, epsg);
memento.putFloat(MEMENTO_KEY_MIN_X, (float) min.getX());
memento.putFloat(MEMENTO_KEY_MIN_Y, (float) min.getY());
memento.putFloat(MEMENTO_KEY_MAX_X, (float) max.getX());
memento.putFloat(MEMENTO_KEY_MAX_Y, (float) max.getY());
memento.putInteger(MEMENTO_KEY_EPSG, epsg);
} catch (IllegalGeoPositionException e) {
// $NON-NLS-1$
log.error("Error saving map state: Could not convert GeoPosition", e);
}
}
use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.
the class PositionStatus method mouseMoved.
/**
* @see MouseAdapter#mouseMoved(MouseEvent)
*/
@Override
public void mouseMoved(MouseEvent e) {
GeoPosition pos = map.convertPointToGeoPosition(e.getPoint());
// convert if needed and possible
int target = epsgProvider.getEpsgCode();
if (target != 0) {
try {
pos = GeotoolsConverter.getInstance().convert(pos, target);
} catch (Exception x) {
// ignore
}
}
final GeoPosition position = pos;
// set current GeoPosition
AreaCalc.getInstance().setCurrentGeoPos(pos);
site.getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
site.getActionBars().getStatusLineManager().setMessage(image, // $NON-NLS-1$ //$NON-NLS-2$
"EPSG:" + position.getEpsgCode() + " - " + format.format(position.getX()) + // $NON-NLS-1$
" / " + format.format(position.getY()));
}
});
}
use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.
the class AreaCalc method triangulate.
/**
* Triangulates the polygon.
*
* @param pos List of {@link GeoPosition}
*
* @return List of {@link Triangle}
*/
private List<Triangle> triangulate(List<GeoPosition> pos) {
// contains all triangles
List<Triangle> triangles = new ArrayList<Triangle>(pos.size() - 1);
// standard epsg code
int epsg = pos.get(0).getEpsgCode();
// check if it's already a triangle
if (pos.size() == 3) {
triangles.add(new Triangle(pos.get(0), pos.get(1), pos.get(2)));
return triangles;
}
// contains all points from the surface
List<Point3D> face = new ArrayList<>();
// convert Point2D to Vertex
for (int i = 0; i < pos.size(); i++) {
GeoPosition p = pos.get(i);
face.add(new Point3D(p.getX(), p.getY(), 0.0));
}
// create FaceSet and triangulate
FaceTriangulation fst = new FaceTriangulation();
List<List<Point3D>> faces = fst.triangulateFace(face);
// convert
for (List<Point3D> f : faces) {
// create GeoPositions
GeoPosition p1, p2, p3;
p1 = new GeoPosition(f.get(0).getX(), f.get(0).getY(), epsg);
p2 = new GeoPosition(f.get(1).getX(), f.get(1).getY(), epsg);
p3 = new GeoPosition(f.get(2).getX(), f.get(2).getY(), epsg);
// add triangle
triangles.add(new Triangle(p1, p2, p3));
}
return triangles;
}
use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.
the class AreaCalc method calculate.
/**
* This function calculates the area of a polygon.
*/
public void calculate() {
if (isActive() && this.geoPos.size() > 0 && !this.calculation && /* && this.updated */
!this.bufferIsFinished) {
// set calculation to true to prevent double calculating
this.calculation = true;
// but allow new position data
// this.updated = false;
List<GeoPosition> pos = new ArrayList<GeoPosition>();
pos.addAll(this.geoPos);
pos.add(this.currentGeoPos);
// contains information for the tooltip
String tip = "";
// check epsg code and maybe convert to a metric system
pos = this.checkEPSG(pos);
// initialize formater
NumberFormat df = NumberFormat.getNumberInstance();
// calculate size
double area = 0.0;
// rectangle
if (pos.size() == 2 && this.selectionType.equals("rectangle")) {
area = this.calculateRectangle(pos.get(0), pos.get(1));
if (area > 1000000) {
area /= 1000000;
tip = df.format(area) + " km\u00B2";
} else {
tip = df.format(area) + " m\u00B2";
}
} else // distance (polygon tool)
if (pos.size() == 2 && this.selectionType.equals("polygon")) {
area = AreaCalc.calculateDistance(pos.get(0), pos.get(1));
tip = df.format(area) + " m";
} else // distance (buffer tool)
if (pos.size() > 1 && this.selectionType.equals("line")) {
double temp = 0.0;
for (int i = 0; i < pos.size() - 1; i++) {
temp += AreaCalc.calculateDistance(pos.get(i), pos.get(i + 1));
}
tip = df.format(temp) + " m";
} else // polygon
if (pos.size() > 2 && this.selectionType.equals("polygon")) {
area = this.calculatePolygon(pos);
if (area > 1000000) {
area /= 1000000;
tip = df.format(area) + " km\u00B2";
} else {
tip = df.format(area) + " m\u00B2";
}
} else // buffer tool
if (this.selectionType.equals("buffer")) {
if (pos.size() == 2) {
area = AreaCalc.calculateDistance(pos.get(0), pos.get(1));
tip = df.format(area) + " m";
} else {
// calculate
area = this.calculatePolygon(pos);
if (area > 1000000) {
area /= 1000000;
tip = df.format(area) + " km\u00B2";
} else {
tip = df.format(area) + " m\u00B2";
}
}
}
// update tooltip
this.area = tip;
fireAreaChanged();
// calculation has finished
this.calculation = false;
}
}
use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.
the class AreaCalc method calculateRectangle.
/**
* Calculate the area of a rectangle.
*
* @param a first {@link GeoPosition}
* @param b second {@link GeoPosition}
*
* @return area
*/
public double calculateRectangle(GeoPosition a, GeoPosition b) {
double value = 0.0;
value = AreaCalc.calculateDistance(new GeoPosition(a.getX(), a.getY(), a.getEpsgCode()), new GeoPosition(b.getX(), a.getY(), a.getEpsgCode())) * AreaCalc.calculateDistance(new GeoPosition(a.getX(), a.getY(), a.getEpsgCode()), new GeoPosition(a.getX(), b.getY(), a.getEpsgCode()));
return Math.abs(value);
}
Aggregations