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 27949)
+++ /applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java	(revision 27950)
@@ -4,5 +4,4 @@
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 import java.util.regex.Pattern;
@@ -24,5 +23,6 @@
 
 public class CanVecTile {
-	canvec_helper plugin_self;
+	canvec_layer layer;
+	public boolean can_download = false;
 	private ArrayList<String> sub_tile_ids = new ArrayList<String>();
 	private boolean zip_scanned = false;
@@ -38,6 +38,6 @@
 	String cordb,cordd;
 	private Bounds bounds;
-	private String tileid;
-	public CanVecTile(String tileid,canvec_helper self) {
+	public String tileid;
+	public CanVecTile(String tileid,canvec_layer layer) {
 		String parta,partb,partc,partd;
 		parta = tileid.substring(0,3);
@@ -48,12 +48,12 @@
 		a = Integer.parseInt(parta);
 		c = Integer.parseInt(partc);
-		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) {
+		real_init(a,partb,c,partd,layer,new ArrayList<String>());
+	}
+	public CanVecTile(int a,String b,int c,String d,canvec_layer layer,ArrayList<String> index) {
+		real_init(a,b,c,d,layer,index);
+	}
+	public void real_init(int a,String b,int c,String d,canvec_layer layer, ArrayList<String> index) {
 		this.index = index;
-		plugin_self = self;
+		this.layer = layer;
 		corda = a;
 		cordb = b;
@@ -181,5 +181,5 @@
 	}
 	private ZipFile open_zip() throws IOException {
-		File download_path = new File(plugin_self.getPluginDir() + File.separator);
+		File download_path = new File(layer.plugin_self.getPluginDir() + File.separator);
 		download_path.mkdir();
 		MirroredInputStream tile_zip;
@@ -201,9 +201,9 @@
 			sub_tile_ids.add(entry.getName());
 			zip_scanned = true;
-			CanVecTile final_tile = new CanVecTile(entry.getName(),plugin_self);
+			CanVecTile final_tile = new CanVecTile(entry.getName(),layer);
 			if (final_tile.isValid()) sub_tiles.add(final_tile);
 		}
 	}
-	private void load_raw_osm() {
+	public void load_raw_osm() {
 		ZipFile zipFile;
 		try {
@@ -212,9 +212,9 @@
 			while (entries.hasMoreElements()) {
 				ZipEntry entry = entries.nextElement();
-				System.out.println(entry.getName());
-				if (false) {
+				if (tileid.equals(entry.getName())) {
+					debug("found myself!");
 					InputStream rawtile = zipFile.getInputStream(entry);
 					OsmImporter importer = new OsmImporter();
-					System.out.println("loading raw osm");
+					debug("loading raw osm");
 					OsmImporterData temp = importer.loadLayer(rawtile, null, entry.getName(), null);
 					Main.worker.submit(temp.getPostLayerTask());
@@ -248,5 +248,5 @@
 					buffer.add(m.group(0));
 				} else {
-					sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer));
+					sub_tiles.add(new CanVecTile(corda,last_cell,0,"",this.layer,buffer));
 					buffer = new ArrayList<String>();
 					buffer.add(m.group(0));
@@ -254,5 +254,5 @@
 				last_cell = cell;
 			}
-			sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer));
+			sub_tiles.add(new CanVecTile(corda,last_cell,0,"",this.layer,buffer));
 			break;
 		case 2:
@@ -269,5 +269,5 @@
 					buffer.add(m.group(0));
 				} else {
-					sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",plugin_self,buffer));
+					sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",this.layer,buffer));
 					buffer = new ArrayList<String>();
 					buffer.add(m.group(0));
@@ -275,5 +275,5 @@
 				last_cell2 = cell;
 			}
-			if (last_cell2 != -1) sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",plugin_self,buffer));
+			if (last_cell2 != -1) sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",this.layer,buffer));
 			break;
 		}
@@ -283,7 +283,16 @@
 		boolean show_sub_tiles = false;
 		if (!isVisible(bounds)) return;
+		if (depth == 4) {
+			layer.openable.add(this);
+		}
 		if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01
-			if (max_zoom == 4) downloadSelf();
-			show_sub_tiles = true;
+			if (zip_scanned) {
+				show_sub_tiles = true;
+			} else if (can_download) {
+				downloadSelf();
+				show_sub_tiles = true;
+			} else {
+				layer.downloadable.add(this);
+			}
 		} else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile
 			make_sub_tiles(2);
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 27949)
+++ /applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java	(revision 27950)
@@ -1,18 +1,20 @@
 package org.openstreetmap.josm.plugins.canvec_helper;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-import org.openstreetmap.josm.gui.layer.Layer;
+import java.awt.Color;
 import java.awt.Component;
-import java.awt.Graphics2D;
 import java.awt.event.ActionEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
+import java.awt.Graphics2D;
 import java.awt.Point;
-import java.awt.Color;
 import java.awt.Toolkit;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.io.IOException;
-
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipException;
 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -21,23 +23,22 @@
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import org.openstreetmap.josm.actions.RenameLayerAction;
+//import org.openstreetmap.josm.actions.RenameLayerAction;
 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;
+import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.MapView;
-import java.util.ArrayList;
-import java.util.zip.ZipException;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-import java.util.List;
+import org.openstreetmap.josm.io.MirroredInputStream;
+import static org.openstreetmap.josm.tools.I18n.tr;
 
 // most of the layout was copied from the openstreetbugs plugin to get things started
 public class canvec_layer extends Layer implements MouseListener {
 	private Icon layerIcon = null;
-	private int max_zoom = 3;
-	canvec_helper plugin_self;
+	private int max_zoom = 4;
+	public canvec_helper plugin_self;
 	private ArrayList<CanVecTile> tiles = new ArrayList<CanVecTile>();
+	public ArrayList<CanVecTile> downloadable = new ArrayList<CanVecTile>();
+	public ArrayList<CanVecTile> openable = new ArrayList<CanVecTile>();
 
 	public canvec_layer(String name,canvec_helper self){
@@ -65,5 +66,5 @@
 						list.add(m.group(0));
 					} else if (last_cell != -1) {
-						CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
+						CanVecTile tile = new CanVecTile(last_cell,"",0,"",this,list);
 						if (tile.isValid()) tiles.add(tile);
 						list = new ArrayList<String>();
@@ -73,5 +74,5 @@
 				} else System.out.print("bad line '" + line + "'\n");
 			}
-			CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
+			CanVecTile tile = new CanVecTile(last_cell,"",0,"",this,list);
 			if (tile.isValid()) tiles.add(tile);
 
@@ -88,5 +89,7 @@
 			SeparatorLayerAction.INSTANCE,
 			new LayerListPopup.InfoAction(this),
-			new MaxZoomAction(this)};
+			new MaxZoomAction(this),
+			new DownloadCanvecAction(this),
+			new OpenOsmAction(this)};
 	}
 	public class MaxZoomAction extends AbstractAction implements LayerAction {
@@ -108,4 +111,58 @@
 		}
 	}
+	private class AllowDownload extends AbstractAction {
+		CanVecTile tile;
+		public AllowDownload(CanVecTile tile) {
+			super(tile.tileid);
+			this.tile = tile;
+		}
+		public void actionPerformed(ActionEvent arg0) {
+			tile.can_download = true;
+		}
+	}
+	private class OpenOsmAction extends AbstractAction implements LayerAction {
+		private canvec_layer layer;
+		public OpenOsmAction(canvec_layer layer) {
+			this.layer = layer;
+		}
+		public void actionPerformed(ActionEvent e) {}
+		public Component createMenuComponent() {
+			JMenu OpenOsm = new JMenu("Open tile");
+			for (int i = 0; i < layer.openable.size(); i++) {
+				OpenOsm.add(new JMenuItem(new DoOpenOsm(layer.openable.get(i))));
+			}
+			return OpenOsm;
+		}
+		public boolean supportLayers(List<Layer> layers) {
+			return false;
+		}
+	}
+	private class DoOpenOsm extends AbstractAction {
+		CanVecTile tile;
+		public DoOpenOsm(CanVecTile tile) {
+			super(tile.tileid);
+			this.tile = tile;
+		}
+		public void actionPerformed(ActionEvent e) {
+			tile.load_raw_osm();
+		}
+	}
+	private class DownloadCanvecAction extends AbstractAction implements LayerAction {
+		private canvec_layer parent;
+		public DownloadCanvecAction(canvec_layer parent) {
+			this.parent = parent;
+		}
+		public void actionPerformed(ActionEvent e) {}
+		public boolean supportLayers(List<Layer> layers) {
+			return false;
+		}
+		public Component createMenuComponent() {
+			JMenu downloadCanvec = new JMenu("Download zip's");
+			for (int i = 0; i < parent.downloadable.size(); i++) {
+				downloadCanvec.add(new JMenuItem(new AllowDownload(parent.downloadable.get(i))));
+			}
+			return downloadCanvec;
+		}
+	}
 	public void setMaxZoom(int max_zoom) {
 		this.max_zoom = max_zoom;
@@ -124,6 +181,8 @@
 	public Icon getIcon() { return layerIcon; }
 	public void paint(Graphics2D g, MapView mv, Bounds bounds) {
-		long start = System.currentTimeMillis();
+		//long start = System.currentTimeMillis();
 		//System.out.println("painting the area covered by "+bounds.toString());
+		downloadable = new ArrayList<CanVecTile>();
+		openable = new ArrayList<CanVecTile>();
 		// loop over each canvec tile in the db and check bounds.intersects(Bounds)
 		g.setColor(Color.red);
