Changeset 14427 in josm for trunk/src/org
- Timestamp:
- 2018-11-16T21:51:56+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r14360 r14427 1770 1770 public class PrecacheTask implements TileLoaderListener { 1771 1771 private final ProgressMonitor progressMonitor; 1772 private int totalCount;1772 private final int totalCount; 1773 1773 private final AtomicInteger processedCount = new AtomicInteger(0); 1774 1774 private final TileLoader tileLoader; 1775 private final Set<Tile> requestedTiles; 1775 1776 1776 1777 /** 1777 1778 * @param progressMonitor that will be notified about progess of the task 1779 * @param bufferY 1780 * @param bufferX 1781 * @param points 1778 1782 */ 1779 public PrecacheTask(ProgressMonitor progressMonitor ) {1783 public PrecacheTask(ProgressMonitor progressMonitor, List<LatLon> points, double bufferX, double bufferY) { 1780 1784 this.progressMonitor = progressMonitor; 1781 1785 this.tileLoader = getTileLoaderFactory().makeTileLoader(this, getHeaders(tileSource), minimumTileExpire); … … 1784 1788 TMSCachedTileLoader.getNewThreadPoolExecutor("Precache downloader")); 1785 1789 } 1790 requestedTiles = new ConcurrentSkipListSet<>( 1791 (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey(), o2.getKey())); 1792 for (LatLon point: points) { 1793 TileXY minTile = tileSource.latLonToTileXY(point.lat() - bufferY, point.lon() - bufferX, currentZoomLevel); 1794 TileXY curTile = tileSource.latLonToTileXY(CoordinateConversion.llToCoor(point), currentZoomLevel); 1795 TileXY maxTile = tileSource.latLonToTileXY(point.lat() + bufferY, point.lon() + bufferX, currentZoomLevel); 1796 1797 // take at least one tile of buffer 1798 int minY = Math.min(curTile.getYIndex() - 1, minTile.getYIndex()); 1799 int maxY = Math.max(curTile.getYIndex() + 1, maxTile.getYIndex()); 1800 int minX = Math.min(curTile.getXIndex() - 1, minTile.getXIndex()); 1801 int maxX = Math.max(curTile.getXIndex() + 1, maxTile.getXIndex()); 1802 1803 for (int x = minX; x <= maxX; x++) { 1804 for (int y = minY; y <= maxY; y++) { 1805 requestedTiles.add(new Tile(tileSource, x, y, currentZoomLevel)); 1806 } 1807 } 1808 } 1809 1810 this.totalCount = requestedTiles.size(); 1811 this.progressMonitor.setTicksCount(requestedTiles.size()); 1812 1786 1813 } 1787 1814 … … 1813 1840 int processed = this.processedCount.incrementAndGet(); 1814 1841 if (success) { 1815 this.progressMonitor.worked(1); 1816 this.progressMonitor.setCustomText(tr("Downloaded {0}/{1} tiles", processed, totalCount)); 1842 synchronized (progressMonitor) { 1843 if (!this.progressMonitor.isCanceled()) { 1844 this.progressMonitor.worked(1); 1845 this.progressMonitor.setCustomText(tr("Downloaded {0}/{1} tiles", processed, totalCount)); 1846 } 1847 } 1817 1848 } else { 1818 1849 Logging.warn("Tile loading failure: " + tile + " - " + tile.getErrorMessage()); … … 1825 1856 public TileLoader getTileLoader() { 1826 1857 return tileLoader; 1858 } 1859 1860 /** 1861 * Execute the download 1862 */ 1863 public void run() { 1864 TileLoader loader = getTileLoader(); 1865 for (Tile t: requestedTiles) { 1866 if (!progressMonitor.isCanceled()) { 1867 loader.createTileLoaderJob(t).submit(); 1868 } 1869 } 1870 1827 1871 } 1828 1872 } … … 1840 1884 * @return precache task representing download task 1841 1885 */ 1842 public AbstractTileSourceLayer<T>.PrecacheTask downloadAreaToCache(final ProgressMonitor progressMonitor, List<LatLon> points,1886 public AbstractTileSourceLayer<T>.PrecacheTask getDownloadAreaToCacheTask(final ProgressMonitor progressMonitor, List<LatLon> points, 1843 1887 double bufferX, double bufferY) { 1844 PrecacheTask precacheTask = new PrecacheTask(progressMonitor); 1845 final Set<Tile> requestedTiles = new ConcurrentSkipListSet<>( 1846 (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey(), o2.getKey())); 1847 for (LatLon point: points) { 1848 TileXY minTile = tileSource.latLonToTileXY(point.lat() - bufferY, point.lon() - bufferX, currentZoomLevel); 1849 TileXY curTile = tileSource.latLonToTileXY(CoordinateConversion.llToCoor(point), currentZoomLevel); 1850 TileXY maxTile = tileSource.latLonToTileXY(point.lat() + bufferY, point.lon() + bufferX, currentZoomLevel); 1851 1852 // take at least one tile of buffer 1853 int minY = Math.min(curTile.getYIndex() - 1, minTile.getYIndex()); 1854 int maxY = Math.max(curTile.getYIndex() + 1, maxTile.getYIndex()); 1855 int minX = Math.min(curTile.getXIndex() - 1, minTile.getXIndex()); 1856 int maxX = Math.max(curTile.getXIndex() + 1, maxTile.getXIndex()); 1857 1858 for (int x = minX; x <= maxX; x++) { 1859 for (int y = minY; y <= maxY; y++) { 1860 requestedTiles.add(new Tile(tileSource, x, y, currentZoomLevel)); 1861 } 1862 } 1863 } 1864 1865 precacheTask.totalCount = requestedTiles.size(); 1866 precacheTask.progressMonitor.setTicksCount(requestedTiles.size()); 1867 1868 TileLoader loader = precacheTask.getTileLoader(); 1869 for (Tile t: requestedTiles) { 1870 loader.createTileLoaderJob(t).submit(); 1871 } 1888 PrecacheTask precacheTask = new PrecacheTask(progressMonitor, points, bufferX, bufferY); 1889 1872 1890 return precacheTask; 1873 1891 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java
r14336 r14427 60 60 @Override 61 61 protected void realRun() throws SAXException, IOException, OsmTransferException { 62 precacheTask = layer.downloadAreaToCache(progressMonitor, points, 0, 0); 62 precacheTask = layer.getDownloadAreaToCacheTask(progressMonitor, points, 0, 0); 63 precacheTask.run(); 63 64 synchronized (this) { 64 65 try {
Note:
See TracChangeset
for help on using the changeset viewer.