Changeset 16032 in osm for applications/viewer/jmapviewer/src/org
- Timestamp:
- 2009-06-21T12:38:54+02:00 (15 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r11783 r16032 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.ActionListener; 12 import java.awt.geom.Point2D;13 12 import java.util.LinkedList; 14 13 import java.util.List; … … 23 22 import org.openstreetmap.gui.jmapviewer.JobDispatcher.JobThread; 24 23 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; 24 import org.openstreetmap.gui.jmapviewer.interfaces.MapSquare; 25 25 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 26 26 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; … … 53 53 54 54 protected List<MapMarker> mapMarkerList; 55 protected List<MapSquare> mapSquareList; 56 55 57 protected boolean mapMarkersVisible; 58 protected boolean mapSquaresVisible; 59 56 60 protected boolean tileGridVisible; 57 61 … … 92 96 jobDispatcher = JobDispatcher.getInstance(); 93 97 mapMarkerList = new LinkedList<MapMarker>(); 98 mapSquareList = new LinkedList<MapSquare>(); 94 99 mapMarkersVisible = true; 100 mapSquaresVisible = true; 95 101 tileGridVisible = false; 96 102 setLayout(null); … … 253 259 } 254 260 255 public Point2D.Double getPosition() {261 public Coordinate getPosition() { 256 262 double lon = OsmMercator.XToLon(center.x, zoom); 257 263 double lat = OsmMercator.YToLat(center.y, zoom); 258 return new Point2D.Double(lat, lon);259 } 260 261 public Point2D.Double getPosition(Point mapPoint) {264 return new Coordinate(lat, lon); 265 } 266 267 public Coordinate getPosition(Point mapPoint) { 262 268 int x = center.x + mapPoint.x - getWidth() / 2; 263 269 int y = center.y + mapPoint.y - getHeight() / 2; 264 270 double lon = OsmMercator.XToLon(x, zoom); 265 271 double lat = OsmMercator.YToLat(y, zoom); 266 return new Point2D.Double(lat, lon); 272 return new Coordinate(lat, lon); 273 } 274 275 public Coordinate getPosition(int mapPointX, int mapPointY) { 276 int x = center.x + mapPointX - getWidth() / 2; 277 int y = center.y + mapPointY - getHeight() / 2; 278 double lon = OsmMercator.XToLon(x, zoom); 279 double lat = OsmMercator.YToLat(y, zoom); 280 return new Coordinate(lat, lon); 267 281 } 268 282 … … 357 371 358 372 // g.drawString("Tiles in cache: " + tileCache.getTileCount(), 50, 20); 359 if (!mapMarkersVisible || mapMarkerList == null) 360 return; 361 for (MapMarker marker : mapMarkerList) { 362 Point p = getMapPosition(marker.getLat(), marker.getLon()); 363 // System.out.println(marker + " -> " + p); 364 if (p != null) 365 marker.paint(g, p); 373 374 if (mapSquaresVisible && mapSquareList != null) { 375 for (MapSquare square : mapSquareList) { 376 Coordinate topLeft = square.getTopLeft(); 377 Coordinate bottomRight = square.getBottomRight(); 378 if (topLeft != null && bottomRight != null) { 379 Point pTopLeft = getMapPosition(topLeft.getLat(), topLeft.getLon()); 380 Point pBottomRight = getMapPosition(bottomRight.getLat(), bottomRight.getLon()); 381 if (pTopLeft != null && pBottomRight != null) { 382 square.paint(g, pTopLeft, pBottomRight); 383 } 384 } 385 } 386 } 387 388 if (mapMarkersVisible && mapMarkerList != null) { 389 for (MapMarker marker : mapMarkerList) { 390 Point p = getMapPosition(marker.getLat(), marker.getLon()); 391 if (p != null) { 392 marker.paint(g, p); 393 } 394 } 366 395 } 367 396 } … … 419 448 if (zoom > tileSource.getMaxZoom() || zoom < tileSource.getMinZoom() || zoom == this.zoom) 420 449 return; 421 Point2D.Double zoomPos = getPosition(mapPoint);450 Coordinate zoomPos = getPosition(mapPoint); 422 451 jobDispatcher.cancelOutstandingJobs(); // Clearing outstanding load 423 452 // requests 424 setDisplayPositionByLatLon(mapPoint, zoomPos. x, zoomPos.y, zoom);453 setDisplayPositionByLatLon(mapPoint, zoomPos.getLat(), zoomPos.getLon(), zoom); 425 454 } 426 455 … … 505 534 } 506 535 536 public void setMapSquareList(List<MapSquare> mapSquareList) { 537 this.mapSquareList = mapSquareList; 538 repaint(); 539 } 540 541 public List<MapSquare> getMapSquareList() { 542 return mapSquareList; 543 } 544 507 545 public void addMapMarker(MapMarker marker) { 508 546 mapMarkerList.add(marker); 547 repaint(); 548 } 549 550 public void addMapSquare(MapSquare square) { 551 mapSquareList.add(square); 552 repaint(); 553 } 554 555 public void removeMapSquare(MapSquare square) { 556 mapSquareList.remove(square); 557 repaint(); 509 558 } 510 559 … … 557 606 } 558 607 608 public boolean isMapSquaresVisible() { 609 return mapSquaresVisible; 610 } 611 612 /** 613 * Enables or disables painting of the {@link MapSquare} 614 * 615 * @param mapMarkersVisible 616 * @see #addMapSquare(MapSquare) 617 * @see #getMapSquareList() 618 */ 619 public void setMapSquaresVisible(boolean mapSquaresVisible) { 620 this.mapSquaresVisible = mapSquaresVisible; 621 repaint(); 622 } 559 623 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/MapMarker.java
r14053 r16032 9 9 10 10 /** 11 * Interface to be implemented by all elements that can be displayed on the map.11 * Interface to be implemented by all one dimensional elements that can be displayed on the map. 12 12 * 13 13 * @author Jan Peter Stotz
Note:
See TracChangeset
for help on using the changeset viewer.