Changeset 15410 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-10-04T00:26:18+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/imagery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java
r14436 r15410 63 63 static final QName QN_OWS_HTTP = new QName(OWS_NS_URL, "HTTP"); 64 64 static final QName QN_OWS_IDENTIFIER = new QName(OWS_NS_URL, "Identifier"); 65 static final QName QN_OWS_LOWER_CORNER = new QName(OWS_NS_URL, "LowerCorner"); 65 66 static final QName QN_OWS_OPERATION = new QName(OWS_NS_URL, "Operation"); 66 67 static final QName QN_OWS_OPERATIONS_METADATA = new QName(OWS_NS_URL, "OperationsMetadata"); 67 68 static final QName QN_OWS_SUPPORTED_CRS = new QName(OWS_NS_URL, "SupportedCRS"); 68 69 static final QName QN_OWS_TITLE = new QName(OWS_NS_URL, "Title"); 70 static final QName QN_OWS_UPPER_CORNER = new QName(OWS_NS_URL, "UpperCorner"); 69 71 static final QName QN_OWS_VALUE = new QName(OWS_NS_URL, "Value"); 72 static final QName QN_OWS_WGS84_BOUNDING_BOX = new QName(OWS_NS_URL, "WGS84BoundingBox"); 70 73 // CHECKSTYLE.ON: SingleSpaceSeparator 71 74 -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r15409 r15410 6 6 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_HTTP; 7 7 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_IDENTIFIER; 8 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_LOWER_CORNER; 8 9 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_OPERATION; 9 10 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_OPERATIONS_METADATA; 10 11 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_SUPPORTED_CRS; 11 12 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_TITLE; 13 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_UPPER_CORNER; 14 import static org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.QN_OWS_WGS84_BOUNDING_BOX; 12 15 import static org.openstreetmap.josm.tools.I18n.tr; 13 16 … … 33 36 import java.util.TreeSet; 34 37 import java.util.concurrent.ConcurrentHashMap; 38 import java.util.function.BiFunction; 35 39 import java.util.regex.Matcher; 36 40 import java.util.regex.Pattern; … … 56 60 import org.openstreetmap.josm.data.imagery.GetCapabilitiesParseHelper.TransferMode; 57 61 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 62 import org.openstreetmap.josm.data.osm.BBox; 58 63 import org.openstreetmap.josm.data.projection.Projection; 59 64 import org.openstreetmap.josm.data.projection.ProjectionRegistry; … … 211 216 private String baseUrl; 212 217 private String style; 218 private BBox bbox; 213 219 private final Collection<String> tileMatrixSetLinks = new ArrayList<>(); 214 220 private final Collection<Dimension> dimensions = new ArrayList<>(); … … 221 227 baseUrl = l.baseUrl; 222 228 style = l.style; 229 bbox = l.bbox; 223 230 tileMatrixSet = new TileMatrixSet(l.tileMatrixSet); 224 231 dimensions.addAll(l.dimensions); … … 276 283 public int getMaxZoom() { 277 284 return tileMatrixSet != null ? tileMatrixSet.getMaxZoom() : 0; 285 } 286 287 /** 288 * Returns the WGS84 bounding box. 289 * @return WGS84 bounding box 290 * @since 15410 291 */ 292 public BBox getBbox() { 293 return bbox; 278 294 } 279 295 } … … 355 371 if (first.getMaxZoom() < info.getMaxZoom()) { 356 372 first = layers.stream().filter(l -> l.getMaxZoom() >= info.getMaxZoom()).findFirst().orElse(first); 373 } 374 // If center of josm bbox not in layer bbox, try to find a better layer 375 if (info.getBounds() != null && first.getBbox() != null) { 376 LatLon center = info.getBounds().getCenter(); 377 if (!first.getBbox().bounds(center)) { 378 first = layers.stream().filter(l -> l.getBbox().bounds(center)).findFirst().orElse(first); 379 } 357 380 } 358 381 this.defaultLayer = new DefaultLayer(info.getImageryType(), first.identifier, first.style, first.tileMatrixSet.identifier); … … 568 591 } else if (QN_TILEMATRIX_SET_LINK.equals(qName)) { 569 592 layer.tileMatrixSetLinks.add(parseTileMatrixSetLink(reader)); 593 } else if (QN_OWS_WGS84_BOUNDING_BOX.equals(qName)) { 594 layer.bbox = parseBoundingBox(reader); 570 595 } else { 571 596 GetCapabilitiesParseHelper.moveReaderToEndCurrentTag(reader); … … 688 713 ret.scaleDenominator = Double.parseDouble(reader.getElementText()); 689 714 } else if (QN_TOPLEFT_CORNER.equals(qName)) { 690 String[] topLeftCorner = reader.getElementText().split(" "); 691 if (matrixProj.switchXY()) { 692 ret.topLeftCorner = new EastNorth(Double.parseDouble(topLeftCorner[1]), Double.parseDouble(topLeftCorner[0])); 693 } else { 694 ret.topLeftCorner = new EastNorth(Double.parseDouble(topLeftCorner[0]), Double.parseDouble(topLeftCorner[1])); 695 } 715 ret.topLeftCorner = parseEastNorth(reader.getElementText(), matrixProj.switchXY()); 696 716 } else if (QN_TILE_HEIGHT.equals(qName)) { 697 717 ret.tileHeight = Integer.parseInt(reader.getElementText()); … … 710 730 } 711 731 return ret; 732 } 733 734 private static <T> T parseCoor(String coor, boolean switchXY, BiFunction<String, String, T> function) { 735 String[] parts = coor.split(" "); 736 if (switchXY) { 737 return function.apply(parts[1], parts[0]); 738 } else { 739 return function.apply(parts[0], parts[1]); 740 } 741 } 742 743 private static EastNorth parseEastNorth(String coor, boolean switchXY) { 744 return parseCoor(coor, switchXY, (e, n) -> new EastNorth(Double.parseDouble(e), Double.parseDouble(n))); 745 } 746 747 private static LatLon parseLatLon(String coor, boolean switchXY) { 748 return parseCoor(coor, switchXY, (lon, lat) -> new LatLon(Double.parseDouble(lat), Double.parseDouble(lon))); 749 } 750 751 /** 752 * Parses WGS84BoundingBox section. Returns when reader is on WGS84BoundingBox closing tag. 753 * @param reader StAX reader instance 754 * @return WGS84 bounding box 755 * @throws XMLStreamException See {@link XMLStreamReader} 756 */ 757 private static BBox parseBoundingBox(XMLStreamReader reader) throws XMLStreamException { 758 LatLon lowerCorner = null; 759 LatLon upperCorner = null; 760 for (int event = reader.getEventType(); 761 reader.hasNext() && !(event == XMLStreamReader.END_ELEMENT && 762 QN_OWS_WGS84_BOUNDING_BOX.equals(reader.getName())); 763 event = reader.next()) { 764 if (event == XMLStreamReader.START_ELEMENT) { 765 QName qName = reader.getName(); 766 if (QN_OWS_LOWER_CORNER.equals(qName)) { 767 lowerCorner = parseLatLon(reader.getElementText(), false); 768 } else if (QN_OWS_UPPER_CORNER.equals(qName)) { 769 upperCorner = parseLatLon(reader.getElementText(), false); 770 } 771 } 772 } 773 if (lowerCorner != null && upperCorner != null) { 774 return new BBox(lowerCorner, upperCorner); 775 } 776 return null; 712 777 } 713 778
Note:
See TracChangeset
for help on using the changeset viewer.