Changeset 32968 in osm for applications/editors/josm/plugins/canvec_helper/src
- Timestamp:
- 2016-09-10T16:45:11+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java
r32483 r32968 1 // License: GPL 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.canvec_helper; 3 3 4 import java.util.ArrayList; 5 import java.util.Enumeration; 6 import java.util.List; 7 import java.util.zip.ZipEntry; 8 import java.util.zip.ZipFile; 9 import java.util.regex.Pattern; 10 import java.util.regex.Matcher; 11 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.Bounds; 14 4 import java.awt.Graphics2D; 15 5 import java.awt.Point; 16 17 import org.openstreetmap.josm.data.coor.LatLon;18 import org.openstreetmap.josm.gui.MapView;19 import org.openstreetmap.josm.io.IllegalDataException;20 import org.openstreetmap.josm.io.CachedFile;21 22 import java.awt.Graphics2D;23 6 import java.awt.Polygon; 24 7 import java.io.File; 25 8 import java.io.IOException; 26 9 import java.io.InputStream; 27 10 import java.util.ArrayList; 11 import java.util.Enumeration; 12 import java.util.List; 13 import java.util.regex.Matcher; 14 import java.util.regex.Pattern; 15 import java.util.zip.ZipEntry; 16 import java.util.zip.ZipFile; 17 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.Bounds; 20 import org.openstreetmap.josm.data.coor.LatLon; 21 import org.openstreetmap.josm.gui.MapView; 22 import org.openstreetmap.josm.io.CachedFile; 23 import org.openstreetmap.josm.io.IllegalDataException; 28 24 import org.openstreetmap.josm.io.OsmImporter; 29 25 import org.openstreetmap.josm.io.OsmImporter.OsmImporterData; … … 34 30 private List<String> subTileIds = new ArrayList<>(); 35 31 private boolean zipScanned = false; 36 32 37 33 private List<CanVecTile> subTiles = new ArrayList<>(); 38 34 private boolean subTilesMade = false; … … 40 36 private List<String> index; 41 37 private int depth; 42 38 43 39 private int corda; 44 40 private int cordc; … … 49 45 String tileid; 50 46 CanVecTile(String tileid, CanvecLayer layer) { 51 String parta, partb,partc,partd;52 parta = tileid.substring(0,3); 47 String parta, partb, partc, partd; 48 parta = tileid.substring(0, 3); 53 49 partb = tileid.substring(3, 4); 54 50 partc = tileid.substring(4, 6); 55 51 partd = tileid.substring(6); 56 int a,c; 52 int a, c; 57 53 a = Integer.parseInt(parta); 58 54 c = Integer.parseInt(partc); 59 realInit(a,partb,c,partd,layer,new ArrayList<String>()); 60 } 61 CanVecTile(int a,String b,int c,String d,CanvecLayer layer, List<String> index) { 62 realInit(a,b,c,d,layer,index); 63 } 64 private void realInit(int a,String b,int c,String d,CanvecLayer layer, List<String> index) { 55 realInit(a, partb, c, partd, layer, new ArrayList<String>()); 56 } 57 58 CanVecTile(int a, String b, int c, String d, CanvecLayer layer, List<String> index) { 59 realInit(a, b, c, d, layer, index); 60 } 61 62 private void realInit(int a, String b, int c, String d, CanvecLayer layer, List<String> index) { 65 63 this.index = index; 66 64 this.layer = layer; … … 81 79 zeroPointLat = 40 + 4 * row; 82 80 zeroPointLon = -56 - 8 * column; 83 81 84 82 // size of each grid 85 83 if (row <= 6) { … … 100 98 if (b.isEmpty()) grid2 = 0; 101 99 else grid2 = b.charAt(0) - 64; 102 int[] rows1 = { 0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3};103 int[] cols1 = { 0, 3,2,1,0, 0,1,2,3, 3,2,1,0, 0,1,2,3};100 int[] rows1 = {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}; 101 int[] cols1 = {0, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3}; 104 102 lat2 = zeroPointLat + (latSpan/4)*rows1[grid2]; 105 103 lon2 = zeroPointLon + (lonSpan/4)*cols1[grid2]; … … 111 109 } 112 110 113 int[] rows3 = { 0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3};111 int[] rows3 = {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}; 114 112 lat2 = lat2 + (latSpan/4)*rows3[c]; 115 int[] cols3 = { 0, 3,2,1,0, 0,1,2,3, 3,2,1,0, 0,1,2,3};113 int[] cols3 = {0, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3}; 116 114 lon2 = lon2 + (lonSpan/4)*cols3[c]; 117 115 … … 121 119 depth = 3; 122 120 } 123 121 124 122 if (!cordd.isEmpty()) { 125 123 depth = 4; … … 153 151 } 154 152 155 bounds = new Bounds(lat2, lon2,lat2+latSpan,lon2+lonSpan);156 if (cordb.isEmpty()) this.tileid = String.format("%03d",corda); 157 else if (cordc == 0) this.tileid = String.format("%03d%s", corda,cordb);158 else if (cordd.isEmpty()) this.tileid = String.format("%03d%s%02d", corda,cordb,cordc);159 else this.tileid = String.format("%03d%s%02d%s", corda,cordb,cordc,cordd);153 bounds = new Bounds(lat2, lon2, lat2+latSpan, lon2+lonSpan); 154 if (cordb.isEmpty()) this.tileid = String.format("%03d", corda); 155 else if (cordc == 0) this.tileid = String.format("%03d%s", corda, cordb); 156 else if (cordd.isEmpty()) this.tileid = String.format("%03d%s%02d", corda, cordb, cordc); 157 else this.tileid = String.format("%03d%s%02d%s", corda, cordb, cordc, cordd); 160 158 valid = true; 161 159 } 160 162 161 boolean isValid() { 163 162 return valid; 164 163 } 164 165 165 String getTileId() { 166 166 return this.tileid; 167 167 } 168 168 169 boolean isVisible(Bounds view) { 169 170 return view.intersects(bounds); 170 171 } 172 171 173 Point[] getCorners(MapView mv) { 172 174 LatLon min = bounds.getMin(); 173 175 LatLon max = bounds.getMax(); 174 LatLon x1 = new LatLon(min.lat(),max.lon()); 175 LatLon x2 = new LatLon(max.lat(),min.lon()); 176 LatLon x1 = new LatLon(min.lat(), max.lon()); 177 LatLon x2 = new LatLon(max.lat(), min.lon()); 176 178 return new Point[] { 177 179 mv.getPoint(min), // south west … … 181 183 }; 182 184 } 185 183 186 public String getDownloadUrl() { 184 return String.format("http://ftp2.cits.rncan.gc.ca/OSM/pub/%1$03d/%2$s/%1$03d%2$s%3$02d.zip",corda,cordb,cordc); 185 } 187 return String.format("http://ftp2.cits.rncan.gc.ca/OSM/pub/%1$03d/%2$s/%1$03d%2$s%3$02d.zip", corda, cordb, cordc); 188 } 189 186 190 private ZipFile openZip() throws IOException { 187 191 File downloadPath = new File(layer.plugin.getPluginDir() + File.separator); … … 192 196 return new ZipFile(tileZip.getFile()); 193 197 } 198 194 199 void downloadSelf() { 195 200 if (zipScanned) return; … … 207 212 subTileIds.add(entry.getName()); 208 213 zipScanned = true; 209 CanVecTile finalTile = new CanVecTile(entry.getName(),layer); 214 CanVecTile finalTile = new CanVecTile(entry.getName(), layer); 210 215 if (finalTile.isValid()) { 211 216 subTiles.add(finalTile); … … 213 218 } 214 219 } 220 215 221 void loadRawOsm() { 216 222 ZipFile zipFile; … … 234 240 } 235 241 } 242 236 243 private void makeSubTiles(int layer) { 237 244 List<String> buffer = new ArrayList<>(); … … 252 259 buffer.add(m.group(0)); 253 260 } else { 254 subTiles.add(new CanVecTile(corda,lastCell, 0,"",this.layer,buffer));261 subTiles.add(new CanVecTile(corda, lastCell, 0, "", this.layer, buffer)); 255 262 buffer = new ArrayList<>(); 256 263 buffer.add(m.group(0)); … … 258 265 lastCell = cell; 259 266 } 260 subTiles.add(new CanVecTile(corda,lastCell, 0,"",this.layer,buffer));267 subTiles.add(new CanVecTile(corda, lastCell, 0, "", this.layer, buffer)); 261 268 break; 262 269 case 2: … … 273 280 buffer.add(m.group(0)); 274 281 } else { 275 subTiles.add(new CanVecTile(corda, cordb,lastCell2,"",this.layer,buffer));282 subTiles.add(new CanVecTile(corda, cordb, lastCell2, "", this.layer, buffer)); 276 283 buffer = new ArrayList<>(); 277 284 buffer.add(m.group(0)); … … 279 286 lastCell2 = cell; 280 287 } 281 if (lastCell2 != -1) subTiles.add(new CanVecTile(corda, cordb,lastCell2,"",this.layer,buffer));288 if (lastCell2 != -1) subTiles.add(new CanVecTile(corda, cordb, lastCell2, "", this.layer, buffer)); 282 289 break; 283 290 } 284 291 subTilesMade = true; 285 292 } 293 286 294 void paint(Graphics2D g, MapView mv, Bounds bounds, int maxZoom) { 287 295 boolean showSubTiles = false; … … 310 318 for (int i = 0; i < subTiles.size(); i++) { 311 319 CanVecTile tile = subTiles.get(i); 312 tile.paint(g, mv,bounds,maxZoom);320 tile.paint(g, mv, bounds, maxZoom); 313 321 } 314 322 } else { 315 323 Point[] corners = getCorners(mv); 316 int[] xs = { 317 int[] ys = { 318 Polygon shape = new Polygon(xs, ys,4);324 int[] xs = {corners[0].x, corners[1].x, corners[2].x, corners[3].x }; 325 int[] ys = {corners[0].y, corners[1].y, corners[2].y, corners[3].y }; 326 Polygon shape = new Polygon(xs, ys, 4); 319 327 g.draw(shape); 320 g.drawString(getTileId(),corners[0].x,corners[0].y); 328 g.drawString(getTileId(), corners[0].x, corners[0].y); 321 329 } 322 330 } -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecHelper.java
r30757 r32968 1 // License: GPL 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.canvec_helper; 3 3 -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecHelperAction.java
r32483 r32968 1 // License: GPL 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.canvec_helper; 3 3 4 import org.openstreetmap.josm.Main; 4 5 import org.openstreetmap.josm.actions.JosmAction; 5 import org.openstreetmap.josm.Main;6 6 7 7 class CanvecHelperAction extends JosmAction { 8 8 private CanvecHelper parentTemp; 9 9 CanvecHelperAction(CanvecHelper parent) { 10 super("CanVec Helper","layericon24", null,null,false);10 super("CanVec Helper", "layericon24", null, null, false); 11 11 parentTemp = parent; 12 12 } … … 14 14 @Override 15 15 public void actionPerformed(java.awt.event.ActionEvent action) { 16 Main.getLayerManager().addLayer(new CanvecLayer("canvec tile helper",parentTemp)); 16 Main.getLayerManager().addLayer(new CanvecLayer("canvec tile helper", parentTemp)); 17 17 } 18 18 } -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecLayer.java
r30757 r32968 1 // License: GPL 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.canvec_helper; 3 3 … … 44 44 List<CanVecTile> openable = new ArrayList<>(); 45 45 46 CanvecLayer(String name, CanvecHelper self){ 46 CanvecLayer(String name, CanvecHelper self) { 47 47 super(name); 48 48 plugin = self; … … 65 65 list.add(m.group(0)); 66 66 } else if (lastCell != -1) { 67 CanVecTile tile = new CanVecTile(lastCell, "",0,"",this,list);67 CanVecTile tile = new CanVecTile(lastCell, "", 0, "", this, list); 68 68 if (tile.isValid()) tiles.add(tile); 69 69 list = new ArrayList<>(); … … 75 75 } 76 76 } 77 CanVecTile tile = new CanVecTile(lastCell, "",0,"",this,list);77 CanVecTile tile = new CanVecTile(lastCell, "", 0, "", this, list); 78 78 if (tile.isValid()) tiles.add(tile); 79 79 … … 87 87 } 88 88 } 89 89 90 @Override 90 91 public Action[] getMenuEntries() { … … 98 99 new OpenOsmAction(this)}; 99 100 } 100 private static class MaxZoomAction extends AbstractAction implements LayerAction { 101 102 private static final class MaxZoomAction extends AbstractAction implements LayerAction { 101 103 private final CanvecLayer parent; 102 104 private MaxZoomAction(CanvecLayer parent) { 103 105 this.parent = parent; 104 106 } 107 105 108 @Override 106 109 public void actionPerformed(ActionEvent e) { 107 110 // Do nothing 108 111 } 112 109 113 @Override 110 114 public boolean supportLayers(List<Layer> layers) { 111 115 return false; 112 116 } 117 113 118 @Override 114 119 public Component createMenuComponent() { 115 120 JMenu maxZoomMenu = new JMenu("max zoom"); 116 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,1))); 117 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,2))); 118 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,3))); 119 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,4))); 121 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent, 1))); 122 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent, 2))); 123 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent, 3))); 124 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent, 4))); 120 125 return maxZoomMenu; 121 126 } 122 127 } 123 private static class AllowDownload extends AbstractAction { 128 129 private static final class AllowDownload extends AbstractAction { 124 130 private final CanVecTile tile; 125 131 private AllowDownload(CanVecTile tile) { … … 127 133 this.tile = tile; 128 134 } 135 129 136 @Override 130 137 public void actionPerformed(ActionEvent arg0) { … … 132 139 } 133 140 } 134 private class OpenOsmAction extends AbstractAction implements LayerAction { 141 142 private final class OpenOsmAction extends AbstractAction implements LayerAction { 135 143 private CanvecLayer layer; 136 144 private OpenOsmAction(CanvecLayer layer) { 137 145 this.layer = layer; 138 146 } 147 139 148 @Override 140 149 public void actionPerformed(ActionEvent e) { 141 150 // Do nothing 142 151 } 152 143 153 @Override 144 154 public Component createMenuComponent() { … … 149 159 return openOsm; 150 160 } 161 151 162 @Override 152 163 public boolean supportLayers(List<Layer> layers) { … … 154 165 } 155 166 } 156 private static class DoOpenOsm extends AbstractAction { 167 168 private static final class DoOpenOsm extends AbstractAction { 157 169 private final CanVecTile tile; 158 170 private DoOpenOsm(CanVecTile tile) { … … 160 172 this.tile = tile; 161 173 } 174 162 175 @Override 163 176 public void actionPerformed(ActionEvent e) { … … 165 178 } 166 179 } 167 private class DownloadCanvecAction extends AbstractAction implements LayerAction { 180 181 private final class DownloadCanvecAction extends AbstractAction implements LayerAction { 168 182 private CanvecLayer parent; 169 183 private DownloadCanvecAction(CanvecLayer parent) { 170 184 this.parent = parent; 171 185 } 186 172 187 @Override 173 188 public void actionPerformed(ActionEvent e) { 174 189 // Do nothing 175 190 } 191 176 192 @Override 177 193 public boolean supportLayers(List<Layer> layers) { 178 194 return false; 179 195 } 196 180 197 @Override 181 198 public Component createMenuComponent() { … … 187 204 } 188 205 } 206 189 207 void setMaxZoom(int maxZoom) { 190 208 this.maxZoom = maxZoom; 191 209 } 210 192 211 @Override 193 212 public Object getInfoComponent() { 194 213 return getToolTipText(); 195 214 } 215 196 216 @Override 197 217 public String getToolTipText() { 198 218 return tr("canvec tile helper"); 199 219 } 220 200 221 @Override 201 222 public void visitBoundingBox(BoundingXYVisitor v) { 202 223 // Do nothing 203 224 } 225 204 226 @Override 205 227 public boolean isMergable(Layer other) { 206 228 return false; 207 229 } 230 208 231 @Override 209 232 public void mergeFrom(Layer from) { 210 233 // Do nothing 211 234 } 235 212 236 @Override 213 237 public Icon getIcon() { 214 238 return layerIcon; 215 239 } 240 216 241 @Override 217 242 public void paint(Graphics2D g, MapView mv, Bounds bounds) { … … 222 247 for (int i = 0; i < tiles.size(); i++) { 223 248 CanVecTile tile = tiles.get(i); 224 tile.paint(g, mv,bounds,maxZoom);249 tile.paint(g, mv, bounds, maxZoom); 225 250 } 226 251 } -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/SetMaxZoom.java
r30757 r32968 1 // License: GPL 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.canvec_helper; 3 3 4 4 import java.awt.event.ActionEvent; 5 5 6 import javax.swing.AbstractAction; 6 7 … … 8 9 private CanvecLayer parent; 9 10 private int level; 10 SetMaxZoom(CanvecLayer parent,int level) { 11 SetMaxZoom(CanvecLayer parent, int level) { 11 12 super(""+level); 12 13 this.level = level; 13 14 this.parent = parent; 14 15 } 16 15 17 @Override 16 18 public void actionPerformed(ActionEvent ev) {
Note:
See TracChangeset
for help on using the changeset viewer.