Skip to content
Merged
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
4 changes: 3 additions & 1 deletion api/android-for-tomtom.api
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public final class com.mapconductor.tomtom.TomTomMapViewController extends com.m
public void setMapDesignTypeChangeListener(kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapDesignTypeInterface<java.lang.String>, kotlin.Unit>);
public java.lang.Object compositionRasterLayers(java.util.List<com.mapconductor.core.raster.RasterLayerState>, kotlin.coroutines.Continuation<? super kotlin.Unit>);
public java.lang.Object updateRasterLayer(com.mapconductor.core.raster.RasterLayerState, kotlin.coroutines.Continuation<? super kotlin.Unit>);
public void mountRasterLayer(com.mapconductor.core.raster.RasterLayerState);
public void unmountRasterLayer(java.lang.String);
public boolean hasRasterLayer(com.mapconductor.core.raster.RasterLayerState);
public java.lang.Object upsertRasterLayer(java.lang.String, java.lang.String, double, int, java.lang.Integer, java.lang.Integer, kotlin.coroutines.Continuation<? super kotlin.Unit>);
public java.lang.Object removeRasterLayer(java.lang.String, kotlin.coroutines.Continuation<? super kotlin.Unit>);
Expand Down Expand Up @@ -150,7 +152,7 @@ public final class com.mapconductor.tomtom.TomTomMapViewHolder implements com.ma
public java.lang.Object getMap();
}
public final class com.mapconductor.tomtom.TomTomMapViewKt {
public static final void TomTomMapView(com.mapconductor.tomtom.TomTomMapViewState, androidx.compose.ui.Modifier, com.mapconductor.core.marker.MarkerTilingOptions, com.mapconductor.core.map.CameraRestriction, kotlin.jvm.functions.Function2<? super android.content.Context, ? super kotlin.coroutines.Continuation<? super java.lang.Boolean>, ? extends java.lang.Object>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapViewStateInterface<?>, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.features.GeoPoint, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.features.GeoPoint, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapCameraPosition, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapCameraPosition, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapCameraPosition, kotlin.Unit>, kotlin.jvm.functions.Function3<? super com.mapconductor.tomtom.TomTomMapViewScope, ? super androidx.compose.runtime.Composer, ? super java.lang.Integer, kotlin.Unit>, androidx.compose.runtime.Composer, int, int, int);
public static final void TomTomMapView(com.mapconductor.tomtom.TomTomMapViewState, androidx.compose.ui.Modifier, com.mapconductor.core.marker.MarkerTilingOptions, com.mapconductor.core.map.CameraRestriction, kotlin.jvm.functions.Function2<? super android.content.Context, ? super kotlin.coroutines.Continuation<? super java.lang.Boolean>, ? extends java.lang.Object>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapViewStateInterface<?>, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.features.GeoPoint, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.features.GeoPoint, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapCameraPosition, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapCameraPosition, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.map.MapCameraPosition, kotlin.Unit>, com.mapconductor.core.map.MapViewStyle, kotlin.jvm.functions.Function1<? super java.util.List<java.lang.String>, kotlin.Unit>, kotlin.jvm.functions.Function3<? super com.mapconductor.tomtom.TomTomMapViewScope, ? super androidx.compose.runtime.Composer, ? super java.lang.Integer, kotlin.Unit>, androidx.compose.runtime.Composer, int, int, int);
public static final com.mapconductor.tomtom.TomTomMapViewController createTomTomMapViewController(com.mapconductor.tomtom.TomTomMapViewHolder, com.mapconductor.core.marker.MarkerTilingOptions, com.mapconductor.core.map.MutableMapServiceRegistry);
}
public final class com.mapconductor.tomtom.TomTomMapViewSaver extends com.mapconductor.compose.map.BaseMapViewSaver<com.mapconductor.tomtom.TomTomMapViewState> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mapconductor/tomtom/TomTomMapDesign.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mapconductor.tomtom

import com.mapconductor.core.map.AttributionRule
import com.mapconductor.core.map.BlankMapStyle
import com.mapconductor.core.map.MapDesignTypeInterface
import com.tomtom.sdk.map.display.style.StandardStyles
import android.net.Uri
import com.mapconductor.core.map.BlankMapStyle
import com.tomtom.sdk.map.display.style.StyleDescriptor
import android.net.Uri

typealias TomTomMapDesignType = MapDesignTypeInterface<String>

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/mapconductor/tomtom/TomTomMapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.mapconductor.core.map.MapCameraPosition
import com.mapconductor.core.map.MapCameraPositionInterface
import com.mapconductor.core.map.MapCapability
import com.mapconductor.core.map.MapCapabilityStatus
import com.mapconductor.core.map.MapViewStyle
import com.mapconductor.core.map.MutableMapServiceRegistry
import com.mapconductor.core.marker.MarkerEventControllerInterface
import com.mapconductor.core.marker.MarkerOverlayRendererInterface
Expand Down Expand Up @@ -54,6 +55,15 @@ fun TomTomMapView(
onCameraMoveStart: OnCameraMoveHandler? = null,
onCameraMove: OnCameraMoveHandler? = null,
onCameraMoveEnd: OnCameraMoveHandler? = null,
/**
* How the map looks, when the app states it rather than naming a design.
*
* A vector style *is* the basemap. `com.mapconductor:vectorstyle` builds
* one; what happens underneath depends on this backend and the app does
* not have to know.
*/
style: MapViewStyle? = null,
onStyleDiagnostics: ((List<String>) -> Unit)? = null,
content: (@Composable TomTomMapViewScope.() -> Unit)? = null,
) {
val scope = remember { TomTomMapViewScope() }
Expand Down Expand Up @@ -182,6 +192,8 @@ fun TomTomMapView(
// 地図が生成されない)。初期化が必要なのは検索/ルーティング等のナビ機能のみ。
sdkInitialize?.invoke(context) ?: true
},
style = style,
onStyleDiagnostics = onStyleDiagnostics,
content = content,
)
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/mapconductor/tomtom/TomTomMapViewController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,23 @@ class TomTomMapViewController internal constructor(
applyPublicRasterLayer(state)
}

/**
* content の外から載せるラスタ(マーカータイル、ベクタースタイルのラスタ化)。
*
* 他プロバイダは [com.mapconductor.core.raster.RasterLayerController] を
* オーバーレイコントローラとして登録してあるので基底の実装で足りるが、
* TomTom はラスタを自前の合成スタイルへ畳み込むのでそれが無い。
* **`publicRasterLayerIds` に入れないこと** — 入れると次の composition が
* 「アプリが宣言していないレイヤ」として掃除してしまう。
*/
override fun mountRasterLayer(state: RasterLayerState) {
mainCoroutine.launch { applyPublicRasterLayer(state) }
}

override fun unmountRasterLayer(id: String) {
mainCoroutine.launch { removeRasterLayer(id) }
}

override fun hasRasterLayer(state: RasterLayerState): Boolean = composedRasterLayers.containsKey(state.id)

override suspend fun upsertRasterLayer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ object TomTomStyleComposer {
/** 可視ベースに使う TomTom ラスタ地図タイル(basic/main)テンプレート(%s = API キー)。 */
private const val BASE_RASTER_TILES = "https://api.tomtom.com/map/1/tile/basic/main/{z}/{x}/{y}.png?key=%s"

/**
* The browsing style's skeleton, kept so a map with no network still has
* the SDK layers it insists on. Private cache only: the JSON carries the
* API key.
*/
private const val BASE_STYLE_CACHE_FILE = "tomtom_base_style.json"

private const val TILE_SIZE = 256

/** 合成スタイルに載せる自前ラスタレイヤー1枚分の指定。 */
Expand Down Expand Up @@ -79,11 +86,22 @@ object TomTomStyleComposer {
withoutBasemap: Boolean = false,
): Uri? =
withContext(Dispatchers.IO) {
// The SDK will not take a style that has none of its own layers
// (it reverts to its default), so every composed style is built
// on the browsing style's skeleton -- which lives on
// api.tomtom.com. Keeping the last copy on disk is what lets the
// map come up at all with no network: the skeleton is reused and
// only the raster layers on top, which are served from the
// device, are drawn.
val cachedBase = File(cacheDir, BASE_STYLE_CACHE_FILE)
val baseJson =
fetch(String.format(BROWSING_STYLE_URL, apiKey)) ?: run {
Log.e(TAG, "Failed to fetch base style JSON")
return@withContext null
}
fetch(String.format(BROWSING_STYLE_URL, apiKey))
?.also { runCatching { cachedBase.writeText(it) } }
?: cachedBase.takeIf { it.isFile }?.let { runCatching { it.readText() }.getOrNull() }
?: run {
Log.e(TAG, "Failed to fetch base style JSON and no cached copy")
return@withContext null
}

val root =
try {
Expand Down Expand Up @@ -114,16 +132,23 @@ object TomTomStyleComposer {
when (type) {
"fill" -> paint.put("fill-opacity", 0)
"line" -> paint.put("line-opacity", 0)
"symbol" -> { paint.put("text-opacity", 0); paint.put("icon-opacity", 0) }
"symbol" -> {
paint.put("text-opacity", 0)
paint.put("icon-opacity", 0)
}
"raster" -> paint.put("raster-opacity", 0)
"fill-extrusion" -> paint.put("fill-extrusion-opacity", 0)
"circle" -> { paint.put("circle-opacity", 0); paint.put("circle-stroke-opacity", 0) }
"circle" -> {
paint.put("circle-opacity", 0)
paint.put("circle-stroke-opacity", 0)
}
"heatmap" -> paint.put("heatmap-opacity", 0)
"hillshade" -> paint.put("hillshade-exaggeration", 0)
}
}
} else {
sources.put("mc-base-raster", rasterSource(String.format(BASE_RASTER_TILES, apiKey), TILE_SIZE, null, null))
sources
.put("mc-base-raster", rasterSource(String.format(BASE_RASTER_TILES, apiKey), TILE_SIZE, null, null))

// 可視ベース地図(ラスタ)は最下層付近("background" の直後)に挿入し、
// ラベル/オーバーレイ/マーカーがその上に来るようにする。
Expand Down
Loading