Changeset 16294 in osm for applications/editors/josm
- Timestamp:
 - 2009-07-03T23:35:00+02:00 (16 years ago)
 - Location:
 - applications/editors/josm/plugins
 - Files:
 - 
      
- 27 edited
 
- 
          
  agpifoj/build.xml (modified) (1 diff)
 - 
          
  agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojLayer.java (modified) (6 diffs)
 - 
          
  agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/CorrelateGpxWithImages.java (modified) (7 diffs)
 - 
          
  editgpx/build.xml (modified) (1 diff)
 - 
          
  editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java (modified) (3 diffs)
 - 
          
  editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java (modified) (1 diff)
 - 
          
  editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java (modified) (1 diff)
 - 
          
  grid/build.xml (modified) (1 diff)
 - 
          
  grid/src/grid/GridLayer.java (modified) (3 diffs)
 - 
          
  imagewaypoint/build.xml (modified) (1 diff)
 - 
          
  imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageEntry.java (modified) (1 diff)
 - 
          
  imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointLayer.java (modified) (1 diff)
 - 
          
  livegps/build.xml (modified) (1 diff)
 - 
          
  livegps/src/livegps/LiveGpsLayer.java (modified) (2 diffs)
 - 
          
  measurement/build.xml (modified) (1 diff)
 - 
          
  measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java (modified) (2 diffs)
 - 
          
  openstreetbugs/build.xml (modified) (1 diff)
 - 
          
  openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbLayer.java (modified) (2 diffs)
 - 
          
  routing/build.xml (modified) (1 diff)
 - 
          
  routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java (modified) (4 diffs)
 - 
          
  routing/src/com/innovant/josm/plugin/routing/actions/MoveRouteNodeAction.java (modified) (1 diff)
 - 
          
  routing/src/com/innovant/josm/plugin/routing/actions/RemoveRouteNodeAction.java (modified) (1 diff)
 - 
          
  slippymap/build.xml (modified) (1 diff)
 - 
          
  slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java (modified) (10 diffs)
 - 
          
  validator/build.xml (modified) (1 diff)
 - 
          
  validator/src/org/openstreetmap/josm/plugins/validator/GridLayer.java (modified) (10 diffs)
 - 
          
  validator/src/org/openstreetmap/josm/plugins/validator/TestError.java (modified) (4 diffs)
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
applications/editors/josm/plugins/agpifoj/build.xml
r16290 r16294 34 34 <attribute name="Plugin-Early" value="false"/> 35 35 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/AgPifoJ"/> 36 <attribute name="Plugin-Mainversion" value="172 2"/>36 <attribute name="Plugin-Mainversion" value="1725"/> 37 37 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 38 38 </manifest>  - 
      
applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojLayer.java
r14916 r16294 29 29 import org.openstreetmap.josm.Main; 30 30 import org.openstreetmap.josm.actions.RenameLayerAction; 31 import org.openstreetmap.josm.data.coor.CachedLatLon; 31 32 import org.openstreetmap.josm.data.coor.EastNorth; 32 33 import org.openstreetmap.josm.data.coor.LatLon; … … 53 54 54 55 private int currentPhoto = -1; 55 56 56 57 // These are used by the auto-guess function to store the result, 57 58 // so when the dialig is re-opened the users modifications don't … … 68 69 Date time; 69 70 LatLon exifCoor; 70 LatLon coor; 71 EastNorth pos; 71 CachedLatLon pos; 72 72 /** Speed in kilometer per second */ 73 73 Double speed; … … 75 75 Double elevation; 76 76 77 public void setCoor(LatLon latlon) 78 { 79 pos = new CachedLatLon(latlon); 80 } 77 81 public int compareTo(ImageEntry image) { 78 82 if (time != null && image.time != null) { … … 362 366 public void visitBoundingBox(BoundingXYVisitor v) { 363 367 for (ImageEntry e : data) 364 v.visit(e.pos); 368 v.visit(e.pos.getEastNorth()); 365 369 } 366 370 … … 411 415 // Store values 412 416 413 e.coor = new LatLon(lat, lon); 414 e.exifCoor = e.coor; 415 e.pos = Main.proj.latlon2eastNorth(e.coor); 417 e.setCoor(new LatLon(lat, lon)); 418 e.exifCoor = e.pos; 416 419 417 420 } catch (Exception p) { 418 e.coor = null;419 421 e.pos = null; 420 422 }  - 
      
applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/CorrelateGpxWithImages.java
r16290 r16294 765 765 // Reset previous position 766 766 for(ImageEntry x : autoImgs) { 767 x.coor = null;768 767 x.pos = null; 769 768 } … … 893 892 if (e.time != null) { 894 893 // Reset previous position 895 e.coor = null;896 894 e.pos = null; 897 895 dateImgLst.add(e); … … 908 906 } else { 909 907 for (ImageEntry e : yLayer.data) { 910 if (e.time != null && e. coor== null) {908 if (e.time != null && e.pos == null) { 911 909 dateImgLst.add(e); 912 910 } … … 999 997 while(i >= 0 && (dateImgLst.get(i).time.getTime()/1000) <= curDateWp 1000 998 && (dateImgLst.get(i).time.getTime()/1000) >= (curDateWp - interval)) { 1001 if(dateImgLst.get(i).coor == null) { 1002 dateImgLst.get(i).pos = curWp.eastNorth; 1003 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos); 999 if(dateImgLst.get(i).pos == null) { 1000 dateImgLst.get(i).setCoor(curWp.getCoor()); 1004 1001 dateImgLst.get(i).speed = speed; 1005 1002 dateImgLst.get(i).elevation = curElevation; … … 1016 1013 while(i >= 0 && (imgDate = dateImgLst.get(i).time.getTime()/1000) >= prevDateWp) { 1017 1014 1018 if(dateImgLst.get(i). coor== null) {1015 if(dateImgLst.get(i).pos == null) { 1019 1016 // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless 1020 1017 // variable 1021 1018 double timeDiff = (double)(imgDate - prevDateWp) / interval; 1022 dateImgLst.get(i).pos = new EastNorth( 1023 interpolate(prevWp.eastNorth.east(), curWp.eastNorth.east(), timeDiff), 1024 interpolate(prevWp.eastNorth.north(), curWp.eastNorth.north(), timeDiff)); 1025 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos); 1019 dateImgLst.get(i).setCoor(prevWp.getCoor().interpolate(curWp.getCoor(), timeDiff)); 1026 1020 dateImgLst.get(i).speed = speed; 1027 1021 1028 1022 if (curElevation != null && prevElevation != null) 1029 dateImgLst.get(i).elevation = interpolate(prevElevation,curElevation,timeDiff);1023 dateImgLst.get(i).elevation = prevElevation + (curElevation - prevElevation) * timeDiff; 1030 1024 1031 1025 ret++; … … 1034 1028 } 1035 1029 return ret; 1036 }1037 1038 private double interpolate(double val1, double val2, double time) {1039 return val1 + (val2 - val1) * time;1040 1030 } 1041 1031 … … 1168 1158 * Formula and earth radius from : http://en.wikipedia.org/wiki/Great-circle_distance */ 1169 1159 public double getDistance(WayPoint p1, WayPoint p2) { 1170 double p1Lat = p1. latlon.lat() * Math.PI / 180;1171 double p1Lon = p1. latlon.lon() * Math.PI / 180;1172 double p2Lat = p2. latlon.lat() * Math.PI / 180;1173 double p2Lon = p2. latlon.lon() * Math.PI / 180;1160 double p1Lat = p1.getCoor().lat() * Math.PI / 180; 1161 double p1Lon = p1.getCoor().lon() * Math.PI / 180; 1162 double p2Lat = p2.getCoor().lat() * Math.PI / 180; 1163 double p2Lon = p2.getCoor().lon() * Math.PI / 180; 1174 1164 double ret = Math.atan2(Math.sqrt(Math.pow(Math.cos(p2Lat) * Math.sin(p2Lon - p1Lon), 2) 1175 1165 + Math.pow(Math.cos(p1Lat) * Math.sin(p2Lat)  - 
      
applications/editors/josm/plugins/editgpx/build.xml
r16290 r16294 26 26 <attribute name="Plugin-Description" value="Allows the user to anonymize timestamps and delete parts of huge GPX tracks very fast." /> 27 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/EditGpx" /> 28 <attribute name="Plugin-Mainversion" value="172 2" />28 <attribute name="Plugin-Mainversion" value="1725" /> 29 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 30 </manifest>  - 
      
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java
r16290 r16294 34 34 import org.openstreetmap.josm.gui.layer.GpxLayer; 35 35 import org.openstreetmap.josm.gui.layer.Layer; 36 import org.openstreetmap.josm.tools.DateUtils; 36 37 import org.openstreetmap.josm.tools.ImageProvider; 37 38 … … 167 168 WayPoint wpt = new WayPoint(n.getCoor()); 168 169 if (anonTime) { 169 wpt.attr.put("time", "1970-01-01T00:00:00"); 170 wpt.attr.put("time", "1970-01-01T00:00:00Z"); 170 171 } else { 171 wpt.attr.put("time", WayPoint.GPXTIMEFMT.format(tstamp));172 wpt.attr.put("time", DateUtils.fromDate(tstamp)); 172 173 } 173 174 wpt.setTime(); … … 185 186 WayPoint wpt = new WayPoint(n.getCoor()); 186 187 if (anonTime) { 187 wpt.attr.put("time", "1970-01-01T00:00:00"); 188 wpt.attr.put("time", "1970-01-01T00:00:00Z"); 188 189 } else { 189 wpt.attr.put("time", WayPoint.GPXTIMEFMT.format(tstamp));190 wpt.attr.put("time", DateUtils.fromDate(tstamp)); 190 191 } 191 192 wpt.setTime();  - 
      
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
r16290 r16294 68 68 //go through nodes and mark the ones in the selection rect as deleted 69 69 for (Node n: dataSet.nodes) { 70 Point p = Main.map.mapView.getPoint(n .getEastNorth());70 Point p = Main.map.mapView.getPoint(n); 71 71 if (r.contains(p)) { 72 72 n.deleted = true; //only set as deleted. this makes reset to beginning possible  - 
      
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java
r14245 r16294 115 115 Way w = new Way(); 116 116 for (WayPoint p : segment) { 117 Node n = new Node(p. latlon);117 Node n = new Node(p.getCoor()); 118 118 String timestr = p.getString("time"); 119 119 if(timestr != null) 120 {121 timestr = timestr.replace("Z","+00:00");122 120 n.setTimestamp(DateUtils.fromString(timestr)); 123 }124 121 dataSet.nodes.add(n); 125 122 w.nodes.add(n); //TODO what to do with these while deletion  - 
      
applications/editors/josm/plugins/grid/build.xml
r14128 r16294 25 25 <attribute name="Plugin-Description" value="Provide a background layer that displays a map grid" /> 26 26 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 27 <attribute name="Plugin-MainVersion" value="1725"/> 27 28 </manifest> 28 29 </jar>  - 
      
applications/editors/josm/plugins/grid/src/grid/GridLayer.java
r13497 r16294 303 303 lli = gridtoworld.transform(new LatLon(lat+latspacing,lon)); 304 304 llj = gridtoworld.transform(new LatLon(lat,lon+lonspacing)); 305 Point p0=mv.getPoint( Main.proj.latlon2eastNorth(ll0));306 Point pi=mv.getPoint( Main.proj.latlon2eastNorth(lli));307 Point pj=mv.getPoint( Main.proj.latlon2eastNorth(llj));305 Point p0=mv.getPoint(ll0); 306 Point pi=mv.getPoint(lli); 307 Point pj=mv.getPoint(llj); 308 308 309 309 if(Math.round(lon/lonspacing)%lonmaj==0) … … 335 335 336 336 private void drawGridLine(Graphics g, final MapView mv, LatLon ll0, LatLon ll1){ 337 Point p0=mv.getPoint( Main.proj.latlon2eastNorth(ll0));338 Point p1=mv.getPoint( Main.proj.latlon2eastNorth(ll1));337 Point p0=mv.getPoint(ll0); 338 Point p1=mv.getPoint(ll1); 339 339 340 340 if(Math.abs(ll0.lon()-ll1.lon())<180){ … … 347 347 if(lon1<0) lon1+=360; 348 348 latm = ll0.lat() + (180-lon0)*(ll1.lat()-ll0.lat())/(lon1-lon0); 349 Point pm1 = mv.getPoint( Main.proj.latlon2eastNorth(new LatLon(latm,180)));350 Point pm2 = mv.getPoint( Main.proj.latlon2eastNorth(new LatLon(latm,-180)));349 Point pm1 = mv.getPoint(new LatLon(latm,180)); 350 Point pm2 = mv.getPoint(new LatLon(latm,-180)); 351 351 if(lon0<=180){ 352 352 g.drawLine(p0.x,p0.y,pm1.x,pm1.y);  - 
      
applications/editors/josm/plugins/imagewaypoint/build.xml
r14120 r16294 26 26 <attribute name="Plugin-Description" value="Another plugin to match images to the waypoints in a GPX file. A match is made when the 'name', 'cmt' or 'desc' attribute of a waypoint tag matches the filename of an image."/> 27 27 <attribute name="Plugin-Early" value="false"/> 28 <attribute name="Plugin-Mainversion" value="1 498"/>28 <attribute name="Plugin-Mainversion" value="1725"/> 29 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 30 </manifest>  - 
      
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageEntry.java
r13497 r16294 151 151 bounds = null; 152 152 } else { 153 final Point point = mapView.getPoint(this.getWayPoint(). eastNorth);153 final Point point = mapView.getPoint(this.getWayPoint().getCoor()); 154 154 bounds = new Rectangle(point.x - ImageEntry.ICON_WIDTH, 155 155 point.y - ImageEntry.ICON_HEIGHT,  - 
      
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointLayer.java
r14122 r16294 150 150 final ImageEntry imageEntry = images[index]; 151 151 152 if (null != imageEntry.getWayPoint() 153 && null != imageEntry.getWayPoint().eastNorth) { 154 visitor.visit(imageEntry.getWayPoint().eastNorth); 155 } 152 if (imageEntry.getWayPoint() != null) 153 visitor.visit(imageEntry.getWayPoint().getCoor()); 156 154 } 157 155 }  - 
      
applications/editors/josm/plugins/livegps/build.xml
r16290 r16294 26 26 <attribute name="Plugin-Description" value="Support live GPS input (moving dot) through a connection to gpsd server."/> 27 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/LiveGPS"/> 28 <attribute name="Plugin-Mainversion" value="172 2"/>28 <attribute name="Plugin-Mainversion" value="1725"/> 29 29 <attribute name="Plugin-Stage" value="50"/> 30 30 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>  - 
      
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r16290 r16294 74 74 { 75 75 if (lastPoint != null) 76 Main.map.mapView.zoomTo(lastPoint. eastNorth);76 Main.map.mapView.zoomTo(lastPoint.getCoor()); 77 77 } 78 78 … … 116 116 if (lastPoint != null) 117 117 { 118 Point screen = mv.getPoint(lastPoint. eastNorth);118 Point screen = mv.getPoint(lastPoint.getCoor()); 119 119 g.setColor(Main.pref.getColor(KEY_LIVEGPS_COLOR, Color.RED)); 120 120 g.drawOval(screen.x-10, screen.y-10,20,20);  - 
      
applications/editors/josm/plugins/measurement/build.xml
r15953 r16294 25 25 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 26 26 <attribute name="Plugin-Description" value="Provide a measurement dialog and a layer to measure length and angle of segments, area surrounded by a (simple) closed way and create measurement paths (which also can be imported from a gps layer)."/> 27 <attribute name="Plugin-Mainversion" value="1 640"/>27 <attribute name="Plugin-Mainversion" value="1725"/> 28 28 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 29 29 </manifest>  - 
      
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java
r15953 r16294 75 75 Point l = null; 76 76 for(WayPoint p:points){ 77 LatLon c = p.latlon; 78 Point pnt = Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(c)); 77 Point pnt = Main.map.mapView.getPoint(p.getCoor()); 79 78 if (l != null){ 80 79 g.drawLine(l.x, l.y, pnt.x, pnt.y); … … 196 195 197 196 public static double calcDistance(WayPoint p1, WayPoint p2){ 198 return calcDistance(p1. latlon, p2.latlon);197 return calcDistance(p1.getCoor(), p2.getCoor()); 199 198 } 200 199 201 200 public static double angleBetween(WayPoint p1, WayPoint p2){ 202 return angleBetween(p1. latlon, p2.latlon);201 return angleBetween(p1.getCoor(), p2.getCoor()); 203 202 } 204 203  - 
      
applications/editors/josm/plugins/openstreetbugs/build.xml
r16290 r16294 26 26 <attribute name="Plugin-Description" value="Imports issues from OpenStreetBugs"/> 27 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/OpenStreetBugs"/> 28 <attribute name="Plugin-Mainversion" value="172 2"/>28 <attribute name="Plugin-Mainversion" value="1725"/> 29 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 30 </manifest>  - 
      
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbLayer.java
r16163 r16294 125 125 } 126 126 127 Point p = mv.getPoint(node .getEastNorth());127 Point p = mv.getPoint(node); 128 128 129 129 ImageIcon icon = OsbPlugin.loadIcon("icon_error16.png"); … … 200 200 if (n.deleted || n.incomplete) 201 201 continue; 202 Point sp = Main.map.mapView.getPoint(n .getEastNorth());202 Point sp = Main.map.mapView.getPoint(n); 203 203 double dist = p.distanceSq(sp); 204 204 if (minDistanceSq > dist && p.distance(sp) < snapDistance) {  - 
      
applications/editors/josm/plugins/routing/build.xml
r16290 r16294 44 44 <attribute name="Plugin-Description" value="Provides routing capabilities."/> 45 45 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/Routing"/> 46 <attribute name="Plugin-Mainversion" value="172 2"/>46 <attribute name="Plugin-Mainversion" value="1725"/> 47 47 <attribute name="Plugin-Stage" value="50"/> 48 48 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>  - 
      
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java
r16290 r16294 139 139 if (n.deleted || n.incomplete) continue; 140 140 141 Point P = Main.map.mapView.getPoint(n .getEastNorth());141 Point P = Main.map.mapView.getPoint(n); 142 142 double dist = p.distanceSq(P); 143 143 if (dist < NavigatableComponent.snapDistance) { … … 275 275 // paint start icon 276 276 Node node = nodes.get(0); 277 Point screen = mv.getPoint(node .getEastNorth());277 Point screen = mv.getPoint(node); 278 278 startIcon.paintIcon(mv, g, screen.x - startIcon.getIconWidth()/2, 279 279 screen.y - startIcon.getIconHeight()); … … 282 282 for(int index = 1; index < nodes.size() - 1; ++index) { 283 283 node = nodes.get(index); 284 screen = mv.getPoint(node .getEastNorth());284 screen = mv.getPoint(node); 285 285 middleIcon.paintIcon(mv, g, screen.x - startIcon.getIconWidth()/2, 286 286 screen.y - middleIcon.getIconHeight()); … … 289 289 if(nodes.size() > 1) { 290 290 node = nodes.get(nodes.size() - 1); 291 screen = mv.getPoint(node .getEastNorth());291 screen = mv.getPoint(node); 292 292 endIcon.paintIcon(mv, g, screen.x - startIcon.getIconWidth()/2, 293 293 screen.y - endIcon.getIconHeight());  - 
      
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/MoveRouteNodeAction.java
r16290 r16294 113 113 for (int i=0;i<nl.size();i++) { 114 114 Node node = nl.get(i); 115 double d = Main.map.mapView.getPoint(node .getEastNorth()).distanceSq(e.getPoint());115 double d = Main.map.mapView.getPoint(node).distanceSq(e.getPoint()); 116 116 if (d < dmax) { 117 117 dmax = d;  - 
      
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/RemoveRouteNodeAction.java
r16290 r16294 102 102 for (int i=0;i<nl.size();i++) { 103 103 Node node = nl.get(i); 104 double d = Main.map.mapView.getPoint(node .getEastNorth()).distanceSq(e.getPoint());104 double d = Main.map.mapView.getPoint(node).distanceSq(e.getPoint()); 105 105 if (d < dmax) { 106 106 dmax = d;  - 
      
applications/editors/josm/plugins/slippymap/build.xml
r15707 r16294 26 26 <attribute name="Plugin-Description" value="Displays a slippy map grid in JOSM. Can load tiles from slippy map as background and request updates."/> 27 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/SlippyMap"/> 28 <attribute name="Plugin-Mainversion" value="1 646"/>28 <attribute name="Plugin-Mainversion" value="1725"/> 29 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 30 </manifest>  - 
      
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r16164 r16294 46 46 * @author LuVar <lubomir.varga@freemap.sk> 47 47 * @author Dave Hansen <dave@sr71.net> 48 * 48 * 49 49 */ 50 50 public class SlippyMapLayer extends Layer implements ImageObserver, … … 131 131 } 132 132 })); 133 133 134 134 tileOptionMenu.add(new JMenuItem( 135 new AbstractAction(tr("Flush Tile Cache")) {136 public void actionPerformed(ActionEvent ae) {137 System.out.print("flushing all tiles...");138 for (SlippyMapTile t : tileStorage.values()) {139 t.dropImage();140 }141 System.out.println("done");142 }143 }));135 new AbstractAction(tr("Flush Tile Cache")) { 136 public void actionPerformed(ActionEvent ae) { 137 System.out.print("flushing all tiles..."); 138 for (SlippyMapTile t : tileStorage.values()) { 139 t.dropImage(); 140 } 141 System.out.println("done"); 142 } 143 })); 144 144 // end of adding menu commands 145 145 … … 176 176 /** 177 177 * Zoom in, go closer to map. 178 * 179 * @return true, if zoom increasing was successfull, false othervise178 * 179 * @return true, if zoom increasing was successfull, false othervise 180 180 */ 181 181 public boolean increaseZoomLevel() { … … 194 194 /** 195 195 * Zoom out from map. 196 * 197 * @return true, if zoom increasing was successfull, false othervise196 * 197 * @return true, if zoom increasing was successfull, false othervise 198 198 */ 199 199 public boolean decreaseZoomLevel() { … … 271 271 272 272 synchronized SlippyMapTile getTile(int x, int y, int zoom) { 273 SlippyMapKey key = new SlippyMapKey(x, y, zoom);274 if (!key.valid) {275 key = null;276 }277 return tileStorage.get(key);278 }279 280 synchronized SlippyMapTile putTile(SlippyMapTile tile, int x, int y, int zoom) {281 SlippyMapKey key = new SlippyMapKey(x, y, zoom);282 if (!key.valid) {283 key = null;284 }285 return tileStorage.put(key, tile);286 }287 288 synchronized SlippyMapTile getOrCreateTile(int x, int y, int zoom) {289 SlippyMapTile tile = getTile(x, y, zoom);290 if (tile != null) {291 return tile;292 }293 tile = new SlippyMapTile(x, y, zoom);294 putTile(tile, x, y, zoom);295 return tile;296 }297 273 SlippyMapKey key = new SlippyMapKey(x, y, zoom); 274 if (!key.valid) { 275 key = null; 276 } 277 return tileStorage.get(key); 278 } 279 280 synchronized SlippyMapTile putTile(SlippyMapTile tile, int x, int y, int zoom) { 281 SlippyMapKey key = new SlippyMapKey(x, y, zoom); 282 if (!key.valid) { 283 key = null; 284 } 285 return tileStorage.put(key, tile); 286 } 287 288 synchronized SlippyMapTile getOrCreateTile(int x, int y, int zoom) { 289 SlippyMapTile tile = getTile(x, y, zoom); 290 if (tile != null) { 291 return tile; 292 } 293 tile = new SlippyMapTile(x, y, zoom); 294 putTile(tile, x, y, zoom); 295 return tile; 296 } 297 298 298 void loadAllTiles() { 299 299 MapView mv = Main.map.mapView; … … 302 302 303 303 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel); 304 304 305 305 // if there is more than 18 tiles on screen in any direction, do not 306 306 // load all tiles! 307 307 if (ts.tilesSpanned() > (18*18)) { 308 System.out.println("Not downloading all tiles because there is more than 18 tiles on an axis!");309 return;308 System.out.println("Not downloading all tiles because there is more than 18 tiles on an axis!"); 309 return; 310 310 } 311 311 312 312 for (Tile t : ts.allTiles()) { 313 SlippyMapTile tile = getOrCreateTile(t.x, t.y, currentZoomLevel);314 if (tile.getImage() == null) {315 this.loadSingleTile(tile);316 }313 SlippyMapTile tile = getOrCreateTile(t.x, t.y, currentZoomLevel); 314 if (tile.getImage() == null) { 315 this.loadSingleTile(tile); 316 } 317 317 }//end of for Tile t 318 318 } 319 319 320 /*321 * Attempt to approximate how much the image is being scaled. For instance,322 * a 100x100 image being scaled to 50x50 would return 0.25.323 */324 Image lastScaledImage = null;325 326 double getImageScaling(Image img, Point p0, Point p1) {327 int realWidth = img.getWidth(this);328 int realHeight = img.getHeight(this);329 if (realWidth == -1 || realHeight == -1) {330 /*331 * We need a good image against which to work. If332 * the current one isn't loaded, then try the last one.333 * Should be good enough. If we've never seen one, then334 * guess.335 */336 if (lastScaledImage != null) {337 return getImageScaling(lastScaledImage, p0, p1);338 }339 realWidth = 256;340 realHeight = 256;341 } else {342 lastScaledImage = img;343 }344 /*345 * If the zoom scale gets really, really off, these can get into346 * the millions, so make this a double to prevent integer347 * overflows.348 */349 double drawWidth = p1.x - p0.x;350 double drawHeight = p1.x - p0.x;351 // stem.out.println("drawWidth: " + drawWidth + " drawHeight: " +352 // drawHeight);353 354 double drawArea = drawWidth * drawHeight;320 /* 321 * Attempt to approximate how much the image is being scaled. For instance, 322 * a 100x100 image being scaled to 50x50 would return 0.25. 323 */ 324 Image lastScaledImage = null; 325 326 double getImageScaling(Image img, Point p0, Point p1) { 327 int realWidth = img.getWidth(this); 328 int realHeight = img.getHeight(this); 329 if (realWidth == -1 || realHeight == -1) { 330 /* 331 * We need a good image against which to work. If 332 * the current one isn't loaded, then try the last one. 333 * Should be good enough. If we've never seen one, then 334 * guess. 335 */ 336 if (lastScaledImage != null) { 337 return getImageScaling(lastScaledImage, p0, p1); 338 } 339 realWidth = 256; 340 realHeight = 256; 341 } else { 342 lastScaledImage = img; 343 } 344 /* 345 * If the zoom scale gets really, really off, these can get into 346 * the millions, so make this a double to prevent integer 347 * overflows. 348 */ 349 double drawWidth = p1.x - p0.x; 350 double drawHeight = p1.x - p0.x; 351 // stem.out.println("drawWidth: " + drawWidth + " drawHeight: " + 352 // drawHeight); 353 354 double drawArea = drawWidth * drawHeight; 355 355 double realArea = realWidth * realHeight; 356 356 … … 358 358 } 359 359 360 boolean imageLoaded(Image i) {361 if (i == null)362 return false;363 364 int status = Toolkit.getDefaultToolkit().checkImage(i, -1, -1, this);365 if ((status & ALLBITS) != 0)366 return true;367 return false;368 }369 370 Double paintTileImages(Graphics g, TileSet ts, int zoom) {371 Double imageScale = null;372 Image img = null;373 for (Tile t : ts.allTiles()) {374 SlippyMapTile tile = getTile(t.x, t.y, zoom);375 if (tile == null) {376 // Don't trigger tile loading if this isn't377 // the exact zoom level we're looking for378 if (zoom != currentZoomLevel)379 continue;380 tile = getOrCreateTile(t.x, t.y, zoom);381 if (SlippyMapPreferences.getAutoloadTiles())382 loadSingleTile(tile);383 }384 img = tile.getImage();385 if (img == null)386 continue;387 if ((zoom != currentZoomLevel) && !tile.isDownloaded())388 continue;389 Point p = t.pixelPos(zoom);390 /*391 * We need to get a box in which to draw, so advance by one tile in392 * each direction to find the other corner of the box393 */394 Tile t2 = new Tile(t.x + 1, t.y + 1);395 Point p2 = t2.pixelPos(zoom);396 397 g.drawImage(img, p.x, p.y, p2.x - p.x, p2.y - p.y, this);398 if (img == null)399 continue;400 if (imageScale == null && zoom == currentZoomLevel)401 imageScale = new Double(getImageScaling(img, p, p2));402 float fadeBackground = SlippyMapPreferences.getFadeBackground();403 if (fadeBackground != 0f) {404 // dimm by painting opaque rect...405 g.setColor(new Color(1f, 1f, 1f, fadeBackground));406 g.fillRect(p.x, p.y, p2.x - p.x, p2.y - p.y);407 }408 }// end of for409 return imageScale;410 }411 412 void paintTileText(TileSet ts, Graphics g, MapView mv, int zoom, Tile t) {413 int fontHeight = g.getFontMetrics().getHeight();414 415 SlippyMapTile tile = getTile(t.x, t.y, zoom);416 if (tile == null) {417 return;418 }419 if (tile.getImage() == null) {420 loadSingleTile(tile);421 }422 Point p = t.pixelPos(zoom);423 int texty = p.y + 2 + fontHeight;424 425 if (SlippyMapPreferences.getDrawDebug()) {426 g.drawString("x=" + t.x + " y=" + t.y + " z=" + zoom + "", p.x + 2, texty);427 texty += 1 + fontHeight;428 if ((t.x % 32 == 0) && (t.y % 32 == 0)) {429 g.drawString("x=" + t.x / 32 + " y=" + t.y / 32 + " z=7", p.x + 2, texty);430 texty += 1 + fontHeight;431 }432 }// end of if draw debug433 434 String md = tile.getMetadata();435 if (md != null) {436 g.drawString(md, p.x + 2, texty);437 texty += 1 + fontHeight;438 }439 440 Image tileImage = tile.getImage();441 if (tileImage == null) {442 g.drawString(tr("image not loaded"), p.x + 2, texty);443 texty += 1 + fontHeight;444 }445 if (!imageLoaded(tileImage)) {446 g.drawString(tr("image loading..."), p.x + 2, texty);447 needRedraw = true;448 Main.map.repaint(100);449 texty += 1 + fontHeight;450 }451 452 if (SlippyMapPreferences.getDrawDebug()) {453 if (ts.leftTile(t)) {454 if (t.y % 32 == 31) {455 g.fillRect(0, p.y - 1, mv.getWidth(), 3);456 } else {457 g.drawLine(0, p.y, mv.getWidth(), p.y);458 }459 }460 }// /end of if draw debug461 }462 463 private class Tile {464 public int x;465 public int y;466 467 Tile(int x, int y) {468 this.x = x;469 this.y = y;470 }471 472 public Point pixelPos(int zoom) {473 double lon = tileXToLon(this.x, zoom);474 LatLon tmpLL = new LatLon(tileYToLat(this.y, zoom), lon);475 MapView mv = Main.map.mapView;476 return mv.getPoint(Main.proj.latlon2eastNorth(tmpLL));477 }478 }479 480 private class TileSet {481 int z12x0, z12x1, z12y0, z12y1;482 int zoom;483 484 TileSet(LatLon topLeft, LatLon botRight, int zoom) {485 this.zoom = zoom;486 z12x0 = lonToTileX(topLeft.lon(), zoom);487 z12x1 = lonToTileX(botRight.lon(), zoom);488 z12y0 = latToTileY(topLeft.lat(), zoom);489 z12y1 = latToTileY(botRight.lat(), zoom);490 if (z12x0 > z12x1) {491 int tmp = z12x0;492 z12x0 = z12x1;493 z12x1 = tmp;494 }495 if (z12y0 > z12y1) {496 int tmp = z12y0;497 z12y0 = z12y1;498 z12y1 = tmp;499 }500 }501 502 int tilesSpanned() {503 int x_span = z12x1 - z12x0;504 int y_span = z12y1 - z12y0;505 return x_span * y_span;506 }507 508 /*509 * This is pretty silly. Should probably just be implemented as an510 * iterator to keep from having to instantiate all these tiles.511 */512 List<Tile> allTiles()360 boolean imageLoaded(Image i) { 361 if (i == null) 362 return false; 363 364 int status = Toolkit.getDefaultToolkit().checkImage(i, -1, -1, this); 365 if ((status & ALLBITS) != 0) 366 return true; 367 return false; 368 } 369 370 Double paintTileImages(Graphics g, TileSet ts, int zoom) { 371 Double imageScale = null; 372 Image img = null; 373 for (Tile t : ts.allTiles()) { 374 SlippyMapTile tile = getTile(t.x, t.y, zoom); 375 if (tile == null) { 376 // Don't trigger tile loading if this isn't 377 // the exact zoom level we're looking for 378 if (zoom != currentZoomLevel) 379 continue; 380 tile = getOrCreateTile(t.x, t.y, zoom); 381 if (SlippyMapPreferences.getAutoloadTiles()) 382 loadSingleTile(tile); 383 } 384 img = tile.getImage(); 385 if (img == null) 386 continue; 387 if ((zoom != currentZoomLevel) && !tile.isDownloaded()) 388 continue; 389 Point p = t.pixelPos(zoom); 390 /* 391 * We need to get a box in which to draw, so advance by one tile in 392 * each direction to find the other corner of the box 393 */ 394 Tile t2 = new Tile(t.x + 1, t.y + 1); 395 Point p2 = t2.pixelPos(zoom); 396 397 g.drawImage(img, p.x, p.y, p2.x - p.x, p2.y - p.y, this); 398 if (img == null) 399 continue; 400 if (imageScale == null && zoom == currentZoomLevel) 401 imageScale = new Double(getImageScaling(img, p, p2)); 402 float fadeBackground = SlippyMapPreferences.getFadeBackground(); 403 if (fadeBackground != 0f) { 404 // dimm by painting opaque rect... 405 g.setColor(new Color(1f, 1f, 1f, fadeBackground)); 406 g.fillRect(p.x, p.y, p2.x - p.x, p2.y - p.y); 407 } 408 }// end of for 409 return imageScale; 410 } 411 412 void paintTileText(TileSet ts, Graphics g, MapView mv, int zoom, Tile t) { 413 int fontHeight = g.getFontMetrics().getHeight(); 414 415 SlippyMapTile tile = getTile(t.x, t.y, zoom); 416 if (tile == null) { 417 return; 418 } 419 if (tile.getImage() == null) { 420 loadSingleTile(tile); 421 } 422 Point p = t.pixelPos(zoom); 423 int texty = p.y + 2 + fontHeight; 424 425 if (SlippyMapPreferences.getDrawDebug()) { 426 g.drawString("x=" + t.x + " y=" + t.y + " z=" + zoom + "", p.x + 2, texty); 427 texty += 1 + fontHeight; 428 if ((t.x % 32 == 0) && (t.y % 32 == 0)) { 429 g.drawString("x=" + t.x / 32 + " y=" + t.y / 32 + " z=7", p.x + 2, texty); 430 texty += 1 + fontHeight; 431 } 432 }// end of if draw debug 433 434 String md = tile.getMetadata(); 435 if (md != null) { 436 g.drawString(md, p.x + 2, texty); 437 texty += 1 + fontHeight; 438 } 439 440 Image tileImage = tile.getImage(); 441 if (tileImage == null) { 442 g.drawString(tr("image not loaded"), p.x + 2, texty); 443 texty += 1 + fontHeight; 444 } 445 if (!imageLoaded(tileImage)) { 446 g.drawString(tr("image loading..."), p.x + 2, texty); 447 needRedraw = true; 448 Main.map.repaint(100); 449 texty += 1 + fontHeight; 450 } 451 452 if (SlippyMapPreferences.getDrawDebug()) { 453 if (ts.leftTile(t)) { 454 if (t.y % 32 == 31) { 455 g.fillRect(0, p.y - 1, mv.getWidth(), 3); 456 } else { 457 g.drawLine(0, p.y, mv.getWidth(), p.y); 458 } 459 } 460 }// /end of if draw debug 461 } 462 463 private class Tile { 464 public int x; 465 public int y; 466 467 Tile(int x, int y) { 468 this.x = x; 469 this.y = y; 470 } 471 472 public Point pixelPos(int zoom) { 473 double lon = tileXToLon(this.x, zoom); 474 LatLon tmpLL = new LatLon(tileYToLat(this.y, zoom), lon); 475 MapView mv = Main.map.mapView; 476 return mv.getPoint(tmpLL); 477 } 478 } 479 480 private class TileSet { 481 int z12x0, z12x1, z12y0, z12y1; 482 int zoom; 483 484 TileSet(LatLon topLeft, LatLon botRight, int zoom) { 485 this.zoom = zoom; 486 z12x0 = lonToTileX(topLeft.lon(), zoom); 487 z12x1 = lonToTileX(botRight.lon(), zoom); 488 z12y0 = latToTileY(topLeft.lat(), zoom); 489 z12y1 = latToTileY(botRight.lat(), zoom); 490 if (z12x0 > z12x1) { 491 int tmp = z12x0; 492 z12x0 = z12x1; 493 z12x1 = tmp; 494 } 495 if (z12y0 > z12y1) { 496 int tmp = z12y0; 497 z12y0 = z12y1; 498 z12y1 = tmp; 499 } 500 } 501 502 int tilesSpanned() { 503 int x_span = z12x1 - z12x0; 504 int y_span = z12y1 - z12y0; 505 return x_span * y_span; 506 } 507 508 /* 509 * This is pretty silly. Should probably just be implemented as an 510 * iterator to keep from having to instantiate all these tiles. 511 */ 512 List<Tile> allTiles() 513 513 { 514 514 List<Tile> ret = new ArrayList<Tile>(); … … 526 526 } 527 527 528 boolean topTile(Tile t) {529 if (t.y == z12y0 - 1)530 return true;531 return false;532 }533 534 boolean leftTile(Tile t) {535 if (t.x == z12x0 - 1)536 return true;537 return false;538 }539 }540 528 boolean topTile(Tile t) { 529 if (t.y == z12y0 - 1) 530 return true; 531 return false; 532 } 533 534 boolean leftTile(Tile t) { 535 if (t.x == z12x0 - 1) 536 return true; 537 return false; 538 } 539 } 540 541 541 /** 542 542 */ 543 543 @Override 544 544 public void paint(Graphics g, MapView mv) { 545 long start = System.currentTimeMillis();546 LatLon topLeft = mv.getLatLon(0, 0);547 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());548 Graphics oldg = g;549 550 if (botRight.lon() == 0.0 || botRight.lat() == 0) {551 // probably still initializing552 return;553 }554 if (lastTopLeft != null && lastBotRight != null && topLeft.equalsEpsilon(lastTopLeft)555 && botRight.equalsEpsilon(lastBotRight) && bufferImage != null556 && mv.getWidth() == bufferImage.getWidth(null) && mv.getHeight() == bufferImage.getHeight(null)557 && !needRedraw) {558 559 g.drawImage(bufferImage, 0, 0, null);560 return;561 }562 563 needRedraw = false;564 lastTopLeft = topLeft;565 lastBotRight = botRight;566 bufferImage = mv.createImage(mv.getWidth(), mv.getHeight());567 g = bufferImage.getGraphics();568 569 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel);570 int zoom = currentZoomLevel;571 572 if (ts.tilesSpanned() > (18*18)) {573 System.out.println("too many tiles, decreasing zoom from " + currentZoomLevel);574 if (decreaseZoomLevel()) {575 this.paint(oldg, mv);576 }577 return;578 }//end of if more than 18*18579 580 if (ts.tilesSpanned() <= 0) {581 System.out.println("doesn't even cover one tile, increasing zoom from " + currentZoomLevel);582 if (increaseZoomLevel()) {583 this.paint(oldg, mv);584 }585 return;586 }587 588 int fontHeight = g.getFontMetrics().getHeight();589 590 g.setColor(Color.DARK_GRAY);591 592 float fadeBackground = SlippyMapPreferences.getFadeBackground();593 594 /*595 * Go looking for tiles in zoom levels *other* than the current596 * one. Even if they might look bad, they look better than a597 * blank tile.598 */599 int otherZooms[] = {2, -2, 1, -1};600 for (int zoomOff : otherZooms) {601 int zoom2 = currentZoomLevel + zoomOff;602 if ((zoom <= 0) || (zoom > SlippyMapPreferences.getMaxZoomLvl())) {603 continue;604 }605 TileSet ts2 = new TileSet(topLeft, botRight, zoom2);606 this.paintTileImages(g, ts2, zoom2);607 }608 /*609 * Save this for last since it will get painted over all the others610 */611 Double imageScale = this.paintTileImages(g, ts, currentZoomLevel);612 g.setColor(Color.red);613 614 for (Tile t : ts.allTiles()) {615 // This draws the vertical lines for the entire616 // column. Only draw them for the top tile in617 // the column.618 if (ts.topTile(t)) {619 Point p = t.pixelPos(currentZoomLevel);620 if (SlippyMapPreferences.getDrawDebug()) {621 if (t.x % 32 == 0) {622 // level 7 tile boundary623 g.fillRect(p.x - 1, 0, 3, mv.getHeight());624 } else {625 g.drawLine(p.x, 0, p.x, mv.getHeight());626 }627 }628 }629 this.paintTileText(ts, g, mv, currentZoomLevel, t);630 }631 632 oldg.drawImage(bufferImage, 0, 0, null);633 634 if (imageScale != null) {635 // If each source image pixel is being stretched into > 3636 // drawn pixels, zoom in... getting too pixelated637 if (imageScale > 3) {638 if (SlippyMapPreferences.getAutozoom()) {639 Main.debug("autozoom increase: scale: " + imageScale);640 increaseZoomLevel();641 }642 this.paint(oldg, mv);643 }644 645 // If each source image pixel is being squished into > 0.32646 // of a drawn pixels, zoom out.647 if (imageScale < 0.32) {648 if (SlippyMapPreferences.getAutozoom()) {649 Main.debug("autozoom decrease: scale: " + imageScale);650 decreaseZoomLevel();651 }652 this.paint(oldg, mv);653 }654 }655 g.setColor(Color.black);656 g.drawString("currentZoomLevel=" + currentZoomLevel, 120, 120);657 }// end of paint method545 long start = System.currentTimeMillis(); 546 LatLon topLeft = mv.getLatLon(0, 0); 547 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 548 Graphics oldg = g; 549 550 if (botRight.lon() == 0.0 || botRight.lat() == 0) { 551 // probably still initializing 552 return; 553 } 554 if (lastTopLeft != null && lastBotRight != null && topLeft.equalsEpsilon(lastTopLeft) 555 && botRight.equalsEpsilon(lastBotRight) && bufferImage != null 556 && mv.getWidth() == bufferImage.getWidth(null) && mv.getHeight() == bufferImage.getHeight(null) 557 && !needRedraw) { 558 559 g.drawImage(bufferImage, 0, 0, null); 560 return; 561 } 562 563 needRedraw = false; 564 lastTopLeft = topLeft; 565 lastBotRight = botRight; 566 bufferImage = mv.createImage(mv.getWidth(), mv.getHeight()); 567 g = bufferImage.getGraphics(); 568 569 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel); 570 int zoom = currentZoomLevel; 571 572 if (ts.tilesSpanned() > (18*18)) { 573 System.out.println("too many tiles, decreasing zoom from " + currentZoomLevel); 574 if (decreaseZoomLevel()) { 575 this.paint(oldg, mv); 576 } 577 return; 578 }//end of if more than 18*18 579 580 if (ts.tilesSpanned() <= 0) { 581 System.out.println("doesn't even cover one tile, increasing zoom from " + currentZoomLevel); 582 if (increaseZoomLevel()) { 583 this.paint(oldg, mv); 584 } 585 return; 586 } 587 588 int fontHeight = g.getFontMetrics().getHeight(); 589 590 g.setColor(Color.DARK_GRAY); 591 592 float fadeBackground = SlippyMapPreferences.getFadeBackground(); 593 594 /* 595 * Go looking for tiles in zoom levels *other* than the current 596 * one. Even if they might look bad, they look better than a 597 * blank tile. 598 */ 599 int otherZooms[] = {2, -2, 1, -1}; 600 for (int zoomOff : otherZooms) { 601 int zoom2 = currentZoomLevel + zoomOff; 602 if ((zoom <= 0) || (zoom > SlippyMapPreferences.getMaxZoomLvl())) { 603 continue; 604 } 605 TileSet ts2 = new TileSet(topLeft, botRight, zoom2); 606 this.paintTileImages(g, ts2, zoom2); 607 } 608 /* 609 * Save this for last since it will get painted over all the others 610 */ 611 Double imageScale = this.paintTileImages(g, ts, currentZoomLevel); 612 g.setColor(Color.red); 613 614 for (Tile t : ts.allTiles()) { 615 // This draws the vertical lines for the entire 616 // column. Only draw them for the top tile in 617 // the column. 618 if (ts.topTile(t)) { 619 Point p = t.pixelPos(currentZoomLevel); 620 if (SlippyMapPreferences.getDrawDebug()) { 621 if (t.x % 32 == 0) { 622 // level 7 tile boundary 623 g.fillRect(p.x - 1, 0, 3, mv.getHeight()); 624 } else { 625 g.drawLine(p.x, 0, p.x, mv.getHeight()); 626 } 627 } 628 } 629 this.paintTileText(ts, g, mv, currentZoomLevel, t); 630 } 631 632 oldg.drawImage(bufferImage, 0, 0, null); 633 634 if (imageScale != null) { 635 // If each source image pixel is being stretched into > 3 636 // drawn pixels, zoom in... getting too pixelated 637 if (imageScale > 3) { 638 if (SlippyMapPreferences.getAutozoom()) { 639 Main.debug("autozoom increase: scale: " + imageScale); 640 increaseZoomLevel(); 641 } 642 this.paint(oldg, mv); 643 } 644 645 // If each source image pixel is being squished into > 0.32 646 // of a drawn pixels, zoom out. 647 if (imageScale < 0.32) { 648 if (SlippyMapPreferences.getAutozoom()) { 649 Main.debug("autozoom decrease: scale: " + imageScale); 650 decreaseZoomLevel(); 651 } 652 this.paint(oldg, mv); 653 } 654 } 655 g.setColor(Color.black); 656 g.drawString("currentZoomLevel=" + currentZoomLevel, 120, 120); 657 }// end of paint method 658 658 659 659 /** … … 662 662 */ 663 663 SlippyMapTile getTileForPixelpos(int px, int py) { 664 MapView mv = Main.map.mapView;665 Point clicked = new Point(px, py);666 LatLon topLeft = mv.getLatLon(0, 0);667 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());668 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel);669 int z = currentZoomLevel;670 671 Tile clickedTile = null;664 MapView mv = Main.map.mapView; 665 Point clicked = new Point(px, py); 666 LatLon topLeft = mv.getLatLon(0, 0); 667 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 668 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel); 669 int z = currentZoomLevel; 670 671 Tile clickedTile = null; 672 672 for (Tile t1 : ts.allTiles()) { 673 673 Tile t2 = new Tile(t1.x+1, t1.y+1); … … 735 735 736 736 private int lonToTileX(double lon, int zoom) { 737 return (int) (Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0);737 return (int) (Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0); 738 738 } 739 739 740 740 private double tileYToLat(int y, int zoom) { 741 741 return Math.atan(Math.sinh(Math.PI 742 - (Math.PI * y / Math.pow(2.0, zoom - 1))))742 - (Math.PI * y / Math.pow(2.0, zoom - 1)))) 743 743 * 180 / Math.PI; 744 744 } 745 745 746 746 private double tileXToLon(int x, int zoom) { 747 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;747 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0; 748 748 } 749 749 750 750 private SlippyMapTile imgToTile(Image img) { 751 // we use the enumeration to avoid ConcurrentUpdateExceptions752 // with other users of the tileStorage753 Enumeration<SlippyMapTile> e = tileStorage.elements();754 while (e.hasMoreElements()) {755 SlippyMapTile t = e.nextElement();756 if (t.getImageNoTimestamp() != img) {757 continue;758 }759 return t;760 }761 return null;762 }763 751 // we use the enumeration to avoid ConcurrentUpdateExceptions 752 // with other users of the tileStorage 753 Enumeration<SlippyMapTile> e = tileStorage.elements(); 754 while (e.hasMoreElements()) { 755 SlippyMapTile t = e.nextElement(); 756 if (t.getImageNoTimestamp() != img) { 757 continue; 758 } 759 return t; 760 } 761 return null; 762 } 763 764 764 private static int nr_loaded = 0; 765 765 private static int at_zoom = -1; 766 766 767 767 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 768 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0);769 SlippyMapTile imageTile = imgToTile(img);770 if (imageTile == null) {771 return false;772 }773 774 if ((infoflags & ERROR) != 0) {775 String url; // = "unknown";776 url = imageTile.getImageURL().toString();777 System.err.println("imageUpdate(" + img + ") error " + url + ")");778 }779 if (((infoflags & ALLBITS) != 0)) {780 int z = imageTile.getZoom();781 if (z == at_zoom) {782 nr_loaded++;783 } else {784 System.out.println("downloaded " + nr_loaded + " at: " + at_zoom + " now going to " + z);785 nr_loaded = 0;786 at_zoom = z;787 }788 imageTile.markAsDownloaded();789 }790 if ((infoflags & SOMEBITS) != 0) {791 // if (y%100 == 0)792 //System.out.println("imageUpdate("+img+") SOMEBITS ("+x+","+y+")");793 }794 // Repaint immediately if we are done, otherwise batch up795 // repaint requests every 100 milliseconds796 needRedraw = true;797 Main.map.repaint(done ? 0 : 100);798 return !done;799 }768 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 769 SlippyMapTile imageTile = imgToTile(img); 770 if (imageTile == null) { 771 return false; 772 } 773 774 if ((infoflags & ERROR) != 0) { 775 String url; // = "unknown"; 776 url = imageTile.getImageURL().toString(); 777 System.err.println("imageUpdate(" + img + ") error " + url + ")"); 778 } 779 if (((infoflags & ALLBITS) != 0)) { 780 int z = imageTile.getZoom(); 781 if (z == at_zoom) { 782 nr_loaded++; 783 } else { 784 System.out.println("downloaded " + nr_loaded + " at: " + at_zoom + " now going to " + z); 785 nr_loaded = 0; 786 at_zoom = z; 787 } 788 imageTile.markAsDownloaded(); 789 } 790 if ((infoflags & SOMEBITS) != 0) { 791 // if (y%100 == 0) 792 //System.out.println("imageUpdate("+img+") SOMEBITS ("+x+","+y+")"); 793 } 794 // Repaint immediately if we are done, otherwise batch up 795 // repaint requests every 100 milliseconds 796 needRedraw = true; 797 Main.map.repaint(done ? 0 : 100); 798 return !done; 799 } 800 800 801 801 /*  - 
      
applications/editors/josm/plugins/validator/build.xml
r16290 r16294 26 26 <attribute name="Plugin-Description" value="An OSM data validator. It checks for problems in data, and provides fixes for the common ones. Spellcheck integrated for tag names."/> 27 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/Validator"/> 28 <attribute name="Plugin-Mainversion" value="172 2"/>28 <attribute name="Plugin-Mainversion" value="1725"/> 29 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 30 </manifest>  - 
      
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/GridLayer.java
r16159 r16294 23 23 /** 24 24 * A debug layer for testing the grid cells a way crosses. 25 * 25 * 26 26 * @author frsantos 27 27 */ … … 29 29 { 30 30 /** 31 * Constructor 31 * Constructor 32 32 * @param name 33 33 */ 34 public GridLayer(String name) 34 public GridLayer(String name) 35 35 { 36 36 super(name); … … 47 47 * Draw the grid and highlight all cells acuppied by any selected primitive. 48 48 */ 49 @Override 50 public void paint(final Graphics g, final MapView mv) 49 @Override 50 public void paint(final Graphics g, final MapView mv) 51 51 { 52 52 if( !Main.pref.hasKey(PreferenceEditor.PREF_DEBUG + ".grid") ) 53 53 return; 54 54 55 55 int gridWidth = Integer.parseInt(Main.pref.get(PreferenceEditor.PREF_DEBUG + ".grid") ); 56 56 int width = mv.getWidth(); … … 67 67 for(OsmPrimitive p : Main.ds.getSelected() ) 68 68 p.visit(visitor); 69 69 70 70 long x0 = (long)Math.floor(origin.east() * gridWidth); 71 71 long x1 = (long)Math.floor(border.east() * gridWidth); 72 72 long y0 = (long)Math.floor(origin.north() * gridWidth) + 1; 73 long y1 = (long)Math.floor(border.north() * gridWidth) + 1; 73 long y1 = (long)Math.floor(border.north() * gridWidth) + 1; 74 74 long aux; 75 75 if( x0 > x1 ) { aux = x0; x0 = x1; x1 = aux; } 76 76 if( y0 > y1 ) { aux = y0; y0 = y1; y1 = aux; } 77 77 78 78 g.setColor(Color.RED.brighter().brighter()); 79 79 for( double x = x0; x <= x1; x++) … … 90 90 } 91 91 92 @Override 93 public String getToolTipText() 92 @Override 93 public String getToolTipText() 94 94 { 95 95 return null; 96 96 } 97 97 98 @Override 98 @Override 99 99 public void mergeFrom(Layer from) {} 100 100 101 @Override 101 @Override 102 102 public boolean isMergable(Layer other) { 103 103 return false; 104 104 } 105 105 106 @Override 106 @Override 107 107 public void visitBoundingBox(BoundingXYVisitor v) {} 108 108 109 @Override 110 public Object getInfoComponent() 109 @Override 110 public Object getInfoComponent() 111 111 { 112 112 return getToolTipText(); 113 113 } 114 114 115 @Override 116 public Component[] getMenuEntries() 115 @Override 116 public Component[] getMenuEntries() 117 117 { 118 118 return new Component[]{ … … 126 126 127 127 @Override public void destroy() { } 128 128 129 129 /** 130 130 * Visitor that highlights all cells the selected primitives go through … … 152 152 this.mv = mv; 153 153 this.gridDetail = gridDetail; 154 154 155 155 Point p = mv.getPoint( new EastNorth(0, 0) ); 156 156 Point p2 = mv.getPoint( new EastNorth(1d/gridDetail, 1d/gridDetail) ); … … 158 158 } 159 159 160 public void visit(Node n) 160 public void visit(Node n) 161 161 { 162 162 double x = n.getEastNorth().east() * gridDetail; … … 166 166 } 167 167 168 public void visit(Way w) 168 public void visit(Way w) 169 169 { 170 170 Node lastN = null; … … 182 182 183 183 public void visit(Relation r) {} 184 185 /** 184 185 /** 186 186 * Draws a solid cell at the (x,y) location 187 187 * @param x  - 
      
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/TestError.java
r16159 r16294 280 280 */ 281 281 public void drawNode(Node n, Color color) { 282 Point p = mv.getPoint(n .getEastNorth());282 Point p = mv.getPoint(n); 283 283 g.setColor(color); 284 284 if (selected) { … … 295 295 */ 296 296 public void drawSegment(Node n1, Node n2, Color color) { 297 Point p1 = mv.getPoint(n1 .getEastNorth());298 Point p2 = mv.getPoint(n2 .getEastNorth());297 Point p1 = mv.getPoint(n1); 298 Point p2 = mv.getPoint(n2); 299 299 g.setColor(color); 300 300 … … 365 365 */ 366 366 protected boolean isNodeVisible(Node n) { 367 Point p = mv.getPoint(n .getEastNorth());367 Point p = mv.getPoint(n); 368 368 return !((p.x < 0) || (p.y < 0) || (p.x > mv.getWidth()) || (p.y > mv.getHeight())); 369 369 } … … 377 377 */ 378 378 protected boolean isSegmentVisible(Node n1, Node n2) { 379 Point p1 = mv.getPoint(n1 .getEastNorth());380 Point p2 = mv.getPoint(n2 .getEastNorth());379 Point p1 = mv.getPoint(n1); 380 Point p2 = mv.getPoint(n2); 381 381 if ((p1.x < 0) && (p2.x < 0)) 382 382 return false;  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.
  