|
From: Adam B. <ab...@us...> - 2005-07-05 23:50:24
|
Update of /cvsroot/hipgmap/gmap/com/trileet/gmap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16325/com/trileet/gmap Modified Files: Tile.java TileSet.java Log Message: Began the update to the new 256x256 tiles and the Mercator projection. I looked up the formula on mathworld; I played around with the web app and the north/south cutoff on the new coordinate system seemed to be about +/- 3.141, so I took a guess that it was PI. Seems to work, more or less. - The mercator calculation with hipfloats is slow, so zoom in/out is sluggish. Perhaps a lookup table or other optimization is warranted. - I changed the tileset to be 3x3 rather than 5x5, since the tiles are huge. However, panning more than a tile's worth doesn't seem to work anymore. Can't figure out why. Nic, could you take a look? - Directions plotting is really slow, and the turn markers don't quite line up. That's all from me for now; if someone can polish it up and release a functional bundle on skdr, I'm sure our 800-some users would really appreciate it. Index: Tile.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Tile.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Tile.java 23 Apr 2005 05:27:19 -0000 1.9 --- Tile.java 5 Jul 2005 23:50:14 -0000 1.10 *************** *** 23,27 **** public class Tile implements ImageCache.Listener { ! public static final int WIDTH = 128; // by default, the tile is empty --- 23,27 ---- public class Tile implements ImageCache.Listener { ! public static final int WIDTH = 256; // by default, the tile is empty *************** *** 90,96 **** public static String makeURL(int x, int y, int zoom) { return "http://hipster.trileet.com/tmpimg/img.php?nocache=true&url=" + ! URLEncoder.encode("http://mt.google.com/mt?v=.1&x=" + x + "&y=" + y + "&zoom=" + zoom); // no direct request till Danger fixes their gateway ! // return "http://mt.google.com/mt?v=.1&x=" + x + "&y=" + y + "&zoom=" // + zoom; } --- 90,96 ---- public static String makeURL(int x, int y, int zoom) { return "http://hipster.trileet.com/tmpimg/img.php?nocache=true&url=" + ! URLEncoder.encode("http://mt.google.com/mt?v=w2.4&x=" + x + "&y=" + y + "&zoom=" + zoom); // no direct request till Danger fixes their gateway ! // return "http://mt.google.com/mt?v=2.4&x=" + x + "&y=" + y + "&zoom=" // + zoom; } Index: TileSet.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/TileSet.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** TileSet.java 10 Apr 2005 23:16:05 -0000 1.26 --- TileSet.java 5 Jul 2005 23:50:14 -0000 1.27 *************** *** 19,23 **** * TileSet * ! * Aggregates a set of Tiles, which are google 128x128 GIF's * * @author <a href='ni...@tr...'>Nic Pottier</a> $Date$ --- 19,23 ---- * TileSet * ! * Aggregates a set of Tiles, which are google 256x256 GIF's * * @author <a href='ni...@tr...'>Nic Pottier</a> $Date$ *************** *** 38,42 **** */ public TileSet() { ! this(5,5); } --- 38,42 ---- */ public TileSet() { ! this(3,3); } *************** *** 53,58 **** // Get our pin bitmap m_pinBitmap = Application.getCurrentApp().getResources().getBitmap( ! Resources.ID_PIN); --- 53,59 ---- // Get our pin bitmap + m_pinBitmap = Application.getCurrentApp().getResources().getBitmap( ! Resources.ID_PIN); *************** *** 66,74 **** } ! public static final hipfloat X_OFFSET = new hipfloat("98.35"); ! public static final hipfloat Y_OFFSET = new hipfloat("39.5"); ! public static final hipfloat X_FACTOR = new hipfloat("0.77162458"); public void zoomOut() { --- 67,79 ---- } ! public static final hipfloat X_OFFSET = new hipfloat("180"); ! public static final hipfloat Y_OFFSET = new hipfloat("90"); ! public static final hipfloat X_FACTOR = new hipfloat("0.7111111"); ! ! public static final hipfloat Y_FACTOR = new hipfloat("0.5"); ! ! public static final hipfloat RAD_FACTOR = hipfloat.PI.div(new hipfloat("180")); public void zoomOut() { *************** *** 181,195 **** // we want to put our center smack dable in the middle of the screen ! // since we are a 5x5 grid and we lay our center _TILE_ in the middle of // that grid // if the center was in the center of that tile, we would have our top // left corner at: ! // y = (128 * 2.5) - 70 ! // x = (128 * 2.5) - 120 // However, since that isn't the case, we figure out what the offset for // our center tile // is and ajust accordingly ! int xRadius = getWidth() / 2; // = 2 ! int yRadius = getHeight() / 2;// = 2 m_offsetX = (TILE_WIDTH * xRadius) + mapXFloat.sub(mapXFloat.floor()).mul(TILE_WIDTH_FLOAT) --- 186,200 ---- // we want to put our center smack dable in the middle of the screen ! // since we are a 3x3 grid and we lay our center _TILE_ in the middle of // that grid // if the center was in the center of that tile, we would have our top // left corner at: ! // y = (256 * 1.5) - 70 ! // x = (256 * 1.5) - 120 // However, since that isn't the case, we figure out what the offset for // our center tile // is and ajust accordingly ! int xRadius = getWidth() / 2; // == 1 ! int yRadius = getHeight() / 2;// == 1 m_offsetX = (TILE_WIDTH * xRadius) + mapXFloat.sub(mapXFloat.floor()).mul(TILE_WIDTH_FLOAT) *************** *** 207,215 **** */ private void setMapTilesByCenter(int mapX, int mapY, int zoom) { ! /** Fine-tuned for the 5x5 tileset. **/ ImageCache.clearAllPriorityRequests(); ! int xRadius = getWidth() / 2; // = 2 ! int yRadius = getHeight() / 2;// = 2 // clear out our areas for our screen tiles --- 212,220 ---- */ private void setMapTilesByCenter(int mapX, int mapY, int zoom) { ! /** Fine-tuned for the 3x3 tileset. **/ ImageCache.clearAllPriorityRequests(); ! int xRadius = getWidth() / 2; // == 1 ! int yRadius = getHeight() / 2;// == 1 // clear out our areas for our screen tiles *************** *** 300,306 **** * as possible between east/west expansion and * north/south expansion. If you think you can do better, please improve it. */ ! int[] loadOrderX = {2,1,3,2,2,3,1,1,3,4,0,2,2,0,0,4,4,1,3,1,3,0,4,4,0}; ! int[] loadOrderY = {2,2,2,1,3,3,1,3,1,2,2,4,0,3,1,1,3,0,4,4,0,4,4,0,0}; int x,y; for (int i=0; i< loadOrderX.length;i++) { --- 305,322 ---- * as possible between east/west expansion and * north/south expansion. If you think you can do better, please improve it. + * + int[] loadOrderX = {2,1,3,2,2,3,1,1,3,4,0,2,2,0,0,4,4,1,3,1,3,0,4,4,0}; + int[] loadOrderY = {2,2,2,1,3,3,1,3,1,2,2,4,0,3,1,1,3,0,4,4,0,4,4,0,0}; */ ! /* ! * New order for 3x3, since the tiles are now 256x256: ! * ! * 6 3 9 ! * 5 1 4 ! * 7 2 8 ! */ ! int[] loadOrderX = {1,1,1,2,0,0,0,2,2}; ! int[] loadOrderY = {1,2,0,1,1,0,2,2,0}; ! int x,y; for (int i=0; i< loadOrderX.length;i++) { *************** *** 323,327 **** ImageCache.stopFetching(); ! /** Fine-tuned for the 5x5 tileset. **/ if (m_offsetX < TILE_WIDTH || m_offsetX > TILE_WIDTH * 2 || m_offsetY < TILE_WIDTH || m_offsetY > TILE_WIDTH * 2) { --- 339,343 ---- ImageCache.stopFetching(); ! /** Fine-tuned for the 3x3 tileset. **/ if (m_offsetX < TILE_WIDTH || m_offsetX > TILE_WIDTH * 2 || m_offsetY < TILE_WIDTH || m_offsetY > TILE_WIDTH * 2) { *************** *** 389,393 **** public static hipfloat getZoomFactor(int zoom) { if (zoomFactors[zoom] == null) { ! zoomFactors[zoom] = new hipfloat(1 << (10 - zoom)); } return zoomFactors[zoom]; --- 405,409 ---- public static hipfloat getZoomFactor(int zoom) { if (zoomFactors[zoom] == null) { ! zoomFactors[zoom] = new hipfloat(1 << (17 - zoom)); } return zoomFactors[zoom]; *************** *** 416,421 **** // now figure out our lat, the equation reversed is: ! // lat = -( mapY / 2^(10-zoom) - 39.5) ! return mapY.div(getZoomFactor(m_zoom)).sub(Y_OFFSET).neg(); } --- 432,440 ---- // now figure out our lat, the equation reversed is: ! // y = (2pi - ln(tan((90 + lat) / 2))) / 2pi * 2^(17 - zoom) ! // lat = (arctan(exp(pi - y / zoomfac * 2pi)) *2 - 90 ! return hipfloat.PI.sub(mapY.div(getZoomFactor(m_zoom)). ! mul(hipfloat.PI2)).exp().arctan().div(RAD_FACTOR). ! mul(hipfloat.TWO).sub(Y_OFFSET); } *************** *** 430,445 **** // now figure out our lat ! // lng = mapX / (2^(10-zoom) * .77162..) - 98.35 ! return mapX.div(getZoomFactor(m_zoom).mul(X_FACTOR)).sub(X_OFFSET); } ! // x = (lng + 98.35) * 2^(10 - zoom) * 0.77162458338772 public static hipfloat getX(hipfloat lng, int zoom) { ! return lng.add(X_OFFSET).mul(getZoomFactor(zoom)).mul(X_FACTOR); } ! // y = (39.5 - lat) * 2^(10 - zoom) public static hipfloat getY(hipfloat lat, int zoom) { ! return Y_OFFSET.sub(lat).mul(getZoomFactor(zoom)); } --- 449,467 ---- // now figure out our lat ! // lng = x * 256^2 / (180 * 2^(17-zoom)) - 180 ! return mapX.mul(TILE_WIDTH_FLOAT).div(X_FACTOR). ! div(getZoomFactor(m_zoom)).sub(X_OFFSET); } ! // x = (lng + 180) * 2^(17 - zoom) * 180 / 256 in pixels, not tiles public static hipfloat getX(hipfloat lng, int zoom) { ! return lng.add(X_OFFSET).mul(getZoomFactor(zoom)).mul(X_FACTOR).div(TILE_WIDTH_FLOAT); } ! // y = (pi - ln(tan((90 + lat) / 2))) / 2pi * 2^(17 - zoom) public static hipfloat getY(hipfloat lat, int zoom) { ! ! return hipfloat.PI.sub(lat.add(Y_OFFSET).div(hipfloat.TWO).mul(RAD_FACTOR).tan().ln()). ! div(hipfloat.PI2).mul(getZoomFactor(zoom)); } *************** *** 783,787 **** public static void main(String[] argv) { ! System.out.println(khToXOff("qtssqtssr")); } /** Our 2d array of tiles, first dimension is x, second is y */ --- 805,817 ---- public static void main(String[] argv) { ! // 37.871667,-122.271667 ! hipfloat mapY = new hipfloat("50617"); ! int zoom = 0; ! ! System.out.println(hipfloat.PI.sub(mapY.div(getZoomFactor(zoom)). ! mul(hipfloat.PI2)).exp().arctan().div(RAD_FACTOR). ! mul(hipfloat.TWO).sub(Y_OFFSET)); ! ! } /** Our 2d array of tiles, first dimension is x, second is y */ *************** *** 796,805 **** /** Size of the tiles (128) */ ! public static final int TILE_WIDTH = 128; public static final hipfloat TILE_WIDTH_FLOAT = new hipfloat(TILE_WIDTH); /** Our drawing offset for our tile set */ ! private int m_offsetX = TILE_WIDTH * 2; ! private int m_offsetY = TILE_WIDTH * 2; --- 826,835 ---- /** Size of the tiles (128) */ ! public static final int TILE_WIDTH = 256; public static final hipfloat TILE_WIDTH_FLOAT = new hipfloat(TILE_WIDTH); /** Our drawing offset for our tile set */ ! private int m_offsetX = TILE_WIDTH; ! private int m_offsetY = TILE_WIDTH; *************** *** 824,828 **** public static final int DISPLAY_ALL = 1; ! public static hipfloat[] zoomFactors = new hipfloat[15]; private boolean m_debug = false; --- 854,858 ---- public static final int DISPLAY_ALL = 1; ! public static hipfloat[] zoomFactors = new hipfloat[18]; private boolean m_debug = false; |