Skip to content

Commit

Permalink
Implement Satellite Imagery custom maxzoom (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnalis authored Jan 1, 2025
1 parent 989600e commit a9e1e7d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ object ApplicationConstants {

const val NOTE_MIN_ZOOM = 15

/** default maximum zoom for satellite imagery */
const val RASTER_DEFAULT_MAXZOOM = 18

/** when new quests that are appearing due to download of an area, show the hint that he can
* disable quests in the settings if more than X quests did appear */
const val QUEST_COUNT_AT_WHICH_TO_SHOW_QUEST_SELECTION_HINT = 600
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/de/westnordost/streetcomplete/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object Prefs {
const val QUEST_MONITOR_DOWNLOAD = "quest_monitor_download"
const val SHOW_GPX_TRACK = "show_gpx_track"
const val RASTER_TILE_URL = "raster_tile_url"
const val RASTER_TILE_MAXZOOM = "raster_tile_maxzoom"
const val CREATE_EXTERNAL_QUESTS = "create_external_quests"
const val SAVE_PHOTOS = "save_photos"
const val EXPERT_MODE = "expert_mode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private data class Text(
).joinToString()
}

fun createMapStyle(name: String, accessToken: String, languages: List<String>, colors: MapColors, rasterSource: String? = null): String {
fun createMapStyle(name: String, accessToken: String, languages: List<String>, colors: MapColors, rasterSource: String? = null, rasterMaxZoom: Int = 25): String {

val pathWidth = listOf(14.0 to 0.5, 16.0 to 1.0, 24.0 to 256.0) // ~1m

Expand Down Expand Up @@ -638,15 +638,15 @@ fun createMapStyle(name: String, accessToken: String, languages: List<String>, c
*/
)

return """${partBeforeLayers(name, accessToken, rasterSource)}
return """${partBeforeLayers(name, accessToken, rasterSource, rasterMaxZoom)}
{ "id": "background", "type": "background", "paint": {"background-color": "${colors.earth}"}},
${layers.joinToString(",\n ") { it.toJson() }}
]
}
"""
}

private fun partBeforeLayers(name: String, accessToken: String, rasterSource: String?) = """{
private fun partBeforeLayers(name: String, accessToken: String, rasterSource: String?, rasterMaxZoom: Int) = """{
"version": 8,
"name": "$name",
"sources": {
Expand All @@ -659,7 +659,7 @@ private fun partBeforeLayers(name: String, accessToken: String, rasterSource: St
"raster-source": {
"type": "raster",
"tiles": ["$rasterSource"],
"maxzoom": 16
"maxzoom": $rasterMaxZoom
}"""}
},
"transition": { "duration": 300, "delay": 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.res.Configuration
import android.provider.Settings
import androidx.annotation.UiThread
import de.westnordost.streetcomplete.ApplicationConstants
import de.westnordost.streetcomplete.BuildConfig
import de.westnordost.streetcomplete.Prefs
import de.westnordost.streetcomplete.data.preferences.Preferences
Expand Down Expand Up @@ -53,7 +54,7 @@ class SceneMapComponent(
}
val styleJsonString = when {
prefs.prefs.getString(Prefs.THEME_BACKGROUND, "MAP") != "MAP" ->
createMapStyle("StreetComplete-Raster", token, emptyList(), rasterBackground(prefs.prefs.getBoolean(Prefs.NO_SATELLITE_LABEL, false)), prefs.prefs.getString(Prefs.RASTER_TILE_URL, "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"))
createMapStyle("StreetComplete-Raster", token, emptyList(), rasterBackground(prefs.prefs.getBoolean(Prefs.NO_SATELLITE_LABEL, false)), prefs.prefs.getString(Prefs.RASTER_TILE_URL, "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"), prefs.prefs.getInt(Prefs.RASTER_TILE_MAXZOOM, ApplicationConstants.RASTER_DEFAULT_MAXZOOM))
prefs.theme == Theme.DARK_CONTRAST -> createMapStyle("StreetComplete-Dark_Contrast", token, emptyList(), themeDarkContrast)
isNightMode -> context.resources.assets.open("map_theme/streetcomplete-night.json").bufferedReader().use { it.readText() }
else -> context.resources.assets.open("map_theme/streetcomplete.json").bufferedReader().use { it.readText() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.widget.EditText
import android.widget.LinearLayout
Expand All @@ -21,6 +22,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import de.westnordost.streetcomplete.ApplicationConstants
import de.westnordost.streetcomplete.Prefs
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.StreetCompleteApplication
Expand Down Expand Up @@ -155,10 +157,16 @@ class DataManagementSettingsFragment :
setText(R.string.pref_tile_source_hide_labels)
isChecked = prefs.getBoolean(Prefs.NO_SATELLITE_LABEL, false)
}
val maxZoom = EditText(requireContext()).apply {
inputType = InputType.TYPE_CLASS_NUMBER
setText(prefs.getInt(Prefs.RASTER_TILE_MAXZOOM, ApplicationConstants.RASTER_DEFAULT_MAXZOOM).toString())
}
val layout = LinearLayout(requireContext()).apply {
orientation = LinearLayout.VERTICAL
addView(TextView(requireContext()).apply { setText(R.string.pref_tile_source_message) })
addView(urlText)
addView(TextView(requireContext()).apply { setText(R.string.pref_tile_maxzoom) })
addView(maxZoom)
addView(hideLabelsSwitch)
}
d = AlertDialog.Builder(requireContext())
Expand All @@ -168,12 +176,14 @@ class DataManagementSettingsFragment :
.setNeutralButton(R.string.action_reset) { _, _ ->
prefs.edit {
remove(Prefs.RASTER_TILE_URL)
remove(Prefs.RASTER_TILE_MAXZOOM)
remove(Prefs.NO_SATELLITE_LABEL)
}
}
.setPositiveButton(android.R.string.ok) { _, _ ->
prefs.edit {
putString(Prefs.RASTER_TILE_URL, urlText.text.toString())
putInt(Prefs.RASTER_TILE_MAXZOOM, maxZoom.text.toString().toInt())
putBoolean(Prefs.NO_SATELLITE_LABEL, hideLabelsSwitch.isChecked)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings_ee.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<string name="pref_tile_source_title">Tile source for satellite / aerial images</string>
<string name="pref_tile_source_message">Tile URL must contain {x}, {y} and {z}</string>
<string name="pref_tile_source_hide_labels">Hide labels</string>
<string name="pref_tile_maxzoom">Max supported zoom</string>
<string name="pref_tree_custom_quest_summary">See message when enabling quest for details</string>
<string name="pref_update_local_statistics">Update statistics on upload</string>
<string name="pref_update_local_statistics_summary">Disabling accelerates upload and stops achievement messages</string>
Expand Down

0 comments on commit a9e1e7d

Please sign in to comment.