Changeset 30875 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2014-12-25T17:17:59+01:00 (10 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r30426 r30875 58 58 59 59 // Listen to the map viewer for user operations so components will 60 // rec ieve events and update60 // receive events and update 61 61 map().addJMVListener(this); 62 63 // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4);64 // map.setTileLoader(new OsmFileCacheTileLoader(map));65 // new DefaultMapController(map);66 62 67 63 setLayout(new BorderLayout()); … … 94 90 } 95 91 }); 96 JComboBox<TileSource> tileSourceSelector = new JComboBox<>(new TileSource[] { new OsmTileSource.Mapnik(), 97 new OsmTileSource.CycleMap(), new BingAerialTileSource(), new MapQuestOsmTileSource(), new MapQuestOpenAerialTileSource() }); 92 JComboBox<TileSource> tileSourceSelector = new JComboBox<>(new TileSource[] { 93 new OsmTileSource.Mapnik(), 94 new OsmTileSource.CycleMap(), 95 new BingAerialTileSource(), 96 new MapQuestOsmTileSource(), 97 new MapQuestOpenAerialTileSource() }); 98 98 tileSourceSelector.addItemListener(new ItemListener() { 99 99 public void itemStateChanged(ItemEvent e) { … … 149 149 panelBottom.add(showTileGrid); 150 150 final JCheckBox showZoomControls = new JCheckBox("Show zoom controls"); 151 showZoomControls.setSelected(map().getZoomCont olsVisible());151 showZoomControls.setSelected(map().getZoomControlsVisible()); 152 152 showZoomControls.addActionListener(new ActionListener() { 153 153 public void actionPerformed(ActionEvent e) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r30769 r30875 96 96 * Creates a standard {@link JMapViewer} instance that can be controlled via 97 97 * mouse: hold right mouse button for moving, double click left mouse button 98 * or use mouse wheel for zooming. Loaded tiles are stored the98 * or use mouse wheel for zooming. Loaded tiles are stored in a 99 99 * {@link MemoryTileCache} and the tile loader uses 4 parallel threads for 100 100 * retrieving the tiles. 101 101 */ 102 @SuppressWarnings("unused")103 102 public JMapViewer() { 104 103 this(new MemoryTileCache(), 8); … … 106 105 } 107 106 107 /** 108 * Creates a new {@link JMapViewer} instance. 109 * @param tileCache The cache where to store tiles 110 * @param downloadThreadCount The number of parallel threads for retrieving the tiles 111 */ 108 112 public JMapViewer(TileCache tileCache, int downloadThreadCount) { 109 super();110 113 JobDispatcher.setMaxWorkers(downloadThreadCount); 111 114 tileSource = new OsmTileSource.Mapnik(); … … 123 126 setPreferredSize(new Dimension(400, 400)); 124 127 setDisplayPosition(new Coordinate(50, 9), 3); 125 //setToolTipText("");126 128 } 127 129 128 130 @Override 129 131 public String getToolTipText(MouseEvent event) { 130 // Point screenPoint = event.getLocationOnScreen();131 // Coordinate c = getPosition(screenPoint);132 132 return super.getToolTipText(event); 133 133 } … … 245 245 246 246 /** 247 * Sets the displayed map pane and zoom level so that all chosen map elements are 248 * visible. 247 * Sets the displayed map pane and zoom level so that all chosen map elements are visible. 249 248 */ 250 249 public void setDisplayToFitMapElements(boolean markers, boolean rectangles, boolean polygons) { … … 329 328 330 329 /** 331 * Sets the displayed map pane and zoom level so that all map markers are 332 * visible. 330 * Sets the displayed map pane and zoom level so that all map markers are visible. 333 331 */ 334 332 public void setDisplayToFitMapMarkers() { … … 337 335 338 336 /** 339 * Sets the displayed map pane and zoom level so that all map rectangles are 340 * visible. 337 * Sets the displayed map pane and zoom level so that all map rectangles are visible. 341 338 */ 342 339 public void setDisplayToFitMapRectangles() { … … 345 342 346 343 /** 347 * Sets the displayed map pane and zoom level so that all map polygons are 348 * visible. 344 * Sets the displayed map pane and zoom level so that all map polygons are visible. 349 345 */ 350 346 public void setDisplayToFitMapPolygons() { … … 798 794 /** 799 795 * Increases the current zoom level by one 796 * @param mapPoint point to choose as center for new zoom level 800 797 */ 801 798 public void zoomIn(Point mapPoint) { … … 965 962 } 966 963 967 public boolean getZoomCont olsVisible() {964 public boolean getZoomControlsVisible() { 968 965 return zoomSlider.isVisible(); 969 966 } … … 973 970 throw new RuntimeException("Maximum zoom level too high"); 974 971 if (tileSource.getMinZoom() < MIN_ZOOM) 975 throw new RuntimeException("Min umim zoom level too low");972 throw new RuntimeException("Minimum zoom level too low"); 976 973 Coordinate position = getPosition(); 977 974 this.tileSource = tileSource; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java
r30426 r30875 32 32 protected final CacheLinkedListElement lruTiles; 33 33 34 /** 35 * Constructs a new {@code MemoryTileCache}. 36 */ 34 37 public MemoryTileCache() { 35 38 hash = new HashMap<>(cacheSize); … … 81 84 } 82 85 83 /** 84 * Clears the cache deleting all tiles from memory 85 */ 86 @Override 86 87 public synchronized void clear() { 87 88 hash.clear(); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
r30426 r30875 71 71 if (input == null) { 72 72 try { 73 System.err.println("Failed loading " + tile.getUrl() +": " + e.getMessage()); 74 } catch(IOException i) { 73 System.err.println("Failed loading " + tile.getUrl() +": " 74 +e.getClass() + ": " + e.getMessage()); 75 } catch (IOException ioe) { 76 ioe.printStackTrace(); 75 77 } 76 78 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r30426 r30875 25 25 26 26 /** 27 * Hourglass image that is displayed until a map tile has been loaded 27 * Hourglass image that is displayed until a map tile has been loaded, except for overlay sources 28 28 */ 29 29 public static BufferedImage LOADING_IMAGE; 30 31 /** 32 * Red cross image that is displayed after a loading error, except for overlay sources 33 */ 30 34 public static BufferedImage ERROR_IMAGE; 31 35 … … 34 38 LOADING_IMAGE = ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png")); 35 39 ERROR_IMAGE = ImageIO.read(JMapViewer.class.getResourceAsStream("images/error.png")); 36 } catch (Exception e1) { 37 LOADING_IMAGE = null; 38 ERROR_IMAGE = null; 40 } catch (Exception ex) { 41 ex.printStackTrace(); 39 42 } 40 43 } … … 57 60 * Creates a tile with empty image. 58 61 * 59 * @param source 60 * @param xtile 61 * @param ytile 62 * @param zoom 62 * @param source Tile source 63 * @param xtile X coordinate 64 * @param ytile Y coordinate 65 * @param zoom Zoom level 63 66 */ 64 67 public Tile(TileSource source, int xtile, int ytile, int zoom) { 65 super(); 68 this(source, xtile, ytile, zoom, LOADING_IMAGE); 69 } 70 71 /** 72 * Creates a tile with specified image. 73 * 74 * @param source Tile source 75 * @param xtile X coordinate 76 * @param ytile Y coordinate 77 * @param zoom Zoom level 78 * @param image Image content 79 */ 80 public Tile(TileSource source, int xtile, int ytile, int zoom, BufferedImage image) { 66 81 this.source = source; 67 82 this.xtile = xtile; 68 83 this.ytile = ytile; 69 84 this.zoom = zoom; 70 this.image = LOADING_IMAGE;85 this.image = image; 71 86 this.key = getTileKey(source, xtile, ytile, zoom); 72 }73 74 public Tile(TileSource source, int xtile, int ytile, int zoom, BufferedImage image) {75 this(source, xtile, ytile, zoom);76 this.image = image;77 87 } 78 88 … … 138 148 139 149 /** 150 * Returns the X coordinate. 140 151 * @return tile number on the x axis of this tile 141 152 */ … … 145 156 146 157 /** 158 * Returns the Y coordinate. 147 159 * @return tile number on the y axis of this tile 148 160 */ … … 152 164 153 165 /** 166 * Returns the zoom level. 154 167 * @return zoom level of this tile 155 168 */ … … 197 210 * position <code>x</code>/<code>y</code>. 198 211 * 199 * @param g 200 * @param x 201 * x-coordinate in <code>g</code> 202 * @param y 203 * y-coordinate in <code>g</code> 212 * @param g the Graphics object 213 * @param x x-coordinate in <code>g</code> 214 * @param y y-coordinate in <code>g</code> 204 215 */ 205 216 public void paint(Graphics g, int x, int y) { … … 286 297 * the meta data. 287 298 * 288 * @param key 289 * @param value 299 * @param key Key 300 * @param value Value 290 301 */ 291 302 public void putValue(String key, String value) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/TileController.java
r30223 r30875 7 7 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 8 8 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 9 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource;10 9 11 10 public class TileController { … … 17 16 18 17 public TileController(TileSource source, TileCache tileCache, TileLoaderListener listener) { 19 t ileSource = new OsmTileSource.Mapnik();20 t ileLoader = new OsmTileLoader(listener);18 this.tileSource = source; 19 this.tileLoader = new OsmTileLoader(listener); 21 20 this.tileCache = tileCache; 22 jobDispatcher = JobDispatcher.getInstance();21 this.jobDispatcher = JobDispatcher.getInstance(); 23 22 } 24 23 … … 81 80 82 81 /** 83 * 82 * Removes all jobs from the queue that are currently not being processed. 84 83 */ 85 84 public void cancelOutstandingJobs() { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileCache.java
r30223 r30875 43 43 */ 44 44 public int getTileCount(); 45 46 /** 47 * Clears the cache deleting all tiles from memory. 48 */ 49 public void clear(); 45 50 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoaderListener.java
r30223 r30875 10 10 * Loaded can mean downloaded or loaded from file cache. 11 11 * 12 * @param tile 12 * @param tile The tile 13 * @param success {@code true} if the tile has been loaded successfully, {@code false} otherwise 13 14 */ 14 15 public void tileLoadingFinished(Tile tile, boolean success); 15 16 /**17 * Return the {@link TileCache} class containing {@link Tile}18 * data for requested and loaded tiles19 *20 * @return tile information caching class21 */22 public TileCache getTileCache();23 16 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java
r30854 r30875 57 57 */ 58 58 public CycleMap() { 59 super("Cyclemap", PATTERN, "opency lemap");59 super("Cyclemap", PATTERN, "opencyclemap"); 60 60 } 61 61
Note:
See TracChangeset
for help on using the changeset viewer.