Skip to content

Commit

Permalink
feat: standalone classic mapview (#181)
Browse files Browse the repository at this point in the history
* feat: implementing separate google map view on flutter side wip

* feat: map view ios separation and example app page wip

* feat: map view android separation wip

* fix: fix tests and format

* fix: flutter analyze fix

* feature: example app multiple map page supports now non-navigation map

* docs: update readme for non-navigation map view

* fix: remove navigation variables and references from map view files

* docs: update dart doc

* refactor: listener and map view refactoring

* refactor: navigation viewcontroller now extends map viewcontroller in flutter

* refactor: android redundant function removal

* fix: general fixes and refactoring

* refactor: android base map view refactoring

* test: update integration tests for regular google map view

* refactor: refactor tests and view handling

* refactor: refactoring and minor fixes

* test: refactor integration tests
  • Loading branch information
illuminati1911 authored Oct 29, 2024
1 parent 8f0283f commit e85f590
Show file tree
Hide file tree
Showing 53 changed files with 5,338 additions and 4,247 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ The view can be controlled with the `GoogleNavigationViewController` that is pas
The `GoogleMapsNavigationView` widget should be used within a widget with a bounded size. Using it
in an unbounded widget will cause the application to throw a Flutter exception.
You can also add a bare GoogleMapsMapView that works as a normal map view without navigation functionality.
### Add a navigation view
```dart
Expand Down Expand Up @@ -139,6 +141,29 @@ class _NavigationSampleState extends State<NavigationSample> {
}
```

### Add a map view

```dart
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Google Maps Navigation Sample')),
body: _navigationSessionInitialized
? GoogleMapsMapView(
onViewCreated: _onViewCreated,
initialCameraPosition: CameraPosition(
// Initialize map to user location.
target: _userLocation!,
zoom: 15,
),
// Other view initialization settings
)
: const Center(child: CircularProgressIndicator()),
);
}
```

See the [example](./example) directory for a complete navigation sample app.

### Requesting and handling permissions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2023 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 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,
viewId: Int,
viewEventApi: ViewEventApi,
private val viewRegistry: GoogleMapsViewRegistry,
imageRegistry: ImageRegistry
) : PlatformView, GoogleMapsBaseMapView(viewId, mapOptions, viewEventApi, imageRegistry) {
private val _mapView: MapView = MapView(context, mapOptions)

override fun getView(): View {
return _mapView
}

init {
// Call all of these three lifecycle functions in sequence to fully
// initialize the map view.
_mapView.onCreate(context.applicationInfo.metaData)
_mapView.onStart()
_mapView.onResume()

_mapView.getMapAsync { map ->
setMap(map)
initListeners()
imageRegistry.mapViewInitializationComplete()
mapReady()
invalidateViewAfterMapLoad()
}

viewRegistry.registerMapView(viewId, this)
}

override fun dispose() {
// When view is disposed, all of these lifecycle functions must be
// called to properly dispose navigation view and prevent leaks.
_mapView.onPause()
_mapView.onStop()
_mapView.onDestroy()

viewRegistry.unregisterMapView(viewId)
}

override fun onStart() {
_mapView.onStart()
}

override fun onResume() {
_mapView.onResume()
}

override fun onStop() {
_mapView.onStop()
}

override fun onPause() {
_mapView.onPause()
}
}
Loading

0 comments on commit e85f590

Please sign in to comment.