Changeset 14521 in josm for trunk/test/unit
- Timestamp:
- 2018-12-08T14:19:23+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14519 r14521 13 13 import java.util.Set; 14 14 import java.util.TreeMap; 15 import java.util.stream.Collectors;16 15 17 16 import org.junit.Rule; 18 17 import org.junit.Test; 18 import org.openstreetmap.gui.jmapviewer.Coordinate; 19 19 import org.openstreetmap.gui.jmapviewer.TileXY; 20 20 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; … … 23 23 import org.openstreetmap.gui.jmapviewer.tilesources.ScanexTileSource; 24 24 import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource; 25 import org.openstreetmap.josm.data.Bounds; 25 26 import org.openstreetmap.josm.data.coor.LatLon; 26 27 import org.openstreetmap.josm.data.imagery.CoordinateConversion; … … 33 34 import org.openstreetmap.josm.data.imagery.WMTSTileSource; 34 35 import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException; 35 import org.openstreetmap.josm.data.projection.Projection;36 36 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 37 37 import org.openstreetmap.josm.testutils.JOSMTestRules; 38 import org.openstreetmap.josm.tools.Geometry;39 38 import org.openstreetmap.josm.tools.HttpClient; 40 39 import org.openstreetmap.josm.tools.HttpClient.Response; … … 106 105 } 107 106 107 private static LatLon getPointInShape(Shape shape) { 108 final Coordinate p1 = shape.getPoints().get(0); 109 final Bounds bounds = new Bounds(p1.getLat(), p1.getLon(), p1.getLat(), p1.getLon()); 110 shape.getPoints().forEach(p -> bounds.extend(p.getLat(), p.getLon())); 111 112 final double w = bounds.getWidth(); 113 final double h = bounds.getHeight(); 114 115 final double x2 = bounds.getMinLon() + (w / 2.0); 116 final double y2 = bounds.getMinLat() + (h / 2.0); 117 118 final LatLon center = new LatLon(y2, x2); 119 120 // check to see if center is inside shape 121 if (shape.contains(center)) { 122 return center; 123 } 124 125 // if center position (C) is not inside shape, try naively some other positions as follows: 126 final double x1 = bounds.getMinLon() + (.25 * w); 127 final double x3 = bounds.getMinLon() + (.75 * w); 128 final double y1 = bounds.getMinLat() + (.25 * h); 129 final double y3 = bounds.getMinLat() + (.75 * h); 130 // +-----------+ 131 // | 5 1 6 | 132 // | 4 C 2 | 133 // | 8 3 7 | 134 // +-----------+ 135 for (LatLon candidate : new LatLon[] { 136 new LatLon(y1, x2), 137 new LatLon(y2, x3), 138 new LatLon(y3, x2), 139 new LatLon(y2, x1), 140 new LatLon(y1, x1), 141 new LatLon(y1, x3), 142 new LatLon(y3, x3), 143 new LatLon(y3, x1) 144 }) { 145 if (shape.contains(candidate)) { 146 return candidate; 147 } 148 } 149 return center; 150 } 151 108 152 private static LatLon getCenter(ImageryBounds bounds) { 109 153 List<Shape> shapes = bounds.getShapes(); 110 Projection proj = ProjectionRegistry.getProjection(); 111 return shapes != null && shapes.size() > 1 112 ? proj.eastNorth2latlon( 113 Geometry.getCentroidEN(shapes.get(0).getPoints().stream() 114 .map(CoordinateConversion::coorToLL) 115 .map(proj::latlon2eastNorth) 116 .collect(Collectors.toList()))) 117 : bounds.getCenter(); 154 return shapes != null && !shapes.isEmpty() ? getPointInShape(shapes.get(0)) : bounds.getCenter(); 118 155 } 119 156
Note:
See TracChangeset
for help on using the changeset viewer.