1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.beans.PropertyChangeEvent;
|
---|
7 | import java.beans.PropertyChangeListener;
|
---|
8 | import java.util.Collections;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.Bounds;
|
---|
12 | import org.openstreetmap.josm.gui.MapView;
|
---|
13 | import org.openstreetmap.josm.gui.NavigatableComponent;
|
---|
14 | import org.openstreetmap.josm.gui.SideButton;
|
---|
15 | import org.openstreetmap.josm.gui.bbox.BBoxChooser;
|
---|
16 | import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * A small map of the current edit location implemented as {@link ToggleDialog}.
|
---|
20 | */
|
---|
21 | public class MinimapDialog extends ToggleDialog implements NavigatableComponent.ZoomChangeListener, PropertyChangeListener {
|
---|
22 |
|
---|
23 | protected final SlippyMapBBoxChooser slippyMap = new SlippyMapBBoxChooser();
|
---|
24 | protected boolean skipEvents;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Constructs a new {@code MinimapDialog}.
|
---|
28 | */
|
---|
29 | public MinimapDialog() {
|
---|
30 | super(tr("Mini map"), "minimap", tr("Displays a small map of the current edit location"), null, 150);
|
---|
31 | createLayout(slippyMap, false, Collections.<SideButton>emptyList());
|
---|
32 | slippyMap.setSizeButtonVisible(false);
|
---|
33 | slippyMap.addPropertyChangeListener(BBoxChooser.BBOX_PROP, this);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void showDialog() {
|
---|
38 | NavigatableComponent.addZoomChangeListener(this);
|
---|
39 | super.showDialog();
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void hideDialog() {
|
---|
44 | NavigatableComponent.removeZoomChangeListener(this);
|
---|
45 | super.hideDialog();
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void zoomChanged() {
|
---|
50 | if (Main.isDisplayingMapView() && !skipEvents) {
|
---|
51 | MapView mv = Main.map.mapView;
|
---|
52 | final Bounds currentBounds = new Bounds(
|
---|
53 | mv.getLatLon(0, mv.getHeight()),
|
---|
54 | mv.getLatLon(mv.getWidth(), 0)
|
---|
55 | );
|
---|
56 | skipEvents = true;
|
---|
57 | slippyMap.setBoundingBox(currentBounds);
|
---|
58 | slippyMap.zoomOut(); // to give a better overview
|
---|
59 | skipEvents = false;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
65 | if (!skipEvents) {
|
---|
66 | skipEvents = true;
|
---|
67 | Main.map.mapView.zoomTo(slippyMap.getBoundingBox());
|
---|
68 | skipEvents = false;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|