Search in sources :

Example 1 with LatLon

use of org.openstreetmap.josm.data.coor.LatLon in project josm by JOSM.

the class AddNodeAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (!isEnabled())
        return;
    // #17682 - Run the action later in EDT to make sure the KeyEvent triggering it is consumed before the dialog is shown
    SwingUtilities.invokeLater(() -> {
        LatLonDialog dialog = new LatLonDialog(MainApplication.getMainFrame(), tr("Add Node..."), ht("/Action/AddNode"));
        if (textLatLon != null) {
            dialog.setLatLonText(textLatLon);
        }
        if (textEastNorth != null) {
            dialog.setEastNorthText(textEastNorth);
        }
        dialog.showDialog();
        if (dialog.getValue() != 1)
            return;
        LatLon coordinates = dialog.getCoordinates();
        if (coordinates == null)
            return;
        textLatLon = dialog.getLatLonText();
        textEastNorth = dialog.getEastNorthText();
        Node nnew = new Node(coordinates);
        // add the node
        DataSet ds = getLayerManager().getEditDataSet();
        UndoRedoHandler.getInstance().add(new AddCommand(ds, nnew));
        ds.setSelected(nnew);
        MapView mapView = MainApplication.getMap().mapView;
        if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
            AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
        }
    });
}
Also used : LatLon(org.openstreetmap.josm.data.coor.LatLon) DataSet(org.openstreetmap.josm.data.osm.DataSet) Node(org.openstreetmap.josm.data.osm.Node) MapView(org.openstreetmap.josm.gui.MapView) LatLonDialog(org.openstreetmap.josm.gui.dialogs.LatLonDialog) AddCommand(org.openstreetmap.josm.command.AddCommand)

Example 2 with LatLon

use of org.openstreetmap.josm.data.coor.LatLon in project josm by JOSM.

the class OffsetBookmark method bookmarkOffset.

/**
 * Add a bookmark for the displacement of that layer
 * @param name The bookmark name
 * @param layer The layer to store the bookmark for
 */
public static void bookmarkOffset(String name, AbstractTileSourceLayer<?> layer) {
    LatLon center;
    if (MainApplication.isDisplayingMapView()) {
        center = ProjectionRegistry.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter());
    } else {
        center = LatLon.ZERO;
    }
    OffsetBookmark nb = new OffsetBookmark(ProjectionRegistry.getProjection().toCode(), layer.getInfo().getId(), layer.getInfo().getName(), name, layer.getDisplaySettings().getDisplacement(), center);
    for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator(); it.hasNext(); ) {
        OffsetBookmark b = it.next();
        if (b.isUsable(layer) && name.equals(b.name)) {
            it.set(nb);
            saveBookmarks();
            return;
        }
    }
    allBookmarks.add(nb);
    saveBookmarks();
}
Also used : LatLon(org.openstreetmap.josm.data.coor.LatLon) ILatLon(org.openstreetmap.josm.data.coor.ILatLon)

Example 3 with LatLon

use of org.openstreetmap.josm.data.coor.LatLon in project josm by JOSM.

the class WMTSTileSource method xyToLatLon.

@Override
public Coordinate xyToLatLon(int x, int y, int zoom) {
    TileMatrix matrix = getTileMatrix(zoom);
    if (matrix == null) {
        return new Coordinate(0, 0);
    }
    double scale = matrix.scaleDenominator * this.crsScale;
    EastNorth ret = new EastNorth(matrix.topLeftCorner.east() + x * scale, matrix.topLeftCorner.north() - y * scale);
    LatLon ll = tileProjection.eastNorth2latlon(ret);
    return new Coordinate(ll.lat(), ll.lon());
}
Also used : LatLon(org.openstreetmap.josm.data.coor.LatLon) Coordinate(org.openstreetmap.gui.jmapviewer.Coordinate) ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate) EastNorth(org.openstreetmap.josm.data.coor.EastNorth)

Example 4 with LatLon

use of org.openstreetmap.josm.data.coor.LatLon in project josm by JOSM.

the class WMTSTileSource method latLonToXY.

@Override
public Point latLonToXY(double lat, double lon, int zoom) {
    TileMatrix matrix = getTileMatrix(zoom);
    if (matrix == null) {
        return new Point(0, 0);
    }
    double scale = matrix.scaleDenominator * this.crsScale;
    EastNorth point = tileProjection.latlon2eastNorth(new LatLon(lat, lon));
    return new Point((int) Math.round((point.east() - matrix.topLeftCorner.east()) / scale), (int) Math.round((matrix.topLeftCorner.north() - point.north()) / scale));
}
Also used : LatLon(org.openstreetmap.josm.data.coor.LatLon) EastNorth(org.openstreetmap.josm.data.coor.EastNorth) Point(java.awt.Point)

Example 5 with LatLon

use of org.openstreetmap.josm.data.coor.LatLon in project josm by JOSM.

the class SlippyMapBBoxChooser method handleMouseMoved.

/**
 * Handles a {@link SlippyMapController#mouseMoved} event
 * @param point The point in the view
 */
public void handleMouseMoved(Point point) {
    final ICoordinate coordinate = getPosition(point);
    final LatLon latLon = new LatLon(coordinate.getLat(), coordinate.getLon());
    firePropertyChange(CURSOR_COORDINATE_PROP, null, latLon);
}
Also used : LatLon(org.openstreetmap.josm.data.coor.LatLon) ICoordinate(org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate)

Aggregations

LatLon (org.openstreetmap.josm.data.coor.LatLon)632 Test (org.junit.jupiter.api.Test)382 Node (org.openstreetmap.josm.data.osm.Node)249 DataSet (org.openstreetmap.josm.data.osm.DataSet)174 Way (org.openstreetmap.josm.data.osm.Way)159 EastNorth (org.openstreetmap.josm.data.coor.EastNorth)87 ArrayList (java.util.ArrayList)79 Bounds (org.openstreetmap.josm.data.Bounds)62 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)56 OsmPrimitive (org.openstreetmap.josm.data.osm.OsmPrimitive)46 OsmDataLayer (org.openstreetmap.josm.gui.layer.OsmDataLayer)45 List (java.util.List)39 Relation (org.openstreetmap.josm.data.osm.Relation)37 RelationMember (org.openstreetmap.josm.data.osm.RelationMember)31 Collectors (java.util.stream.Collectors)29 WayPoint (org.openstreetmap.josm.data.gpx.WayPoint)29 ILatLon (org.openstreetmap.josm.data.coor.ILatLon)26 Projection (org.openstreetmap.josm.data.projection.Projection)26 Point (java.awt.Point)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25