Search in sources :

Example 1 with ICoordinate

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());
    }
}
Also used : Coordinate(org.openstreetmap.gui.jmapviewer.Coordinate) ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate) IActor(org.freeplane.core.undo.IActor)

Example 2 with ICoordinate

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());
    }
}
Also used : ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate)

Example 3 with ICoordinate

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());
        }
    };
}
Also used : ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate) IActor(org.freeplane.core.undo.IActor) MapModel(org.freeplane.features.map.MapModel)

Example 4 with ICoordinate

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);
            }
        }
    }
}
Also used : ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate) Point(java.awt.Point) LinkedList(java.util.LinkedList) Point(java.awt.Point)

Example 5 with ICoordinate

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);
}
Also used : MapPolygon(org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon) MapMarker(org.openstreetmap.gui.jmapviewer.interfaces.MapMarker) ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate) MapRectangle(org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle) Point(java.awt.Point)

Aggregations

ICoordinate (org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate)5 Point (java.awt.Point)2 IActor (org.freeplane.core.undo.IActor)2 LinkedList (java.util.LinkedList)1 MapModel (org.freeplane.features.map.MapModel)1 Coordinate (org.openstreetmap.gui.jmapviewer.Coordinate)1 MapMarker (org.openstreetmap.gui.jmapviewer.interfaces.MapMarker)1 MapPolygon (org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon)1 MapRectangle (org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle)1