Changeset 30769 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2014-10-28T07:14:02+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r30759 r30769 10 10 import java.awt.event.ActionListener; 11 11 import java.awt.event.MouseEvent; 12 import java.util.Collections; 12 13 import java.util.LinkedList; 13 14 import java.util.List; … … 85 86 VERTICAL 86 87 } 88 87 89 protected ZOOM_BUTTON_STYLE zoomButtonStyle; 88 90 … … 109 111 tileSource = new OsmTileSource.Mapnik(); 110 112 tileController = new TileController(tileSource, tileCache, this); 111 mapMarkerList = new LinkedList<>();112 mapPolygonList = new LinkedList<>();113 mapRectangleList = new LinkedList<>();113 mapMarkerList = Collections.synchronizedList(new LinkedList<MapMarker>()); 114 mapPolygonList = Collections.synchronizedList(new LinkedList<MapPolygon>()); 115 mapRectangleList = Collections.synchronizedList(new LinkedList<MapRectangle>()); 114 116 mapMarkersVisible = true; 115 117 mapRectanglesVisible = true; … … 264 266 265 267 if (markers) { 266 for (MapMarker marker : mapMarkerList) { 267 if(marker.isVisible()){ 268 int x = tileSource.LonToX(marker.getLon(), mapZoomMax); 269 int y = tileSource.LatToY(marker.getLat(), mapZoomMax); 270 x_max = Math.max(x_max, x); 271 y_max = Math.max(y_max, y); 272 x_min = Math.min(x_min, x); 273 y_min = Math.min(y_min, y); 274 } 275 } 276 } 277 278 if (rectangles) { 279 for (MapRectangle rectangle : mapRectangleList) { 280 if(rectangle.isVisible()){ 281 x_max = Math.max(x_max, tileSource.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax)); 282 y_max = Math.max(y_max, tileSource.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax)); 283 x_min = Math.min(x_min, tileSource.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax)); 284 y_min = Math.min(y_min, tileSource.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax)); 285 } 286 } 287 } 288 289 if (polygons) { 290 for (MapPolygon polygon : mapPolygonList) { 291 if(polygon.isVisible()){ 292 for (ICoordinate c : polygon.getPoints()) { 293 int x = tileSource.LonToX(c.getLon(), mapZoomMax); 294 int y = tileSource.LatToY(c.getLat(), mapZoomMax); 268 synchronized (mapMarkerList) { 269 for (MapMarker marker : mapMarkerList) { 270 if (marker.isVisible()) { 271 int x = tileSource.LonToX(marker.getLon(), mapZoomMax); 272 int y = tileSource.LatToY(marker.getLat(), mapZoomMax); 295 273 x_max = Math.max(x_max, x); 296 274 y_max = Math.max(y_max, y); 297 275 x_min = Math.min(x_min, x); 298 276 y_min = Math.min(y_min, y); 277 } 278 } 279 } 280 } 281 282 if (rectangles) { 283 synchronized (mapRectangleList) { 284 for (MapRectangle rectangle : mapRectangleList) { 285 if (rectangle.isVisible()) { 286 x_max = Math.max(x_max, tileSource.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax)); 287 y_max = Math.max(y_max, tileSource.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax)); 288 x_min = Math.min(x_min, tileSource.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax)); 289 y_min = Math.min(y_min, tileSource.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax)); 290 } 291 } 292 } 293 } 294 295 if (polygons) { 296 synchronized (mapPolygonList) { 297 for (MapPolygon polygon : mapPolygonList) { 298 if (polygon.isVisible()) { 299 for (ICoordinate c : polygon.getPoints()) { 300 int x = tileSource.LonToX(c.getLon(), mapZoomMax); 301 int y = tileSource.LatToY(c.getLat(), mapZoomMax); 302 x_max = Math.max(x_max, x); 303 y_max = Math.max(y_max, y); 304 x_min = Math.min(x_min, x); 305 y_min = Math.min(y_min, y); 306 } 299 307 } 300 308 } … … 320 328 } 321 329 322 323 330 /** 324 331 * Sets the displayed map pane and zoom level so that all map markers are … … 430 437 */ 431 438 public Integer getLatOffset(double lat, double offset, boolean checkOutside) { 432 int y = tileSource.LatToY(lat +offset, zoom);439 int y = tileSource.LatToY(lat + offset, zoom); 433 440 y -= center.y - getHeight() / 2; 434 441 if (checkOutside) { … … 457 464 */ 458 465 public Integer getRadius(MapMarker marker, Point p) { 459 if (marker.getMarkerStyle() == MapMarker.STYLE.FIXED)460 return (int) marker.getRadius();461 else if (p!=null){466 if (marker.getMarkerStyle() == MapMarker.STYLE.FIXED) 467 return (int) marker.getRadius(); 468 else if (p != null) { 462 469 Integer radius = getLatOffset(marker.getLat(), marker.getRadius(), false); 463 radius = radius ==null?null:p.y-radius.intValue();470 radius = radius == null ? null : p.y - radius.intValue(); 464 471 return radius; 465 }else return null; 472 } else 473 return null; 466 474 } 467 475 … … 500 508 */ 501 509 public double getMeterPerPixel() { 502 Point origin =new Point(5,5);503 Point center =new Point(getWidth()/2, getHeight()/2);504 505 double pDistance =center.distance(origin);506 507 Coordinate originCoord =getPosition(origin);508 Coordinate centerCoord =getPosition(center);510 Point origin = new Point(5, 5); 511 Point center = new Point(getWidth() / 2, getHeight() / 2); 512 513 double pDistance = center.distance(origin); 514 515 Coordinate originCoord = getPosition(origin); 516 Coordinate centerCoord = getPosition(center); 509 517 510 518 double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(), 511 519 centerCoord.getLat(), centerCoord.getLon()); 512 520 513 return mDistance /pDistance;521 return mDistance / pDistance; 514 522 } 515 523 … … 614 622 615 623 if (mapPolygonsVisible && mapPolygonList != null) { 616 for (MapPolygon polygon : mapPolygonList) { 617 if(polygon.isVisible()) paintPolygon(g, polygon); 624 synchronized (mapPolygonList) { 625 for (MapPolygon polygon : mapPolygonList) { 626 if (polygon.isVisible()) 627 paintPolygon(g, polygon); 628 } 618 629 } 619 630 } 620 631 621 632 if (mapRectanglesVisible && mapRectangleList != null) { 622 for (MapRectangle rectangle : mapRectangleList) { 623 if(rectangle.isVisible()) paintRectangle(g, rectangle); 633 synchronized (mapRectangleList) { 634 for (MapRectangle rectangle : mapRectangleList) { 635 if (rectangle.isVisible()) 636 paintRectangle(g, rectangle); 637 } 624 638 } 625 639 } 626 640 627 641 if (mapMarkersVisible && mapMarkerList != null) { 628 for (MapMarker marker : mapMarkerList) { 629 if(marker.isVisible())paintMarker(g, marker); 642 synchronized (mapMarkerList) { 643 for (MapMarker marker : mapMarkerList) { 644 if (marker.isVisible()) 645 paintMarker(g, marker); 646 } 630 647 } 631 648 } … … 638 655 */ 639 656 protected void paintMarker(Graphics g, MapMarker marker) { 640 Point p = getMapPosition(marker.getLat(), marker.getLon(), marker.getMarkerStyle() ==MapMarker.STYLE.FIXED);657 Point p = getMapPosition(marker.getLat(), marker.getLon(), marker.getMarkerStyle() == MapMarker.STYLE.FIXED); 641 658 Integer radius = getRadius(marker, p); 642 659 if (scrollWrapEnabled) { … … 1026 1043 } 1027 1044 switch (style) { 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1045 case HORIZONTAL: 1046 zoomSlider.setBounds(10, 10, 30, 150); 1047 zoomInButton.setBounds(4, 155, 18, 18); 1048 zoomOutButton.setBounds(26, 155, 18, 18); 1049 break; 1050 case VERTICAL: 1051 zoomSlider.setBounds(10, 27, 30, 150); 1052 zoomInButton.setBounds(14, 8, 20, 20); 1053 zoomOutButton.setBounds(14, 176, 20, 20); 1054 break; 1055 default: 1056 zoomSlider.setBounds(10, 10, 30, 150); 1057 zoomInButton.setBounds(4, 155, 18, 18); 1058 zoomOutButton.setBounds(26, 155, 18, 18); 1059 break; 1043 1060 } 1044 1061 repaint(); … … 1088 1105 void fireJMVEvent(JMVCommandEvent evt) { 1089 1106 Object[] listeners = evtListenerList.getListenerList(); 1090 for (int i =0; i<listeners.length; i+=2) {1091 if (listeners[i] ==JMapViewerEventListener.class) {1092 ((JMapViewerEventListener) listeners[i+1]).processCommand(evt);1107 for (int i = 0; i < listeners.length; i += 2) { 1108 if (listeners[i] == JMapViewerEventListener.class) { 1109 ((JMapViewerEventListener) listeners[i + 1]).processCommand(evt); 1093 1110 } 1094 1111 }
Note:
See TracChangeset
for help on using the changeset viewer.