Index: applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java
===================================================================
--- applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java	(revision 27920)
+++ applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java	(revision 27924)
@@ -6,4 +6,6 @@
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
@@ -28,4 +30,7 @@
 	private ArrayList<CanVecTile> sub_tiles = new ArrayList<CanVecTile>();
 	private boolean sub_tiles_made = false;
+
+	private ArrayList<String> index;
+	private int depth;
 	
 	int corda,cordc;
@@ -43,10 +48,11 @@
 		a = Integer.parseInt(parta);
 		c = Integer.parseInt(partc);
-		real_init(a,partb,c,partd,self);
-	}
-	public CanVecTile(int a,String b,int c,String d,canvec_helper self) {
-		real_init(a,b,c,d,self);
-	}
-	public void real_init(int a,String b,int c,String d,canvec_helper self) {
+		real_init(a,partb,c,partd,self,new ArrayList<String>());
+	}
+	public CanVecTile(int a,String b,int c,String d,canvec_helper self,ArrayList<String> index) {
+		real_init(a,b,c,d,self,index);
+	}
+	public void real_init(int a,String b,int c,String d,canvec_helper self, ArrayList<String> index) {
+		this.index = index;
 		plugin_self = self;
 		corda = a;
@@ -72,4 +78,5 @@
 				lat_span = 4;
 				lon_span = 8;
+				depth = 1;
 			} else {
 				return;
@@ -92,4 +99,5 @@
 			lat_span = lat_span / 4;
 			lon_span = lon_span / 4;
+			depth = 2;
 		}
 
@@ -102,7 +110,9 @@
 			lat_span = lat_span / 4;
 			lon_span = lon_span / 4;
+			depth = 3;
 		}
 		
 		if (cordd != "") {
+			depth = 4;
 			System.out.println("cordd: "+cordd);
 			String foo[] = cordd.split("\\.");
@@ -142,9 +152,12 @@
 		else this.tileid = String.format("%03d%s%02d%s",corda,cordb,cordc,cordd);
 		valid = true;
-		System.out.println(this.tileid);
+		debug("creating tileid: "+this.tileid);
 	}
 	public boolean isValid() { return valid; }
 	public String getTileId() {
 		return this.tileid;
+	}
+	private void debug(String line) {
+		System.out.println(depth + "_" + tileid + ": " + line);
 	}
 	public boolean isVisible(Bounds view) {
@@ -220,12 +233,35 @@
 		switch (layer) {
 		case 1:
-			for (int i = 1; i < 17; i++) {
-				char temp[] = { (char) (64 + i) };
-				sub_tiles.add(new CanVecTile(corda,new String(temp),0,"",plugin_self));
-			}
+			ArrayList<String> buffer = new ArrayList<String>();
+			Pattern p = Pattern.compile("\\d\\d\\d([A-Z])(.*)");
+			String last_cell = "";
+//			for (int i = 1; i < 17; i++) {
+			for (int i = 0; i < index.size(); i++) {
+				debug(index.get(i));
+				Matcher m = p.matcher(index.get(i));
+				m.matches();
+
+				String cell = m.group(1);
+				debug("a " + cell + last_cell);
+				if (cell.equals(last_cell)) {
+					buffer.add(m.group(0));
+				} else if (last_cell == "") {
+				} else {
+				//char temp[] = { (char) (64 + i) };
+					debug("b "+corda+" "+last_cell);
+					debug(buffer.toString());
+					sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer));
+					buffer = new ArrayList<String>();
+					buffer.add(m.group(0));
+				}
+				last_cell = cell;
+			}
+			debug("c "+corda+" "+last_cell);
+			debug(buffer.toString());
+			sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer));
 			break;
 		case 2:
 			for (int i = 1; i < 17; i++) {
-				sub_tiles.add(new CanVecTile(corda,cordb,i,"",plugin_self));
+				sub_tiles.add(new CanVecTile(corda,cordb,i,"",plugin_self,new ArrayList<String>())); // FIXME
 			}
 			break;
@@ -236,12 +272,12 @@
 		boolean show_sub_tiles = false;
 		if (!isVisible(bounds)) return;
-		if ((cordb != "") && (cordc > 0) && (cordd == "") && (bounds.getArea() < 0.5)) { // 022B01
+		if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01
 			downloadSelf();
-			System.out.println(sub_tile_ids.toString());
+			debug(sub_tile_ids.toString());
 			show_sub_tiles = true;
-		} else if ((cordc == 0) && (bounds.getArea() < 20)) { // its a layer2 tile
+		} else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile
 			make_sub_tiles(2);
 			show_sub_tiles = true;
-		} else if ((cordb == "") && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small
+		} else if ((depth == 1) && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small
 			// draw layer2 tiles for self
 			make_sub_tiles(1);
Index: applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java
===================================================================
--- applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java	(revision 27920)
+++ applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java	(revision 27924)
@@ -9,4 +9,6 @@
 import java.awt.Color;
 import java.awt.Toolkit;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.io.IOException;
 
@@ -17,4 +19,5 @@
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
+import org.openstreetmap.josm.io.MirroredInputStream;
 import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
 import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
@@ -22,4 +25,6 @@
 import java.util.ArrayList;
 import java.util.zip.ZipException;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 // most of the layout was copied from the openstreetbugs plugin to get things started
@@ -33,9 +38,40 @@
 		plugin_self = self;
 		this.setBackgroundLayer(true);
-		for (int i = 0; i < 119; i++) {
+/*		for (int i = 0; i < 119; i++) {
 			CanVecTile tile = new CanVecTile(i,"",0,"",plugin_self);
 			if (tile.isValid()) tiles.add(tile);
+		}*/
+		layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png")));
+		try {
+			long start = System.currentTimeMillis();
+			Pattern p = Pattern.compile("(\\d\\d\\d)([A-Z]\\d\\d).*");
+			MirroredInputStream index = new MirroredInputStream("http://ftp2.cits.rncan.gc.ca/osm/pub/ZippedOsm.txt");
+			BufferedReader br = new BufferedReader(new InputStreamReader(index));
+			String line;
+			int last_cell = -1;
+			ArrayList<String> list = new ArrayList<String>();
+			while ((line = br.readLine()) != null) {
+				Matcher m = p.matcher(line);
+				if (m.find()) {
+					int cell = Integer.parseInt(m.group(1));
+					if (cell == last_cell) {
+						list.add(m.group(0));
+					} else if (last_cell != -1) {
+						CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
+						if (tile.isValid()) tiles.add(tile);
+						list = new ArrayList<String>();
+						list.add(m.group(0));
+					}
+					last_cell = cell;
+				} else System.out.print("bad line '" + line + "'\n");
+			}
+			CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
+			if (tile.isValid()) tiles.add(tile);
+
+			long end = System.currentTimeMillis();
+			System.out.println((end-start)+"ms spent");
+		} catch (IOException e) {
+			System.out.println("exception getting index");
 		}
-		layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png")));
 	}
 	public Action[] getMenuEntries() {
@@ -60,5 +96,5 @@
 	public void paint(Graphics2D g, MapView mv, Bounds bounds) {
 		long start = System.currentTimeMillis();
-		System.out.println("painting the area covered by "+bounds.toString());
+		//System.out.println("painting the area covered by "+bounds.toString());
 		// loop over each canvec tile in the db and check bounds.intersects(Bounds)
 		g.setColor(Color.red);
@@ -68,5 +104,5 @@
 		}
 		long end = System.currentTimeMillis();
-		System.out.println((end-start)+"ms spent");
+		//System.out.println((end-start)+"ms spent");
 	}
 	public void mouseExited(MouseEvent e) {}
