Skip to content

Commit

Permalink
VectorTile Support #544
Browse files Browse the repository at this point in the history
* add maplibre support
* create maplibre view
* create osmbase interface
  • Loading branch information
liodali committed Nov 3, 2024
1 parent 9390c52 commit e2d4d2a
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 10 deletions.
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
}

defaultConfig {
minSdkVersion 19
minSdkVersion 20
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -64,7 +64,7 @@ android {
}
dependencies {

def coroutines_version ="1.8.1"
def coroutines_version ="1.9.0"

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
Expand All @@ -88,6 +88,8 @@ dependencies {
implementation 'org.osmdroid:osmdroid-android:6.1.20'
implementation 'com.github.MKergall:osmbonuspack:6.9.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'org.maplibre.gl:android-sdk:11.5.2'
implementation 'org.maplibre.gl:android-plugin-annotation-v9:3.0.1'

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ class FlutterOsmView(
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
try {
when (call.method) {
"initMap" -> {
initPosition(call, result)
}
"change#tile" -> {
val args = call.arguments as HashMap<String, Any>?
when (!args.isNullOrEmpty()) {
Expand Down Expand Up @@ -395,9 +398,6 @@ class FlutterOsmView(
result.success(isEnabled)
}

"initMap" -> {
initPosition(call, result)
}

"limitArea" -> {
limitCameraArea(call, result)
Expand Down Expand Up @@ -514,7 +514,7 @@ class FlutterOsmView(
}

"draw#rect" -> {
drawShape(call, result, )
drawShape(call, result)
}

"remove#rect" -> {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ class FlutterOsmView(
}


private fun drawShape(call: MethodCall, result: MethodChannel.Result,) {
private fun drawShape(call: MethodCall, result: MethodChannel.Result) {
val args = call.arguments!! as HashMap<*, *>
val key = args["key"] as String
val shape = OSMShape(args, map!!)
Expand All @@ -1049,7 +1049,7 @@ class FlutterOsmView(
}
folderShape.items.add(shape)
if (!map!!.overlays.contains(folderShape)) {
map!!.overlays.add(1,folderShape)
map!!.overlays.add(1, folderShape)
}
map!!.invalidate()
result.success(null)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ class FlutterOsmView(
}

else -> folderShape.items.removeAll { shape ->
shape is OSMShape && shape.shape == Shape.CIRCLE
shape is OSMShape && shape.shape == Shape.CIRCLE
}
}
map!!.invalidate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package hamza.dali.flutter_osm_plugin

import io.flutter.plugin.common.MethodCall

// Define all possible method calls as a sealed class
sealed class MapMethodChannelCall(val methodName: String) {
object Init : MapMethodChannelCall("initMap")
object ChangeTile : MapMethodChannelCall("change#tile")
object InfoWindowVisibility : MapMethodChannelCall("use#visiblityInfoWindow")
object ZoomConfiguration : MapMethodChannelCall("config#Zoom")
object SetZoom : MapMethodChannelCall("Zoom")
object GetZoom : MapMethodChannelCall("get#Zoom")
object SetStepZoom : MapMethodChannelCall("change#stepZoom")
object ZoomToRegion : MapMethodChannelCall("zoomToRegion")
object ShowZoomController : MapMethodChannelCall("showZoomController")
object CurrentLocation : MapMethodChannelCall("currentLocation")
object LimitArea : MapMethodChannelCall("limitArea")
object RemoveLimitArea : MapMethodChannelCall("remove#limitArea")
object TrackMe : MapMethodChannelCall("trackMe")
object DeactivateTrackMe : MapMethodChannelCall("deactivateTrackMe")
object StartLocationUpdating : MapMethodChannelCall("startLocationUpdating")
object StopLocationUpdating : MapMethodChannelCall("stopLocationUpdating")
object Center : MapMethodChannelCall("map#center")
object Bounds : MapMethodChannelCall("map#bounds")
object UserPosition : MapMethodChannelCall("user#position")
object MoveTo : MapMethodChannelCall("moveTo#position")
object RemoveMarkerPosition : MapMethodChannelCall("user#removeMarkerPosition")
object DeleteRoad : MapMethodChannelCall("delete#road")
object DrawMultiRoad : MapMethodChannelCall("draw#multi#road")
object ClearRoads : MapMethodChannelCall("clear#roads")
object DefaultMarkerIcon : MapMethodChannelCall("marker#icon")
object DrawRoadManually : MapMethodChannelCall("drawRoad#manually")
object StaticPosition : MapMethodChannelCall("staticPosition")
object StaticPositionIconMarker : MapMethodChannelCall("staticPosition#IconMarker")
object DrawCircle : MapMethodChannelCall("draw#circle")
object RemoveCircle : MapMethodChannelCall("remove#circle")
object DrawRect : MapMethodChannelCall("draw#rect")
object RemoveRect : MapMethodChannelCall("remove#rect")
object ClearShapes : MapMethodChannelCall("clear#shapes")
object MapOrientation : MapMethodChannelCall("map#orientation")
object LocationMarkers : MapMethodChannelCall("user#locationMarkers")
object AddMarker : MapMethodChannelCall("add#Marker")
object UpdateMarker : MapMethodChannelCall("update#Marker")
object ChangeMarker : MapMethodChannelCall("change#Marker")
object GetMarkers : MapMethodChannelCall("get#geopoints")
object DeleteMakers : MapMethodChannelCall("delete#markers")
object ToggleLayers : MapMethodChannelCall("toggle#Alllayer")
// Add more method calls as needed

companion object {
fun fromMethodCall(call: MethodCall): MapMethodChannelCall? {
return when (call.method) {
Init.methodName -> Init
ChangeTile.methodName -> ChangeTile
InfoWindowVisibility.methodName -> InfoWindowVisibility
ZoomConfiguration.methodName -> ZoomConfiguration
SetZoom.methodName -> SetZoom
GetZoom.methodName -> GetZoom
SetStepZoom.methodName -> SetStepZoom
ZoomToRegion.methodName -> ZoomToRegion
ShowZoomController.methodName -> ShowZoomController
CurrentLocation.methodName -> CurrentLocation
LimitArea.methodName -> LimitArea
RemoveLimitArea.methodName -> RemoveLimitArea
TrackMe.methodName -> TrackMe
DeactivateTrackMe.methodName -> DeactivateTrackMe
StartLocationUpdating.methodName -> StartLocationUpdating
StopLocationUpdating.methodName -> StopLocationUpdating
Center.methodName -> Center
Bounds.methodName -> Bounds
UserPosition.methodName -> UserPosition
MoveTo.methodName -> MoveTo
DeleteRoad.methodName -> DeleteRoad
DrawMultiRoad.methodName -> DrawMultiRoad
DefaultMarkerIcon.methodName -> DefaultMarkerIcon
ClearRoads.methodName -> ClearRoads
DefaultMarkerIcon.methodName -> DefaultMarkerIcon
DrawRoadManually.methodName -> DrawRoadManually
StaticPosition.methodName -> StaticPosition
StaticPositionIconMarker.methodName -> StaticPositionIconMarker
DrawCircle.methodName -> DrawCircle
RemoveCircle.methodName -> RemoveCircle
DrawRect.methodName -> DrawRect
RemoveRect.methodName -> RemoveRect
ClearShapes.methodName -> ClearShapes
MapOrientation.methodName -> MapOrientation
AddMarker.methodName -> AddMarker
LocationMarkers.methodName -> LocationMarkers
AddMarker.methodName -> AddMarker
RemoveMarkerPosition.methodName -> RemoveMarkerPosition
UpdateMarker.methodName -> UpdateMarker
ChangeMarker.methodName -> ChangeMarker
GetMarkers.methodName -> GetMarkers
DeleteMakers.methodName -> DeleteMakers
ToggleLayers.methodName -> ToggleLayers

else -> null
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package hamza.dali.flutter_osm_plugin.maplibre

import androidx.collection.LongSparseArray
import androidx.collection.forEach
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.geometry.LatLngBounds
import org.maplibre.android.plugins.annotation.Symbol
import org.osmdroid.api.IGeoPoint
import org.osmdroid.util.BoundingBox
import org.osmdroid.util.GeoPoint

fun IGeoPoint.toLngLat(): LatLng = LatLng(latitude = latitude, longitude = longitude)
fun LatLng.toGeoPoint(): IGeoPoint = GeoPoint(latitude, longitude)
fun BoundingBox.toBoundsLibre(): LatLngBounds = LatLngBounds.fromLatLngs(
arrayOf(
LatLng(latNorth, lonEast),
LatLng(latSouth, lonWest)
).toList()
)
fun LatLngBounds.toBoundingBox(): BoundingBox = BoundingBox.fromGeoPoints(
this.toLatLngs().toGeoPoints()
)
fun Array<LatLng>.toGeoPoints(): List<IGeoPoint> {
return map {
it.toGeoPoint()
}.toList()
}
fun LongSparseArray<Symbol>.where(f: (Symbol) -> Boolean): Symbol? {
this.forEach { k, symbol ->
if (f(symbol)) {
return symbol
}
}

return null
}
Loading

0 comments on commit e2d4d2a

Please sign in to comment.