Changeset 5675 in osm for applications/editors/josm/plugins/slippymap
- Timestamp:
- 2007-11-22T12:46:39+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r5674 r5675 34 34 * 35 35 * @author Frederik Ramm <frederik@remote.org> 36 * 36 * 37 37 */ 38 public class SlippyMapLayer extends Layer implements ImageObserver { 39 40 ArrayList<HashMap<Integer, SlippyMapTile>> tileStorage = new ArrayList<HashMap<Integer, SlippyMapTile>>(20); 41 Point[][] pixelpos = new Point[21][21]; 42 LatLon lastTopLeft; 43 LatLon lastBotRight; 44 45 int z12x0, z12x1, z12y0, z12y1; 46 47 private Image bufferImage; 48 private SlippyMapTile clickedTile; 49 private boolean needRedraw; 50 51 private JPopupMenu tileOptionMenu; 52 53 public SlippyMapLayer() 54 { 55 super("Slippy Map"); 56 for (int i=0; i<18; i++) 57 tileStorage.add(new HashMap<Integer, SlippyMapTile>()); 58 59 tileOptionMenu = new JPopupMenu(); 60 tileOptionMenu.add(new JMenuItem(new AbstractAction("Load Tile") { 61 public void actionPerformed(ActionEvent ae) { 62 if (clickedTile != null) 63 { 64 clickedTile.loadImage(); 65 needRedraw = true; 66 Main.map.repaint(); 67 } 68 } 69 })); 70 71 tileOptionMenu.add(new JMenuItem(new AbstractAction("Show Tile Status") { 72 public void actionPerformed(ActionEvent ae) { 73 if (clickedTile != null) 74 { 75 clickedTile.loadMetadata(); 76 needRedraw = true; 77 Main.map.repaint(); 78 } 79 } 80 })); 81 82 tileOptionMenu.add(new JMenuItem(new AbstractAction("Request Update") { 83 public void actionPerformed(ActionEvent ae) { 84 if (clickedTile != null) 85 { 86 clickedTile.requestUpdate(); 87 needRedraw = true; 88 Main.map.repaint(); 89 } 90 } 91 })); 92 93 tileOptionMenu.add(new JMenuItem(new AbstractAction("Load All Tiles") { 94 public void actionPerformed(ActionEvent ae) { 95 loadAllTiles(); 96 needRedraw = true; 97 Main.map.repaint(); 98 } 99 })); 100 101 SwingUtilities.invokeLater(new Runnable(){ 102 public void run() { 103 Main.map.mapView.addMouseListener(new MouseAdapter() { 104 @Override public void mouseClicked(MouseEvent e) { 105 if (e.getButton() != MouseEvent.BUTTON3) 106 return; 107 clickedTile = getTileForPixelpos(e.getX(), e.getY()); 108 tileOptionMenu.show(e.getComponent(), e.getX(), e.getY()); 109 } 110 }); 111 112 Main.map.mapView.addLayerChangeListener(new MapView.LayerChangeListener(){ 113 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 114 public void layerAdded(Layer newLayer) {} 115 public void layerRemoved(Layer oldLayer) { 116 Main.pref.listener.remove(SlippyMapLayer.this); 117 } 118 }); 119 } 120 }); 121 } 122 123 void loadAllTiles() 124 { 125 MapView mv = Main.map.mapView; 126 LatLon topLeft = mv.getLatLon(0, 0); 127 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 128 z12x0 = lonToTileX(topLeft.lon()); 129 z12x1 = lonToTileX(botRight.lon()); 130 z12y0 = latToTileY(topLeft.lat()); 131 z12y1 = latToTileY(botRight.lat()); 132 if (z12x0>z12x1) { int tmp = z12x0; z12x0=z12x1; z12x1=tmp; } 133 if (z12y0>z12y1) { int tmp = z12y0; z12y0=z12y1; z12y1=tmp; } 134 if (z12x1-z12x0 > 18) return; 135 if (z12y1-z12y0 > 18) return; 136 for(int x = z12x0-1; x <= z12x1; x++) 137 { 138 for (int y=z12y0-1; y <= z12y1; y++) 139 { 140 int key = (y <<19) + x; 141 SlippyMapTile tile = tileStorage.get(12).get(key); 142 if (tile.getImage() == null) tile.loadImage(); 143 } 144 } 145 } 146 147 148 /** 149 */ 150 @Override public void paint(Graphics g, MapView mv) 151 { 152 LatLon topLeft = mv.getLatLon(0, 0); 153 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 154 Graphics oldg = g; 155 156 if (lastTopLeft != null && 157 lastBotRight != null && 158 topLeft.equalsEpsilon(lastTopLeft) && 159 botRight.equalsEpsilon(lastBotRight) && 160 bufferImage != null && 161 mv.getWidth() == bufferImage.getWidth(null) && 162 mv.getHeight() == bufferImage.getHeight(null) && 163 !needRedraw) 164 { 165 166 g.drawImage(bufferImage, 0, 0, null); 167 return; 168 } 169 170 needRedraw = false; 171 lastTopLeft = topLeft; 172 lastBotRight = botRight; 173 bufferImage = mv.createImage(mv.getWidth(), mv.getHeight()); 174 g = bufferImage.getGraphics(); 175 176 z12x0 = lonToTileX(topLeft.lon()); 177 z12x1 = lonToTileX(botRight.lon()); 178 z12y0 = latToTileY(topLeft.lat()); 179 z12y1 = latToTileY(botRight.lat()); 180 181 if (z12x0>z12x1) { int tmp = z12x0; z12x0=z12x1; z12x1=tmp; } 182 if (z12y0>z12y1) { int tmp = z12y0; z12y0=z12y1; z12y1=tmp; } 183 184 if (z12x1-z12x0 > 18) return; 185 if (z12y1-z12y0 > 18) return; 186 187 for (int x = z12x0 -1; x <= z12x1+1; x++) 188 { 189 double lon = tileXToLon(x); 190 for (int y = z12y0 -1; y <= z12y1+1; y++) 191 { 192 LatLon tmpLL = new LatLon(tileYToLat(y), lon); 193 pixelpos[x-z12x0+1][y-z12y0+1] = mv.getPoint(Main.proj.latlon2eastNorth(tmpLL)); 194 } 195 } 196 197 int fontHeight = g.getFontMetrics().getHeight(); 198 199 g.setColor(Color.DARK_GRAY); 200 201 for (int x = z12x0 -1; x <= z12x1; x++) 202 { 203 for (int y = z12y0 -1; y <= z12y1; y++) 204 { 205 int key = (y << 19) + x; 206 SlippyMapTile tile = tileStorage.get(12).get(key); 207 208 if (tile == null) 209 { 210 tileStorage.get(12).put(key, tile = new SlippyMapTile(x, y, 12)); 211 } 212 Image img = tile.getImage(); 213 214 if (img != null) 215 { 216 Point p = pixelpos[x-z12x0+1][y-z12y0+1]; 217 Point p2 = pixelpos[x-z12x0+2][y-z12y0+2]; 218 g.drawImage(img, p.x, p.y, p2.x-p.x, p2.y-p.y, this); 219 } 220 } 221 } 222 223 for (int x = z12x0 -1; x <= z12x1; x++) 224 { 225 Point p = pixelpos[x-z12x0+1][0]; 226 227 if (x % 32 == 0) 228 { 229 // level 7 tile boundary 230 g.fillRect(p.x - 1, 0, 3, mv.getHeight()); 231 } 232 else 233 { 234 g.drawLine(p.x, 0, p.x, mv.getHeight()); 235 } 236 237 for (int y = z12y0 -1; y <= z12y1; y++) 238 { 239 int key = (y <<19) + x; 240 int texty = p.y + 2 + fontHeight; 241 SlippyMapTile tile = tileStorage.get(12).get(key); 242 p = pixelpos[x-z12x0+1][y-z12y0+2]; 243 g.drawString("x=" + x + " y="+ y + " z=12", p.x + 2, texty); 244 texty += 1 + fontHeight; 245 if ((x % 32 == 0) && (y % 32 == 0)) 246 { 247 g.drawString("x=" + x/32 + " y="+ y/32 + " z=7", p.x+2, texty); 248 texty += 1 + fontHeight; 249 } 250 251 String md = tile.getMetadata(); 252 if (md != null) 253 { 254 g.drawString(md, p.x+2, texty); 255 texty += 1 + fontHeight; 256 } 257 258 if (tile.getImage() == null) 259 { 260 g.drawString("image not loaded", p.x+2, texty); 261 texty += 1 + fontHeight; 262 } 263 264 if (x == z12x0-1) 265 { 266 if (y % 32 == 31) 267 { 268 g.fillRect(0, p.y - 1, mv.getWidth(), 3); 269 } 270 else 271 { 272 g.drawLine(0, p.y, mv.getWidth(), p.y); 273 } 274 } 275 } 276 } 277 278 oldg.drawImage(bufferImage, 0, 0, null); 279 280 } 281 282 SlippyMapTile getTileForPixelpos(int px, int py) 283 { 284 int tilex=z12x1; 285 int tiley=z12y1; 286 for (int x = z12x0; x <= z12x1; x++) 287 { 288 289 if (pixelpos[x-z12x0+1][0].x > px) 290 { 291 tilex = x-1; 292 break; 293 } 294 } 295 if (tilex==-1) return null; 296 for (int y = z12y0; y <= z12y1; y++) 297 { 298 299 if (pixelpos[0][y-z12y0+1].y > py) 300 { 301 tiley = y-1; 302 break; 303 } 304 } 305 if (tiley==-1) return null; 306 307 int key = (tiley <<19) + tilex; 308 SlippyMapTile tile = tileStorage.get(12).get(key); 309 if (tile==null) tileStorage.get(12).put(key, tile = new SlippyMapTile(tilex, tiley, 12)); 310 return tile; 311 } 312 313 @Override 314 public Icon getIcon() { 315 // TODO Auto-generated method stub 316 return ImageProvider.get("slippymap"); 317 } 318 319 @Override 320 public Object getInfoComponent() { 321 // TODO Auto-generated method stub 322 return null; 323 } 324 325 @Override public Component[] getMenuEntries() { 326 /* 327 JMenuItem color = new JMenuItem(tr("Customize Color"), ImageProvider.get("colorchooser")); 328 color.addActionListener(new ActionListener(){ 329 public void actionPerformed(ActionEvent e) { 330 String col = Main.pref.get("color.layer "+name, Main.pref.get("color.gps marker", ColorHelper.color2html(Color.gray))); 331 JColorChooser c = new JColorChooser(ColorHelper.html2color(col)); 332 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 333 int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 334 switch (answer) { 335 case 0: 336 Main.pref.put("color.layer "+name, ColorHelper.color2html(c.getColor())); 337 break; 338 case 1: 339 return; 340 case 2: 341 Main.pref.put("color.layer "+name, null); 342 break; 343 } 344 Main.map.repaint(); 345 } 346 }); 347 */ 348 349 return new Component[] { 350 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 351 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 352 new JSeparator(), 353 // color, 354 new JMenuItem(new RenameLayerAction(associatedFile, this)), 355 new JSeparator(), 356 new JMenuItem(new LayerListPopup.InfoAction(this)) 357 }; 358 } 359 360 @Override 361 public String getToolTipText() { 362 // TODO Auto-generated method stub 363 return null; 364 } 365 366 @Override 367 public boolean isMergable(Layer other) { 368 return false; 369 } 370 371 @Override 372 public void mergeFrom(Layer from) { 373 } 374 375 @Override 376 public void visitBoundingBox(BoundingXYVisitor v) { 377 // TODO Auto-generated method stub 378 } 379 380 private int latToTileY(double lat) { 381 double l = lat / 180 * Math.PI; 382 double pf = Math.log(Math.tan(l) + (1/Math.cos(l))); 383 return (int) (2048.0 * (Math.PI - pf) / Math.PI); 384 } 385 386 private int lonToTileX(double lon) { 387 return (int) (512.0 * (lon + 180.0) / 45.0); 388 } 389 390 private double tileYToLat(int y) { 391 return Math.atan(Math.sinh(Math.PI - (Math.PI*y / 2048.0))) * 180 / Math.PI; 392 } 393 394 private double tileXToLon(int x) { 395 return x * 45.0 / 512.0 - 180.0; 396 } 397 398 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 399 400 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 401 // Repaint immediately if we are done, otherwise batch up 402 // repaint requests every 100 milliseconds 403 needRedraw = true; 404 Main.map.repaint(done ? 0 : 100); 405 return !done; 406 } 38 public class SlippyMapLayer extends Layer implements ImageObserver 39 { 40 41 ArrayList<HashMap<Integer, SlippyMapTile>> tileStorage = new ArrayList<HashMap<Integer, SlippyMapTile>>( 42 20); 43 44 Point[][] pixelpos = new Point[21][21]; 45 LatLon lastTopLeft; 46 LatLon lastBotRight; 47 int z12x0, z12x1, z12y0, z12y1; 48 private Image bufferImage; 49 private SlippyMapTile clickedTile; 50 private boolean needRedraw; 51 private JPopupMenu tileOptionMenu; 52 53 public SlippyMapLayer() 54 { 55 super("Slippy Map"); 56 for (int i = 0; i < 18; i++) 57 tileStorage.add(new HashMap<Integer, SlippyMapTile>()); 58 59 tileOptionMenu = new JPopupMenu(); 60 tileOptionMenu.add(new JMenuItem(new AbstractAction("Load Tile") 61 { 62 public void actionPerformed(ActionEvent ae) 63 { 64 if (clickedTile != null) 65 { 66 clickedTile.loadImage(); 67 needRedraw = true; 68 Main.map.repaint(); 69 } 70 } 71 })); 72 73 tileOptionMenu.add(new JMenuItem(new AbstractAction("Show Tile Status") 74 { 75 public void actionPerformed(ActionEvent ae) 76 { 77 if (clickedTile != null) 78 { 79 clickedTile.loadMetadata(); 80 needRedraw = true; 81 Main.map.repaint(); 82 } 83 } 84 })); 85 86 tileOptionMenu.add(new JMenuItem(new AbstractAction("Request Update") 87 { 88 public void actionPerformed(ActionEvent ae) 89 { 90 if (clickedTile != null) 91 { 92 clickedTile.requestUpdate(); 93 needRedraw = true; 94 Main.map.repaint(); 95 } 96 } 97 })); 98 99 tileOptionMenu.add(new JMenuItem(new AbstractAction("Load All Tiles") 100 { 101 public void actionPerformed(ActionEvent ae) 102 { 103 loadAllTiles(); 104 needRedraw = true; 105 Main.map.repaint(); 106 } 107 })); 108 109 SwingUtilities.invokeLater(new Runnable() 110 { 111 public void run() 112 { 113 Main.map.mapView.addMouseListener(new MouseAdapter() 114 { 115 @Override 116 public void mouseClicked(MouseEvent e) 117 { 118 if (e.getButton() != MouseEvent.BUTTON3) 119 return; 120 clickedTile = getTileForPixelpos(e.getX(), e.getY()); 121 tileOptionMenu.show(e.getComponent(), e.getX(), e 122 .getY()); 123 } 124 }); 125 126 Main.map.mapView 127 .addLayerChangeListener(new MapView.LayerChangeListener() 128 { 129 public void activeLayerChange(Layer oldLayer, 130 Layer newLayer) 131 { 132 } 133 134 public void layerAdded(Layer newLayer) 135 { 136 } 137 138 public void layerRemoved(Layer oldLayer) 139 { 140 Main.pref.listener.remove(SlippyMapLayer.this); 141 } 142 }); 143 } 144 }); 145 } 146 147 void loadAllTiles() 148 { 149 MapView mv = Main.map.mapView; 150 LatLon topLeft = mv.getLatLon(0, 0); 151 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 152 z12x0 = lonToTileX(topLeft.lon()); 153 z12x1 = lonToTileX(botRight.lon()); 154 z12y0 = latToTileY(topLeft.lat()); 155 z12y1 = latToTileY(botRight.lat()); 156 if (z12x0 > z12x1) 157 { 158 int tmp = z12x0; 159 z12x0 = z12x1; 160 z12x1 = tmp; 161 } 162 if (z12y0 > z12y1) 163 { 164 int tmp = z12y0; 165 z12y0 = z12y1; 166 z12y1 = tmp; 167 } 168 if (z12x1 - z12x0 > 18) 169 return; 170 if (z12y1 - z12y0 > 18) 171 return; 172 for (int x = z12x0 - 1; x <= z12x1; x++) 173 { 174 for (int y = z12y0 - 1; y <= z12y1; y++) 175 { 176 int key = (y << 19) + x; 177 SlippyMapTile tile = tileStorage.get(12).get(key); 178 if (tile.getImage() == null) 179 tile.loadImage(); 180 } 181 } 182 } 183 184 /** 185 */ 186 @Override 187 public void paint(Graphics g, MapView mv) 188 { 189 LatLon topLeft = mv.getLatLon(0, 0); 190 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 191 Graphics oldg = g; 192 193 if (lastTopLeft != null && lastBotRight != null 194 && topLeft.equalsEpsilon(lastTopLeft) 195 && botRight.equalsEpsilon(lastBotRight) && bufferImage != null 196 && mv.getWidth() == bufferImage.getWidth(null) 197 && mv.getHeight() == bufferImage.getHeight(null) && !needRedraw) 198 { 199 200 g.drawImage(bufferImage, 0, 0, null); 201 return; 202 } 203 204 needRedraw = false; 205 lastTopLeft = topLeft; 206 lastBotRight = botRight; 207 bufferImage = mv.createImage(mv.getWidth(), mv.getHeight()); 208 g = bufferImage.getGraphics(); 209 210 z12x0 = lonToTileX(topLeft.lon()); 211 z12x1 = lonToTileX(botRight.lon()); 212 z12y0 = latToTileY(topLeft.lat()); 213 z12y1 = latToTileY(botRight.lat()); 214 215 if (z12x0 > z12x1) 216 { 217 int tmp = z12x0; 218 z12x0 = z12x1; 219 z12x1 = tmp; 220 } 221 if (z12y0 > z12y1) 222 { 223 int tmp = z12y0; 224 z12y0 = z12y1; 225 z12y1 = tmp; 226 } 227 228 if (z12x1 - z12x0 > 18) 229 return; 230 if (z12y1 - z12y0 > 18) 231 return; 232 233 for (int x = z12x0 - 1; x <= z12x1 + 1; x++) 234 { 235 double lon = tileXToLon(x); 236 for (int y = z12y0 - 1; y <= z12y1 + 1; y++) 237 { 238 LatLon tmpLL = new LatLon(tileYToLat(y), lon); 239 pixelpos[x - z12x0 + 1][y - z12y0 + 1] = mv.getPoint(Main.proj 240 .latlon2eastNorth(tmpLL)); 241 } 242 } 243 244 int fontHeight = g.getFontMetrics().getHeight(); 245 246 g.setColor(Color.DARK_GRAY); 247 248 for (int x = z12x0 - 1; x <= z12x1; x++) 249 { 250 for (int y = z12y0 - 1; y <= z12y1; y++) 251 { 252 int key = (y << 19) + x; 253 SlippyMapTile tile = tileStorage.get(12).get(key); 254 255 if (tile == null) 256 { 257 tileStorage.get(12).put(key, 258 tile = new SlippyMapTile(x, y, 12)); 259 } 260 Image img = tile.getImage(); 261 262 if (img != null) 263 { 264 Point p = pixelpos[x - z12x0 + 1][y - z12y0 + 1]; 265 Point p2 = pixelpos[x - z12x0 + 2][y - z12y0 + 2]; 266 g.drawImage(img, p.x, p.y, p2.x - p.x, p2.y - p.y, this); 267 } 268 } 269 } 270 271 for (int x = z12x0 - 1; x <= z12x1; x++) 272 { 273 Point p = pixelpos[x - z12x0 + 1][0]; 274 275 if (x % 32 == 0) 276 { 277 // level 7 tile boundary 278 g.fillRect(p.x - 1, 0, 3, mv.getHeight()); 279 } 280 else 281 { 282 g.drawLine(p.x, 0, p.x, mv.getHeight()); 283 } 284 285 for (int y = z12y0 - 1; y <= z12y1; y++) 286 { 287 int key = (y << 19) + x; 288 int texty = p.y + 2 + fontHeight; 289 SlippyMapTile tile = tileStorage.get(12).get(key); 290 p = pixelpos[x - z12x0 + 1][y - z12y0 + 2]; 291 g.drawString("x=" + x + " y=" + y + " z=12", p.x + 2, texty); 292 texty += 1 + fontHeight; 293 if ((x % 32 == 0) && (y % 32 == 0)) 294 { 295 g.drawString("x=" + x / 32 + " y=" + y / 32 + " z=7", 296 p.x + 2, texty); 297 texty += 1 + fontHeight; 298 } 299 300 String md = tile.getMetadata(); 301 if (md != null) 302 { 303 g.drawString(md, p.x + 2, texty); 304 texty += 1 + fontHeight; 305 } 306 307 if (tile.getImage() == null) 308 { 309 g.drawString("image not loaded", p.x + 2, texty); 310 texty += 1 + fontHeight; 311 } 312 313 if (x == z12x0 - 1) 314 { 315 if (y % 32 == 31) 316 { 317 g.fillRect(0, p.y - 1, mv.getWidth(), 3); 318 } 319 else 320 { 321 g.drawLine(0, p.y, mv.getWidth(), p.y); 322 } 323 } 324 } 325 } 326 327 oldg.drawImage(bufferImage, 0, 0, null); 328 329 } 330 331 SlippyMapTile getTileForPixelpos(int px, int py) 332 { 333 int tilex = z12x1; 334 int tiley = z12y1; 335 for (int x = z12x0; x <= z12x1; x++) 336 { 337 338 if (pixelpos[x - z12x0 + 1][0].x > px) 339 { 340 tilex = x - 1; 341 break; 342 } 343 } 344 if (tilex == -1) 345 return null; 346 for (int y = z12y0; y <= z12y1; y++) 347 { 348 349 if (pixelpos[0][y - z12y0 + 1].y > py) 350 { 351 tiley = y - 1; 352 break; 353 } 354 } 355 if (tiley == -1) 356 return null; 357 358 int key = (tiley << 19) + tilex; 359 SlippyMapTile tile = tileStorage.get(12).get(key); 360 if (tile == null) 361 tileStorage.get(12).put(key, 362 tile = new SlippyMapTile(tilex, tiley, 12)); 363 return tile; 364 } 365 366 @Override 367 public Icon getIcon() 368 { 369 return ImageProvider.get("slippymap"); 370 } 371 372 @Override 373 public Object getInfoComponent() 374 { 375 return null; 376 } 377 378 @Override 379 public Component[] getMenuEntries() 380 { 381 return new Component[] 382 { 383 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 384 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 385 new JSeparator(), 386 // color, 387 new JMenuItem(new RenameLayerAction(associatedFile, this)), 388 new JSeparator(), 389 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 390 } 391 392 @Override 393 public String getToolTipText() 394 { 395 return null; 396 } 397 398 @Override 399 public boolean isMergable(Layer other) 400 { 401 return false; 402 } 403 404 @Override 405 public void mergeFrom(Layer from) 406 { 407 } 408 409 @Override 410 public void visitBoundingBox(BoundingXYVisitor v) 411 { 412 } 413 414 private int latToTileY(double lat) 415 { 416 double l = lat / 180 * Math.PI; 417 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l))); 418 return (int) (2048.0 * (Math.PI - pf) / Math.PI); 419 } 420 421 private int lonToTileX(double lon) 422 { 423 return (int) (512.0 * (lon + 180.0) / 45.0); 424 } 425 426 private double tileYToLat(int y) 427 { 428 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / 2048.0))) * 180 429 / Math.PI; 430 } 431 432 private double tileXToLon(int x) 433 { 434 return x * 45.0 / 512.0 - 180.0; 435 } 436 437 public boolean imageUpdate(Image img, int infoflags, int x, int y, 438 int width, int height) 439 { 440 441 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 442 // Repaint immediately if we are done, otherwise batch up 443 // repaint requests every 100 milliseconds 444 needRedraw = true; 445 Main.map.repaint(done ? 0 : 100); 446 return !done; 447 } 407 448 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPlugin.java
r5674 r5675 9 9 * 10 10 * @author Frederik Ramm <frederik@remote.org> 11 * 11 * 12 12 */ 13 public class SlippyMapPlugin extends Plugin 14 { 15 public SlippyMapPlugin() 13 public class SlippyMapPlugin extends Plugin 14 { 15 public SlippyMapPlugin() 16 16 { 17 17 18 18 } 19 20 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 21 22 23 24 25 19 20 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 21 { 22 SlippyMapLayer smlayer; 23 smlayer = new SlippyMapLayer(); 24 Main.main.addLayer(smlayer); 25 } 26 26 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java
r5674 r5675 11 11 /** 12 12 * Class that contains information about one single slippy map tile. 13 * 13 * 14 14 * @author Frederik Ramm <frederik@remote.org> 15 * 15 * 16 16 */ 17 17 public class SlippyMapTile 18 18 { 19 private Image tileImage; 19 20 20 private Image tileImage; 21 22 int x; 23 int y; 24 int z; 21 int x; 22 int y; 23 int z; 25 24 26 25 private String metadata; 27 26 28 29 30 31 32 33 27 public SlippyMapTile(int x, int y, int z) 28 { 29 this.x = x; 30 this.y = y; 31 this.z = z; 32 } 34 33 35 36 37 38 34 public String getMetadata() 35 { 36 return metadata; 37 } 39 38 40 public void loadImage() 41 { 42 try 43 { 44 tileImage = Toolkit.getDefaultToolkit().createImage(new URL("http://tah.openstreetmap.org/Tiles/tile/"+z+"/"+x+"/"+y+".png")); 45 } 46 catch (MalformedURLException mfu) 47 { 48 mfu.printStackTrace(); 49 } 50 } 51 52 public Image getImage() 53 { 54 return tileImage; 55 } 56 57 public void loadMetadata() 58 { 39 public void loadImage() 40 { 59 41 try 60 42 { 61 URL dev = new URL("http://tah.openstreetmap.org/Tiles/info_short.php?x=" + 62 x + "&y=" + y + "&z=12/layer=tile"); 43 tileImage = Toolkit.getDefaultToolkit().createImage( 44 new URL("http://tah.openstreetmap.org/Tiles/tile/" + z 45 + "/" + x + "/" + y + ".png")); 46 } 47 catch (MalformedURLException mfu) 48 { 49 mfu.printStackTrace(); 50 } 51 } 52 53 public Image getImage() 54 { 55 return tileImage; 56 } 57 58 public void loadMetadata() 59 { 60 try 61 { 62 URL dev = new URL( 63 "http://tah.openstreetmap.org/Tiles/info_short.php?x=" + x 64 + "&y=" + y + "&z=12/layer=tile"); 63 65 URLConnection devc = dev.openConnection(); 64 BufferedReader in = new BufferedReader(new InputStreamReader(devc.getInputStream())); 66 BufferedReader in = new BufferedReader(new InputStreamReader(devc 67 .getInputStream())); 65 68 metadata = in.readLine(); 66 69 } … … 70 73 } 71 74 72 75 } 73 76 74 77 public void requestUpdate() … … 76 79 try 77 80 { 78 URL dev = new URL("http://tah.openstreetmap.org/NeedRender?x=" + 79 x+ "&y=" + y + "&priority=1&src=slippymap_plugin");81 URL dev = new URL("http://tah.openstreetmap.org/NeedRender?x=" + x 82 + "&y=" + y + "&priority=1&src=slippymap_plugin"); 80 83 URLConnection devc = dev.openConnection(); 81 BufferedReader in = new BufferedReader(new InputStreamReader(devc.getInputStream())); 82 metadata = "requested: "+ in.readLine(); 84 BufferedReader in = new BufferedReader(new InputStreamReader(devc 85 .getInputStream())); 86 metadata = "requested: " + in.readLine(); 83 87 } 84 88 catch (Exception ex) … … 88 92 } 89 93 90 91 92 if (!(o instanceof SlippyMapTile)) return false; 93 SlippyMapTile other = (SlippyMapTile) o;94 return (this.x == other.x && this.y == other.y && this.z == other.z);95 } 96 94 public boolean equals(Object o) 95 { 96 if (!(o instanceof SlippyMapTile)) 97 return false; 98 SlippyMapTile other = (SlippyMapTile) o; 99 return (this.x == other.x && this.y == other.y && this.z == other.z); 100 } 97 101 }
Note:
See TracChangeset
for help on using the changeset viewer.