Skip to content

Commit

Permalink
Improve VectorView in Android
Browse files Browse the repository at this point in the history
  • Loading branch information
liodali committed Nov 3, 2024
1 parent e2d4d2a commit dc7cff2
Show file tree
Hide file tree
Showing 11 changed files with 885 additions and 437 deletions.
58 changes: 41 additions & 17 deletions android/src/main/kotlin/hamza/dali/flutter_osm_plugin/OsmFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package hamza.dali.flutter_osm_plugin

import android.app.Activity
import android.content.Context
import hamza.dali.flutter_osm_plugin.map.FlutterMapLibreView
import hamza.dali.flutter_osm_plugin.map.FlutterOsmView
import hamza.dali.flutter_osm_plugin.map.OSM
import hamza.dali.flutter_osm_plugin.models.CustomTile
import hamza.dali.flutter_osm_plugin.models.fromMapToCustomTile
import hamza.dali.flutter_osm_plugin.models.OSMTile
import hamza.dali.flutter_osm_plugin.models.VectorOSMTile
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.StandardMessageCodec
Expand All @@ -14,7 +18,7 @@ open class OsmFactory(
private val binaryMessenger: BinaryMessenger,
private val provider: ProviderLifecycle,
) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
private lateinit var osmFlutterView: FlutterOsmView
private lateinit var osmFlutterView: OSM

private var activity: Activity? = null
private var binding: ActivityPluginBinding? = null
Expand All @@ -24,28 +28,48 @@ open class OsmFactory(
args: Any?,
): PlatformView {
val keyUUID = (args as HashMap<*, *>)["uuid"] as String
var customTile: CustomTile? = null
var customTile: OSMTile? = null
var enableRotationGesture = false
var isVector = false
val staticMap = when {
args.containsKey("isStaticMap")-> args["isStaticMap"] as Boolean
args.containsKey("isStaticMap") -> args["isStaticMap"] as Boolean
else -> false
}
if ((args).containsKey("customTile")) {
customTile = CustomTile.fromMap(args["customTile"] as HashMap<String, Any>)
if (args.containsKey("isVectorTile")) {
isVector = args["isVectorTile"] as Boolean? == true
}
if ((args).containsKey("enableRotationGesture")) {
customTile = when {
args.containsKey("customTile") && !isVector -> CustomTile.fromMap(args["customTile"] as HashMap<String, Any>)
args.containsKey("customTile") && isVector -> VectorOSMTile((args["customTile"] as HashMap<String, *>)["serverStyleUrl"] as String)
else -> null
}
if (args.containsKey("enableRotationGesture")) {
enableRotationGesture = args["enableRotationGesture"] as Boolean
}
osmFlutterView = FlutterOsmView(
requireNotNull(context),
binaryMessenger,
viewId,
provider,
keyUUID,
customTile = customTile,
isEnabledRotationGesture = enableRotationGesture,
isStaticMap = staticMap
)
osmFlutterView = when (isVector) {
true -> FlutterMapLibreView(
requireNotNull(context),
binaryMessenger,
viewId,
provider,
keyUUID,
customTile = customTile,
isEnabledRotationGesture = enableRotationGesture,
isStaticMap = staticMap
)

else -> FlutterOsmView(
requireNotNull(context),
binaryMessenger,
viewId,
provider,
keyUUID,
customTile = customTile as CustomTile,
isEnabledRotationGesture = enableRotationGesture,
isStaticMap = staticMap
)
}

return osmFlutterView
}

Expand Down
Loading

0 comments on commit dc7cff2

Please sign in to comment.