Changeset 11013 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-09-17T17:38:39+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java
r10993 r11013 18 18 * 19 19 */ 20 public class GetCapabilitiesParseHelper {20 public final class GetCapabilitiesParseHelper { 21 21 enum TransferMode { 22 22 KVP("KVP"), … … 68 68 // CHECKSTYLE.ON: SingleSpaceSeparator 69 69 70 private GetCapabilitiesParseHelper() { 71 // Hide default constructor for utilities classes 72 } 70 73 71 74 /** 72 75 * @param in InputStream with pointing to GetCapabilities XML stream 73 76 * @return safe XMLStreamReader, that is not validating external entities, nor loads DTD's 74 * @throws IOException 75 * @throws XMLStreamException 77 * @throws IOException if any I/O error occurs 78 * @throws XMLStreamException if any XML stream error occurs 76 79 */ 77 80 public static XMLStreamReader getReader(InputStream in) throws IOException, XMLStreamException { … … 93 96 QName tag = reader.getName(); 94 97 for (int event = reader.getEventType(); reader.hasNext(); event = reader.next()) { 95 switch (event) { 96 case XMLStreamReader.START_ELEMENT: 98 if (XMLStreamReader.START_ELEMENT == event) { 97 99 level += 1; 98 break; 99 case XMLStreamReader.END_ELEMENT: 100 } else if (XMLStreamReader.END_ELEMENT == event) { 100 101 level -= 1; 101 102 if (level == 0 && tag.equals(reader.getName())) { … … 187 188 188 189 /** 189 * @param url 190 * @param url URL 190 191 * @return normalized URL 191 * @throws MalformedURLException 192 * @throws MalformedURLException in case of malformed URL 192 193 * @since 10993 193 194 */ … … 199 200 200 201 /** 201 * 202 * @param crsIdentifier 202 * Convert CRS identifier to plain code 203 * @param crsIdentifier CRS identifier 203 204 * @return CRS Identifier as it is used within JOSM (without prefix) 204 205 */ -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r10993 r11013 141 141 private String baseUrl; 142 142 private String style; 143 p ublicCollection<String> tileMatrixSetLinks = new ArrayList<>();143 private Collection<String> tileMatrixSetLinks = new ArrayList<>(); 144 144 145 145 Layer(Layer l) { … … 266 266 private String handleTemplate(String url) { 267 267 Pattern pattern = Pattern.compile(PATTERN_HEADER); 268 StringBuffer output = new StringBuffer(); // NOSONAR268 StringBuffer output = new StringBuffer(); 269 269 Matcher matcher = pattern.matcher(url); 270 270 while (matcher.find()) { … … 513 513 GetCapabilitiesParseHelper.QN_OWS_OPERATIONS_METADATA.equals(reader.getName())); 514 514 event = reader.next()) { 515 if (event == XMLStreamReader.START_ELEMENT) { 516 if (GetCapabilitiesParseHelper.QN_OWS_OPERATION.equals(reader.getName()) && "GetTile".equals(reader.getAttributeValue("", "name")) && 517 GetCapabilitiesParseHelper.moveReaderToTag(reader, new QName[]{ 518 GetCapabilitiesParseHelper.QN_OWS_DCP, 519 GetCapabilitiesParseHelper.QN_OWS_HTTP, 520 GetCapabilitiesParseHelper.QN_OWS_GET, 521 522 })) { 523 this.baseUrl = reader.getAttributeValue(GetCapabilitiesParseHelper.XLINK_NS_URL, "href"); 524 this.transferMode = GetCapabilitiesParseHelper.getTransferMode(reader); 525 } 515 if (event == XMLStreamReader.START_ELEMENT && 516 GetCapabilitiesParseHelper.QN_OWS_OPERATION.equals(reader.getName()) && 517 "GetTile".equals(reader.getAttributeValue("", "name")) && 518 GetCapabilitiesParseHelper.moveReaderToTag(reader, new QName[] { 519 GetCapabilitiesParseHelper.QN_OWS_DCP, 520 GetCapabilitiesParseHelper.QN_OWS_HTTP, 521 GetCapabilitiesParseHelper.QN_OWS_GET, 522 })) { 523 this.baseUrl = reader.getAttributeValue(GetCapabilitiesParseHelper.XLINK_NS_URL, "href"); 524 this.transferMode = GetCapabilitiesParseHelper.getTransferMode(reader); 526 525 } 527 526 } … … 573 572 // no support for non-square tiles (tileHeight != tileWidth) 574 573 // and for different tile sizes at different zoom levels 575 Collection<Layer> layers = getLayers(null, Main.getProjection().toCode());576 if (! layers.isEmpty()) {577 return layers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight;574 Collection<Layer> projLayers = getLayers(null, Main.getProjection().toCode()); 575 if (!projLayers.isEmpty()) { 576 return projLayers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight; 578 577 } 579 578 // if no layers is found, fallback to default mercator tile size. Maybe it will work … … 584 583 @Override 585 584 public String getTileUrl(int zoom, int tilex, int tiley) { 586 String url;587 585 if (currentLayer == null) { 588 586 return ""; 589 587 } 590 588 589 String url; 591 590 if (currentLayer.baseUrl != null && transferMode == null) { 592 591 url = currentLayer.baseUrl; -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r10977 r11013 87 87 import org.openstreetmap.josm.gui.MapFrame; 88 88 import org.openstreetmap.josm.gui.MapView; 89 import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle;90 89 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener; 91 90 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 107 106 /** 108 107 * Base abstract class that supports displaying images provided by TileSource. It might be TMS source, WMS or WMTS 109 *110 108 * It implements all standard functions of tilesource based layers: autozoom, tile reloads, layer saving, loading,etc. 111 109 * … … 119 117 implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener, DisplaySettingsChangeListener { 120 118 private static final String PREFERENCE_PREFIX = "imagery.generic"; 121 /** 122 * Registers all setting properties 123 */ 124 static { 119 static { // Registers all setting properties 125 120 new TileSourceDisplaySettings(); 126 121 } … … 138 133 139 134 //public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false); 140 /** 141 * Zoomlevel at which tiles is currently downloaded. 142 * Initial zoom lvl is set to bestZoom 143 */ 135 /** Zoomlevel at which tiles is currently downloaded. Initial zoom lvl is set to bestZoom */ 144 136 public int currentZoomLevel; 145 137 … … 164 156 protected TileLoader tileLoader; 165 157 166 /** 167 * A timer that is used to delay invalidation events if required. 168 */ 158 /** A timer that is used to delay invalidation events if required. */ 169 159 private final Timer invalidateLaterTimer = new Timer(100, e -> this.invalidate()); 170 160 … … 284 274 * 285 275 * If the current tileLoader is an instance of OsmTileLoader, a new 286 * TmsTileClearController is created and passed to the according clearCache 287 * method. 276 * TmsTileClearController is created and passed to the according clearCache method. 288 277 * 289 278 * @param monitor not used in this implementation - as cache clear is instaneus … … 387 376 * maps as a imagery layer 388 377 */ 389 390 378 int intResult = (int) Math.round(result + 1 + ZOOM_OFFSET.get() / 1.9); 391 379 … … 406 394 407 395 private String getSizeString(int size) { 408 StringBuilder ret = new StringBuilder(); 409 return ret.append(size).append('x').append(size).toString(); 396 return new StringBuilder().append(size).append('x').append(size).toString(); 410 397 } 411 398 … … 667 654 @Override 668 655 public void hookUpMapView() { 669 // this needs to be here and not in constructor to allow empty TileSource class construction 670 // using SessionWriter 656 // this needs to be here and not in constructor to allow empty TileSource class construction using SessionWriter 671 657 initializeIfRequired(); 672 658 … … 685 671 } 686 672 687 // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not 688 // start loading. 673 // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not start loading. 689 674 // FIXME: Check if this is still required. 690 675 event.getMapView().repaint(500); … … 949 934 950 935 /* 951 * We use these for quick, hackish calculations. They 952 * are temporary only and intentionally not inserted 953 * into the tileCache. 936 * We use these for quick, hackish calculations. They are temporary only and intentionally not inserted into the tileCache. 954 937 */ 955 938 private Tile tempCornerTile(Tile t) { … … 1011 994 1012 995 private TileSet getVisibleTileSet() { 1013 MapView mv = Main.map.mapView; 1014 MapViewRectangle area = mv.getState().getViewArea(); 1015 ProjectionBounds bounds = area.getProjectionBounds(); 996 ProjectionBounds bounds = Main.map.mapView.getState().getViewArea().getProjectionBounds(); 1016 997 return getTileSet(bounds.getMin(), bounds.getMax(), currentZoomLevel); 1017 998 } … … 1085 1066 } 1086 1067 1087 // 'source' is the pixel coordinates for the area that 1088 // the img is capable of filling in. However, we probably 1089 // only want a portion of it. 1068 // 'source' is the pixel coordinates for the area that the img is capable of filling in. 1069 // However, we probably only want a portion of it. 1090 1070 // 1091 // 'border' is the screen cordinates that need to be drawn. 1092 // We must not draw outside of it. 1071 // 'border' is the screen cordinates that need to be drawn. We must not draw outside of it. 1093 1072 private void drawImageInside(Graphics g, Image sourceImg, Rectangle2D source, Rectangle2D border) { 1094 1073 Rectangle2D target = source; 1095 1074 1096 // If a border is specified, only draw the intersection 1097 // if what we have combined with what we are supposed to draw. 1075 // If a border is specified, only draw the intersection if what we have combined with what we are supposed to draw. 1098 1076 if (border != null) { 1099 1077 target = source.createIntersection(border); … … 1103 1081 } 1104 1082 1105 // All of the rectangles are in screen coordinates. We need 1106 // to how these correlate to the sourceImg pixels. We could 1107 // avoid doing this by scaling the image up to the 'source' size, 1108 // but this should be cheaper. 1083 // All of the rectangles are in screen coordinates. We need to how these correlate to the sourceImg pixels. 1084 // We could avoid doing this by scaling the image up to the 'source' size, but this should be cheaper. 1109 1085 // 1110 1086 // In some projections, x any y are scaled differently enough to … … 1160 1136 } 1161 1137 1162 // This function is called for several zoom levels, not just 1163 // the current one. It should not trigger any tiles to be 1164 // downloaded. It should also avoid polluting the tile cache 1165 // with any tiles since these tiles are not mandatory. 1138 // This function is called for several zoom levels, not just the current one. 1139 // It should not trigger any tiles to be downloaded. 1140 // It should also avoid polluting the tile cache with any tiles since these tiles are not mandatory. 1166 1141 // 1167 // The "border" tile tells us the boundaries of where we may 1168 // draw. It will not be from the zoom level that is being 1169 // drawn currently. If drawing the displayZoomLevel, 1170 // border is null and we draw the entire tile set. 1142 // The "border" tile tells us the boundaries of where we may drawn. 1143 // It will not be from the zoom level that is being drawn currently. 1144 // If drawing the displayZoomLevel, border is null and we draw the entire tile set. 1171 1145 private List<Tile> paintTileImages(Graphics g, TileSet ts, int zoom, Tile border) { 1172 1146 if (zoom <= 0) return Collections.emptyList(); 1173 1147 Rectangle2D borderRect = coordinateConverter.getRectangleForTile(border); 1174 1148 List<Tile> missedTiles = new LinkedList<>(); 1175 // The callers of this code *require* that we return any tiles 1176 // that we do not draw in missedTiles. ts.allExistingTiles() by 1177 // default will only return already-existing tiles. However, we 1178 // need to return *all* tiles to the callers, so force creation here. 1149 // The callers of this code *require* that we return any tiles that we do not draw in missedTiles. 1150 // ts.allExistingTiles() by default will only return already-existing tiles. 1151 // However, we need to return *all* tiles to the callers, so force creation here. 1179 1152 for (Tile tile : ts.allTilesCreate()) { 1180 1153 Image img = getLoadedTileImage(tile); … … 1243 1216 texty += 1 + fontHeight; 1244 1217 } 1245 } */1246 1247 /*String tileStatus = tile.getStatus();1218 } 1219 1220 String tileStatus = tile.getStatus(); 1248 1221 if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) { 1249 1222 myDrawString(g, tr("image " + tileStatus), p.x + 2, texty); … … 1291 1264 return getShiftedLatLon(Main.getProjection().latlon2eastNorth(new LatLon(latLon))); 1292 1265 } 1293 1294 1266 1295 1267 private final TileSet nullTileSet = new TileSet(); … … 1344 1316 * The position of a single tile. 1345 1317 * @author Michael Zangl 1346 * @since xxx1347 1318 */ 1348 1319 private static class TilePosition { … … 1351 1322 private final int zoom; 1352 1323 TilePosition(int x, int y, int zoom) { 1353 super();1354 1324 this.x = x; 1355 1325 this.y = y; … … 1384 1354 @Override 1385 1355 public String toString() { 1386 return "TilePosition [x=" + x + ", y=" + y + ", zoom=" + zoom + "]";1356 return "TilePosition [x=" + x + ", y=" + y + ", zoom=" + zoom + ']'; 1387 1357 } 1388 1358 } … … 1448 1418 public Stream<TilePosition> tilePositions() { 1449 1419 if (this.insane()) { 1450 // Tileset is either empty or too large 1451 return Stream.empty(); 1420 return Stream.empty(); // Tileset is either empty or too large 1452 1421 } else { 1453 1422 return super.tilePositions(); … … 1489 1458 1490 1459 /** 1491 * Call the given paint method for all tiles in this tile set. 1492 * <p> 1460 * Call the given paint method for all tiles in this tile set.<p> 1493 1461 * Uses a parallel stream. 1494 1462 * @param visitor A visitor to call for each tile. … … 1711 1679 Tile t2 = tempCornerTile(missed); 1712 1680 TileSet ts2 = getTileSet(getShiftedLatLon(tileSource.tileXYToLatLon(missed)), 1713 getShiftedLatLon(tileSource.tileXYToLatLon(t2)), 1714 newzoom); 1681 getShiftedLatLon(tileSource.tileXYToLatLon(t2)), newzoom); 1715 1682 // Instantiating large TileSets is expensive. If there are no loaded tiles, don't bother even trying. 1716 1683 if (ts2.allLoadedTiles().isEmpty()) { … … 1784 1751 EastNorth topLeft = mv.getEastNorth(0, 0); 1785 1752 EastNorth botRight = mv.getEastNorth(mv.getWidth(), mv.getHeight()); 1786 int z = currentZoomLevel; 1787 TileSet ts = getTileSet(topLeft, botRight, z); 1753 TileSet ts = getTileSet(topLeft, botRight, currentZoomLevel); 1788 1754 1789 1755 if (!ts.tooLarge()) { … … 1860 1826 @Override 1861 1827 public boolean isChanged() { 1862 // we use #invalidate() 1863 return false; 1828 return false; // we use #invalidate() 1864 1829 } 1865 1830 … … 1946 1911 (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey(), o2.getKey())); 1947 1912 for (LatLon point: points) { 1948 1949 1913 TileXY minTile = tileSource.latLonToTileXY(point.lat() - bufferY, point.lon() - bufferX, currentZoomLevel); 1950 1914 TileXY curTile = tileSource.latLonToTileXY(point.toCoordinate(), currentZoomLevel); … … 1991 1955 1992 1956 private class TileSourcePainter extends CompatibilityModeLayerPainter { 1993 /** 1994 * The memory handle that will hold our tile source. 1995 */ 1957 /** The memory handle that will hold our tile source. */ 1996 1958 private MemoryHandle<?> memory; 1997 1959 … … 2005 1967 2006 1968 private void doPaint(MapViewGraphics graphics) { 2007 ProjectionBounds pb = graphics.getClipBounds().getProjectionBounds(); 2008 2009 drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), pb); 1969 drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), graphics.getClipBounds().getProjectionBounds()); 2010 1970 } 2011 1971
Note:
See TracChangeset
for help on using the changeset viewer.