Changeset 19289 in josm for trunk/test


Ignore:
Timestamp:
2025-01-24T14:05:46+01:00 (3 weeks ago)
Author:
taylor.smock
Message:

Fix #24097: Zoom to imagery layer

This fixes two issues:

  1. Adds implementation for visitBoundingBox used by the Zoom to layer action
  2. Uses addLayer(Layer, boolean) to avoid zooming to the bounds of the layer on layer add

Also, clean up some deprecation warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java

    r19155 r19289  
    88import static org.junit.jupiter.api.Assertions.assertTrue;
    99
     10import java.util.Arrays;
    1011import java.util.List;
    1112
     
    1314import org.junit.jupiter.api.Test;
    1415import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
     16import org.openstreetmap.josm.data.Bounds;
    1517import org.openstreetmap.josm.data.imagery.ImageryInfo;
     18import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1620import org.openstreetmap.josm.gui.MainApplication;
     21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1722import org.openstreetmap.josm.gui.layer.TMSLayer;
    1823import org.openstreetmap.josm.gui.layer.WMSLayer;
     24import org.openstreetmap.josm.gui.util.GuiHelper;
    1925import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    2026import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     27import org.openstreetmap.josm.testutils.annotations.Main;
    2128import org.openstreetmap.josm.testutils.annotations.OsmApi;
    2229import org.openstreetmap.josm.testutils.annotations.Projection;
     
    99106        assertTrue(MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
    100107    }
     108
     109
     110    /**
     111     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/24097">#24097</a>: Zoom to imagery layer
     112     * This tests two things:
     113     * <ul>
     114     *     <li>Imagery layer zoom to action works properly</li>
     115     *     <li>Imagery layer bounds is not zoomed to on layer add</li>
     116     * </ul>
     117     */
     118    @Main
     119    @Test
     120    void testNonRegression24097() {
     121        // First, add a new data layer
     122        MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(),
     123                "AddImageryLayerActionTest#testNonRegression24097", null));
     124        // Now zoom to a random area
     125        MainApplication.getMap().mapView.zoomTo(new Bounds(39.0665807, -108.5212326, 39.0793079, -108.4986591));
     126        // Initialize the zoom actions
     127        MainApplication.getMenu().initialize();
     128        final Bounds startingBounds = MainApplication.getMap().mapView.getRealBounds();
     129        ImageryInfo testInfo = new ImageryInfo("Test", "https://127.0.0.1/{zoom}/{x}/{y}.png", "tms", null, null, "Test");
     130        testInfo.setBounds(new ImageryInfo.ImageryBounds("-0.001,-0.001,0.001,0.001", ","));
     131        new AddImageryLayerAction(testInfo).actionPerformed(null);
     132        GuiHelper.runInEDTAndWait(() -> { /* Sync GUI thread */ });
     133        // There is a bit of zooming done during the load of the imagery
     134        assertTrue(startingBounds.toBBox().bboxIsFunctionallyEqual(MainApplication.getMap().mapView.getRealBounds().toBBox(), 0.001),
     135                "Adding an imagery layer should not zoom to the imagery layer bounds");
     136        assertEquals(1, MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).size());
     137        final TMSLayer tmsLayer = MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).get(0);
     138        final AutoScaleAction autoScaleAction = Arrays.stream(tmsLayer.getMenuEntries()).filter(AutoScaleAction.class::isInstance)
     139                .map(AutoScaleAction.class::cast).findFirst().orElseThrow();
     140        autoScaleAction.actionPerformed(null);
     141        // We can't check the bbox here, since the mapView doesn't have any actual width/height.
     142        // So we just check the center.
     143        assertTrue(new Bounds(-0.001, -0.001, 0.001, 0.001)
     144                .contains(ProjectionRegistry.getProjection().eastNorth2latlon(
     145                        MainApplication.getMap().mapView.getCenter())),
     146                "The action should have zoomed to the bbox for the imagery layer");
     147    }
    101148}
Note: See TracChangeset for help on using the changeset viewer.