source: osm/applications/editors/josm/plugins/slippy_map_chooser/src/OsmTile.java@ 7199

Last change on this file since 7199 was 7199, checked in by tim, 18 years ago

Initial import of slippy_map_chooser source version 1.1

File size: 2.0 KB
Line 
1// License: GPL. Copyright 2007 by Tim Haussmann
2
3import java.awt.image.BufferedImage;
4import java.awt.Color;
5import java.awt.Graphics;
6
7/**
8 * @author Tim Haussmann
9 */
10
11
12public class OsmTile {
13
14 public static final int WIDTH = 256;
15 public static final int HEIGHT = 256;
16
17 private int iX = 0;
18 private int iY = 0;
19
20 public static final int TileBackgroundColor = 0xe9d3b1;
21
22 private BufferedImage iMapImage;
23
24 private int iZoomLevel = -1;
25 private int iIndexY = -1;
26 private int iIndexX = -1;
27
28 //image does not exist
29 private boolean isInvalid = false;
30
31 //for a faster equals implementation
32 private int iHash;
33
34 public OsmTile( int aZoomLevel, int aIndexX, int aIndexY){
35
36 iZoomLevel = aZoomLevel;
37 iIndexX = aIndexX;
38 iIndexY = aIndexY;
39
40 iX = WIDTH * iIndexX;
41 iY = HEIGHT * iIndexY;
42
43 iHash = toString().hashCode();
44 }
45
46 public int getZoomlevel(){
47 return iZoomLevel;
48 }
49
50 public void paint(Graphics g){
51
52 if(iMapImage != null && ! isInvalid){
53 g.drawImage( iMapImage, iX, iY, null );
54 }
55 else if(isInvalid){
56 //draw nothing
57 }
58 else{
59 g.setColor(Color.RED);
60 g.drawLine(iX, iY, iX+WIDTH-1, iY+HEIGHT-1);
61 g.drawLine(iX, iY+HEIGHT-1, iX+WIDTH-1, iY);
62 g.drawRect(iX, iY, WIDTH-1, HEIGHT-1);
63 }
64 }
65
66 public String toString() {
67 return String.valueOf(iZoomLevel) +"/" +
68 String.valueOf(iIndexX) + "/" +
69 String.valueOf(iIndexY);
70 }
71 public static String key(int aZoomLevel, int aIndexX, int aIndexY){
72 return String.valueOf(aZoomLevel) +"/" +
73 String.valueOf(aIndexX) + "/" +
74 String.valueOf(aIndexY);
75 }
76
77 /**
78 * Callback for the TileDB to set the Image of this tile after loading.
79 * @param aImage
80 */
81 public void setImage(BufferedImage aImage) {
82 iMapImage = aImage;
83 if(iMapImage == null){
84 isInvalid = true;
85 }
86 }
87
88 /**
89 * @return the path of this map tile on the remote server (i.e. '/1/2/12.png')
90 */
91 public String getRemotePath() {
92 return "/"+toString()+".png";
93 }
94
95}
Note: See TracBrowser for help on using the repository browser.