# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Users\Franz\Documents\NetBeansProjects\JOSM-Plugins\core\src\org\openstreetmap\josm\gui\layer
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
|
|
|
66 | 66 | import org.openstreetmap.josm.data.preferences.IntegerProperty; |
67 | 67 | import org.openstreetmap.josm.data.preferences.StringProperty; |
68 | 68 | import org.openstreetmap.josm.data.projection.Projection; |
| 69 | import org.openstreetmap.josm.gui.MapFrame; |
69 | 70 | import org.openstreetmap.josm.gui.MapView; |
70 | 71 | import org.openstreetmap.josm.gui.MapView.LayerChangeListener; |
71 | 72 | import org.openstreetmap.josm.gui.PleaseWaitRunnable; |
… |
… |
|
123 | 124 | |
124 | 125 | HashSet<Tile> tileRequestsOutstanding = new HashSet<Tile>(); |
125 | 126 | @Override |
126 | | public synchronized void tileLoadingFinished(Tile tile, boolean success) |
127 | | { |
| 127 | public synchronized void tileLoadingFinished(Tile tile, boolean success) { |
128 | 128 | if (tile.hasError()) { |
129 | 129 | success = false; |
130 | 130 | tile.setImage(null); |
… |
… |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | @Override |
145 | | public TileCache getTileCache() |
146 | | { |
| 145 | public TileCache getTileCache() { |
147 | 146 | return tileCache; |
148 | 147 | } |
149 | 148 | |
… |
… |
|
188 | 187 | } |
189 | 188 | } |
190 | 189 | |
191 | | void clearTileCache(ProgressMonitor monitor) |
192 | | { |
| 190 | /** |
| 191 | * Clears the tile cache. |
| 192 | * |
| 193 | * If the current tileLoader is an instance of OsmTileLoader, a new |
| 194 | * TmsTileClearController is created and passed to the according clearCache |
| 195 | * method. |
| 196 | * |
| 197 | * @param monitor |
| 198 | * @see MemoryTileCache#clear() |
| 199 | * @see OsmFileCacheTileLoader#clearCache(org.openstreetmap.gui.jmapviewer.interfaces.TileSource, org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader.TileClearController) |
| 200 | */ |
| 201 | void clearTileCache(ProgressMonitor monitor) { |
193 | 202 | tileCache.clear(); |
194 | 203 | if (tileLoader instanceof OsmFileCacheTileLoader) { |
195 | 204 | ((OsmFileCacheTileLoader)tileLoader).clearCache(tileSource, new TmsTileClearController(monitor)); |
… |
… |
|
216 | 225 | protected boolean autoLoad; |
217 | 226 | protected boolean showErrors; |
218 | 227 | |
219 | | void redraw() |
220 | | { |
| 228 | /** |
| 229 | * Initiates a repaint of Main.map |
| 230 | * |
| 231 | * @see Main#map |
| 232 | * @see MapFrame#repaint() |
| 233 | */ |
| 234 | void redraw() { |
221 | 235 | needRedraw = true; |
222 | 236 | Main.map.repaint(); |
223 | 237 | } |
224 | 238 | |
225 | | static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) |
226 | | { |
| 239 | static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) { |
227 | 240 | if(maxZoomLvl > MAX_ZOOM) { |
228 | 241 | /*Main.debug("Max. zoom level should not be more than 30! Setting to 30.");*/ |
229 | 242 | maxZoomLvl = MAX_ZOOM; |
… |
… |
|
238 | 251 | return maxZoomLvl; |
239 | 252 | } |
240 | 253 | |
241 | | public static int getMaxZoomLvl(TileSource ts) |
242 | | { |
| 254 | public static int getMaxZoomLvl(TileSource ts) { |
243 | 255 | return checkMaxZoomLvl(PROP_MAX_ZOOM_LVL.get(), ts); |
244 | 256 | } |
245 | 257 | |
… |
… |
|
248 | 260 | PROP_MAX_ZOOM_LVL.put(maxZoomLvl); |
249 | 261 | } |
250 | 262 | |
251 | | static int checkMinZoomLvl(int minZoomLvl, TileSource ts) |
252 | | { |
| 263 | static int checkMinZoomLvl(int minZoomLvl, TileSource ts) { |
253 | 264 | if(minZoomLvl < MIN_ZOOM) { |
254 | 265 | /*Main.debug("Min. zoom level should not be less than "+MIN_ZOOM+"! Setting to that.");*/ |
255 | 266 | minZoomLvl = MIN_ZOOM; |
… |
… |
|
265 | 276 | return minZoomLvl; |
266 | 277 | } |
267 | 278 | |
268 | | public static int getMinZoomLvl(TileSource ts) |
269 | | { |
| 279 | public static int getMinZoomLvl(TileSource ts) { |
270 | 280 | return checkMinZoomLvl(PROP_MIN_ZOOM_LVL.get(), ts); |
271 | 281 | } |
272 | 282 | |
… |
… |
|
316 | 326 | } |
317 | 327 | } |
318 | 328 | |
| 329 | /** |
| 330 | * Creates and returns a new TileSource instance depending on the {@link ImageryType} |
| 331 | * of the passed ImageryInfo object. |
| 332 | * |
| 333 | * If no appropriate TileSource is found, null is returned. |
| 334 | * Currently supported ImageryType are {@link ImageryType#TMS}, |
| 335 | * {@link ImageryType#BING}, {@link ImageryType#SCANEX}. |
| 336 | * |
| 337 | * @param info |
| 338 | * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found. |
| 339 | * @throws IllegalArgumentException |
| 340 | */ |
319 | 341 | public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException { |
320 | 342 | if (info.getImageryType() == ImageryType.TMS) { |
321 | 343 | checkUrl(info.getUrl()); |
… |
… |
|
350 | 372 | } |
351 | 373 | } |
352 | 374 | |
353 | | private void initTileSource(TileSource tileSource) |
354 | | { |
| 375 | private void initTileSource(TileSource tileSource) { |
355 | 376 | this.tileSource = tileSource; |
356 | 377 | attribution.initialize(tileSource); |
357 | 378 | |
… |
… |
|
623 | 644 | }); |
624 | 645 | } |
625 | 646 | |
626 | | void zoomChanged() |
627 | | { |
| 647 | void zoomChanged() { |
628 | 648 | /*if (debug) { |
629 | 649 | Main.debug("zoomChanged(): " + currentZoomLevel); |
630 | 650 | }*/ |
… |
… |
|
633 | 653 | tileRequestsOutstanding.clear(); |
634 | 654 | } |
635 | 655 | |
636 | | int getMaxZoomLvl() |
637 | | { |
| 656 | int getMaxZoomLvl() { |
638 | 657 | if (info.getMaxZoom() != 0) |
639 | 658 | return checkMaxZoomLvl(info.getMaxZoom(), tileSource); |
640 | 659 | else |
641 | 660 | return getMaxZoomLvl(tileSource); |
642 | 661 | } |
643 | 662 | |
644 | | int getMinZoomLvl() |
645 | | { |
| 663 | int getMinZoomLvl() { |
646 | 664 | return getMinZoomLvl(tileSource); |
647 | 665 | } |
648 | 666 | |
… |
… |
|
651 | 669 | * |
652 | 670 | * @return true, if zoom increasing was successfull, false othervise |
653 | 671 | */ |
654 | | public boolean zoomIncreaseAllowed() |
655 | | { |
| 672 | public boolean zoomIncreaseAllowed() { |
656 | 673 | boolean zia = currentZoomLevel < this.getMaxZoomLvl(); |
657 | 674 | /*if (debug) { |
658 | 675 | Main.debug("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() ); |
659 | 676 | }*/ |
660 | 677 | return zia; |
661 | 678 | } |
662 | | public boolean increaseZoomLevel() |
663 | | { |
| 679 | |
| 680 | public boolean increaseZoomLevel() { |
664 | 681 | if (zoomIncreaseAllowed()) { |
665 | 682 | currentZoomLevel++; |
666 | 683 | /*if (debug) { |
… |
… |
|
675 | 692 | return true; |
676 | 693 | } |
677 | 694 | |
678 | | public boolean setZoomLevel(int zoom) |
679 | | { |
| 695 | public boolean setZoomLevel(int zoom) { |
680 | 696 | if (zoom == currentZoomLevel) return true; |
681 | 697 | if (zoom > this.getMaxZoomLvl()) return false; |
682 | 698 | if (zoom < this.getMinZoomLvl()) return false; |
… |
… |
|
690 | 706 | * |
691 | 707 | * @return true, if zoom increasing was successfull, false othervise |
692 | 708 | */ |
693 | | public boolean zoomDecreaseAllowed() |
694 | | { |
| 709 | public boolean zoomDecreaseAllowed() { |
695 | 710 | return currentZoomLevel > this.getMinZoomLvl(); |
696 | 711 | } |
| 712 | |
697 | 713 | public boolean decreaseZoomLevel() { |
698 | 714 | //int minZoom = this.getMinZoomLvl(); |
699 | 715 | if (zoomDecreaseAllowed()) { |
… |
… |
|
723 | 739 | return tile; |
724 | 740 | return new Tile(tileSource, x, y, zoom); |
725 | 741 | } |
| 742 | |
726 | 743 | synchronized Tile getOrCreateTile(int x, int y, int zoom) { |
727 | 744 | Tile tile = getTile(x, y, zoom); |
728 | 745 | if (tile == null) { |
… |
… |
|
745 | 762 | return tile; |
746 | 763 | } |
747 | 764 | |
748 | | synchronized boolean loadTile(Tile tile, boolean force) |
749 | | { |
| 765 | synchronized boolean loadTile(Tile tile, boolean force) { |
750 | 766 | if (tile == null) |
751 | 767 | return false; |
752 | 768 | if (!force && (tile.hasError() || tile.isLoaded())) |
… |
… |
|
802 | 818 | Main.map.repaint(done ? 0 : 100); |
803 | 819 | return !done; |
804 | 820 | } |
| 821 | |
805 | 822 | boolean imageLoaded(Image i) { |
806 | 823 | if (i == null) |
807 | 824 | return false; |
… |
… |
|
810 | 827 | return true; |
811 | 828 | return false; |
812 | 829 | } |
813 | | Image getLoadedTileImage(Tile tile) |
814 | | { |
| 830 | |
| 831 | /** |
| 832 | * Returns the image for the given tile if both tile and image are loaded. |
| 833 | * Otherwise returns null. |
| 834 | * |
| 835 | * @param tile the Tile for which the image should be returned |
| 836 | * @return the image of the tile or null. |
| 837 | */ |
| 838 | Image getLoadedTileImage(Tile tile) { |
815 | 839 | if (!tile.isLoaded()) |
816 | 840 | return null; |
817 | 841 | Image img = tile.getImage(); |
… |
… |
|
820 | 844 | return img; |
821 | 845 | } |
822 | 846 | |
823 | | LatLon tileLatLon(Tile t) |
824 | | { |
| 847 | LatLon tileLatLon(Tile t) { |
825 | 848 | int zoom = t.getZoom(); |
826 | 849 | return new LatLon(tileSource.tileYToLat(t.getYtile(), zoom), |
827 | 850 | tileSource.tileXToLon(t.getXtile(), zoom)); |
828 | 851 | } |
829 | 852 | |
830 | | Rectangle tileToRect(Tile t1) |
831 | | { |
| 853 | Rectangle tileToRect(Tile t1) { |
832 | 854 | /* |
833 | 855 | * We need to get a box in which to draw, so advance by one tile in |
834 | 856 | * each direction to find the other corner of the box. |
… |
… |
|
846 | 868 | // |
847 | 869 | // 'border' is the screen cordinates that need to be drawn. |
848 | 870 | // We must not draw outside of it. |
849 | | void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border) |
850 | | { |
| 871 | void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border) { |
851 | 872 | Rectangle target = source; |
852 | 873 | |
853 | 874 | // If a border is specified, only draw the intersection |
… |
… |
|
898 | 919 | target.width, target.height); |
899 | 920 | } |
900 | 921 | } |
| 922 | |
901 | 923 | // This function is called for several zoom levels, not just |
902 | 924 | // the current one. It should not trigger any tiles to be |
903 | 925 | // downloaded. It should also avoid polluting the tile cache |
… |
… |
|
1017 | 1039 | private Point pixelPos(LatLon ll) { |
1018 | 1040 | return Main.map.mapView.getPoint(Main.getProjection().latlon2eastNorth(ll).add(getDx(), getDy())); |
1019 | 1041 | } |
| 1042 | |
1020 | 1043 | private Point pixelPos(Tile t) { |
1021 | 1044 | double lon = tileSource.tileXToLon(t.getXtile(), t.getZoom()); |
1022 | 1045 | LatLon tmpLL = new LatLon(tileSource.tileYToLat(t.getYtile(), t.getZoom()), lon); |
1023 | 1046 | return pixelPos(tmpLL); |
1024 | 1047 | } |
| 1048 | |
1025 | 1049 | private LatLon getShiftedLatLon(EastNorth en) { |
1026 | 1050 | return Main.getProjection().eastNorth2latlon(en.add(-getDx(), -getDy())); |
1027 | 1051 | } |
| 1052 | |
1028 | 1053 | private Coordinate getShiftedCoord(EastNorth en) { |
1029 | 1054 | LatLon ll = getShiftedLatLon(en); |
1030 | 1055 | return new Coordinate(ll.lat(),ll.lon()); |
… |
… |
|
1079 | 1104 | y1 = tileMax; |
1080 | 1105 | } |
1081 | 1106 | } |
| 1107 | |
1082 | 1108 | boolean tooSmall() { |
1083 | 1109 | return this.tilesSpanned() < 2.1; |
1084 | 1110 | } |
| 1111 | |
1085 | 1112 | boolean tooLarge() { |
1086 | 1113 | return this.tilesSpanned() > 10; |
1087 | 1114 | } |
| 1115 | |
1088 | 1116 | boolean insane() { |
1089 | 1117 | return this.tilesSpanned() > 100; |
1090 | 1118 | } |
| 1119 | |
1091 | 1120 | double tilesSpanned() { |
1092 | 1121 | return Math.sqrt(1.0 * this.size()); |
1093 | 1122 | } |
… |
… |
|
1102 | 1131 | * Get all tiles represented by this TileSet that are |
1103 | 1132 | * already in the tileCache. |
1104 | 1133 | */ |
1105 | | List<Tile> allExistingTiles() |
1106 | | { |
| 1134 | List<Tile> allExistingTiles() { |
1107 | 1135 | return this.__allTiles(false); |
1108 | 1136 | } |
1109 | | List<Tile> allTilesCreate() |
1110 | | { |
| 1137 | |
| 1138 | List<Tile> allTilesCreate() { |
1111 | 1139 | return this.__allTiles(true); |
1112 | 1140 | } |
1113 | | private List<Tile> __allTiles(boolean create) |
1114 | | { |
| 1141 | |
| 1142 | private List<Tile> __allTiles(boolean create) { |
1115 | 1143 | // Tileset is either empty or too large |
1116 | 1144 | if (zoom == 0 || this.insane()) |
1117 | 1145 | return Collections.emptyList(); |
… |
… |
|
1131 | 1159 | } |
1132 | 1160 | return ret; |
1133 | 1161 | } |
1134 | | private List<Tile> allLoadedTiles() |
1135 | | { |
| 1162 | |
| 1163 | private List<Tile> allLoadedTiles() { |
1136 | 1164 | List<Tile> ret = new ArrayList<Tile>(); |
1137 | 1165 | for (Tile t : this.allExistingTiles()) { |
1138 | 1166 | if (t.isLoaded()) |
… |
… |
|
1141 | 1169 | return ret; |
1142 | 1170 | } |
1143 | 1171 | |
1144 | | void loadAllTiles(boolean force) |
1145 | | { |
| 1172 | void loadAllTiles(boolean force) { |
1146 | 1173 | if (!autoLoad && !force) |
1147 | 1174 | return; |
1148 | 1175 | for (Tile t : this.allTilesCreate()) { |
… |
… |
|
1150 | 1177 | } |
1151 | 1178 | } |
1152 | 1179 | |
1153 | | void loadAllErrorTiles(boolean force) |
1154 | | { |
| 1180 | void loadAllErrorTiles(boolean force) { |
1155 | 1181 | if (!autoLoad && !force) |
1156 | 1182 | return; |
1157 | 1183 | for (Tile t : this.allTilesCreate()) { |
… |
… |
|
1193 | 1219 | final int minZoom, maxZoom; |
1194 | 1220 | private final TileSet[] tileSets; |
1195 | 1221 | private final TileSetInfo[] tileSetInfos; |
| 1222 | |
1196 | 1223 | public DeepTileSet(EastNorth topLeft, EastNorth botRight, int minZoom, int maxZoom) { |
1197 | 1224 | this.topLeft = topLeft; |
1198 | 1225 | this.botRight = botRight; |
… |
… |
|
1201 | 1228 | this.tileSets = new TileSet[maxZoom - minZoom + 1]; |
1202 | 1229 | this.tileSetInfos = new TileSetInfo[maxZoom - minZoom + 1]; |
1203 | 1230 | } |
| 1231 | |
1204 | 1232 | public TileSet getTileSet(int zoom) { |
1205 | 1233 | if (zoom < minZoom) |
1206 | 1234 | return nullTileSet; |
… |
… |
|
1211 | 1239 | } |
1212 | 1240 | return ts; |
1213 | 1241 | } |
| 1242 | |
1214 | 1243 | public TileSetInfo getTileSetInfo(int zoom) { |
1215 | 1244 | if (zoom < minZoom) |
1216 | 1245 | return new TileSetInfo(); |
… |
… |
|
1223 | 1252 | } |
1224 | 1253 | } |
1225 | 1254 | |
1226 | | /** |
1227 | | */ |
1228 | 1255 | @Override |
1229 | 1256 | public void paint(Graphics2D g, MapView mv, Bounds bounds) { |
1230 | 1257 | //long start = System.currentTimeMillis(); |