Changeset 29513 in osm for applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
- Timestamp:
- 2013-04-19T17:17:22+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r29466 r29513 24 24 import org.openstreetmap.gui.jmapviewer.events.JMVCommandEvent; 25 25 import org.openstreetmap.gui.jmapviewer.events.JMVCommandEvent.COMMAND; 26 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 26 27 import org.openstreetmap.gui.jmapviewer.interfaces.JMapViewerEventListener; 27 28 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; … … 269 270 if (markers) { 270 271 for (MapMarker marker : mapMarkerList) { 271 int x = OsmMercator.LonToX(marker.getLon(), mapZoomMax); 272 int y = OsmMercator.LatToY(marker.getLat(), mapZoomMax); 273 x_max = Math.max(x_max, x); 274 y_max = Math.max(y_max, y); 275 x_min = Math.min(x_min, x); 276 y_min = Math.min(y_min, y); 277 } 278 } 279 280 if (rectangles) { 281 for (MapRectangle rectangle : mapRectangleList) { 282 x_max = Math.max(x_max, OsmMercator.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax)); 283 y_max = Math.max(y_max, OsmMercator.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax)); 284 x_min = Math.min(x_min, OsmMercator.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax)); 285 y_min = Math.min(y_min, OsmMercator.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax)); 286 } 287 } 288 289 if (polygons) { 290 for (MapPolygon polygon : mapPolygonList) { 291 for (Coordinate c : polygon.getPoints()) { 292 int x = OsmMercator.LonToX(c.getLon(), mapZoomMax); 293 int y = OsmMercator.LatToY(c.getLat(), mapZoomMax); 272 if(marker.isVisible()){ 273 int x = OsmMercator.LonToX(marker.getLon(), mapZoomMax); 274 int y = OsmMercator.LatToY(marker.getLat(), mapZoomMax); 294 275 x_max = Math.max(x_max, x); 295 276 y_max = Math.max(y_max, y); 296 277 x_min = Math.min(x_min, x); 297 278 y_min = Math.min(y_min, y); 279 } 280 } 281 } 282 283 if (rectangles) { 284 for (MapRectangle rectangle : mapRectangleList) { 285 if(rectangle.isVisible()){ 286 x_max = Math.max(x_max, OsmMercator.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax)); 287 y_max = Math.max(y_max, OsmMercator.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax)); 288 x_min = Math.min(x_min, OsmMercator.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax)); 289 y_min = Math.min(y_min, OsmMercator.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax)); 290 } 291 } 292 } 293 294 if (polygons) { 295 for (MapPolygon polygon : mapPolygonList) { 296 if(polygon.isVisible()){ 297 for (ICoordinate c : polygon.getPoints()) { 298 int x = OsmMercator.LonToX(c.getLon(), mapZoomMax); 299 int y = OsmMercator.LatToY(c.getLat(), mapZoomMax); 300 x_max = Math.max(x_max, x); 301 y_max = Math.max(y_max, y); 302 x_min = Math.min(x_min, x); 303 y_min = Math.min(y_min, y); 304 } 298 305 } 299 306 } … … 418 425 return new Point(x, y); 419 426 } 427 428 /** 429 * Calculates the position on the map of a given coordinate 430 * 431 * @param lat Latitude 432 * @param offset Offset respect Latitude 433 * @param checkOutside 434 * @return Integer the radius in pixels 435 */ 436 public Integer getLatOffset(double lat, double offset, boolean checkOutside) { 437 int y = OsmMercator.LatToY(lat+offset, zoom); 438 y -= center.y - getHeight() / 2; 439 if (checkOutside) { 440 if (y < 0 || y > getHeight()) 441 return null; 442 } 443 return y; 444 } 420 445 421 446 /** … … 428 453 public Point getMapPosition(double lat, double lon) { 429 454 return getMapPosition(lat, lon, true); 455 } 456 457 /** 458 * Calculates the position on the map of a given coordinate 459 * 460 * @param marker MapMarker object that define the x,y coordinate 461 * @return Integer the radius in pixels 462 */ 463 public Integer getRadius(MapMarker marker, Point p) { 464 if(marker.getMarkerStyle() == MapMarker.STYLE.FIXED) 465 return (int)marker.getRadius(); 466 else if(p!=null){ 467 Integer radius = getLatOffset(marker.getLat(), marker.getRadius(), false); 468 radius = radius==null?null:p.y-radius.intValue(); 469 return radius; 470 }else return null; 430 471 } 431 472 … … 450 491 * and checkOutside set to <code>true</code> 451 492 */ 452 public Point getMapPosition(Coordinate coord, boolean checkOutside) { 493 public Point getMapPosition(ICoordinate coord, boolean checkOutside) { 453 494 if (coord != null) 454 495 return getMapPosition(coord.getLat(), coord.getLon(), checkOutside); … … 579 620 if (mapPolygonsVisible && mapPolygonList != null) { 580 621 for (MapPolygon polygon : mapPolygonList) { 581 paintPolygon(g, polygon); 622 if(polygon.isVisible()) paintPolygon(g, polygon); 582 623 } 583 624 } … … 585 626 if (mapRectanglesVisible && mapRectangleList != null) { 586 627 for (MapRectangle rectangle : mapRectangleList) { 587 paintRectangle(g, rectangle); 628 if(rectangle.isVisible()) paintRectangle(g, rectangle); 588 629 } 589 630 } … … 591 632 if (mapMarkersVisible && mapMarkerList != null) { 592 633 for (MapMarker marker : mapMarkerList) { 593 paintMarker(g, marker); 634 if(marker.isVisible())paintMarker(g, marker); 594 635 } 595 636 } … … 602 643 */ 603 644 protected void paintMarker(Graphics g, MapMarker marker) { 604 Point p = getMapPosition(marker.getLat(), marker.getLon()); 645 Point p = getMapPosition(marker.getLat(), marker.getLon(), marker.getMarkerStyle()==MapMarker.STYLE.FIXED); 646 Integer radius = getRadius(marker, p); 605 647 if (scrollWrapEnabled) { 606 648 int tilesize = tileSource.getTileSize(); … … 608 650 if (p == null) { 609 651 p = getMapPosition(marker.getLat(), marker.getLon(), false); 610 } 611 marker.paint(g, p); 652 radius = getRadius(marker, p); 653 } 654 marker.paint(g, p, radius); 612 655 int xSave = p.x; 613 656 int xWrap = xSave; … … 615 658 while ((xWrap -= mapSize) >= -15) { 616 659 p.x = xWrap; 617 marker.paint(g, p); 660 marker.paint(g, p, radius); 618 661 } 619 662 xWrap = xSave; 620 663 while ((xWrap += mapSize) <= getWidth() + 15) { 621 664 p.x = xWrap; 622 marker.paint(g, p); 665 marker.paint(g, p, radius); 623 666 } 624 667 } else { 625 668 if (p != null) { 626 marker.paint(g, p); 669 marker.paint(g, p, radius); 627 670 } 628 671 } … … 671 714 */ 672 715 protected void paintPolygon(Graphics g, MapPolygon polygon) { 673 List<Coordinate> coords = polygon.getPoints(); 716 List<ICoordinate> coords = polygon.getPoints(); 674 717 if (coords != null && coords.size() >= 3) { 675 718 List<Point> points = new LinkedList<Point>(); 676 for (Coordinate c : coords) { 719 for (ICoordinate c : coords) { 677 720 Point p = getMapPosition(c, false); 678 721 if (p == null) {
Note:
See TracChangeset
for help on using the changeset viewer.