Changeset 16290 in osm for applications/editors/josm/plugins/wmsplugin/src
- Timestamp:
- 2009-07-03T12:34:14+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java
r15858 r16290 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data. Bounds;12 import org.openstreetmap.josm.data.coor. LatLon;11 import org.openstreetmap.josm.data.ProjectionBounds; 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 13 import org.openstreetmap.josm.data.projection.Projection; 14 14 import org.openstreetmap.josm.gui.MapView; … … 16 16 17 17 abstract public class Grabber implements Runnable { 18 protected Bounds b;18 protected ProjectionBounds b; 19 19 protected Projection proj; 20 20 protected double pixelPerDegree; … … 24 24 protected CacheFiles cache; 25 25 26 Grabber( Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache)26 Grabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) 27 27 { 28 if (b.min != null && b.max != null && WMSPlugin.doOverlap) 29 { 30 double latCent = (b.min.lat() + b.max.lat()) / 2; 31 double lonCent = (b.min.lon() + b.max.lon()) / 2; 32 33 double latSize = b.max.lat() - b.min.lat(); 34 double lonSize = b.max.lon() - b.min.lon(); 35 36 double latCoef = (100.0 + WMSPlugin.overlapLat) / 100.0 / 2.0; 37 double lonCoef = (100.0 + WMSPlugin.overlapLon) / 100.0 / 2.0; 38 39 this.b = new Bounds( new LatLon(latCent - latCoef * latSize, 40 lonCent - lonCoef * lonSize), 41 new LatLon(latCent + latCoef * latSize, 42 lonCent + lonCoef * lonSize)); 43 } 44 else 45 this.b = b; 46 28 this.b = b; 47 29 this.proj = Main.main.proj; 48 30 this.pixelPerDegree = layer.pixelPerDegree; … … 56 38 57 39 int width(){ 58 return (int) ((b.max. lon() - b.min.lon()) * pixelPerDegree);40 return (int) ((b.max.north() - b.min.north()) * pixelPerDegree); 59 41 } 60 42 int height(){ 61 return (int) ((b.max. lat() - b.min.lat()) * pixelPerDegree);43 return (int) ((b.max.east() - b.min.east()) * pixelPerDegree); 62 44 } 63 45 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java
r15961 r16290 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.data.Bounds; 26 import org.openstreetmap.josm.data.ProjectionBounds; 27 import org.openstreetmap.josm.data.coor.EastNorth; 28 import org.openstreetmap.josm.data.coor.LatLon; 29 import org.openstreetmap.josm.data.projection.Epsg4326; 30 import org.openstreetmap.josm.data.projection.Mercator; 27 31 import org.openstreetmap.josm.gui.MapView; 28 32 import org.openstreetmap.josm.io.CacheFiles; … … 35 39 private final boolean urlWithPatterns; 36 40 37 WMSGrabber( Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {41 WMSGrabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) { 38 42 super(b, image, mv, layer, cache); 39 43 this.baseURL = layer.baseURL; … … 51 55 try { 52 56 url = getURL( 53 b.min. lon(), b.min.lat(),54 b.max. lon(), b.max.lat(),57 b.min.east(), b.min.north(), 58 b.max.east(), b.max.north(), 55 59 width(), height()); 56 60 57 image.min = proj.latlon2eastNorth(b.min);58 image.max = proj.latlon2eastNorth(b.max);61 image.min = b.min; 62 image.max = b.max; 59 63 64 System.out.println(url + " " + b + " " + image.min + " " + image.max); 60 65 if(image.isVisible(mv)) { //don't download, if the image isn't visible already 61 66 image.image = grab(url); … … 73 78 protected URL getURL(double w, double s,double e,double n, 74 79 int wi, int ht) throws MalformedURLException { 80 String proj = Main.proj.toCode(); 81 if(Main.proj instanceof Mercator) // don't use mercator code directly 82 { 83 LatLon sw = Main.proj.eastNorth2latlon(new EastNorth(s, w)); 84 LatLon ne = Main.proj.eastNorth2latlon(new EastNorth(n, e)); 85 proj = "EPSG:4326"; 86 s = sw.lat(); 87 w = sw.lon(); 88 n = ne.lat(); 89 e = ne.lon(); 90 } 91 /* else if(!(Main.proj instanceof Epsg4326)) 92 { 93 EastNorth sw = Main.proj.latlon2eastNorth(new LatLon(s, w)); 94 EastNorth ne = Main.proj.latlon2eastNorth(new LatLon(n, e)); 95 s = sw.north(); 96 w = sw.east(); 97 n = ne.north(); 98 e = ne.east(); 99 } 100 */ 75 101 String str = baseURL; 76 102 String bbox = latLonFormat.format(w) + "," … … 80 106 81 107 if (urlWithPatterns) { 82 String proj = Main.proj.toCode();83 if(Main.proj instanceof org.openstreetmap.josm.data.projection.Mercator) // don't use mercator code directly84 proj = "EPSG:4326";85 86 108 str = MessageFormat.format(str, proj, bbox, wi, ht); 87 109 } else { … … 99 121 { 100 122 String projname = Main.proj.toCode(); 101 if(Main.proj instanceof org.openstreetmap.josm.data.projection.Mercator) // don't use mercator code123 if(Main.proj instanceof Mercator) // don't use mercator code 102 124 projname = "EPSG:4326"; 103 125 String res = ""; -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r15858 r16290 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.actions.DiskAccessAction; 28 import org.openstreetmap.josm.data. Bounds;28 import org.openstreetmap.josm.data.ProjectionBounds; 29 29 import org.openstreetmap.josm.data.coor.EastNorth; 30 30 import org.openstreetmap.josm.data.coor.LatLon; … … 79 79 WMSGrabber.getProjection(baseURL, true); 80 80 mv = Main.map.mapView; 81 getPPD();81 pixelPerDegree = getPPD(); 82 82 83 83 executor = Executors.newFixedThreadPool(3); … … 92 92 } 93 93 94 public void getPPD(){ 95 pixelPerDegree = mv.getWidth() / (bounds().max.lon() - bounds().min.lon()); 94 public double getPPD(){ 95 ProjectionBounds bounds = mv.getProjectionBounds(); 96 return mv.getWidth() / (bounds.max.east() - bounds.min.east()); 96 97 } 97 98 … … 128 129 } 129 130 130 private Bounds XYtoBounds (int x, int y) {131 return new Bounds(132 new LatLon( x * ImageSize / pixelPerDegree, y * ImageSize / pixelPerDegree),133 new LatLon((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree));131 private ProjectionBounds XYtoBounds (int x, int y) { 132 return new ProjectionBounds( 133 new EastNorth( x * ImageSize / pixelPerDegree, y * ImageSize / pixelPerDegree), 134 new EastNorth((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree)); 134 135 } 135 136 … … 138 139 } 139 140 140 protected Bounds bounds(){141 return new Bounds(142 mv.getLatLon(0, mv.getHeight()),143 mv.getLatLon(mv.getWidth(), 0));144 }145 146 141 @Override public void paint(Graphics g, final MapView mv) { 147 142 if(baseURL == null) return; 148 143 149 if( !startstop.isSelected() || (pixelPerDegree / (mv.getWidth() / (bounds().max.lon() - bounds().min.lon())) > minZoom) ){ //don't download when it's too outzoomed144 if( !startstop.isSelected() || (pixelPerDegree / getPPD() > minZoom) ){ //don't download when it's too outzoomed 150 145 for(int x = 0; x<dax; ++x) 151 146 for(int y = 0; y<day; ++y) … … 161 156 162 157 protected void downloadAndPaintVisible(Graphics g, final MapView mv){ 163 int bminx= (int)Math.floor ((bounds().min.lat() * pixelPerDegree ) / ImageSize ); 164 int bminy= (int)Math.floor ((bounds().min.lon() * pixelPerDegree ) / ImageSize ); 165 int bmaxx= (int)Math.ceil ((bounds().max.lat() * pixelPerDegree ) / ImageSize ); 166 int bmaxy= (int)Math.ceil ((bounds().max.lon() * pixelPerDegree ) / ImageSize ); 158 ProjectionBounds bounds = mv.getProjectionBounds(); 159 int bminx= (int)Math.floor ((bounds.min.east() * pixelPerDegree ) / ImageSize ); 160 int bminy= (int)Math.floor ((bounds.min.north() * pixelPerDegree ) / ImageSize ); 161 int bmaxx= (int)Math.ceil ((bounds.max.east() * pixelPerDegree ) / ImageSize ); 162 int bmaxy= (int)Math.ceil ((bounds.max.north() * pixelPerDegree ) / ImageSize ); 167 163 168 164 if((bmaxx - bminx > dax) || (bmaxy - bminy > day)){ … … 241 237 initializeImages(); 242 238 resolution = scale(); 243 getPPD();239 pixelPerDegree = getPPD(); 244 240 mv.repaint(); 245 241 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
r15858 r16290 25 25 import org.openstreetmap.josm.Main; 26 26 import org.openstreetmap.josm.actions.JosmAction; 27 import org.openstreetmap.josm.data. Bounds;27 import org.openstreetmap.josm.data.ProjectionBounds; 28 28 import org.openstreetmap.josm.gui.IconToggleButton; 29 29 import org.openstreetmap.josm.gui.MainMenu; … … 43 43 static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>(); 44 44 static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>(); 45 46 static boolean doOverlap = false;47 static int overlapLat = 4;48 static int overlapLon = 14;49 45 50 46 // remember state of menu item to restore on changed preferences … … 89 85 90 86 TreeSet<String> keys = new TreeSet<String>(prefs.keySet()); 91 92 // Here we load the settings for "overlap" checkbox and spinboxes.93 94 try {95 doOverlap = Boolean.valueOf(prefs.get("wmsplugin.url.overlap"));96 } catch (Exception e) {} // If sth fails, we drop to default settings.97 98 try {99 overlapLat = Integer.valueOf(prefs.get("wmsplugin.url.overlapLat"));100 } catch (Exception e) {} // If sth fails, we drop to default settings.101 102 try {103 overlapLon = Integer.valueOf(prefs.get("wmsplugin.url.overlapLon"));104 } catch (Exception e) {} // If sth fails, we drop to default settings.105 87 106 88 // And then the names+urls of WMS servers … … 207 189 } 208 190 209 // baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this 210 // Grabber gr = WMSPlugin.getGrabber(XYtoBounds(x,y), img, mv, this); 211 public static Grabber getGrabber(Bounds bounds, GeorefImage img, MapView mv, WMSLayer layer){ 191 public static Grabber getGrabber(ProjectionBounds bounds, GeorefImage img, MapView mv, WMSLayer layer){ 212 192 if(layer.baseURL.startsWith("yahoo://")) 213 193 return new YAHOOGrabber(bounds, img, mv, layer, cache); 214 194 else 215 195 return new WMSGrabber(bounds, img, mv, layer, cache); 216 217 // OSBGrabber should be rewrite for thread support first218 //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") )219 // return new OSGBGrabber(_b, _proj, _pixelPerDegree, _images, _mv, _layer);220 196 } 221 197 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java
r15940 r16290 33 33 private DefaultTableModel model; 34 34 private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>(); 35 36 JCheckBox overlapCheckBox;37 JSpinner spinLat;38 JSpinner spinLon;39 35 40 36 public void addGui(final PreferenceDialog gui) { … … 117 113 p.add(buttonPanel); 118 114 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 119 120 overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap );121 JLabel labelLat = new JLabel(tr("% of lat:"));122 JLabel labelLon = new JLabel(tr("% of lon:"));123 spinLat = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLat, 1, 50, 1));124 spinLon = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLon, 1, 50, 1));125 126 JPanel overlapPanel = new JPanel(new FlowLayout());127 overlapPanel.add(overlapCheckBox);128 overlapPanel.add(labelLat);129 overlapPanel.add(spinLat);130 overlapPanel.add(labelLon);131 overlapPanel.add(spinLon);132 133 p.add(overlapPanel);134 115 } 135 116 … … 170 151 171 152 if (change) WMSPlugin.refreshMenu(); 172 173 WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();174 WMSPlugin.overlapLat = (Integer) spinLat.getModel().getValue();175 WMSPlugin.overlapLon = (Integer) spinLon.getModel().getValue();176 177 Main.pref.put("wmsplugin.url.overlap", String.valueOf(WMSPlugin.doOverlap));178 Main.pref.put("wmsplugin.url.overlapLat", String.valueOf(WMSPlugin.overlapLat));179 Main.pref.put("wmsplugin.url.overlapLon", String.valueOf(WMSPlugin.overlapLon));180 153 181 154 return false; -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/YAHOOGrabber.java
r15890 r16290 10 10 import javax.imageio.ImageIO; 11 11 12 import org.openstreetmap.josm.data. Bounds;12 import org.openstreetmap.josm.data.ProjectionBounds; 13 13 import org.openstreetmap.josm.gui.MapView; 14 14 import org.openstreetmap.josm.io.CacheFiles; … … 18 18 protected String browserCmd; 19 19 20 YAHOOGrabber( Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {20 YAHOOGrabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) { 21 21 super(b, image, mv, layer, cache); 22 22 this.baseURL = "file:///" + WMSPlugin.getPrefsPath() + "ymap.html?";
Note:
See TracChangeset
for help on using the changeset viewer.