Changeset 27924 in osm
- Timestamp:
- 2012-02-23T00:20:31+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java
r27915 r27924 6 6 import java.util.zip.ZipException; 7 7 import java.util.zip.ZipFile; 8 import java.util.regex.Pattern; 9 import java.util.regex.Matcher; 8 10 import org.openstreetmap.josm.Main; 9 11 import org.openstreetmap.josm.data.Bounds; … … 28 30 private ArrayList<CanVecTile> sub_tiles = new ArrayList<CanVecTile>(); 29 31 private boolean sub_tiles_made = false; 32 33 private ArrayList<String> index; 34 private int depth; 30 35 31 36 int corda,cordc; … … 43 48 a = Integer.parseInt(parta); 44 49 c = Integer.parseInt(partc); 45 real_init(a,partb,c,partd,self); 46 } 47 public CanVecTile(int a,String b,int c,String d,canvec_helper self) { 48 real_init(a,b,c,d,self); 49 } 50 public void real_init(int a,String b,int c,String d,canvec_helper self) { 50 real_init(a,partb,c,partd,self,new ArrayList<String>()); 51 } 52 public CanVecTile(int a,String b,int c,String d,canvec_helper self,ArrayList<String> index) { 53 real_init(a,b,c,d,self,index); 54 } 55 public void real_init(int a,String b,int c,String d,canvec_helper self, ArrayList<String> index) { 56 this.index = index; 51 57 plugin_self = self; 52 58 corda = a; … … 72 78 lat_span = 4; 73 79 lon_span = 8; 80 depth = 1; 74 81 } else { 75 82 return; … … 92 99 lat_span = lat_span / 4; 93 100 lon_span = lon_span / 4; 101 depth = 2; 94 102 } 95 103 … … 102 110 lat_span = lat_span / 4; 103 111 lon_span = lon_span / 4; 112 depth = 3; 104 113 } 105 114 106 115 if (cordd != "") { 116 depth = 4; 107 117 System.out.println("cordd: "+cordd); 108 118 String foo[] = cordd.split("\\."); … … 142 152 else this.tileid = String.format("%03d%s%02d%s",corda,cordb,cordc,cordd); 143 153 valid = true; 144 System.out.println(this.tileid);154 debug("creating tileid: "+this.tileid); 145 155 } 146 156 public boolean isValid() { return valid; } 147 157 public String getTileId() { 148 158 return this.tileid; 159 } 160 private void debug(String line) { 161 System.out.println(depth + "_" + tileid + ": " + line); 149 162 } 150 163 public boolean isVisible(Bounds view) { … … 220 233 switch (layer) { 221 234 case 1: 222 for (int i = 1; i < 17; i++) { 223 char temp[] = { (char) (64 + i) }; 224 sub_tiles.add(new CanVecTile(corda,new String(temp),0,"",plugin_self)); 225 } 235 ArrayList<String> buffer = new ArrayList<String>(); 236 Pattern p = Pattern.compile("\\d\\d\\d([A-Z])(.*)"); 237 String last_cell = ""; 238 // for (int i = 1; i < 17; i++) { 239 for (int i = 0; i < index.size(); i++) { 240 debug(index.get(i)); 241 Matcher m = p.matcher(index.get(i)); 242 m.matches(); 243 244 String cell = m.group(1); 245 debug("a " + cell + last_cell); 246 if (cell.equals(last_cell)) { 247 buffer.add(m.group(0)); 248 } else if (last_cell == "") { 249 } else { 250 //char temp[] = { (char) (64 + i) }; 251 debug("b "+corda+" "+last_cell); 252 debug(buffer.toString()); 253 sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer)); 254 buffer = new ArrayList<String>(); 255 buffer.add(m.group(0)); 256 } 257 last_cell = cell; 258 } 259 debug("c "+corda+" "+last_cell); 260 debug(buffer.toString()); 261 sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer)); 226 262 break; 227 263 case 2: 228 264 for (int i = 1; i < 17; i++) { 229 sub_tiles.add(new CanVecTile(corda,cordb,i,"",plugin_self ));265 sub_tiles.add(new CanVecTile(corda,cordb,i,"",plugin_self,new ArrayList<String>())); // FIXME 230 266 } 231 267 break; … … 236 272 boolean show_sub_tiles = false; 237 273 if (!isVisible(bounds)) return; 238 if (( cordb != "") && (cordc > 0) && (cordd == "") && (bounds.getArea() < 0.5)) { // 022B01274 if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01 239 275 downloadSelf(); 240 System.out.println(sub_tile_ids.toString());276 debug(sub_tile_ids.toString()); 241 277 show_sub_tiles = true; 242 } else if (( cordc == 0) && (bounds.getArea() < 20)) { // its a layer2 tile278 } else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile 243 279 make_sub_tiles(2); 244 280 show_sub_tiles = true; 245 } else if (( cordb == "") && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small281 } else if ((depth == 1) && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small 246 282 // draw layer2 tiles for self 247 283 make_sub_tiles(1); -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java
r27920 r27924 9 9 import java.awt.Color; 10 10 import java.awt.Toolkit; 11 import java.io.BufferedReader; 12 import java.io.InputStreamReader; 11 13 import java.io.IOException; 12 14 … … 17 19 import org.openstreetmap.josm.data.Bounds; 18 20 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 21 import org.openstreetmap.josm.io.MirroredInputStream; 19 22 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 20 23 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 22 25 import java.util.ArrayList; 23 26 import java.util.zip.ZipException; 27 import java.util.regex.Pattern; 28 import java.util.regex.Matcher; 24 29 25 30 // most of the layout was copied from the openstreetbugs plugin to get things started … … 33 38 plugin_self = self; 34 39 this.setBackgroundLayer(true); 35 for (int i = 0; i < 119; i++) {40 /* for (int i = 0; i < 119; i++) { 36 41 CanVecTile tile = new CanVecTile(i,"",0,"",plugin_self); 37 42 if (tile.isValid()) tiles.add(tile); 43 }*/ 44 layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png"))); 45 try { 46 long start = System.currentTimeMillis(); 47 Pattern p = Pattern.compile("(\\d\\d\\d)([A-Z]\\d\\d).*"); 48 MirroredInputStream index = new MirroredInputStream("http://ftp2.cits.rncan.gc.ca/osm/pub/ZippedOsm.txt"); 49 BufferedReader br = new BufferedReader(new InputStreamReader(index)); 50 String line; 51 int last_cell = -1; 52 ArrayList<String> list = new ArrayList<String>(); 53 while ((line = br.readLine()) != null) { 54 Matcher m = p.matcher(line); 55 if (m.find()) { 56 int cell = Integer.parseInt(m.group(1)); 57 if (cell == last_cell) { 58 list.add(m.group(0)); 59 } else if (last_cell != -1) { 60 CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list); 61 if (tile.isValid()) tiles.add(tile); 62 list = new ArrayList<String>(); 63 list.add(m.group(0)); 64 } 65 last_cell = cell; 66 } else System.out.print("bad line '" + line + "'\n"); 67 } 68 CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list); 69 if (tile.isValid()) tiles.add(tile); 70 71 long end = System.currentTimeMillis(); 72 System.out.println((end-start)+"ms spent"); 73 } catch (IOException e) { 74 System.out.println("exception getting index"); 38 75 } 39 layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png")));40 76 } 41 77 public Action[] getMenuEntries() { … … 60 96 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 61 97 long start = System.currentTimeMillis(); 62 System.out.println("painting the area covered by "+bounds.toString());98 //System.out.println("painting the area covered by "+bounds.toString()); 63 99 // loop over each canvec tile in the db and check bounds.intersects(Bounds) 64 100 g.setColor(Color.red); … … 68 104 } 69 105 long end = System.currentTimeMillis(); 70 System.out.println((end-start)+"ms spent");106 //System.out.println((end-start)+"ms spent"); 71 107 } 72 108 public void mouseExited(MouseEvent e) {}
Note:
See TracChangeset
for help on using the changeset viewer.