Changeset 29513 in osm for applications
- Timestamp:
- 2013-04-19T17:17:22+02:00 (12 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 15 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Coordinate.java
r18772 r29513 9 9 import java.io.Serializable; 10 10 11 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 12 11 13 /** 12 14 * This class encapsulates a Point2D.Double and provide access … … 16 18 * 17 19 */ 18 public class Coordinate implements Serializable {20 public class Coordinate implements Serializable, ICoordinate { 19 21 private transient Point2D.Double data; 20 22 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r29244 r29513 5 5 import java.awt.BorderLayout; 6 6 import java.awt.Cursor; 7 import java.awt.Point; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.ActionListener; … … 22 23 import org.openstreetmap.gui.jmapviewer.events.JMVCommandEvent; 23 24 import org.openstreetmap.gui.jmapviewer.interfaces.JMapViewerEventListener; 25 import org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon; 24 26 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 25 27 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; … … 40 42 private static final long serialVersionUID = 1L; 41 43 42 private JMapViewer map = null;44 private JMapViewerTree treeMap = null; 43 45 44 46 private JLabel zoomLabel=null; … … 52 54 setSize(400, 400); 53 55 54 map = new JMapViewer();56 treeMap = new JMapViewerTree("Zones"); 55 57 56 58 // Listen to the map viewer for user operations so components will 57 59 // recieve events and update 58 map .addJMVListener(this);60 map().addJMVListener(this); 59 61 60 62 // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4); … … 71 73 72 74 mperpLabelName=new JLabel("Meters/Pixels: "); 73 mperpLabelValue=new JLabel(String.format("%s",map .getMeterPerPixel()));75 mperpLabelValue=new JLabel(String.format("%s",map().getMeterPerPixel())); 74 76 75 77 zoomLabel=new JLabel("Zoom: "); 76 zoomValue=new JLabel(String.format("%s", map .getZoom()));78 zoomValue=new JLabel(String.format("%s", map().getZoom())); 77 79 78 80 add(panel, BorderLayout.NORTH); … … 88 90 89 91 public void actionPerformed(ActionEvent e) { 90 map .setDisplayToFitMapMarkers();91 } 92 }); 93 JComboBox tileSourceSelector = new JComboBox(new TileSource[] { new OsmTileSource.Mapnik(),92 map().setDisplayToFitMapMarkers(); 93 } 94 }); 95 JComboBox<TileSource> tileSourceSelector = new JComboBox(new TileSource[] { new OsmTileSource.Mapnik(), 94 96 new OsmTileSource.CycleMap(), new BingAerialTileSource(), new MapQuestOsmTileSource(), new MapQuestOpenAerialTileSource() }); 95 97 tileSourceSelector.addItemListener(new ItemListener() { 96 98 public void itemStateChanged(ItemEvent e) { 97 map .setTileSource((TileSource) e.getItem());98 } 99 }); 100 JComboBox tileLoaderSelector;99 map().setTileSource((TileSource) e.getItem()); 100 } 101 }); 102 JComboBox<TileLoader> tileLoaderSelector; 101 103 try { 102 tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmFileCacheTileLoader(map ),103 new OsmTileLoader(map ) });104 tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmFileCacheTileLoader(map()), 105 new OsmTileLoader(map()) }); 104 106 } catch (IOException e) { 105 tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmTileLoader(map ) });107 tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmTileLoader(map()) }); 106 108 } 107 109 tileLoaderSelector.addItemListener(new ItemListener() { 108 110 public void itemStateChanged(ItemEvent e) { 109 map .setTileLoader((TileLoader) e.getItem());110 } 111 }); 112 map .setTileLoader((TileLoader) tileLoaderSelector.getSelectedItem());111 map().setTileLoader((TileLoader) e.getItem()); 112 } 113 }); 114 map().setTileLoader((TileLoader) tileLoaderSelector.getSelectedItem()); 113 115 panelTop.add(tileSourceSelector); 114 116 panelTop.add(tileLoaderSelector); 115 117 final JCheckBox showMapMarker = new JCheckBox("Map markers visible"); 116 showMapMarker.setSelected(map .getMapMarkersVisible());118 showMapMarker.setSelected(map().getMapMarkersVisible()); 117 119 showMapMarker.addActionListener(new ActionListener() { 118 119 public void actionPerformed(ActionEvent e) { 120 map.setMapMarkerVisible(showMapMarker.isSelected()); 120 public void actionPerformed(ActionEvent e) { 121 map().setMapMarkerVisible(showMapMarker.isSelected()); 121 122 } 122 123 }); 123 124 panelBottom.add(showMapMarker); 125 /// 126 final JCheckBox showTreeLayers = new JCheckBox("Tree Layers visible"); 127 showTreeLayers.addActionListener(new ActionListener() { 128 public void actionPerformed(ActionEvent e) { 129 treeMap.setTreeVisible(showTreeLayers.isSelected()); 130 } 131 }); 132 panelBottom.add(showTreeLayers); 133 /// 134 final JCheckBox showToolTip = new JCheckBox("ToolTip visible"); 135 showToolTip.addActionListener(new ActionListener() { 136 public void actionPerformed(ActionEvent e) { 137 map().setToolTipText(null); 138 } 139 }); 140 panelBottom.add(showToolTip); 141 /// 124 142 final JCheckBox showTileGrid = new JCheckBox("Tile grid visible"); 125 showTileGrid.setSelected(map .isTileGridVisible());143 showTileGrid.setSelected(map().isTileGridVisible()); 126 144 showTileGrid.addActionListener(new ActionListener() { 127 128 public void actionPerformed(ActionEvent e) { 129 map.setTileGridVisible(showTileGrid.isSelected()); 145 public void actionPerformed(ActionEvent e) { 146 map().setTileGridVisible(showTileGrid.isSelected()); 130 147 } 131 148 }); 132 149 panelBottom.add(showTileGrid); 133 150 final JCheckBox showZoomControls = new JCheckBox("Show zoom controls"); 134 showZoomControls.setSelected(map .getZoomContolsVisible());151 showZoomControls.setSelected(map().getZoomContolsVisible()); 135 152 showZoomControls.addActionListener(new ActionListener() { 136 137 public void actionPerformed(ActionEvent e) { 138 map.setZoomContolsVisible(showZoomControls.isSelected()); 153 public void actionPerformed(ActionEvent e) { 154 map().setZoomContolsVisible(showZoomControls.isSelected()); 139 155 } 140 156 }); … … 143 159 scrollWrapEnabled.addActionListener(new ActionListener() { 144 160 public void actionPerformed(ActionEvent e) { 145 map .setScrollWrapEnabled(scrollWrapEnabled.isSelected());161 map().setScrollWrapEnabled(scrollWrapEnabled.isSelected()); 146 162 } 147 163 }); … … 154 170 panelTop.add(mperpLabelValue); 155 171 156 add( map, BorderLayout.CENTER);172 add(treeMap, BorderLayout.CENTER); 157 173 158 174 // 159 map.addMapMarker(new MapMarkerDot(49.814284999, 8.642065999)); 160 map.addMapMarker(new MapMarkerDot(49.91, 8.24)); 161 map.addMapMarker(new MapMarkerDot(49.71, 8.64)); 162 map.addMapMarker(new MapMarkerDot(48.71, -1)); 163 map.addMapMarker(new MapMarkerDot(49.8588, 8.643)); 175 LayerGroup germanyGroup = new LayerGroup("Germany"); 176 Layer germanyWestLayer = germanyGroup.addLayer("Germany West"); 177 Layer germanyEastLayer = germanyGroup.addLayer("Germany East"); 178 MapMarkerDot eberstadt = new MapMarkerDot(germanyEastLayer, "Eberstadt", 49.814284999, 8.642065999); 179 MapMarkerDot ebersheim = new MapMarkerDot(germanyWestLayer, "Ebersheim", 49.91, 8.24); 180 MapMarkerDot empty = new MapMarkerDot(germanyEastLayer, 49.71, 8.64); 181 MapMarkerDot darmstadt = new MapMarkerDot(germanyEastLayer, "Darmstadt", 49.8588, 8.643); 182 map().addMapMarker(eberstadt); 183 map().addMapMarker(ebersheim); 184 map().addMapMarker(empty); 185 Layer franceLayer = treeMap.addLayer("France"); 186 map().addMapMarker(new MapMarkerDot(franceLayer, "La Gallerie", 48.71, -1)); 187 map().addMapMarker(darmstadt); 188 treeMap.addLayer(germanyWestLayer); 189 treeMap.addLayer(germanyEastLayer); 190 191 MapPolygon bermudas = new MapPolygonImpl(c(49,1), c(45,10), c(40,5)); 192 map().addMapPolygon( bermudas ); 193 map().addMapPolygon( new MapPolygonImpl(germanyEastLayer, "Riedstadt", ebersheim, darmstadt, eberstadt, empty)); 194 195 map().addMapMarker(new MapMarkerCircle(germanyWestLayer, "North of Suisse", new Coordinate(48, 7), .5)); 196 Layer spain = treeMap.addLayer("Spain"); 197 map().addMapMarker(new MapMarkerCircle(spain, "La Garena", new Coordinate(40.4838, -3.39), .002)); 198 spain.setVisible(false); 199 200 Layer wales = treeMap.addLayer("UK"); 201 map().addMapRectangle(new MapRectangleImpl(wales, "Wales", c(53.35,-4.57), c(51.64,-2.63))); 164 202 165 203 // map.setDisplayPositionByLatLon(49.807, 8.6, 11); 166 204 // map.setTileGridVisible(true); 167 205 168 map .addMouseListener(new MouseAdapter() {206 map().addMouseListener(new MouseAdapter() { 169 207 @Override 170 208 public void mouseClicked(MouseEvent e) { 171 209 if (e.getButton() == MouseEvent.BUTTON1) { 172 map .getAttribution().handleAttribution(e.getPoint(), true);210 map().getAttribution().handleAttribution(e.getPoint(), true); 173 211 } 174 212 } 175 213 }); 176 214 177 map .addMouseMotionListener(new MouseAdapter() {215 map().addMouseMotionListener(new MouseAdapter() { 178 216 @Override 179 217 public void mouseMoved(MouseEvent e) { 180 boolean cursorHand = map.getAttribution().handleAttributionCursor(e.getPoint()); 218 Point p = e.getPoint(); 219 boolean cursorHand = map().getAttribution().handleAttributionCursor(p); 181 220 if (cursorHand) { 182 map .setCursor(new Cursor(Cursor.HAND_CURSOR));221 map().setCursor(new Cursor(Cursor.HAND_CURSOR)); 183 222 } else { 184 map .setCursor(new Cursor(Cursor.DEFAULT_CURSOR));223 map().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 185 224 } 186 } 187 }); 225 if(showToolTip.isSelected()) map().setToolTipText(map().getPosition(p).toString()); 226 } 227 }); 228 } 229 private JMapViewer map(){ 230 return treeMap.getViewer(); 231 } 232 private static Coordinate c(double lat, double lon){ 233 return new Coordinate(lat, lon); 188 234 } 189 235 … … 200 246 private void updateZoomParameters() { 201 247 if (mperpLabelValue!=null) 202 mperpLabelValue.setText(String.format("%s",map .getMeterPerPixel()));248 mperpLabelValue.setText(String.format("%s",map().getMeterPerPixel())); 203 249 if (zoomValue!=null) 204 zoomValue.setText(String.format("%s", map .getZoom()));250 zoomValue.setText(String.format("%s", map().getZoom())); 205 251 } 206 252 -
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) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MapMarkerDot.java
r18772 r29513 4 4 5 5 import java.awt.Color; 6 import java.awt.Graphics;7 import java.awt.Point;8 6 9 7 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; … … 17 15 * 18 16 */ 19 public class MapMarkerDot implements MapMarker{17 public class MapMarkerDot extends MapMarkerCircle { 20 18 21 double lat; 22 double lon; 23 Color color; 19 public static final int DOT_RADIUS = 5; 24 20 25 public MapMarkerDot( double lat, double lon) {26 this( Color.YELLOW, lat, lon);21 public MapMarkerDot(String name, Coordinate coord) { 22 this(null, name, coord); 27 23 } 28 29 public MapMarkerDot(Color color, double lat, double lon) { 30 super(); 31 this.color = color; 32 this.lat = lat; 33 this.lon = lon; 24 public MapMarkerDot(Layer layer, Coordinate coord) { 25 this(layer, null, coord); 34 26 } 35 36 public double getLat() { 37 return lat; 27 public MapMarkerDot(Layer layer, String name, Coordinate coord) { 28 this(layer, name, coord, getDefaultStyle()); 38 29 } 39 40 public double getLon() { 41 return lon; 30 public MapMarkerDot(Layer layer, double lat, double lon) { 31 this(layer, null, lat, lon); 42 32 } 43 44 public void paint(Graphics g, Point position) { 45 int size_h = 5; 46 int size = size_h * 2; 47 g.setColor(color); 48 g.fillOval(position.x - size_h, position.y - size_h, size, size); 49 g.setColor(Color.BLACK); 50 g.drawOval(position.x - size_h, position.y - size_h, size, size); 33 public MapMarkerDot(Layer layer, String name, double lat, double lon) { 34 this(layer, name, new Coordinate(lat, lon), getDefaultStyle()); 51 35 } 52 53 @Override 54 public String toString() { 55 return "MapMarker at " + lat + " " + lon; 36 public MapMarkerDot(Layer layer, String name, Coordinate coord, Style style) { 37 super(layer, name, coord, DOT_RADIUS, STYLE.FIXED, style); 56 38 } 57 39 40 public static Style getDefaultStyle(){ 41 return new Style(Color.BLACK, Color.YELLOW, null, getDefaultFont()); 42 } 58 43 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MapPolygonImpl.java
r26652 r29513 2 2 package org.openstreetmap.gui.jmapviewer; 3 3 4 import java.awt.AlphaComposite; 4 5 import java.awt.BasicStroke; 5 6 import java.awt.Color; 7 import java.awt.Composite; 6 8 import java.awt.Graphics; 7 9 import java.awt.Graphics2D; 8 10 import java.awt.Point; 9 11 import java.awt.Polygon; 12 import java.awt.Rectangle; 10 13 import java.awt.Stroke; 14 import java.util.Arrays; 11 15 import java.util.List; 12 16 17 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 13 18 import org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon; 14 19 … … 17 22 * 18 23 */ 19 public class MapPolygonImpl implements MapPolygon {24 public class MapPolygonImpl extends MapObjectImpl implements MapPolygon { 20 25 21 private List<Coordinate> points; 22 private Color color; 23 private Stroke stroke; 26 private List<ICoordinate> points; 24 27 25 public MapPolygonImpl( List<Coordinate>points) {26 this( points, Color.BLUE, new BasicStroke(2));28 public MapPolygonImpl(ICoordinate ... points) { 29 this(null, null, points); 27 30 } 28 29 public MapPolygonImpl(List<Coordinate> points, Color color, Stroke stroke) { 31 public MapPolygonImpl(String name, List<ICoordinate> points) { 32 this(null, name, points); 33 } 34 public MapPolygonImpl(String name, ICoordinate ... points) { 35 this(null, name, points); 36 } 37 public MapPolygonImpl(Layer layer, List<ICoordinate> points) { 38 this(layer, null, points); 39 } 40 public MapPolygonImpl(Layer layer, String name, List<ICoordinate> points) { 41 this(layer, name, points, getDefaultStyle()); 42 } 43 public MapPolygonImpl(Layer layer, String name, ICoordinate ... points) { 44 this(layer, name, Arrays.asList(points), getDefaultStyle()); 45 } 46 public MapPolygonImpl(Layer layer, String name, List<ICoordinate> points, Style style) { 47 super(layer, name, style); 30 48 this.points = points; 31 this.color = color;32 this.stroke = stroke;33 49 } 34 50 … … 37 53 */ 38 54 @Override 39 public List< Coordinate> getPoints() {55 public List<ICoordinate> getPoints() { 40 56 return this.points; 41 57 } … … 60 76 // Prepare graphics 61 77 Color oldColor = g.getColor(); 62 g.setColor(color); 78 g.setColor(getColor()); 79 63 80 Stroke oldStroke = null; 64 81 if (g instanceof Graphics2D) { 65 82 Graphics2D g2 = (Graphics2D) g; 66 83 oldStroke = g2.getStroke(); 67 g2.setStroke( stroke);84 g2.setStroke(getStroke()); 68 85 } 69 86 // Draw 70 87 g.drawPolygon(polygon); 88 if (g instanceof Graphics2D && getBackColor()!=null) { 89 Graphics2D g2 = (Graphics2D) g; 90 Composite oldComposite = g2.getComposite(); 91 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); 92 g2.setPaint(getBackColor()); 93 g2.fillPolygon(polygon); 94 g2.setComposite(oldComposite); 95 } 71 96 // Restore graphics 72 97 g.setColor(oldColor); … … 74 99 ((Graphics2D) g).setStroke(oldStroke); 75 100 } 101 Rectangle rec = polygon.getBounds(); 102 Point corner = rec.getLocation(); 103 Point p= new Point(corner.x+(rec.width/2), corner.y+(rec.height/2)); 104 if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p); 76 105 } 77 106 107 public static Style getDefaultStyle(){ 108 return new Style(Color.BLUE, new Color(100,100,100,50), new BasicStroke(2), getDefaultFont()); 109 } 78 110 /* (non-Javadoc) 79 111 * @see java.lang.Object#toString() -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java
r26668 r29513 7 7 import java.awt.Graphics2D; 8 8 import java.awt.Point; 9 import java.awt.Rectangle; 9 10 import java.awt.Stroke; 10 11 … … 15 16 * 16 17 */ 17 public class MapRectangleImpl implements MapRectangle {18 public class MapRectangleImpl extends MapObjectImpl implements MapRectangle { 18 19 19 20 private Coordinate topLeft; 20 21 private Coordinate bottomRight; 21 private Color color;22 private Stroke stroke;23 22 24 public MapRectangleImpl( Coordinate topLeft, Coordinate bottomRight) {25 this( topLeft, bottomRight, Color.BLUE, new BasicStroke(2));23 public MapRectangleImpl(String name, Coordinate topLeft, Coordinate bottomRight) { 24 this(null, name, topLeft, bottomRight); 26 25 } 27 28 public MapRectangleImpl(Coordinate topLeft, Coordinate bottomRight, Color color, Stroke stroke) { 26 public MapRectangleImpl(Layer layer, Coordinate topLeft, Coordinate bottomRight) { 27 this(layer, null, topLeft, bottomRight); 28 } 29 public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight) { 30 this(layer, name, topLeft, bottomRight, getDefaultStyle()); 31 } 32 public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight, Style style) { 33 super(layer, name, style); 29 34 this.topLeft = topLeft; 30 35 this.bottomRight = bottomRight; 31 this.color = color;32 this.stroke = stroke;33 36 } 34 37 … … 56 59 // Prepare graphics 57 60 Color oldColor = g.getColor(); 58 g.setColor( color);61 g.setColor(getColor()); 59 62 Stroke oldStroke = null; 60 63 if (g instanceof Graphics2D) { 61 64 Graphics2D g2 = (Graphics2D) g; 62 65 oldStroke = g2.getStroke(); 63 g2.setStroke( stroke);66 g2.setStroke(getStroke()); 64 67 } 65 68 // Draw … … 70 73 ((Graphics2D) g).setStroke(oldStroke); 71 74 } 75 int width=bottomRight.x-topLeft.x; 76 int height=bottomRight.y-topLeft.y; 77 Point p= new Point(topLeft.x+(width/2), topLeft.y+(height/2)); 78 if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p); 72 79 } 73 80 public static Style getDefaultStyle(){ 81 return new Style(Color.BLUE, null, new BasicStroke(2), getDefaultFont()); 82 } 74 83 @Override 75 84 public String toString() { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/MapMarker.java
r18772 r29513 6 6 import java.awt.Point; 7 7 8 import org.openstreetmap.gui.jmapviewer.Coordinate; 8 9 import org.openstreetmap.gui.jmapviewer.JMapViewer; 9 10 … … 15 16 * @see JMapViewer#getMapMarkerList() 16 17 */ 17 public interface MapMarker {18 public interface MapMarker extends MapObject, ICoordinate{ 18 19 20 public static enum STYLE {FIXED, VARIABLE}; 21 22 /** 23 * @return Latitude and Longitude of the map marker position 24 */ 25 public Coordinate getCoordinate(); 19 26 /** 20 27 * @return Latitude of the map marker position … … 26 33 */ 27 34 public double getLon(); 35 36 /** 37 * @return Radius of the map marker position 38 */ 39 public double getRadius(); 40 41 /** 42 * @return Style of the map marker 43 */ 44 public STYLE getMarkerStyle(); 28 45 29 46 /** … … 33 50 * @param g 34 51 * @param position 52 * @param radio 35 53 */ 36 public void paint(Graphics g, Point position );54 public void paint(Graphics g, Point position, int radio); 37 55 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/MapPolygon.java
r26652 r29513 14 14 * @author Vincent 15 15 */ 16 public interface MapPolygon {16 public interface MapPolygon extends MapObject{ 17 17 18 18 /** 19 19 * @return Latitude/Longitude of each point of polygon 20 20 */ 21 public List< Coordinate> getPoints();21 public List<ICoordinate> getPoints(); 22 22 23 23 /** -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/MapRectangle.java
r28505 r29513 16 16 * @see JMapViewer#getMapRectangleList() 17 17 */ 18 public interface MapRectangle {18 public interface MapRectangle extends MapObject{ 19 19 20 20 /**
Note:
See TracChangeset
for help on using the changeset viewer.