Changeset 18838 in osm for applications/editors/josm
- Timestamp:
- 2009-11-28T17:05:44+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r18720 r18838 106 106 // till here 107 107 108 if (reply == JOptionPane.OK_OPTION) { 109 return loadCache(file, wmsLayer.getLambertZone()); 110 } else 111 file.delete(); 108 if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) { 109 return true; 110 } else { 111 delete(file); 112 } 112 113 } 113 114 } catch (Exception e) { … … 122 123 if (Main.proj instanceof LambertCC9Zones) 123 124 extension = cLambertCC9Z + extension; 124 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension); 125 if (file.exists()) 126 file.delete(); 125 delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension)); 127 126 } catch (Exception e) { 128 127 e.printStackTrace(System.out); 129 128 } 130 129 } 130 131 private void delete(File file) { 132 System.out.println("Delete file "+file); 133 if (file.exists()) 134 file.delete(); 135 while (file.exists()) // wait until file is really gone (otherwise appends to existing one) 136 CadastrePlugin.safeSleep(500); 137 } 131 138 132 139 public boolean loadCache(File file, int currentLambertZone) { 140 boolean successfulRead = false; 133 141 try { 134 142 FileInputStream fis = new FileInputStream(file); 135 143 ObjectInputStream ois = new ObjectInputStream(fis); 136 if (wmsLayer.read(ois, currentLambertZone) == false) 137 return false; 144 successfulRead = wmsLayer.read(ois, currentLambertZone); 138 145 ois.close(); 139 146 fis.close(); 140 147 } catch (Exception ex) { 141 148 ex.printStackTrace(System.out); 142 JOptionPane.showMessageDialog(Main.parent, tr("Error loading file "), tr("Error"), JOptionPane.ERROR_MESSAGE);149 JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."), tr("Error"), JOptionPane.ERROR_MESSAGE); 143 150 return false; 144 151 } 145 if ( wmsLayer.isRaster()) {152 if (successfulRead && wmsLayer.isRaster()) { 146 153 // serialized raster bufferedImage hangs-up on Java6. Recreate them here 147 154 wmsLayer.images.get(0).image = RasterImageModifier.fixRasterImage(wmsLayer.images.get(0).image); 148 155 } 149 return true;156 return successfulRead; 150 157 } 151 158 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r18544 r18838 182 182 System.out.println("GET "+interfaceURL); 183 183 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 184 // while(in.readLine() != null) {} //read the buffer otherwise we sent POST too early184 // read the buffer otherwise we sent POST too early 185 185 while ((ln = in.readLine()) != null) { 186 186 lines += ln; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r18743 r18838 86 86 * support of subprojections in preferences for zones setting and UTM20N 87 87 * - removed autosourcing of empty new nodes 88 * 1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer (possible since projection rework) 88 89 */ 89 90 public class CadastrePlugin extends Plugin { 90 static String VERSION = "1. 4";91 static String VERSION = "1.6"; 91 92 92 93 static JMenu cadastreJMenu; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
r18544 r18838 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.data.Bounds; 10 import org.openstreetmap.josm.data.projection.LambertCC9Zones;11 10 import org.openstreetmap.josm.gui.MapView; 12 11 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 32 31 try { 33 32 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) { 33 boolean useFactor = true; 34 34 if (wmsLayer.images.isEmpty()) { 35 35 // first time we grab an image for this layer 36 36 if (CacheControl.cacheEnabled) { 37 37 if (wmsLayer.getCacheControl().loadCacheIfExist()) { 38 Main.map.mapView.repaint(); 38 Main.map.mapView.zoomTo(wmsLayer.getCommuneBBox().toBounds()); 39 //Main.map.mapView.repaint(); 39 40 return; 40 41 } … … 46 47 // set vectorized commune bounding box by opening the standard web window 47 48 grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer); 48 // if it is the first layer, use the communeBBox as grab bbox 49 if (Main. proj instanceof LambertCC9Zones && Main.map.mapView.getAllLayers().size() == 1 ) {49 // if it is the first layer, use the communeBBox as grab bbox (and not divided) 50 if (Main.map.mapView.getAllLayers().size() == 1 ) { 50 51 bounds = wmsLayer.getCommuneBBox().toBounds(); 51 52 Main.map.mapView.zoomTo(bounds); 53 useFactor = false; 52 54 } 53 55 } 54 56 } 55 57 // grab new images from wms server into active layer 56 wmsLayer.grab(grabber, bounds );58 wmsLayer.grab(grabber, bounds, useFactor); 57 59 } 58 60 } catch (DuplicateLayerException e) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
r18544 r18838 11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.projection.LambertCC9Zones;14 13 import org.openstreetmap.josm.tools.Shortcut; 15 14 … … 30 29 31 30 public void actionPerformed(ActionEvent e) { 32 // with the new projection LambertCC9Zones, we are able to determin the zone and thus lat/lon of 33 // downloaded commune bounding box 34 if (Main.map != null || Main.proj instanceof LambertCC9Zones) { 31 if (Main.map != null) { 35 32 if (CadastrePlugin.isCadastreProjection()) { 36 33 WMSLayer wmsLayer = WMSDownloadAction.getLayer(); … … 43 40 + "projections and retry")); 44 41 } 45 } 42 } else 43 new MenuActionNewLocation().actionPerformed(e); 46 44 } 47 45 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
r18720 r18838 36 36 37 37 public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) { 38 /*if (Main.map == null) { 39 JOptionPane.showMessageDialog(Main.parent, 40 tr("Open a layer first (GPX, OSM, cache)")); 38 String location = ""; 39 String codeDepartement = ""; 40 String codeCommune = ""; 41 boolean resetCookie = false; 42 JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer")); 43 JPanel p = new JPanel(new GridBagLayout()); 44 JLabel labelLocation = new JLabel(tr("Location")); 45 final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") ); 46 inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>" 47 + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>")); 48 49 p.add(labelSectionNewLocation, GBC.eol()); 50 p.add(labelLocation, GBC.std().insets(10, 0, 0, 0)); 51 p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 52 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) { 53 private static final long serialVersionUID = 1L; 54 55 @Override 56 public void selectInitialValue() { 57 inputTown.requestFocusInWindow(); 58 inputTown.selectAll(); 59 } 60 }; 61 pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true); 62 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 41 63 return null; 42 } else {*/43 String location = "";44 String codeDepartement = "";45 String codeCommune = "";46 boolean resetCookie = false;47 JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));48 JPanel p = new JPanel(new GridBagLayout());49 JLabel labelLocation = new JLabel(tr("Location"));50 final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );51 inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"52 + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));53 64 54 p.add(labelSectionNewLocation, GBC.eol()); 55 p.add(labelLocation, GBC.std().insets(10, 0, 0, 0)); 56 p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 57 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) { 58 private static final long serialVersionUID = 1L; 59 60 @Override 61 public void selectInitialValue() { 62 inputTown.requestFocusInWindow(); 63 inputTown.selectAll(); 64 } 65 }; 66 pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true); 67 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 68 return null; 69 70 WMSLayer wmsLayer = null; 71 if (!inputTown.getText().equals("")) { 72 location = inputTown.getText().toUpperCase(); 73 resetCookie = true; 74 Main.pref.put("cadastrewms.location", location); 75 Main.pref.put("cadastrewms.codeCommune", codeCommune); 76 if (Main.map != null) { 77 for (Layer l : Main.map.mapView.getAllLayers()) { 78 if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) { 79 return null; 80 } 65 WMSLayer wmsLayer = null; 66 if (!inputTown.getText().equals("")) { 67 location = inputTown.getText().toUpperCase(); 68 resetCookie = true; 69 Main.pref.put("cadastrewms.location", location); 70 Main.pref.put("cadastrewms.codeCommune", codeCommune); 71 if (Main.map != null) { 72 for (Layer l : Main.map.mapView.getAllLayers()) { 73 if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) { 74 return null; 81 75 } 82 76 } 83 // add the layer if it doesn't exist84 int zone = -1;85 if (Main.proj instanceof LambertCC9Zones)86 zone = ((LambertCC9Zones)Main.proj).getLayoutZone();87 else if (Main.proj instanceof Lambert)88 zone = ((Lambert)Main.proj).getLayoutZone();89 else if (Main.proj instanceof UTM_20N_France_DOM)90 zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic();91 wmsLayer = new WMSLayer(location, codeCommune, zone);92 Main.main.addLayer(wmsLayer);93 System.out.println("Add new layer with Location:" + inputTown.getText());94 } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) {95 wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer();96 resetCookie = true;97 77 } 78 // add the layer if it doesn't exist 79 int zone = -1; 80 if (Main.proj instanceof LambertCC9Zones) 81 zone = ((LambertCC9Zones)Main.proj).getLayoutZone(); 82 else if (Main.proj instanceof Lambert) 83 zone = ((Lambert)Main.proj).getLayoutZone(); 84 else if (Main.proj instanceof UTM_20N_France_DOM) 85 zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic(); 86 wmsLayer = new WMSLayer(location, codeCommune, zone); 87 Main.main.addLayer(wmsLayer); 88 System.out.println("Add new layer with Location:" + inputTown.getText()); 89 } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) { 90 wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer(); 91 resetCookie = true; 92 } 98 93 99 if (resetCookie) 100 CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName()); 101 return wmsLayer; 102 //} 94 if (resetCookie) 95 CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName()); 96 return wmsLayer; 103 97 } 104 98 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r18720 r18838 100 100 101 101 public void grab(CadastreGrabber grabber, Bounds b) throws IOException { 102 if (isRaster) { 103 b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax)); 104 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", 105 CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER))); 102 grab(grabber, b, true); 103 } 104 105 public void grab(CadastreGrabber grabber, Bounds b, boolean useFactor) throws IOException { 106 if (useFactor) { 107 if (isRaster) { 108 b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax)); 109 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", 110 CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER))); 111 } else 112 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString()))); 106 113 } else 107 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())));114 divideBbox(b, 1); 108 115 109 116 for (EastNorthBound n : dividedBbox) { … … 440 447 } 441 448 } 449 System.out.println("Cache loaded for location "+location+" with "+images.size()+" images"); 442 450 return true; 443 451 }
Note:
See TracChangeset
for help on using the changeset viewer.