Skip to content

Commit 8ce6468

Browse files
author
nokutu
committed
When zooming to show a set of images, the zoom level has a maximum value, so it can't too high.
git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins/mapillary@31495 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
1 parent ec79d07 commit 8ce6468

File tree

7 files changed

+187
-31
lines changed

7 files changed

+187
-31
lines changed

src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public MapillaryData getData() {
189189
@Override
190190
public void destroy() {
191191
setMode(null);
192-
192+
MapillaryRecord.getInstance().reset();
193193
AbstractMode.resetThread();
194194
MapillaryDownloader.stopAll();
195195
MapillaryMainDialog.getInstance().setImage(null);
@@ -212,29 +212,6 @@ public static void clearInstance() {
212212
INSTANCE = null;
213213
}
214214

215-
/**
216-
* Zooms to fit all the {@link MapillaryAbstractImage} icons into the map
217-
* view.
218-
*/
219-
public void showAllPictures() {
220-
double minLat = 90;
221-
double minLon = 180;
222-
double maxLat = -90;
223-
double maxLon = -180;
224-
for (MapillaryAbstractImage img : this.data.getImages()) {
225-
if (img.getLatLon().lat() < minLat)
226-
minLat = img.getLatLon().lat();
227-
if (img.getLatLon().lon() < minLon)
228-
minLon = img.getLatLon().lon();
229-
if (img.getLatLon().lat() > maxLat)
230-
maxLat = img.getLatLon().lat();
231-
if (img.getLatLon().lon() > maxLon)
232-
maxLon = img.getLatLon().lon();
233-
}
234-
Main.map.mapView.zoomTo(new Bounds(new LatLon(minLat, minLon), new LatLon(
235-
maxLat, maxLon)));
236-
}
237-
238215
@Override
239216
public boolean isModified() {
240217
for (MapillaryAbstractImage image : this.data.getImages())

src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ else if (extension.equals("png"))
117117
}
118118
}
119119
MapillaryRecord.getInstance().addCommand(new CommandImport(images));
120-
MapillaryLayer.getInstance().showAllPictures();
120+
MapillaryUtils.showAllPictures();
121121
}
122122
}
123123

src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void actionPerformed(ActionEvent arg0) {
115115
joinImages();
116116
MapillaryRecord.getInstance().addCommand(new CommandImport(this.images));
117117
}
118-
MapillaryLayer.getInstance().showAllPictures();
118+
MapillaryUtils.showAllPictures();
119119
}
120120

121121
/**

src/org/openstreetmap/josm/plugins/mapillary/gui/FinishedUploadDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public FinishedUploadDialog() {
3535
JLabel text = new JLabel(tr("Uploaded {0} images", PluginState.imagesUploaded));
3636
text.setAlignmentX(Component.CENTER_ALIGNMENT);
3737
this.add(text);
38-
JButton web = new JButton("Approve upload in the website.");
38+
JButton web = new JButton("Approve upload on the website.");
3939
web.addActionListener(new WebAction());
4040
web.setAlignmentX(Component.CENTER_ALIGNMENT);
4141
this.add(web, Component.CENTER_ALIGNMENT);

src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,31 @@
88
import java.awt.GridBagLayout;
99
import java.awt.event.ActionEvent;
1010
import java.awt.event.KeyEvent;
11+
import java.awt.event.MouseEvent;
12+
import java.awt.event.MouseListener;
1113
import java.util.ArrayList;
1214
import java.util.Arrays;
15+
import java.util.concurrent.ConcurrentHashMap;
1316

1417
import javax.swing.AbstractAction;
1518
import javax.swing.Box;
1619
import javax.swing.JPanel;
1720
import javax.swing.JSeparator;
1821
import javax.swing.JTree;
1922
import javax.swing.SwingUtilities;
23+
import javax.swing.event.TreeSelectionEvent;
24+
import javax.swing.event.TreeSelectionListener;
2025
import javax.swing.tree.DefaultTreeCellRenderer;
2126
import javax.swing.tree.DefaultTreeModel;
27+
import javax.swing.tree.TreeSelectionModel;
2228

2329
import org.openstreetmap.josm.gui.SideButton;
2430
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
2531
import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
2632
import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecordListener;
33+
import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
2734
import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand;
35+
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
2836
import org.openstreetmap.josm.tools.GBC;
2937
import org.openstreetmap.josm.tools.ImageProvider;
3038
import org.openstreetmap.josm.tools.Shortcut;
@@ -47,6 +55,9 @@ public class MapillaryHistoryDialog extends ToggleDialog implements
4755

4856
private static MapillaryHistoryDialog INSTANCE;
4957

58+
private transient UndoRedoSelectionListener undoSelectionListener;
59+
private transient UndoRedoSelectionListener redoSelectionListener;
60+
5061
private final DefaultTreeModel undoTreeModel = new DefaultTreeModel(
5162
new DefaultMutableTreeNode());
5263
private final DefaultTreeModel redoTreeModel = new DefaultTreeModel(
@@ -60,6 +71,8 @@ public class MapillaryHistoryDialog extends ToggleDialog implements
6071
private SideButton undoButton;
6172
private SideButton redoButton;
6273

74+
private ConcurrentHashMap<Object, MapillaryCommand> map;
75+
6376
private MapillaryHistoryDialog() {
6477
super(tr("Mapillary history"), "mapillaryhistory.png",
6578
tr("Open Mapillary history dialog"), Shortcut.registerShortcut(
@@ -68,14 +81,29 @@ private MapillaryHistoryDialog() {
6881

6982
MapillaryRecord.getInstance().addListener(this);
7083

84+
this.map = new ConcurrentHashMap<>();
85+
7186
this.undoTree.expandRow(0);
7287
this.undoTree.setShowsRootHandles(true);
7388
this.undoTree.setRootVisible(false);
7489
this.undoTree.setCellRenderer(new MapillaryCellRenderer());
90+
this.undoTree.getSelectionModel().setSelectionMode(
91+
TreeSelectionModel.SINGLE_TREE_SELECTION);
92+
this.undoTree.addMouseListener(new MouseEventHandler());
93+
this.undoSelectionListener = new UndoRedoSelectionListener(this.undoTree);
94+
this.undoTree.getSelectionModel().addTreeSelectionListener(
95+
this.undoSelectionListener);
96+
7597
this.redoTree.expandRow(0);
7698
this.redoTree.setCellRenderer(new MapillaryCellRenderer());
7799
this.redoTree.setShowsRootHandles(true);
78100
this.redoTree.setRootVisible(false);
101+
this.redoTree.getSelectionModel().setSelectionMode(
102+
TreeSelectionModel.SINGLE_TREE_SELECTION);
103+
this.redoTree.addMouseListener(new MouseEventHandler());
104+
this.redoSelectionListener = new UndoRedoSelectionListener(this.redoTree);
105+
this.redoTree.getSelectionModel().addTreeSelectionListener(
106+
this.redoSelectionListener);
79107

80108
JPanel treesPanel = new JPanel(new GridBagLayout());
81109
treesPanel.add(this.spacer, GBC.eol());
@@ -129,13 +157,22 @@ private void buildTree() {
129157
DefaultMutableTreeNode redoRoot = new DefaultMutableTreeNode();
130158
DefaultMutableTreeNode undoRoot = new DefaultMutableTreeNode();
131159

160+
this.map.clear();
132161
for (MapillaryCommand command : undoCommands) {
133-
if (command != null)
134-
undoRoot.add(new DefaultMutableTreeNode(command.toString()));
162+
if (command != null) {
163+
DefaultMutableTreeNode node = new DefaultMutableTreeNode(
164+
command.toString());
165+
this.map.put(node, command);
166+
undoRoot.add(node);
167+
}
135168
}
136169
for (MapillaryCommand command : redoCommands) {
137-
if (command != null)
138-
redoRoot.add(new DefaultMutableTreeNode(command.toString()));
170+
if (command != null) {
171+
DefaultMutableTreeNode node = new DefaultMutableTreeNode(
172+
command.toString());
173+
this.map.put(node, command);
174+
redoRoot.add(node);
175+
}
139176
}
140177

141178
this.separator.setVisible(!undoCommands.isEmpty()
@@ -212,4 +249,70 @@ public Component getTreeCellRendererComponent(JTree tree, Object value,
212249
public static void destroyInstance() {
213250
MapillaryHistoryDialog.INSTANCE = null;
214251
}
252+
253+
private class MouseEventHandler implements MouseListener {
254+
255+
@Override
256+
public void mouseClicked(MouseEvent e) {
257+
}
258+
259+
@Override
260+
public void mouseEntered(MouseEvent e) {
261+
}
262+
263+
@Override
264+
public void mouseExited(MouseEvent e) {
265+
}
266+
267+
@Override
268+
public void mousePressed(MouseEvent e) {
269+
if (e.getClickCount() == 2) {
270+
if (MapillaryHistoryDialog.this.undoTree.getSelectionPath() != null) {
271+
MapillaryCommand cmd = MapillaryHistoryDialog.this.map
272+
.get(MapillaryHistoryDialog.this.undoTree.getSelectionPath()
273+
.getLastPathComponent());
274+
if (!(cmd instanceof CommandDelete))
275+
MapillaryUtils.showPictures(cmd.images, true);
276+
} else
277+
MapillaryUtils.showPictures(MapillaryHistoryDialog.this.map
278+
.get(MapillaryHistoryDialog.this.redoTree.getSelectionPath()
279+
.getLastPathComponent()).images, true);
280+
}
281+
}
282+
283+
@Override
284+
public void mouseReleased(MouseEvent e) {
285+
}
286+
}
287+
288+
private class UndoRedoSelectionListener implements TreeSelectionListener {
289+
290+
private JTree source;
291+
292+
private UndoRedoSelectionListener(JTree source) {
293+
this.source = source;
294+
}
295+
296+
@Override
297+
public void valueChanged(TreeSelectionEvent e) {
298+
if (this.source == MapillaryHistoryDialog.this.undoTree) {
299+
MapillaryHistoryDialog.this.redoTree.getSelectionModel()
300+
.removeTreeSelectionListener(
301+
MapillaryHistoryDialog.this.redoSelectionListener);
302+
MapillaryHistoryDialog.this.redoTree.clearSelection();
303+
MapillaryHistoryDialog.this.redoTree.getSelectionModel()
304+
.addTreeSelectionListener(
305+
MapillaryHistoryDialog.this.redoSelectionListener);
306+
}
307+
if (this.source == MapillaryHistoryDialog.this.redoTree) {
308+
MapillaryHistoryDialog.this.undoTree.getSelectionModel()
309+
.removeTreeSelectionListener(
310+
MapillaryHistoryDialog.this.undoSelectionListener);
311+
MapillaryHistoryDialog.this.undoTree.clearSelection();
312+
MapillaryHistoryDialog.this.undoTree.getSelectionModel()
313+
.addTreeSelectionListener(
314+
MapillaryHistoryDialog.this.undoSelectionListener);
315+
}
316+
}
317+
}
215318
}

src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,12 @@ private void fireRecordChanged() {
126126
if (lis != null)
127127
lis.recordChanged();
128128
}
129+
130+
/**
131+
* Resets the object to its start state.
132+
*/
133+
public void reset() {
134+
this.commandList.clear();
135+
this.position = -1;
136+
}
129137
}

src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
import java.net.URISyntaxException;
88
import java.net.URL;
99
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
import javax.swing.SwingUtilities;
1013

1114
import org.apache.commons.imaging.common.RationalNumber;
1215
import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
1316
import org.openstreetmap.josm.Main;
17+
import org.openstreetmap.josm.data.Bounds;
18+
import org.openstreetmap.josm.data.coor.LatLon;
1419
import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
1520
import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
1621
import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
@@ -24,6 +29,9 @@
2429
*
2530
*/
2631
public class MapillaryUtils {
32+
33+
private static double MIN_ZOOM_SQUARE_SIDE = 0.002;
34+
2735
/**
2836
* Updates the help text at the bottom of the window.
2937
*/
@@ -198,4 +206,64 @@ public synchronized static void unjoin(MapillaryImportedImage img1,
198206
if (Main.main != null)
199207
MapillaryData.dataUpdated();
200208
}
209+
210+
/**
211+
* Zooms to fit all the given {@link MapillaryAbstractImage} objects.
212+
*
213+
* @param images
214+
* The images your are zooming to.
215+
* @param select
216+
* Whether the added images must be selected or not.
217+
*/
218+
public static void showPictures(final List<MapillaryAbstractImage> images,
219+
final boolean select) {
220+
if (!SwingUtilities.isEventDispatchThread()) {
221+
SwingUtilities.invokeLater(new Runnable() {
222+
@Override
223+
public void run() {
224+
showPictures(images, select);
225+
}
226+
});
227+
} else {
228+
double minLat = 90;
229+
double minLon = 180;
230+
double maxLat = -90;
231+
double maxLon = -180;
232+
for (MapillaryAbstractImage img : images) {
233+
if (img.getLatLon().lat() < minLat)
234+
minLat = img.getLatLon().lat();
235+
if (img.getLatLon().lon() < minLon)
236+
minLon = img.getLatLon().lon();
237+
if (img.getLatLon().lat() > maxLat)
238+
maxLat = img.getLatLon().lat();
239+
if (img.getLatLon().lon() > maxLon)
240+
maxLon = img.getLatLon().lon();
241+
}
242+
Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon), new LatLon(
243+
maxLat, maxLon));
244+
// The zoom rectangle must have a minimum size.
245+
double latExtent = zoomBounds.getMaxLat() - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
246+
.getMaxLat() - zoomBounds.getMinLat()
247+
: MIN_ZOOM_SQUARE_SIDE;
248+
double lonExtent = zoomBounds.getMaxLon() - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
249+
.getMaxLon() - zoomBounds.getMinLon()
250+
: MIN_ZOOM_SQUARE_SIDE;
251+
zoomBounds = new Bounds(zoomBounds.getCenter(), latExtent, lonExtent);
252+
253+
Main.map.mapView.zoomTo(zoomBounds);
254+
MapillaryLayer.getInstance().getData().setSelectedImage(null);
255+
if (select)
256+
MapillaryLayer.getInstance().getData().addMultiSelectedImage(images);
257+
if (Main.main != null)
258+
MapillaryData.dataUpdated();
259+
}
260+
}
261+
262+
/**
263+
* Zooms to fit all the {@link MapillaryAbstractImage} objects stored in the
264+
* database.
265+
*/
266+
public static void showAllPictures() {
267+
showPictures(MapillaryLayer.getInstance().getData().getImages(), false);
268+
}
201269
}

0 commit comments

Comments
 (0)