Skip to content

Commit

Permalink
Merge branch 'support_crs_84'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Dec 10, 2023
2 parents ebe62e7 + 49209bc commit 57702d9
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 8 deletions.
22 changes: 17 additions & 5 deletions src/main/java/de/blau/android/resources/TileLayerSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class TileLayerSource implements Serializable {
EPSG_3785);
// latlon
public static final String EPSG_4326 = "EPSG:4326";
public static final String CRS_84 = "CRS:84";
//
public static final String TYPE_TMS = "tms";
public static final String TYPE_WMS = "wms";
Expand Down Expand Up @@ -1858,12 +1859,13 @@ String wmsBox(@NonNull final MapTile aTile) {
return buildBox(boxBuilder, GeoMath.tile2lonMerc(tileWidth, aTile.x, zoomLevel), GeoMath.tile2latMerc(tileHeight, y, zoomLevel),
GeoMath.tile2lonMerc(tileWidth, aTile.x + 1, zoomLevel), GeoMath.tile2latMerc(tileHeight, y + 1, zoomLevel));
}
if (EPSG_4326.equals(proj)) {
// note this is hack that simply squashes the vertical axis to fit to square tiles
boolean crs84 = CRS_84.equals(proj);
if (EPSG_4326.equals(proj) || crs84) {
// note this is a hack that simply squashes the vertical axis to fit to square tiles
if (wmsAxisOrder == null) {
wmsAxisOrder = getWmsAxisOrder();
}
if (WMS_AXIS_XY.equals(wmsAxisOrder)) {
if (WMS_AXIS_XY.equals(wmsAxisOrder) || crs84) {
return buildBox(boxBuilder, GeoMath.tile2lon(aTile.x, zoomLevel), GeoMath.tile2lat(aTile.y + 1, zoomLevel),
GeoMath.tile2lon(aTile.x + 1, zoomLevel), GeoMath.tile2lat(aTile.y, zoomLevel));
}
Expand Down Expand Up @@ -2440,14 +2442,24 @@ public static boolean is3857compatible(@Nullable String proj) {
return EPSG_3857_COMPATIBLE.contains(proj);
}

/**
* Check if proj is EPSG_4326 or CRS:84
*
* @param proj the projection
* @return true if compatible
*/
public static boolean isLatLon(@Nullable String proj) {
return EPSG_4326.equals(proj) || CRS_84.equals(proj);
}

/**
* Check if proj is a supported projection
*
* @param proj the projection
* @return true if supported
*/
public static boolean supportedProjection(@Nullable String proj) {
return EPSG_3857_COMPATIBLE.contains(proj) || EPSG_4326.equals(proj);
return EPSG_3857_COMPATIBLE.contains(proj) || isLatLon(proj);
}

private static final Pattern APIKEY_PATTERN = Pattern.compile(".*\\{" + APIKEY_PLACEHOLDER + "\\}.*", Pattern.CASE_INSENSITIVE);
Expand Down Expand Up @@ -2502,7 +2514,7 @@ public void setSource(@NonNull String source) {
*
* @param proj the proj to set
*/
private void setProj(@Nullable String proj) {
void setProj(@Nullable String proj) {
this.proj = proj;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/resources/eli/Eli.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static TileLayerSource geojsonToServer(@NonNull Context ctx, @NonNull Fea
if (projections != null) {
for (JsonElement p : projections) {
String supportedProj = p.getAsString();
boolean latLon = TileLayerSource.EPSG_4326.equals(supportedProj);
boolean latLon = TileLayerSource.isLatLon(supportedProj);
if (TileLayerSource.is3857compatible(supportedProj) || latLon) {
proj = supportedProj;
if (latLon) {
Expand Down
18 changes: 17 additions & 1 deletion src/test/java/de/blau/android/resources/TileLayerSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,36 @@ public void wmsUrl() {
getClass().getResourceAsStream("/wms.geojson"), true);
TileLayerSource.getListsLocked(ApplicationProvider.getApplicationContext(), db.getReadableDatabase(), true);
String[] ids = TileLayerSource.getIds(null, false, null, null);
assertEquals(2, ids.length);
assertEquals(4, ids.length);
// test with EPSG:3857 WMS 1.3
TileLayerSource swisstopo = TileLayerSource.get(ApplicationProvider.getApplicationContext(), "swisstopo_swissimage", false);
assertNotNull(swisstopo);
MapTile tile = new MapTile("", 16, 34387, 22901);
String url = swisstopo.getTileURLString(tile);
assertEquals(
"https://wms.geo.admin.ch?LAYERS=ch.swisstopo.swissimage&STYLES=default&FORMAT=image/jpeg&CRS=EPSG:3857&WIDTH=512&HEIGHT=512&BBOX=990012.3903496042,6033021.768492393,990623.8865758851,6033633.264718674&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap",
url);
// test with EPSG:4326 WMS 1.3
TileLayerSource thurgau = TileLayerSource.get(ApplicationProvider.getApplicationContext(), "kt_tg_av", false);
assertNotNull(thurgau);
url = thurgau.getTileURLString(tile);
assertEquals(
"https://ows.geo.tg.ch/geofy_access_proxy/basisplanf?LAYERS=Basisplan_farbig&STYLES=&FORMAT=image/png&CRS=EPSG:4326&WIDTH=256&HEIGHT=256&BBOX=47.554286701279565,8.8934326171875,47.55799385903775,8.89892578125&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap",
url);
// test with CRS:84 WMS 1.3
TileLayerSource thurgauCrs84 = TileLayerSource.get(ApplicationProvider.getApplicationContext(), "kt_tg_av_crs_84", false);
assertNotNull(thurgauCrs84);
url = thurgauCrs84.getTileURLString(tile);
assertEquals(
"https://ows.geo.tg.ch/geofy_access_proxy/basisplanf?LAYERS=Basisplan_farbig&STYLES=&FORMAT=image/png&CRS=CRS:84&WIDTH=256&HEIGHT=256&BBOX=8.8934326171875,47.554286701279565,8.89892578125,47.55799385903775&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap",
url);
// test with EPSG:4326 WMS 1.1.1
TileLayerSource eoxAT = TileLayerSource.get(ApplicationProvider.getApplicationContext(), "EOXAT2022CLOUDLESS", false);
assertNotNull(eoxAT);
url = eoxAT.getTileURLString(tile);
assertEquals(
"https://s2maps-tiles.eu/?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=s2cloudless-2022_3857&STYLES=&SRS=EPSG:4326&WIDTH=256&HEIGHT=256&BBOX=8.8934326171875,47.554286701279565,8.89892578125,47.55799385903775",
url);
} catch (IOException e) {
fail(e.getMessage());
}
Expand Down
Loading

0 comments on commit 57702d9

Please sign in to comment.