Skip to content

Commit

Permalink
Don't add layers with unsupported image format or projection
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Aug 27, 2023
1 parent 252b991 commit 8df29f1
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/main/java/de/blau/android/resources/WmsCapabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import de.blau.android.exception.UnsupportedFormatException;
import de.blau.android.osm.BoundingBox;
import de.blau.android.osm.Node;
import de.blau.android.util.GeoMath;
Expand Down Expand Up @@ -66,6 +67,12 @@ public class WmsCapabilities {
private static final String REQUEST = "Request";
private static final String GETMAP = "GetMap";
private static final String GET = "Get";
private static final String MAXY_ATTR = "maxy";
private static final String MAXX_ATTR = "maxx";
private static final String MINY_ATTR = "miny";
private static final String MINX_ATTR = "minx";
private static final String ONLINE_RESOURCE = "OnlineResource";
private static final String XLINK_HREF_ATTR = "xlink:href";

private static final String IMAGE_BMP = "image/bmp";
private static final String IMAGE_PNG = "image/png";
Expand Down Expand Up @@ -224,10 +231,10 @@ public void startElement(String uri, String localName, String name, Attributes a
if (TileLayerSource.EPSG_4326.equals(tempCrs)
|| (TileLayerSource.is3857compatible(tempCrs) && !TileLayerSource.EPSG_4326.equals(current.boxCrs))) {
try {
current.minx = new BigDecimal(attr.getValue("minx"));
current.miny = new BigDecimal(attr.getValue("miny"));
current.maxx = new BigDecimal(attr.getValue("maxx"));
current.maxy = new BigDecimal(attr.getValue("maxy"));
current.minx = new BigDecimal(attr.getValue(MINX_ATTR));
current.miny = new BigDecimal(attr.getValue(MINY_ATTR));
current.maxx = new BigDecimal(attr.getValue(MAXX_ATTR));
current.maxy = new BigDecimal(attr.getValue(MAXY_ATTR));
current.boxCrs = tempCrs;
} catch (NumberFormatException e) {
Log.e(DEBUG_TAG, "Error in bounding box " + e.getMessage());
Expand Down Expand Up @@ -309,8 +316,8 @@ public void startElement(String uri, String localName, String name, Attributes a
}
break;
case GET:
if ("OnlineResource".equals(name)) {
getMapUrl = attr.getValue("xlink:href");
if (ONLINE_RESOURCE.equals(name)) {
getMapUrl = attr.getValue(XLINK_HREF_ATTR);
}
break;
default:
Expand Down Expand Up @@ -362,8 +369,12 @@ public void endElement(String uri, String localName, String name) throws SAXExce
break;
case LAYER:
if (!current.group && current.name != null) {
Layer layer = constructLayer(layerStack);
layers.add(layer);
try {
Layer layer = constructLayer(layerStack);
layers.add(layer);
} catch (UnsupportedFormatException fex) {
Log.e(DEBUG_TAG, fex.getMessage());
}
}
layerStack.pop();
currentState = stateStack.pop();
Expand Down Expand Up @@ -483,10 +494,13 @@ public void endElement(String uri, String localName, String name) throws SAXExce
* @return a Layer object
*/
@NonNull
Layer constructLayer(@NonNull Deque<LayerTemp> stack) {
private Layer constructLayer(@NonNull Deque<LayerTemp> stack) {
Layer layer = new Layer();
layer.wmsVersion = wmsVersion;
layer.format = tileFormat;
if (layer.format == null) {
throw new UnsupportedFormatException("No supported image format");
}
StringBuilder resultTitle = new StringBuilder();
boolean first = true;
Iterator<LayerTemp> it = stack.descendingIterator();
Expand All @@ -506,6 +520,8 @@ Layer constructLayer(@NonNull Deque<LayerTemp> stack) {
}
if (t.crs != null) {
layer.proj = t.crs;
} else {
throw new UnsupportedFormatException("No supported projection");
}
if (t.boxCrs != null) {
try {
Expand Down

0 comments on commit 8df29f1

Please sign in to comment.