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
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ plugins {
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.kotlinSerialization) apply false
alias(libs.plugins.vanniktechPublish) apply false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ovh.plrapps.mapcompose.demo.ui.screens

import androidx.compose.runtime.Composable
import androidx.lifecycle.viewmodel.compose.viewModel
import ovh.plrapps.mapcompose.demo.viewmodels.SwissMapVectorDemoVM

actual object SwissMapVectorDemo {
@Composable
actual fun Content() {
val viewModel: SwissMapVectorDemoVM = viewModel()

SwissMapVectorCommonUi(viewModel)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ovh.plrapps.mapcompose.demo.ui.screens

import androidx.compose.runtime.Composable
import androidx.lifecycle.viewmodel.compose.viewModel
import ovh.plrapps.mapcompose.demo.viewmodels.VectorDemoVM

actual object VectorDemo {
@Composable
actual fun Content() {
val screenModel: VectorDemoVM = viewModel()

VectorCommonUi(screenModel)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package ovh.plrapps.mapcompose.demo.viewmodels

import kotlinx.io.Buffer
import kotlinx.io.RawSource
import kotlinx.io.asSource
import org.jetbrains.compose.resources.ExperimentalResourceApi
import ovh.plrapps.mapcompose.core.TileStreamProvider
import ovh.plrapps.mapcompose.vector.core.VectorTileStreamProvider
import ovh.plrapps.mapcomposemp.demo.Res
import java.net.HttpURLConnection
import java.net.URL

Expand Down Expand Up @@ -42,4 +47,44 @@ actual fun makeOsmTileStreamProvider() : TileStreamProvider {
null
}
}
}

actual class OSMVectorTileStreamProvider actual constructor(actual override val styleUrl: String) :
VectorTileStreamProvider {

@OptIn(ExperimentalResourceApi::class)
actual override suspend fun loadResources(url: String): RawSource? {
return when (url) {
"files/style_street_v2.json" -> {
val buffer = Buffer()
buffer.write(Res.readBytes(url))
buffer
}
else -> getResourceAsStream(url)
}
}

actual override suspend fun getTileStream(
tileUrl: String,
row: Int,
col: Int,
zoomLvl: Int
): RawSource? {
return getResourceAsStream(tileUrl)
}

private fun getResourceAsStream(url: String): RawSource? {
return try {
val url = URL(url)
val connection = url.openConnection() as HttpURLConnection
// OSM requires a user-agent
connection.setRequestProperty("User-Agent", "Chrome/120.0.0.0 Safari/537.36")
connection.doInput = true
connection.connect()
connection.inputStream.asSource()
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
Loading