mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Merge pull request #7340 from hayaksi1/fix/7289-custom-map-style-url
Do not append the application MapTiler key to a custom map style url
This commit is contained in:
+5
-8
@@ -29,14 +29,11 @@ internal class MapTilerTileServerStyleUriBuilder(
|
|||||||
customMapStyleUrl: String?,
|
customMapStyleUrl: String?,
|
||||||
darkMode: Boolean,
|
darkMode: Boolean,
|
||||||
): String {
|
): String {
|
||||||
return buildString {
|
return if (customMapStyleUrl.isNullOrBlank()) {
|
||||||
if (customMapStyleUrl.isNullOrBlank()) {
|
val mapId = if (darkMode) darkMapId else lightMapId
|
||||||
val mapId = if (darkMode) darkMapId else lightMapId
|
"$baseUrl/$mapId/style.json?key=$apiKey"
|
||||||
append("$baseUrl/$mapId/style.json")
|
} else {
|
||||||
} else {
|
customMapStyleUrl
|
||||||
append(customMapStyleUrl)
|
|
||||||
}
|
|
||||||
append("?key=$apiKey")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-2
@@ -46,7 +46,7 @@ class MapTilerTileServerStyleUriBuilderTest {
|
|||||||
customMapStyleUrl = "https://custom.url/style.json",
|
customMapStyleUrl = "https://custom.url/style.json",
|
||||||
darkMode = false,
|
darkMode = false,
|
||||||
)
|
)
|
||||||
).isEqualTo("https://custom.url/style.json?key=anApiKey")
|
).isEqualTo("https://custom.url/style.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -56,6 +56,36 @@ class MapTilerTileServerStyleUriBuilderTest {
|
|||||||
customMapStyleUrl = "https://custom.url/style.json",
|
customMapStyleUrl = "https://custom.url/style.json",
|
||||||
darkMode = true,
|
darkMode = true,
|
||||||
)
|
)
|
||||||
).isEqualTo("https://custom.url/style.json?key=anApiKey")
|
).isEqualTo("https://custom.url/style.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `custom map uri with its own api key is not altered`() {
|
||||||
|
assertThat(
|
||||||
|
builder.build(
|
||||||
|
customMapStyleUrl = "https://api.maptiler.com/maps/streets-v2/style.json?key=anOperatorKey",
|
||||||
|
darkMode = false,
|
||||||
|
)
|
||||||
|
).isEqualTo("https://api.maptiler.com/maps/streets-v2/style.json?key=anOperatorKey")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `custom map uri with an existing query is not altered`() {
|
||||||
|
assertThat(
|
||||||
|
builder.build(
|
||||||
|
customMapStyleUrl = "https://self.hosted/style.json?foo=bar",
|
||||||
|
darkMode = true,
|
||||||
|
)
|
||||||
|
).isEqualTo("https://self.hosted/style.json?foo=bar")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `blank custom map uri falls back to the built-in style`() {
|
||||||
|
assertThat(
|
||||||
|
builder.build(
|
||||||
|
customMapStyleUrl = " ",
|
||||||
|
darkMode = false,
|
||||||
|
)
|
||||||
|
).isEqualTo("https://base.url/aLightMapId/style.json?key=anApiKey")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user