Skip to content

Commit 4d0e2fa

Browse files
committed
Replace switch: params before url parsing
1 parent 2cf8194 commit 4d0e2fa

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/main/java/de/blau/android/resources/TileLayerSource.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public class TileLayerSource implements Serializable {
108108
public static final String LAYER_NOOVERLAY = "NOOVERLAY";
109109
public static final String LAYER_BING = "BING";
110110

111+
private static final String SWITCH_START = "{switch:";
112+
111113
private static final String WMS_VERSION_130 = "1.3.0";
112114

113115
public enum TileType {
@@ -616,6 +618,19 @@ public TileLayerSource(@NonNull final Context ctx, @Nullable final String id, @N
616618
readOnly = true;
617619
}
618620

621+
// extract switch values
622+
// this needs to happen before URL parsing, as the ":" will trip things up
623+
int switchPos = tileUrl.indexOf(SWITCH_START);
624+
if (switchPos >= 0) {
625+
int switchEnd = tileUrl.indexOf('}', switchPos);
626+
if (switchEnd >= 0) {
627+
String switchValues = tileUrl.substring(switchPos + SWITCH_START.length(), switchEnd);
628+
Collections.addAll(getSubdomains(), switchValues.split(","));
629+
StringBuilder t = new StringBuilder(tileUrl);
630+
setTileUrl(t.replace(switchPos, switchEnd + 1, "{subdomain}").toString());
631+
}
632+
}
633+
619634
String urlPath = null;
620635
try {
621636
URL parsedUrl = new URL(tileUrl);
@@ -675,19 +690,6 @@ protected Void doInBackground(String... params) {
675690
setImageExtension(FileExtensions.JPG);
676691
return;
677692
}
678-
679-
// extract switch values
680-
final String SWITCH_START = "{switch:";
681-
int switchPos = tileUrl.indexOf(SWITCH_START);
682-
if (switchPos >= 0) {
683-
int switchEnd = tileUrl.indexOf('}', switchPos);
684-
if (switchEnd >= 0) {
685-
String switchValues = tileUrl.substring(switchPos + SWITCH_START.length(), switchEnd);
686-
Collections.addAll(getSubdomains(), switchValues.split(","));
687-
StringBuilder t = new StringBuilder(tileUrl);
688-
setTileUrl(t.replace(switchPos, switchEnd + 1, "{subdomain}").toString());
689-
}
690-
}
691693
}
692694

693695
/**

0 commit comments

Comments
 (0)