Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import kotlinx.serialization.Serializable
import org.owntracks.android.R
import org.owntracks.android.preferences.types.FromConfiguration
import org.owntracks.android.ui.map.osm.OSMMapFragment
import org.osmdroid.tileprovider.tilesource.ITileSource
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.tileprovider.tilesource.XYTileSource
import org.osmdroid.util.MapTileIndex

@Serializable
enum class MapLayerStyle {
Expand All @@ -13,10 +17,12 @@ enum class MapLayerStyle {
GoogleMapSatellite,
GoogleMapTerrain,
OpenStreetMapNormal,
OpenStreetMapWikimedia;
OpenStreetMapWikimedia,
AmapVector,
AmapSatellite;

fun isSameProviderAs(mapLayerStyle: MapLayerStyle): Boolean {
return setOf("GoogleMap", "OpenStreetMap").any {
return setOf("GoogleMap", "OpenStreetMap", "Amap").any {
name.startsWith(it) && mapLayerStyle.name.startsWith(it)
}
}
Expand All @@ -28,10 +34,24 @@ enum class MapLayerStyle {
GoogleMapSatellite,
GoogleMapTerrain -> GoogleMapFragment::class.java
OpenStreetMapNormal,
OpenStreetMapWikimedia -> OSMMapFragment::class.java
OpenStreetMapWikimedia,
AmapVector,
AmapSatellite -> OSMMapFragment::class.java
}
}

fun getTileSource(): ITileSource =
when (this) {
OpenStreetMapNormal -> TileSourceFactory.MAPNIK
OpenStreetMapWikimedia -> TileSourceFactory.WIKIMEDIA
AmapVector -> AMAP_VECTOR
AmapSatellite -> AMAP_SATELLITE
GoogleMapDefault,
GoogleMapHybrid,
GoogleMapSatellite,
GoogleMapTerrain -> TileSourceFactory.MAPNIK
}

companion object {
@JvmStatic
@FromConfiguration
Expand All @@ -40,10 +60,58 @@ enum class MapLayerStyle {
}
}

private val AMAP_VECTOR: ITileSource =
object :
XYTileSource(
"AmapVector",
1,
18,
256,
".png",
arrayOf(
"https://webrd01.is.autonavi.com/",
"https://webrd02.is.autonavi.com/",
"https://webrd03.is.autonavi.com/",
"https://webrd04.is.autonavi.com/")) {
override fun getTileURLString(pMapTileIndex: Long): String {
val z = MapTileIndex.getZoom(pMapTileIndex)
val x = MapTileIndex.getX(pMapTileIndex)
val y = MapTileIndex.getY(pMapTileIndex)
return "${getBaseUrl()}appmaptile?lang=zh_cn&size=1&scale=1&style=8&x=$x&y=$y&z=$z"
}

override fun getCopyrightNotice(): String = "© Amap.com"
}

private val AMAP_SATELLITE: ITileSource =
object :
XYTileSource(
"AmapSatellite",
1,
18,
256,
".jpg",
arrayOf(
"https://webst01.is.autonavi.com/",
"https://webst02.is.autonavi.com/",
"https://webst03.is.autonavi.com/",
"https://webst04.is.autonavi.com/")) {
override fun getTileURLString(pMapTileIndex: Long): String {
val z = MapTileIndex.getZoom(pMapTileIndex)
val x = MapTileIndex.getX(pMapTileIndex)
val y = MapTileIndex.getY(pMapTileIndex)
return "${getBaseUrl()}appmaptile?style=6&x=$x&y=$y&z=$z"
}

override fun getCopyrightNotice(): String = "© Amap.com"
}

val mapLayerSelectorButtonsToStyles =
mapOf(
R.id.fabMapLayerGoogleNormal to MapLayerStyle.GoogleMapDefault,
R.id.fabMapLayerGoogleHybrid to MapLayerStyle.GoogleMapHybrid,
R.id.fabMapLayerGoogleTerrain to MapLayerStyle.GoogleMapTerrain,
R.id.fabMapLayerOpenStreetMap to MapLayerStyle.OpenStreetMapNormal,
R.id.fabMapLayerOpenStreetMapWikimedia to MapLayerStyle.OpenStreetMapWikimedia)
R.id.fabMapLayerOpenStreetMapWikimedia to MapLayerStyle.OpenStreetMapWikimedia,
R.id.fabMapLayerAmapVector to MapLayerStyle.AmapVector,
R.id.fabMapLayerAmapSatellite to MapLayerStyle.AmapSatellite)
45 changes: 45 additions & 0 deletions project/app/src/gms/res/layout/map_layer_bottom_sheet_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,51 @@
android:textAlignment="center" />
</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/fabMapLayerAmapVector"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_margin="12dp"
android:background="@drawable/round_button"
android:backgroundTint="@color/primary_dark"
android:src="@drawable/ic_amap_logo" />

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/mapLayerAmapVectorLabel"
android:textAlignment="center" />
</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/fabMapLayerAmapSatellite"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_margin="12dp"
android:background="@drawable/round_button"
android:backgroundTint="@color/primary_dark"
android:src="@drawable/ic_amap_logo" />

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/mapLayerAmapSatelliteLabel"
android:textAlignment="center" />
</androidx.appcompat.widget.LinearLayoutCompat>

</androidx.appcompat.widget.LinearLayoutCompat>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.osmdroid.events.DelayedMapListener
import org.osmdroid.events.MapListener
import org.osmdroid.events.ScrollEvent
import org.osmdroid.events.ZoomEvent
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.util.TileSystemWebMercator
import org.osmdroid.views.CustomZoomButtonsController
import org.osmdroid.views.MapView
Expand Down Expand Up @@ -440,13 +439,7 @@ internal constructor(
}

override fun setMapLayerType(mapLayerStyle: MapLayerStyle) {
when (mapLayerStyle) {
MapLayerStyle.OpenStreetMapNormal ->
binding.osmMapView.setTileSource(TileSourceFactory.MAPNIK)
MapLayerStyle.OpenStreetMapWikimedia ->
binding.osmMapView.setTileSource(TileSourceFactory.WIKIMEDIA)
else -> Timber.w("Unsupported map layer type $mapLayerStyle")
}
binding.osmMapView.setTileSource(mapLayerStyle.getTileSource())
}

fun createPolygon(mapView: MapView, waypoint: WaypointModel): Polygon {
Expand Down
9 changes: 9 additions & 0 deletions project/app/src/main/res/drawable/ic_amap_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:fillColor="#FFFFFF"
android:pathData="M699.052008 894.366428l-253.855434-159.289336-115.571175 114.768472 44.746184-157.983686L887.097839 163.880236 312.470884 651.791088l-205.584597-128.995835L887.097839 163.876212 699.056031 894.364417zM348.039293 321.886051h122.859882L348.039293 374.779976V321.886051z m675.960707 0v-75.373642C1024 109.706813 917.443646 0 782.927466 0H698.090373v224.076951l-80.471512 34.642986V0H242.63167C108.113477 0-0.002012 109.706813-0.002012 246.51442V321.886051h195.143419v80.471513H0v376.276746C0 915.439906 108.115489 1024 242.63167 1024h374.985179v-145.906923l80.471512 51.270412V1024h84.837093C917.445658 1024 1024 915.439906 1024 778.63431V402.357564h-172.255308l20.717391-80.471513H1024z" />
</vector>
2 changes: 2 additions & 0 deletions project/app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
<string name="mapLayerGoogleMapTerrainLabel">"Google 地形"</string>
<string name="mapLayerOpenStreetMapLabel">"OpenStreetMap"</string>
<string name="mapLayerOpenStreetMapWikimediaLabel">"维基媒体"</string>
<string name="mapLayerAmapVectorLabel">"高德地图"</string>
<string name="mapLayerAmapSatelliteLabel">"高德卫星图"</string>
<string name="menuClear">"清除"</string>
<string name="menuContactNavigate">"导航"</string>
<string name="mode_heading">"模式"</string>
Expand Down
2 changes: 2 additions & 0 deletions project/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ To allow this, please enable Location in the device settings."</string>
<string name="mapLayerGoogleMapTerrainLabel">"Google Terrain"</string>
<string name="mapLayerOpenStreetMapLabel">"OpenStreetMap"</string>
<string name="mapLayerOpenStreetMapWikimediaLabel">"Wikimedia"</string>
<string name="mapLayerAmapVectorLabel">"Amap"</string>
<string name="mapLayerAmapSatelliteLabel">"Amap Satellite"</string>
<string name="menuClear">"Clear"</string>
<string name="menuContactNavigate">"Navigate"</string>
<string name="menuContactRequestLocation">"Request Location"</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,104 @@ package org.owntracks.android.ui.map
import kotlinx.serialization.Serializable
import org.owntracks.android.R
import org.owntracks.android.preferences.types.FromConfiguration
import org.osmdroid.tileprovider.tilesource.ITileSource
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.tileprovider.tilesource.XYTileSource
import org.osmdroid.util.MapTileIndex

@Serializable
enum class MapLayerStyle {
OpenStreetMapNormal,
OpenStreetMapWikimedia;
OpenStreetMapWikimedia,
AmapVector,
AmapSatellite;

fun isSameProviderAs(@Suppress("UNUSED_PARAMETER") mapLayerStyle: MapLayerStyle): Boolean = true
fun isSameProviderAs(mapLayerStyle: MapLayerStyle): Boolean {
return providerGroup() == mapLayerStyle.providerGroup()
}

private fun providerGroup(): String =
when (this) {
OpenStreetMapNormal,
OpenStreetMapWikimedia -> "OpenStreetMap"
AmapVector,
AmapSatellite -> "Amap"
}

fun getTileSource(): ITileSource =
when (this) {
OpenStreetMapNormal -> TileSourceFactory.MAPNIK
OpenStreetMapWikimedia -> TileSourceFactory.WIKIMEDIA
AmapVector -> AMAP_VECTOR
AmapSatellite -> AMAP_SATELLITE
}

companion object {
@JvmStatic
@FromConfiguration
fun getByValue(value: String): MapLayerStyle =
MapLayerStyle.values().firstOrNull { it.name.equals(value, true) } ?: OpenStreetMapNormal
entries.firstOrNull { it.name.equals(value, true) } ?: OpenStreetMapNormal
}
}

/**
* Amap (高德) vector tiles served over HTTPS without an API key. The URL pattern uses query
* string parameters rather than the standard `{z}/{x}/{y}.png` slippy map convention, so we
* subclass XYTileSource to override the URL builder.
*/
private val AMAP_VECTOR: ITileSource =
object :
XYTileSource(
"AmapVector",
1,
18,
256,
".png",
arrayOf(
"https://webrd01.is.autonavi.com/",
"https://webrd02.is.autonavi.com/",
"https://webrd03.is.autonavi.com/",
"https://webrd04.is.autonavi.com/")) {
override fun getTileURLString(pMapTileIndex: Long): String {
val z = MapTileIndex.getZoom(pMapTileIndex)
val x = MapTileIndex.getX(pMapTileIndex)
val y = MapTileIndex.getY(pMapTileIndex)
return "${getBaseUrl()}appmaptile?lang=zh_cn&size=1&scale=1&style=8&x=$x&y=$y&z=$z"
}

override fun getCopyrightNotice(): String = "© Amap.com"
}

/**
* Amap satellite imagery tiles (no API key required). Uses the `webst0X` subdomain (different
* from the vector layer's `webrd0X`) and the `style=6` parameter for raster imagery.
*/
private val AMAP_SATELLITE: ITileSource =
object :
XYTileSource(
"AmapSatellite",
1,
18,
256,
".jpg",
arrayOf(
"https://webst01.is.autonavi.com/",
"https://webst02.is.autonavi.com/",
"https://webst03.is.autonavi.com/",
"https://webst04.is.autonavi.com/")) {
override fun getTileURLString(pMapTileIndex: Long): String {
val z = MapTileIndex.getZoom(pMapTileIndex)
val x = MapTileIndex.getX(pMapTileIndex)
val y = MapTileIndex.getY(pMapTileIndex)
return "${getBaseUrl()}appmaptile?style=6&x=$x&y=$y&z=$z"
}

override fun getCopyrightNotice(): String = "© Amap.com"
}

val mapLayerSelectorButtonsToStyles =
mapOf(
R.id.fabMapLayerOpenStreetMap to MapLayerStyle.OpenStreetMapNormal,
R.id.fabMapLayerOpenStreetMapWikimedia to MapLayerStyle.OpenStreetMapWikimedia)
R.id.fabMapLayerOpenStreetMapWikimedia to MapLayerStyle.OpenStreetMapWikimedia,
R.id.fabMapLayerAmapVector to MapLayerStyle.AmapVector,
R.id.fabMapLayerAmapSatellite to MapLayerStyle.AmapSatellite)
Loading