Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add map padding #232

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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 @@ -121,7 +121,7 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
mViewRegistry = viewRegistry
mAutoMapView =
GoogleMapsAutoMapView(
GoogleMapOptions(),
MapOptions(GoogleMapOptions(), null),
viewRegistry,
imageRegistry,
navigationView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ object Convert {
* @param options pigeon message [NavigationViewCreationOptionsDto].
* @return Google Map Options [GoogleMapOptions].
*/
fun convertMapOptionsFromDto(options: MapOptionsDto): GoogleMapOptions {
val mapOptions = GoogleMapOptions()
fun convertMapOptionsFromDto(options: MapOptionsDto): MapOptions {
val googleMapOptions = GoogleMapOptions()

mapOptions.camera(convertCameraPositionFromDto(options.cameraPosition))
mapOptions.mapType(convertMapTypeFromDto(options.mapType))
mapOptions.compassEnabled(options.compassEnabled)
mapOptions.rotateGesturesEnabled(options.rotateGesturesEnabled)
mapOptions.scrollGesturesEnabled(options.scrollGesturesEnabled)
mapOptions.tiltGesturesEnabled(options.tiltGesturesEnabled)
mapOptions.zoomGesturesEnabled(options.zoomGesturesEnabled)
mapOptions.scrollGesturesEnabledDuringRotateOrZoom(
googleMapOptions.camera(convertCameraPositionFromDto(options.cameraPosition))
googleMapOptions.mapType(convertMapTypeFromDto(options.mapType))
googleMapOptions.compassEnabled(options.compassEnabled)
googleMapOptions.rotateGesturesEnabled(options.rotateGesturesEnabled)
googleMapOptions.scrollGesturesEnabled(options.scrollGesturesEnabled)
googleMapOptions.tiltGesturesEnabled(options.tiltGesturesEnabled)
googleMapOptions.zoomGesturesEnabled(options.zoomGesturesEnabled)
googleMapOptions.scrollGesturesEnabledDuringRotateOrZoom(
options.scrollGesturesEnabledDuringRotateOrZoom
)
mapOptions.mapToolbarEnabled(options.mapToolbarEnabled)
googleMapOptions.mapToolbarEnabled(options.mapToolbarEnabled)
options.cameraTargetBounds?.let {
mapOptions.latLngBoundsForCameraTarget(convertLatLngBoundsFromDto(it))
googleMapOptions.latLngBoundsForCameraTarget(convertLatLngBoundsFromDto(it))
}
options.minZoomPreference?.let { mapOptions.minZoomPreference(it.toFloat()) }
options.maxZoomPreference?.let { mapOptions.maxZoomPreference(it.toFloat()) }
mapOptions.zoomControlsEnabled(options.zoomControlsEnabled)
options.minZoomPreference?.let { googleMapOptions.minZoomPreference(it.toFloat()) }
options.maxZoomPreference?.let { googleMapOptions.maxZoomPreference(it.toFloat()) }
googleMapOptions.zoomControlsEnabled(options.zoomControlsEnabled)

return mapOptions
return MapOptions(googleMapOptions, options.padding)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ package com.google.maps.flutter.navigation

import android.content.Context
import android.view.View
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.gms.maps.MapView
import io.flutter.plugin.platform.PlatformView

class GoogleMapView
internal constructor(
context: Context,
mapOptions: GoogleMapOptions,
mapOptions: MapOptions,
viewId: Int,
viewEventApi: ViewEventApi,
private val viewRegistry: GoogleMapsViewRegistry,
imageRegistry: ImageRegistry,
) : PlatformView, GoogleMapsBaseMapView(viewId, mapOptions, viewEventApi, imageRegistry) {
private val _mapView: MapView = MapView(context, mapOptions)
private val _mapView: MapView = MapView(context, mapOptions.googleMapOptions)

override fun getView(): View {
return _mapView
Expand All @@ -51,6 +50,7 @@ internal constructor(
initListeners()
imageRegistry.mapViewInitializationComplete()
mapReady()
mapOptions.padding?.let { setPadding(it) }
jokerttu marked this conversation as resolved.
Show resolved Hide resolved
invalidateViewAfterMapLoad()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ package com.google.maps.flutter.navigation

import android.view.View
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.libraries.navigation.NavigationViewForAuto

class GoogleMapsAutoMapView
internal constructor(
mapOptions: GoogleMapOptions,
mapOptions: MapOptions,
private val viewRegistry: GoogleMapsViewRegistry,
imageRegistry: ImageRegistry,
private val mapView: NavigationViewForAuto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,8 @@ class GoogleMapsAutoViewMessageHandler(private val viewRegistry: GoogleMapsViewR
override fun isAutoScreenAvailable(): Boolean {
return viewRegistry.getAndroidAutoView() != null
}

override fun setPadding(padding: MapPaddingDto) {
getView().setPadding(padding)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.google.android.gms.maps.CameraUpdate
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.Circle
import com.google.android.gms.maps.model.FollowMyLocationOptions
Expand All @@ -39,7 +38,7 @@ import com.google.android.libraries.navigation.NavigationView

abstract class GoogleMapsBaseMapView(
protected val viewId: Int?,
mapOptions: GoogleMapOptions,
mapOptions: MapOptions,
protected val viewEventApi: ViewEventApi?,
private val imageRegistry: ImageRegistry,
) {
Expand Down Expand Up @@ -100,8 +99,8 @@ abstract class GoogleMapsBaseMapView(
}

init {
_minZoomLevelPreference = mapOptions.minZoomPreference
_maxZoomLevelPreference = mapOptions.maxZoomPreference
_minZoomLevelPreference = mapOptions.googleMapOptions.minZoomPreference
_maxZoomLevelPreference = mapOptions.googleMapOptions.maxZoomPreference
}

protected fun mapReady() {
Expand Down Expand Up @@ -942,4 +941,14 @@ abstract class GoogleMapsBaseMapView(
) {}
}
}

fun setPadding(padding: MapPaddingDto) {
getMap()
.setPadding(
padding.left.toInt(),
padding.top.toInt(),
padding.right.toInt(),
padding.bottom.toInt(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ import android.content.Context
import android.content.res.Configuration
import android.view.View
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.libraries.navigation.NavigationView
import io.flutter.plugin.platform.PlatformView

class GoogleMapsNavigationView
internal constructor(
context: Context,
mapOptions: GoogleMapOptions,
mapOptions: MapOptions,
navigationOptions: NavigationViewOptions?,
viewId: Int,
private val viewRegistry: GoogleMapsViewRegistry,
viewEventApi: ViewEventApi,
private val imageRegistry: ImageRegistry,
) : PlatformView, GoogleMapsBaseMapView(viewId, mapOptions, viewEventApi, imageRegistry) {
private val _navigationView: NavigationView = NavigationView(context, mapOptions)
private val _navigationView: NavigationView = NavigationView(context, mapOptions.googleMapOptions)

/// Default values for UI features.
private var _isNavigationTripProgressBarEnabled: Boolean = false
Expand Down Expand Up @@ -79,11 +78,12 @@ internal constructor(
// respected.
_navigationView.isNavigationUiEnabled = navigationViewEnabled
if (!navigationViewEnabled) {
map.moveCamera(CameraUpdateFactory.newCameraPosition(mapOptions.camera))
map.moveCamera(CameraUpdateFactory.newCameraPosition(mapOptions.googleMapOptions.camera))
}

// Call and clear view ready callback if available.
mapReady()
mapOptions.padding?.let { setPadding(it) }
invalidateViewAfterMapLoad()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,8 @@ class GoogleMapsViewMessageHandler(private val viewRegistry: GoogleMapsViewRegis
override fun registerOnCameraChangedListener(viewId: Long) {
getView(viewId.toInt()).registerOnCameraChangedListener()
}

override fun setPadding(viewId: Long, padding: MapPaddingDto) {
getView(viewId.toInt()).setPadding(padding)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.maps.flutter.navigation

import com.google.android.gms.maps.GoogleMapOptions

class MapOptions(val googleMapOptions: GoogleMapOptions, val padding: MapPaddingDto?) {}
Loading
Loading