use of org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate in project freeplane by freeplane.
the class OpenMapsNodeHook method setLocationChoiceUndoable.
private void setLocationChoiceUndoable(final OpenMapsExtension extension, final ICoordinate locationChoosen, final int zoomChoosen) {
final Coordinate currentLocation = extension.getLocation();
final int currentZoom = extension.getZoom();
if (!currentLocation.equals(locationChoosen)) {
final IActor actor = createUndoActor(extension, locationChoosen, currentLocation, zoomChoosen, currentZoom);
Controller.getCurrentModeController().execute(actor, Controller.getCurrentModeController().getController().getMap());
}
}
use of org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate in project freeplane by freeplane.
the class OpenMapsController method mouseClicked.
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
final ICoordinate locationChoosen = getSelectedLocation(e.getPoint());
setMarkerAtLocation(locationChoosen);
sendLocation(locationChoosen, getCurrentZoomLevel());
}
}
use of org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate in project freeplane by freeplane.
the class OpenMapsNodeHook method createUndoActor.
private IActor createUndoActor(final OpenMapsExtension extension, final ICoordinate newlyChoosenLocation, final ICoordinate currentlyStoredLocation, final int newlyChoosenZoom, final int currentlyStoredZoom) {
return new IActor() {
private final ICoordinate oldLocation = currentlyStoredLocation;
private final int oldZoom = currentlyStoredZoom;
public void act() {
extension.updateLocation(newlyChoosenLocation);
extension.updateZoom(newlyChoosenZoom);
final MapModel map = Controller.getCurrentModeController().getController().getMap();
Controller.getCurrentModeController().getMapController().setSaved(map, false);
}
public String getDescription() {
return "setOpenMapsLocationChoiceUndoable";
}
public void undo() {
if (oldLocation.getLat() == 500 && oldLocation.getLon() == 500) {
removeLocationFromCurrentlySelectedNode();
} else {
extension.updateLocation(oldLocation);
extension.updateZoom(oldZoom);
}
refreshNode(getCurrentlySelectedNode());
}
};
}
use of org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate in project Course_Generator by patrovite.
the class JMapViewer method paintPolygon.
/**
* Paint a single polygon.
*/
protected void paintPolygon(Graphics g, MapPolygon polygon) {
List<? extends ICoordinate> coords = polygon.getPoints();
if (coords != null && coords.size() >= 3) {
List<Point> points = new LinkedList<>();
for (ICoordinate c : coords) {
Point p = getMapPosition(c, false);
if (p == null) {
return;
}
points.add(p);
}
polygon.paint(g, points);
if (scrollWrapEnabled) {
int tilesize = tileSource.getTileSize();
int mapSize = tilesize << zoom;
List<Point> pointsWrapped = new LinkedList<>(points);
boolean keepWrapping = true;
while (keepWrapping) {
for (Point p : pointsWrapped) {
p.x -= mapSize;
if (p.x < 0) {
keepWrapping = false;
}
}
polygon.paint(g, pointsWrapped);
}
pointsWrapped = new LinkedList<>(points);
keepWrapping = true;
while (keepWrapping) {
for (Point p : pointsWrapped) {
p.x += mapSize;
if (p.x > getWidth()) {
keepWrapping = false;
}
}
polygon.paint(g, pointsWrapped);
}
}
}
}
use of org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate in project Course_Generator by patrovite.
the class JMapViewer method setDisplayToFitMapElements.
/**
* Sets the displayed map pane and zoom level so that all chosen map elements are
* visible.
*/
public void setDisplayToFitMapElements(boolean markers, boolean rectangles, boolean polygons) {
int nbElemToCheck = 0;
if (markers && mapMarkerList != null)
nbElemToCheck += mapMarkerList.size();
if (rectangles && mapRectangleList != null)
nbElemToCheck += mapRectangleList.size();
if (polygons && mapPolygonList != null)
nbElemToCheck += mapPolygonList.size();
if (nbElemToCheck == 0)
return;
int x_min = Integer.MAX_VALUE;
int y_min = Integer.MAX_VALUE;
int x_max = Integer.MIN_VALUE;
int y_max = Integer.MIN_VALUE;
int mapZoomMax = tileController.getTileSource().getMaxZoom();
if (markers) {
for (MapMarker marker : mapMarkerList) {
if (marker.isVisible()) {
int x = tileSource.LonToX(marker.getLon(), mapZoomMax);
int y = tileSource.LatToY(marker.getLat(), mapZoomMax);
x_max = Math.max(x_max, x);
y_max = Math.max(y_max, y);
x_min = Math.min(x_min, x);
y_min = Math.min(y_min, y);
}
}
}
if (rectangles) {
for (MapRectangle rectangle : mapRectangleList) {
if (rectangle.isVisible()) {
x_max = Math.max(x_max, tileSource.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax));
y_max = Math.max(y_max, tileSource.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax));
x_min = Math.min(x_min, tileSource.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax));
y_min = Math.min(y_min, tileSource.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax));
}
}
}
if (polygons) {
for (MapPolygon polygon : mapPolygonList) {
if (polygon.isVisible()) {
for (ICoordinate c : polygon.getPoints()) {
int x = tileSource.LonToX(c.getLon(), mapZoomMax);
int y = tileSource.LatToY(c.getLat(), mapZoomMax);
x_max = Math.max(x_max, x);
y_max = Math.max(y_max, y);
x_min = Math.min(x_min, x);
y_min = Math.min(y_min, y);
}
}
}
}
int height = Math.max(0, getHeight());
int width = Math.max(0, getWidth());
int newZoom = mapZoomMax;
int x = x_max - x_min;
int y = y_max - y_min;
while (x > width || y > height) {
newZoom--;
x >>= 1;
y >>= 1;
}
x = x_min + (x_max - x_min) / 2;
y = y_min + (y_max - y_min) / 2;
int z = 1 << (mapZoomMax - newZoom);
x /= z;
y /= z;
setDisplayPosition(x, y, newZoom);
}
Aggregations