Ticket #13049: patch-mapview-state-update-projection.patch

File patch-mapview-state-update-projection.patch, 4.2 KB (added by michael2402, 3 years ago)
  • src/org/openstreetmap/josm/Main.java

    diff --git a/src/org/openstreetmap/josm/Main.java b/src/org/openstreetmap/josm/Main.java
    index fddff1a..7d028d4 100644
    a b public abstract class Main { 
    14301430    private static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds) {
    14311431        if (newValue == null ^ oldValue == null
    14321432                || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
    1433 
     1433            if (Main.map != null) {
     1434                // This needs to be called first
     1435                Main.map.mapView.fixProjection();
     1436            }
    14341437            synchronized (Main.class) {
    14351438                Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
    14361439                while (it.hasNext()) {
  • src/org/openstreetmap/josm/gui/MapViewState.java

    diff --git a/src/org/openstreetmap/josm/gui/MapViewState.java b/src/org/openstreetmap/josm/gui/MapViewState.java
    index 982ccf7..6d143d7 100644
    a b public final class MapViewState { 
    9999        topLeftOnScreen = position.getLocationOnScreen();
    100100    }
    101101
     102    private MapViewState(Projection projection, MapViewState mapViewState) {
     103        this.projection = projection;
     104        this.scale = mapViewState.scale;
     105        this.topLeft = mapViewState.topLeft;
     106
     107        viewWidth = mapViewState.viewWidth;
     108        viewHeight = mapViewState.viewHeight;
     109        topLeftInWindow = mapViewState.topLeftInWindow;
     110        topLeftOnScreen = mapViewState.topLeftOnScreen;
     111    }
     112
    102113    /**
    103114     * The scale in east/north units per pixel.
    104115     * @return The scale.
    public final class MapViewState { 
    235246    }
    236247
    237248    /**
     249     * Creates a state that uses the projection.
     250     * @param projection The projection to use.
     251     * @return The new state.
     252     */
     253    public MapViewState usingProjection(Projection projection) {
     254        if (projection.equals(this.projection)) {
     255            return this;
     256        } else {
     257            return new MapViewState(projection, this);
     258        }
     259    }
     260
     261    /**
    238262     * Create the default {@link MapViewState} object for the given map view. The screen position won't be set so that this method can be used
    239263     * before the view was added to the hirarchy.
    240264     * @param width The view width
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    diff --git a/src/org/openstreetmap/josm/gui/NavigatableComponent.java b/src/org/openstreetmap/josm/gui/NavigatableComponent.java
    index b6a15e5..3fcd541 100644
    a b import org.openstreetmap.josm.data.preferences.BooleanProperty; 
    5050import org.openstreetmap.josm.data.preferences.DoubleProperty;
    5151import org.openstreetmap.josm.data.preferences.IntegerProperty;
    5252import org.openstreetmap.josm.data.projection.Projection;
     53import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    5354import org.openstreetmap.josm.data.projection.Projections;
    5455import org.openstreetmap.josm.gui.help.Helpful;
    5556import org.openstreetmap.josm.gui.layer.NativeScaleLayer;
    public class NavigatableComponent extends JComponent implements Helpful { 
    176177    public NavigatableComponent() {
    177178        setLayout(null);
    178179        state = MapViewState.createDefaultState(getWidth(), getHeight());
     180        // uses weak link.
     181        Main.addProjectionChangeListener(new ProjectionChangeListener() {
     182            @Override
     183            public void projectionChanged(Projection oldValue, Projection newValue) {
     184                fixProjection();
     185            }
     186        });
    179187    }
    180188
    181189    @Override
    public class NavigatableComponent extends JComponent implements Helpful { 
    326334    }
    327335
    328336    /**
     337     * Changes the projection settings used for this map view.
     338     * <p>
     339     * Made public temporarely, will be made private later.
     340     */
     341    public void fixProjection() {
     342        state = state.usingProjection(Main.getProjection());
     343        repaint();
     344    }
     345
     346    /**
    329347     * Gets the current view state. This includes the scale, the current view area and the position.
    330348     * @return The current state.
    331349     */