[608] | 1 | // License: GPL. See LICENSE file for details.
|
---|
| 2 |
|
---|
[283] | 3 | package org.openstreetmap.josm.gui;
|
---|
| 4 |
|
---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
| 7 | import java.awt.Color;
|
---|
| 8 | import java.awt.Graphics;
|
---|
[635] | 9 | import java.awt.Graphics2D;
|
---|
[283] | 10 | import java.awt.Point;
|
---|
[1750] | 11 | import java.awt.event.ComponentAdapter;
|
---|
| 12 | import java.awt.event.ComponentEvent;
|
---|
[811] | 13 | import java.awt.event.MouseEvent;
|
---|
| 14 | import java.awt.event.MouseMotionListener;
|
---|
[635] | 15 | import java.awt.image.BufferedImage;
|
---|
[283] | 16 | import java.util.ArrayList;
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.Collections;
|
---|
[1750] | 19 | import java.util.Enumeration;
|
---|
[283] | 20 | import java.util.LinkedList;
|
---|
| 21 |
|
---|
[1379] | 22 | import javax.swing.AbstractButton;
|
---|
[526] | 23 | import javax.swing.JComponent;
|
---|
[283] | 24 | import javax.swing.JOptionPane;
|
---|
| 25 |
|
---|
| 26 | import org.openstreetmap.josm.Main;
|
---|
| 27 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
---|
[1023] | 28 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
[1750] | 29 | import org.openstreetmap.josm.actions.MoveAction;
|
---|
[1379] | 30 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
[1722] | 31 | import org.openstreetmap.josm.data.ProjectionBounds;
|
---|
[283] | 32 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
[290] | 33 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[1022] | 34 | import org.openstreetmap.josm.data.osm.DataSource;
|
---|
[283] | 35 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 36 | import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
|
---|
| 37 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
[608] | 38 | import org.openstreetmap.josm.gui.layer.MapViewPaintable;
|
---|
[283] | 39 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
| 40 | import org.openstreetmap.josm.gui.layer.OsmDataLayer.ModifiedChangedListener;
|
---|
[572] | 41 | import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
|
---|
| 42 | import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker;
|
---|
[1685] | 43 | import org.openstreetmap.josm.tools.AudioPlayer;
|
---|
[283] | 44 |
|
---|
| 45 | /**
|
---|
| 46 | * This is a component used in the MapFrame for browsing the map. It use is to
|
---|
| 47 | * provide the MapMode's enough capabilities to operate.
|
---|
| 48 | *
|
---|
| 49 | * MapView hold meta-data about the data set currently displayed, as scale level,
|
---|
| 50 | * center point viewed, what scrolling mode or editing mode is selected or with
|
---|
| 51 | * what projection the map is viewed etc..
|
---|
| 52 | *
|
---|
| 53 | * MapView is able to administrate several layers.
|
---|
| 54 | *
|
---|
| 55 | * @author imi
|
---|
| 56 | */
|
---|
| 57 | public class MapView extends NavigatableComponent {
|
---|
| 58 |
|
---|
[1750] | 59 |
|
---|
[1169] | 60 | /**
|
---|
| 61 | * A list of all layers currently loaded.
|
---|
| 62 | */
|
---|
| 63 | private ArrayList<Layer> layers = new ArrayList<Layer>();
|
---|
| 64 | /**
|
---|
| 65 | * The play head marker: there is only one of these so it isn't in any specific layer
|
---|
| 66 | */
|
---|
| 67 | public PlayHeadMarker playHeadMarker = null;
|
---|
[1750] | 68 |
|
---|
[1169] | 69 | /**
|
---|
| 70 | * The layer from the layers list that is currently active.
|
---|
| 71 | */
|
---|
| 72 | private Layer activeLayer;
|
---|
[1023] | 73 |
|
---|
[1169] | 74 | /**
|
---|
| 75 | * The last event performed by mouse.
|
---|
| 76 | */
|
---|
| 77 | public MouseEvent lastMEvent;
|
---|
[811] | 78 |
|
---|
[1169] | 79 | private LinkedList<MapViewPaintable> temporaryLayers = new LinkedList<MapViewPaintable>();
|
---|
[1023] | 80 |
|
---|
[1169] | 81 | private BufferedImage offscreenBuffer;
|
---|
[1023] | 82 |
|
---|
[1169] | 83 | public MapView() {
|
---|
| 84 | addComponentListener(new ComponentAdapter(){
|
---|
| 85 | @Override public void componentResized(ComponentEvent e) {
|
---|
| 86 | removeComponentListener(this);
|
---|
[1677] | 87 |
|
---|
[1518] | 88 | MapSlider zoomSlider = new MapSlider(MapView.this);
|
---|
| 89 | add(zoomSlider);
|
---|
| 90 | zoomSlider.setBounds(3, 0, 114, 30);
|
---|
[506] | 91 |
|
---|
[1722] | 92 | MapScaler scaler = new MapScaler(MapView.this);
|
---|
[1518] | 93 | add(scaler);
|
---|
| 94 | scaler.setLocation(10,30);
|
---|
| 95 |
|
---|
[1750] | 96 | if (!zoomToEditLayerBoundingBox()) {
|
---|
[1169] | 97 | new AutoScaleAction("data").actionPerformed(null);
|
---|
[1750] | 98 | }
|
---|
[506] | 99 |
|
---|
[1169] | 100 | new MapMover(MapView.this, Main.contentPane);
|
---|
| 101 | JosmAction mv;
|
---|
| 102 | mv = new MoveAction(MoveAction.Direction.UP);
|
---|
| 103 | if (mv.getShortcut() != null) {
|
---|
| 104 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "UP");
|
---|
| 105 | Main.contentPane.getActionMap().put("UP", mv);
|
---|
| 106 | }
|
---|
| 107 | mv = new MoveAction(MoveAction.Direction.DOWN);
|
---|
| 108 | if (mv.getShortcut() != null) {
|
---|
| 109 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "DOWN");
|
---|
| 110 | Main.contentPane.getActionMap().put("DOWN", mv);
|
---|
| 111 | }
|
---|
| 112 | mv = new MoveAction(MoveAction.Direction.LEFT);
|
---|
| 113 | if (mv.getShortcut() != null) {
|
---|
| 114 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "LEFT");
|
---|
| 115 | Main.contentPane.getActionMap().put("LEFT", mv);
|
---|
| 116 | }
|
---|
| 117 | mv = new MoveAction(MoveAction.Direction.RIGHT);
|
---|
| 118 | if (mv.getShortcut() != null) {
|
---|
| 119 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "RIGHT");
|
---|
| 120 | Main.contentPane.getActionMap().put("RIGHT", mv);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | });
|
---|
[283] | 124 |
|
---|
[1169] | 125 | // listend to selection changes to redraw the map
|
---|
| 126 | DataSet.selListeners.add(new SelectionChangedListener(){
|
---|
| 127 | public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
|
---|
| 128 | repaint();
|
---|
| 129 | }
|
---|
| 130 | });
|
---|
[811] | 131 |
|
---|
[1169] | 132 | //store the last mouse action
|
---|
| 133 | this.addMouseMotionListener(new MouseMotionListener() {
|
---|
| 134 | public void mouseDragged(MouseEvent e) {
|
---|
| 135 | mouseMoved(e);
|
---|
| 136 | }
|
---|
| 137 | public void mouseMoved(MouseEvent e) {
|
---|
| 138 | lastMEvent = e;
|
---|
| 139 | }
|
---|
| 140 | });
|
---|
| 141 | }
|
---|
[283] | 142 |
|
---|
[1169] | 143 | /**
|
---|
| 144 | * Add a layer to the current MapView. The layer will be added at topmost
|
---|
| 145 | * position.
|
---|
| 146 | */
|
---|
| 147 | public void addLayer(Layer layer) {
|
---|
| 148 | if (layer instanceof OsmDataLayer) {
|
---|
[1750] | 149 | OsmDataLayer editLayer = (OsmDataLayer)layer;
|
---|
[1169] | 150 | Main.ds = editLayer.data;
|
---|
| 151 | editLayer.listenerModified.add(new ModifiedChangedListener(){
|
---|
| 152 | public void modifiedChanged(boolean value, OsmDataLayer source) {
|
---|
[1179] | 153 | JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")
|
---|
[1750] | 154 | +tr("Java OpenStreetMap Editor"));
|
---|
[1169] | 155 | }
|
---|
| 156 | });
|
---|
| 157 | }
|
---|
[1750] | 158 | if (layer instanceof MarkerLayer && playHeadMarker == null) {
|
---|
[1169] | 159 | playHeadMarker = PlayHeadMarker.create();
|
---|
[1750] | 160 | }
|
---|
[1169] | 161 | int pos = layers.size();
|
---|
[1750] | 162 | while(pos > 0 && layers.get(pos-1).background) {
|
---|
[1169] | 163 | --pos;
|
---|
[1750] | 164 | }
|
---|
[1169] | 165 | layers.add(pos, layer);
|
---|
[283] | 166 |
|
---|
[1750] | 167 | for (Layer.LayerChangeListener l : Layer.listeners) {
|
---|
[1169] | 168 | l.layerAdded(layer);
|
---|
[1750] | 169 | }
|
---|
[1169] | 170 | if (layer instanceof OsmDataLayer || activeLayer == null) {
|
---|
| 171 | // autoselect the new layer
|
---|
| 172 | Layer old = activeLayer;
|
---|
| 173 | setActiveLayer(layer);
|
---|
[1750] | 174 | for (Layer.LayerChangeListener l : Layer.listeners) {
|
---|
[1169] | 175 | l.activeLayerChange(old, layer);
|
---|
[1750] | 176 | }
|
---|
[1169] | 177 | }
|
---|
[1685] | 178 | AudioPlayer.reset();
|
---|
[1169] | 179 | repaint();
|
---|
| 180 | }
|
---|
[283] | 181 |
|
---|
[1169] | 182 | @Override
|
---|
[1750] | 183 | protected DataSet getData() {
|
---|
[1169] | 184 | if(activeLayer != null && activeLayer instanceof OsmDataLayer)
|
---|
| 185 | return ((OsmDataLayer)activeLayer).data;
|
---|
| 186 | return new DataSet();
|
---|
| 187 | }
|
---|
[845] | 188 |
|
---|
[1750] | 189 | /**
|
---|
| 190 | * Replies true if the active layer is drawable.
|
---|
| 191 | *
|
---|
| 192 | * @return true if the active layer is drawable, false otherwise
|
---|
| 193 | */
|
---|
| 194 | public boolean isActiveLayerDrawable() {
|
---|
[1169] | 195 | return activeLayer != null && activeLayer instanceof OsmDataLayer;
|
---|
| 196 | }
|
---|
[1677] | 197 |
|
---|
[1750] | 198 | /**
|
---|
| 199 | * Replies true if the active layer is visible.
|
---|
| 200 | *
|
---|
| 201 | * @return true if the active layer is visible, false otherwise
|
---|
| 202 | */
|
---|
| 203 | public boolean isActiveLayerVisible() {
|
---|
| 204 | return isActiveLayerDrawable() && activeLayer.visible;
|
---|
[1418] | 205 | }
|
---|
[845] | 206 |
|
---|
[1169] | 207 | /**
|
---|
| 208 | * Remove the layer from the mapview. If the layer was in the list before,
|
---|
| 209 | * an LayerChange event is fired.
|
---|
| 210 | */
|
---|
| 211 | public void removeLayer(Layer layer) {
|
---|
[1808] | 212 | if (layer == activeLayer) {
|
---|
| 213 | if (layer instanceof OsmDataLayer) {
|
---|
| 214 | Main.ds = null;
|
---|
| 215 | }
|
---|
| 216 | activeLayer = null;
|
---|
| 217 | }
|
---|
[1169] | 218 | if (layers.remove(layer)) {
|
---|
[1750] | 219 | for (Layer.LayerChangeListener l : Layer.listeners) {
|
---|
[1169] | 220 | l.layerRemoved(layer);
|
---|
[1750] | 221 | }
|
---|
[1169] | 222 | }
|
---|
| 223 | layer.destroy();
|
---|
[1685] | 224 | AudioPlayer.reset();
|
---|
[1169] | 225 | }
|
---|
[283] | 226 |
|
---|
[1750] | 227 | private boolean virtualNodesEnabled = false;
|
---|
| 228 | public void setVirtualNodesEnabled(boolean enabled) {
|
---|
| 229 | if(virtualNodesEnabled != enabled) {
|
---|
| 230 | virtualNodesEnabled = enabled;
|
---|
[1169] | 231 | repaint();
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
[1750] | 234 | public boolean isVirtualNodesEnabled() {
|
---|
| 235 | return virtualNodesEnabled;
|
---|
[1169] | 236 | }
|
---|
[805] | 237 |
|
---|
[1169] | 238 | /**
|
---|
| 239 | * Moves the layer to the given new position. No event is fired.
|
---|
| 240 | * @param layer The layer to move
|
---|
| 241 | * @param pos The new position of the layer
|
---|
| 242 | */
|
---|
| 243 | public void moveLayer(Layer layer, int pos) {
|
---|
| 244 | int curLayerPos = layers.indexOf(layer);
|
---|
| 245 | if (curLayerPos == -1)
|
---|
| 246 | throw new IllegalArgumentException(tr("layer not in list."));
|
---|
| 247 | if (pos == curLayerPos)
|
---|
| 248 | return; // already in place.
|
---|
| 249 | layers.remove(curLayerPos);
|
---|
[1750] | 250 | if (pos >= layers.size()) {
|
---|
[1169] | 251 | layers.add(layer);
|
---|
[1750] | 252 | } else {
|
---|
[1169] | 253 | layers.add(pos, layer);
|
---|
[1750] | 254 | }
|
---|
[1685] | 255 | AudioPlayer.reset();
|
---|
[1169] | 256 | }
|
---|
[283] | 257 |
|
---|
[1265] | 258 |
|
---|
| 259 | public int getLayerPos(Layer layer) {
|
---|
| 260 | int curLayerPos = layers.indexOf(layer);
|
---|
| 261 | if (curLayerPos == -1)
|
---|
| 262 | throw new IllegalArgumentException(tr("layer not in list."));
|
---|
| 263 | return curLayerPos;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
[1169] | 266 | /**
|
---|
| 267 | * Draw the component.
|
---|
| 268 | */
|
---|
| 269 | @Override public void paint(Graphics g) {
|
---|
| 270 | if (center == null)
|
---|
| 271 | return; // no data loaded yet.
|
---|
[775] | 272 |
|
---|
[1169] | 273 | // re-create offscreen-buffer if we've been resized, otherwise
|
---|
| 274 | // just re-use it.
|
---|
| 275 | if (null == offscreenBuffer || offscreenBuffer.getWidth() != getWidth()
|
---|
[1750] | 276 | || offscreenBuffer.getHeight() != getHeight()) {
|
---|
[1169] | 277 | offscreenBuffer = new BufferedImage(getWidth(), getHeight(),
|
---|
| 278 | BufferedImage.TYPE_INT_ARGB);
|
---|
[1750] | 279 | }
|
---|
[775] | 280 |
|
---|
[1169] | 281 | Graphics2D tempG = offscreenBuffer.createGraphics();
|
---|
| 282 | tempG.setColor(Main.pref.getColor("background", Color.BLACK));
|
---|
| 283 | tempG.fillRect(0, 0, getWidth(), getHeight());
|
---|
[283] | 284 |
|
---|
[1169] | 285 | for (int i = layers.size()-1; i >= 0; --i) {
|
---|
| 286 | Layer l = layers.get(i);
|
---|
[1750] | 287 | if (l.visible/* && l != getActiveLayer()*/) {
|
---|
[1169] | 288 | l.paint(tempG, this);
|
---|
[1750] | 289 | }
|
---|
[1169] | 290 | }
|
---|
[283] | 291 |
|
---|
[1169] | 292 | /*if (getActiveLayer() != null && getActiveLayer().visible)
|
---|
| 293 | getActiveLayer().paint(tempG, this);*/
|
---|
[845] | 294 |
|
---|
[1169] | 295 | for (MapViewPaintable mvp : temporaryLayers) {
|
---|
| 296 | mvp.paint(tempG, this);
|
---|
| 297 | }
|
---|
[1023] | 298 |
|
---|
[1169] | 299 | // draw world borders
|
---|
| 300 | tempG.setColor(Color.WHITE);
|
---|
[1722] | 301 | ProjectionBounds b = getProjection().getWorldBounds();
|
---|
| 302 | Point min = getPoint(b.min);
|
---|
| 303 | Point max = getPoint(b.max);
|
---|
[1169] | 304 | int x1 = Math.min(min.x, max.x);
|
---|
| 305 | int y1 = Math.min(min.y, max.y);
|
---|
| 306 | int x2 = Math.max(min.x, max.x);
|
---|
| 307 | int y2 = Math.max(min.y, max.y);
|
---|
[1750] | 308 | if (x1 > 0 || y1 > 0 || x2 < getWidth() || y2 < getHeight()) {
|
---|
[1169] | 309 | tempG.drawRect(x1, y1, x2-x1+1, y2-y1+1);
|
---|
[1750] | 310 | }
|
---|
[1023] | 311 |
|
---|
[1750] | 312 | if (playHeadMarker != null) {
|
---|
[1169] | 313 | playHeadMarker.paint(tempG, this);
|
---|
[1750] | 314 | }
|
---|
[572] | 315 |
|
---|
[1169] | 316 | g.drawImage(offscreenBuffer, 0, 0, null);
|
---|
| 317 | super.paint(g);
|
---|
| 318 | }
|
---|
[283] | 319 |
|
---|
[1169] | 320 | /**
|
---|
[1722] | 321 | * Set the new dimension to the view.
|
---|
[1169] | 322 | */
|
---|
| 323 | public void recalculateCenterScale(BoundingXYVisitor box) {
|
---|
[1797] | 324 | if (box == null) {
|
---|
[1722] | 325 | box = new BoundingXYVisitor();
|
---|
[1750] | 326 | }
|
---|
[1797] | 327 | if (box.getBounds() == null) {
|
---|
[1722] | 328 | box.visit(getProjection().getWorldBounds());
|
---|
[1750] | 329 | }
|
---|
[1797] | 330 | if (!box.hasExtend()) {
|
---|
[1750] | 331 | box.enlargeBoundingBox();
|
---|
| 332 | }
|
---|
[283] | 333 |
|
---|
[1722] | 334 | zoomTo(box.getBounds());
|
---|
[1169] | 335 | }
|
---|
[283] | 336 |
|
---|
[1169] | 337 | /**
|
---|
[1750] | 338 | * @return An unmodifiable collection of all layers
|
---|
[1169] | 339 | */
|
---|
| 340 | public Collection<Layer> getAllLayers() {
|
---|
| 341 | return Collections.unmodifiableCollection(layers);
|
---|
| 342 | }
|
---|
[283] | 343 |
|
---|
[1169] | 344 | /**
|
---|
[1750] | 345 | * Sets the active layer to <code>layer</code>. If <code>layer</code> is an instance
|
---|
| 346 | * of {@see OsmDataLayer} also sets {@see #editLayer} to <code>layer</code>.
|
---|
| 347 | *
|
---|
| 348 | * @param layer the layer to be activate; must be one of the layers in the list of layers
|
---|
| 349 | * @exception IllegalArgumentException thrown if layer is not in the lis of layers
|
---|
[1169] | 350 | */
|
---|
| 351 | public void setActiveLayer(Layer layer) {
|
---|
| 352 | if (!layers.contains(layer))
|
---|
[1750] | 353 | throw new IllegalArgumentException(tr("Layer {0} must be in list of layers", layer.toString()));
|
---|
[1169] | 354 | if (layer instanceof OsmDataLayer) {
|
---|
[1750] | 355 | OsmDataLayer editLayer = (OsmDataLayer)layer;
|
---|
[1169] | 356 | Main.ds = editLayer.data;
|
---|
[1750] | 357 | } else {
|
---|
| 358 | Main.ds.setSelected();
|
---|
[1169] | 359 | }
|
---|
| 360 | DataSet.fireSelectionChanged(Main.ds.getSelected());
|
---|
| 361 | Layer old = activeLayer;
|
---|
| 362 | activeLayer = layer;
|
---|
| 363 | if (old != layer) {
|
---|
[1750] | 364 | for (Layer.LayerChangeListener l : Layer.listeners) {
|
---|
[1169] | 365 | l.activeLayerChange(old, layer);
|
---|
[1750] | 366 | }
|
---|
[1169] | 367 | }
|
---|
[1662] | 368 |
|
---|
[1379] | 369 | /* This only makes the buttons look disabled. Disabling the actions as well requires
|
---|
| 370 | * the user to re-select the tool after i.e. moving a layer. While testing I found
|
---|
| 371 | * that I switch layers and actions at the same time and it was annoying to mind the
|
---|
| 372 | * order. This way it works as visual clue for new users */
|
---|
[1415] | 373 | for (Enumeration<AbstractButton> e = Main.map.toolGroup.getElements() ; e.hasMoreElements() ;) {
|
---|
| 374 | AbstractButton x=e.nextElement();
|
---|
[1379] | 375 | x.setEnabled(((MapMode)x.getAction()).layerIsSupported(layer));
|
---|
| 376 | }
|
---|
[1685] | 377 | AudioPlayer.reset();
|
---|
[1169] | 378 | repaint();
|
---|
| 379 | }
|
---|
[283] | 380 |
|
---|
[1169] | 381 | /**
|
---|
[1750] | 382 | * Replies the currently active layer
|
---|
| 383 | *
|
---|
| 384 | * @return the currently active layer (may be null)
|
---|
[1169] | 385 | */
|
---|
| 386 | public Layer getActiveLayer() {
|
---|
| 387 | return activeLayer;
|
---|
| 388 | }
|
---|
[283] | 389 |
|
---|
[1169] | 390 | /**
|
---|
[1750] | 391 | * Replies the current edit layer, if any
|
---|
| 392 | *
|
---|
| 393 | * @return the current edit layer. May be null.
|
---|
| 394 | */
|
---|
| 395 | public OsmDataLayer getEditLayer() {
|
---|
| 396 | if (activeLayer instanceof OsmDataLayer)
|
---|
| 397 | return (OsmDataLayer)activeLayer;
|
---|
| 398 | return null;
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | /**
|
---|
| 402 | * replies true if the list of layers managed by this map view contain layer
|
---|
| 403 | *
|
---|
| 404 | * @param layer the layer
|
---|
| 405 | * @return true if the list of layers managed by this map view contain layer
|
---|
| 406 | */
|
---|
| 407 | public boolean hasLayer(Layer layer) {
|
---|
| 408 | return layers.contains(layer);
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | /**
|
---|
[1169] | 412 | * Tries to zoom to the download boundingbox[es] of the current edit layer
|
---|
| 413 | * (aka {@link OsmDataLayer}). If the edit layer has multiple download bounding
|
---|
| 414 | * boxes it zooms to a large virtual bounding box containing all smaller ones.
|
---|
| 415 | * This implementation can be used for resolving ticket #1461.
|
---|
| 416 | *
|
---|
| 417 | * @return <code>true</code> if a zoom operation has been performed
|
---|
| 418 | */
|
---|
| 419 | public boolean zoomToEditLayerBoundingBox() {
|
---|
| 420 | // workaround for #1461 (zoom to download bounding box instead of all data)
|
---|
| 421 | // In case we already have an existing data layer ...
|
---|
[1808] | 422 | OsmDataLayer layer= getEditLayer();
|
---|
| 423 | if (layer == null)
|
---|
| 424 | return false;
|
---|
| 425 | Collection<DataSource> dataSources = layer.data.dataSources;
|
---|
[1169] | 426 | // ... with bounding box[es] of data loaded from OSM or a file...
|
---|
| 427 | BoundingXYVisitor bbox = new BoundingXYVisitor();
|
---|
| 428 | for (DataSource ds : dataSources) {
|
---|
[1722] | 429 | bbox.visit(ds.bounds);
|
---|
| 430 | if (bbox.hasExtend()) {
|
---|
[1169] | 431 | // ... we zoom to it's bounding box
|
---|
| 432 | recalculateCenterScale(bbox);
|
---|
| 433 | return true;
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 | return false;
|
---|
| 437 | }
|
---|
[1023] | 438 |
|
---|
[1169] | 439 | public boolean addTemporaryLayer(MapViewPaintable mvp) {
|
---|
| 440 | if (temporaryLayers.contains(mvp)) return false;
|
---|
| 441 | return temporaryLayers.add(mvp);
|
---|
| 442 | }
|
---|
[1023] | 443 |
|
---|
[1169] | 444 | public boolean removeTemporaryLayer(MapViewPaintable mvp) {
|
---|
| 445 | return temporaryLayers.remove(mvp);
|
---|
| 446 | }
|
---|
[283] | 447 | }
|
---|