Ticket #17551: 17551.patch
File 17551.patch, 6.2 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java
7 7 import java.awt.geom.Area; 8 8 import java.awt.geom.Path2D; 9 9 import java.awt.geom.Rectangle2D; 10 import java.util.ArrayList; 11 import java.util.Collection; 10 12 11 13 import org.openstreetmap.josm.actions.DownloadAlongAction; 12 14 import org.openstreetmap.josm.data.coor.LatLon; … … 18 20 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 19 21 import org.openstreetmap.josm.gui.help.HelpUtil; 20 22 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 23 import org.openstreetmap.josm.tools.Logging; 21 24 import org.openstreetmap.josm.tools.Utils; 22 25 23 26 /** … … 50 53 this.data = data; 51 54 } 52 55 56 /** 57 * Calculate list of points between two given points so that the distance between two consecutive points is below a limit. 58 * @param p1 first point or null 59 * @param p2 second point (must not be null) 60 * @param bufferDist the maximum distance 61 * @return a list of points with at least one point (p2) and maybe more. 62 */ 63 private static Collection<? extends LatLon> calcBetween(LatLon p1, LatLon p2, double bufferDist) { 64 ArrayList<LatLon> intermediateNodes = new ArrayList<>(); 65 intermediateNodes.add(p2); 66 if (p1 != null && p2.greatCircleDistance(p1) > bufferDist) { 67 Double d = p2.greatCircleDistance(p1) / bufferDist; 68 int nbNodes = d.intValue(); 69 if (Logging.isDebugEnabled()) { 70 Logging.debug(tr("{0} intermediate nodes to download.", nbNodes)); 71 Logging.debug(tr("between {0} {1} and {2} {3}", p2.lat(), p2.lon(), p1.lat(), p1.lon())); 72 } 73 double latStep = (p2.lat() - p1.lat()) / (nbNodes + 1); 74 double lonStep = (p2.lon() - p1.lon()) / (nbNodes + 1); 75 for (int i = 1; i <= nbNodes; i++) { 76 LatLon intermediate = new LatLon(p1.lat() + i * latStep, p1.lon() + i * lonStep); 77 intermediateNodes.add(intermediate); 78 if (Logging.isTraceEnabled()) { 79 Logging.trace(tr(" adding {0} {1}", intermediate.lat(), intermediate.lon())); 80 } 81 } 82 } 83 return intermediateNodes; 84 } 85 53 86 PleaseWaitRunnable createTask() { 54 87 final DownloadAlongPanel panel = new DownloadAlongPanel( 55 88 PREF_DOWNLOAD_ALONG_TRACK_OSM, PREF_DOWNLOAD_ALONG_TRACK_GPS, … … 100 133 final double bufferX = bufferY / scale; 101 134 final int totalTicks = latcnt; 102 135 // guess if a progress bar might be useful. 103 final boolean displayProgress = totalTicks > 20 0_000 && bufferY < 0.01;136 final boolean displayProgress = totalTicks > 20_000 && bufferY < 0.01; 104 137 105 138 class CalculateDownloadArea extends PleaseWaitRunnable { 106 139 … … 129 162 return; 130 163 } 131 164 confirmAndDownloadAreas(new Area(path), maxArea, panel.isDownloadOsmData(), panel.isDownloadGpxData(), 132 tr("Download from OSM along this track"), progressMonitor);165 tr("Download from OSM along this track"), NullProgressMonitor.INSTANCE); 133 166 } 134 167 135 168 /** … … 142 175 } 143 176 } 144 177 145 /**146 * calculate area for single, given way point and return new LatLon if the147 * way point has been used to modify the area.148 */149 private LatLon calcAreaForWayPoint(WayPoint p, LatLon previous) {150 tick();151 LatLon c = p.getCoor();152 if (previous == null || c.greatCircleDistance(previous) > bufferDist) {153 // we add a buffer around the point.154 r.setRect(c.lon() - bufferX, c.lat() - bufferY, 2 * bufferX, 2 * bufferY);155 path.append(r, false);156 return c;157 }158 return previous;159 }160 161 178 @Override 162 179 protected void realRun() { 163 180 progressMonitor.setTicksCount(totalTicks); … … 166 183 * points that lie closer to the previous point than the given buffer size because 167 184 * otherwise this operation takes ages. 168 185 */ 169 LatLon previous = null;170 186 if (near == NEAR_TRACK || near == NEAR_BOTH) { 171 187 for (GpxTrack trk : data.tracks) { 172 188 for (GpxTrackSegment segment : trk.getSegments()) { 189 LatLon previous = null; 173 190 for (WayPoint p : segment.getWayPoints()) { 174 if (cancel) { 175 return; 191 tick(); 192 LatLon c = p.getCoor(); 193 for (LatLon d : calcBetween(previous, c, bufferDist)) { 194 // we add a buffer around the point. 195 r.setRect(d.lon() - bufferX, d.lat() - bufferY, 2 * bufferX, 2 * bufferY); 196 path.append(r, false); 176 197 } 177 previous = c alcAreaForWayPoint(p, previous);198 previous = c; 178 199 } 179 200 } 180 201 } … … 181 202 } 182 203 if (near == NEAR_WAYPOINTS || near == NEAR_BOTH) { 183 204 for (WayPoint p : data.waypoints) { 184 if (cancel) {185 return;186 }187 p revious = calcAreaForWayPoint(p, previous);205 tick(); 206 LatLon c = p.getCoor(); 207 r.setRect(c.lon() - bufferX, c.lat() - bufferY, 2 * bufferX, 2 * bufferY); 208 path.append(r, false); 188 209 } 189 210 } 190 211 }