Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter_web] First version of the plugin. #2933

Merged
merged 58 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d2e53de
Partially implement google_maps_flutter_web
cylyl Mar 6, 2020
b397672
default loc;
cylyl Mar 20, 2020
239b8c9
buildView document
cylyl Mar 31, 2020
0e980a5
Circle
cylyl Apr 1, 2020
188c8dd
onCircleTap
cylyl Apr 2, 2020
7ec2505
Marker events
cylyl Apr 15, 2020
266f473
refactor convert function
cylyl Apr 17, 2020
e95425c
updateMapOptions
cylyl Apr 17, 2020
9ce8771
setMapStyle
cylyl Apr 17, 2020
d03b83f
update pubspec
cylyl Apr 26, 2020
f990aae
Repo surgery
ditman Apr 30, 2020
c16b730
Use creationMapId as a cache key in the buildView method.
ditman Jun 19, 2020
ba3113d
Broadcast Camera Move event.
ditman Jun 24, 2020
687687c
Add CameraMoveStartedEvent, CameraIdleEvent. Remove LongPress on doub…
ditman Jun 24, 2020
dd7be6f
Make controllers emit their own events instead of calling maps contro…
ditman Jun 25, 2020
c52a301
ontab -> onTap
ditman Jun 25, 2020
b78bafa
Support custom marker images from Assets.
ditman Jun 25, 2020
74f9b5a
Implement moveCamera
ditman Jun 26, 2020
eadc5cd
Fix some analyzer issues.
ditman Jul 8, 2020
4c57a93
Refactor options to always use the map setter.
ditman Jul 16, 2020
ca74def
Split _mapStyles in smaller chunks. Fix typos with featureType conver…
ditman Jul 20, 2020
e898703
Add fake podspec
ditman Jul 24, 2020
a8a7c69
Solve flutter analyze (except for missing docs)
ditman Jul 24, 2020
c5579a2
Add documentation
ditman Jul 24, 2020
3f49c88
add license
ditman Jul 24, 2020
6482d13
Automatic pass of dartfmt -w .
ditman Jul 24, 2020
998f378
Test circle.dart
ditman Jul 27, 2020
b9144ab
Format and add tests to Polyline and PolygonControllers
ditman Jul 28, 2020
d219038
Format Marker and add tests
ditman Jul 28, 2020
8798c5e
Make onTap independent from consumeTapEvents
ditman Jul 29, 2020
eadab63
Convert tests in e2e tests with flutter driver
ditman Jul 29, 2020
3c092d5
'Resolve' asset URL so custom pins work in prod.
ditman Jul 29, 2020
2745d15
Update test command to use debug so test failures are visible.
ditman Jul 30, 2020
556cec6
Update README with info about Markers jumping back to their original …
ditman Jul 31, 2020
25dedb7
Reconcile new Marker with existing gmaps.Marker.
ditman Jul 31, 2020
cbe22e2
Use icon width/height if present when converting.
ditman Jul 31, 2020
4de56cc
Use the new new attribute name
ditman Aug 3, 2020
d49481b
Add tests for CirclesController.
ditman Aug 4, 2020
8cdfc26
Test MarkersController.
ditman Aug 4, 2020
e5d91e1
Some formatting/analyzer fixes.
ditman Aug 4, 2020
8520de3
Test MarkersController infoWindow open/close
ditman Aug 5, 2020
1536ea6
Format and test the rest of the shapes.
ditman Aug 5, 2020
f5e5433
Apply BOTH size and scaledSize properties to custom markers
ditman Aug 5, 2020
9fcb61d
Check if the size has actually been passed from the plugin.
ditman Aug 5, 2020
fe950ac
Add traffic layer support, when creating the map, and toggling options.
ditman Aug 6, 2020
deca0eb
Add InfoWindow support.
ditman Aug 6, 2020
74fff64
Hide most of the directly accessible properties in the GoogleMap Cont…
ditman Aug 6, 2020
825eff8
Add e2e to dev_deps so the package becomes publishable
ditman Aug 6, 2020
de87fee
Make flutter analyze happy again.
ditman Aug 6, 2020
9f9a6df
some of the infoWindow content may be null.
ditman Aug 6, 2020
8dd132c
Do not share the StreamController across mapIds.
ditman Aug 7, 2020
a1fe1d7
Do not cache the StreamController in the Plugin, leave it only in the…
ditman Aug 8, 2020
941e511
Update minimum platform_interface version to 1.0.4 to have an overrid…
ditman Aug 12, 2020
cb7a793
Remove all 'options' handling from the plugin implementation, and int…
ditman Aug 12, 2020
ac1d09a
Add tests for GoogleMapsPlugin class.
ditman Aug 13, 2020
b059196
Add tests for google_maps_controller.dart
ditman Aug 16, 2020
5eaeb9e
Address PR comments.
ditman Aug 18, 2020
7292a65
backtick the onTap mention in the CircleController class.
ditman Aug 18, 2020
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
@@ -0,0 +1,3 @@
## 0.1.0

* First open-source version
26 changes: 26 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter_web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2017, the Flutter project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 changes: 51 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter_web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# google_maps_flutter_web

This is an implementation of the [google_maps_flutter](https://pub.dev/packages/google_maps_flutter) plugin for web. Behind the scenes, it uses a14n's [google_maps](https://pub.dev/packages/google_maps) dart JS interop layer.

## Usage

### Depend on the package

This package is not an endorsed implementation of the google_maps_flutter plugin yet, so you'll need to modify the `pubspec.yaml` file of your app to depend on this package:

```yaml
dependencies:
google_maps_flutter: ^0.5.28
google_maps_flutter_web: ^0.1.0
```

### Modify web/index.html

Get an API Key for Google Maps JavaScript API. Get started [here](https://developers.google.com/maps/documentation/javascript/get-api-key).

Modify the `<head>` tag of your `web/index.html` to load the Google Maps JavaScript API, like so:

```html
<head>

<!-- // Other stuff -->

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
</head>
```

Now you should be able to use the Google Maps plugin normally.

## Limitations of the web version

The following map options are not available in web, because the map doesn't rotate there:

* `compassEnabled`
* `rotateGesturesEnabled`
* `tiltGesturesEnabled`

There's no "Map Toolbar" in web, so the `mapToolbarEnabled` option is unused.

There's no "My Location" widget in web ([tracking issue](https://github.com/flutter/flutter/issues/64073)), so the following options are ignored, for now:

* `myLocationButtonEnabled`
* `myLocationEnabled`

There's no `defaultMarkerWithHue` in web. If you need colored pins/markers, you may need to use your own asset images.

Indoor and building layers are still not available on the web. Traffic is.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is a temporary file to allow us to unblock the flutter/plugins repo CI.
# It disables some of lints that were disabled inline. Disabling lints inline
# is no longer possible, so this file is required.
# TODO(ditman) https://github.com/flutter/flutter/issues/55000 (clean this up)

include: ../../../analysis_options.yaml

analyzer:
errors:
undefined_prefixed_name: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint google_maps_flutter_web.podspec' to validate before publishing.
#
Pod::Spec.new do |s|
s.name = 'google_maps_flutter_web'
s.version = '0.1.0'
s.summary = 'No-op implementation of google maps flutter web plugin to avoid build issues on iOS'
s.description = <<-DESC
temp fake google_maps_flutter_web plugin
DESC
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_web'
s.license = { :file => '../LICENSE' }
s.author = { 'Flutter Team' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '8.0'

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
s.swift_version = '5.0'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

library google_maps_flutter_web;

import 'dart:async';
import 'dart:html';
import 'dart:ui' as ui;
import 'dart:convert';

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/gestures.dart';

import 'package:sanitize_html/sanitize_html.dart';

import 'package:stream_transform/stream_transform.dart';

import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:google_maps/google_maps.dart' as gmaps;

import 'src/types.dart';

part 'src/google_maps_flutter_web.dart';
part 'src/google_maps_controller.dart';
part 'src/circle.dart';
part 'src/circles.dart';
part 'src/polygon.dart';
part 'src/polygons.dart';
part 'src/polyline.dart';
part 'src/polylines.dart';
part 'src/marker.dart';
part 'src/markers.dart';
part 'src/convert.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of google_maps_flutter_web;

/// The `CircleController` class wraps a [gmaps.Circle] and its `onTap` behavior.
class CircleController {
gmaps.Circle _circle;

final bool _consumeTapEvents;

/// Creates a `CircleController`, which wraps a [gmaps.Circle] object and its `onTap` behavior.
CircleController({
@required gmaps.Circle circle,
bool consumeTapEvents = false,
ui.VoidCallback onTap,
}) : _circle = circle,
_consumeTapEvents = consumeTapEvents {
if (onTap != null) {
circle.onClick.listen((_) {
onTap.call();
});
}
}

/// Returns the wrapped [gmaps.Circle]. Only used for testing.
@visibleForTesting
gmaps.Circle get circle => _circle;

/// Returns `true` if this Controller will use its own `onTap` handler to consume events.
bool get consumeTapEvents => _consumeTapEvents;

/// Updates the options of the wrapped [gmaps.Circle] object.
void update(gmaps.CircleOptions options) {
_circle.options = options;
}

/// Disposes of the currently wrapped [gmaps.Circle].
void remove() {
_circle.visible = false;
_circle.radius = 0;
_circle.map = null;
_circle = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of google_maps_flutter_web;

/// This class manages all the [CircleController]s associated to a [GoogleMapController].
class CirclesController extends GeometryController {
// A cache of [CircleController]s indexed by their [CircleId].
final Map<CircleId, CircleController> _circleIdToController;

// The stream over which circles broadcast their events
StreamController<MapEvent> _streamController;

/// Initialize the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers.
CirclesController({
@required StreamController<MapEvent> stream,
}) : _streamController = stream,
_circleIdToController = Map<CircleId, CircleController>();

/// Returns the cache of [CircleController]s. Test only.
@visibleForTesting
Map<CircleId, CircleController> get circles => _circleIdToController;

/// Adds a set of [Circle] objects to the cache.
///
/// Wraps each [Circle] into its corresponding [CircleController].
void addCircles(Set<Circle> circlesToAdd) {
circlesToAdd?.forEach((circle) {
_addCircle(circle);
});
}

void _addCircle(Circle circle) {
if (circle == null) {
return;
}

final populationOptions = _circleOptionsFromCircle(circle);
gmaps.Circle gmCircle = gmaps.Circle(populationOptions);
gmCircle.map = googleMap;
CircleController controller = CircleController(
circle: gmCircle,
consumeTapEvents: circle.consumeTapEvents,
onTap: () {
_onCircleTap(circle.circleId);
});
_circleIdToController[circle.circleId] = controller;
}

/// Updates a set of [Circle] objects with new options.
void changeCircles(Set<Circle> circlesToChange) {
circlesToChange?.forEach((circleToChange) {
_changeCircle(circleToChange);
});
}

void _changeCircle(Circle circle) {
final circleController = _circleIdToController[circle?.circleId];
circleController?.update(_circleOptionsFromCircle(circle));
}

/// Removes a set of [CircleId]s from the cache.
void removeCircles(Set<CircleId> circleIdsToRemove) {
circleIdsToRemove?.forEach((circleId) {
final CircleController circleController = _circleIdToController[circleId];
circleController?.remove();
_circleIdToController.remove(circleId);
});
}

// Handles the global onCircleTap function to funnel events from circles into the stream.
bool _onCircleTap(CircleId circleId) {
// Have you ended here on your debugging? Is this wrong?
// Comment here: https://github.com/flutter/flutter/issues/64084
_streamController.add(CircleTapEvent(mapId, circleId));
return _circleIdToController[circleId]?.consumeTapEvents ?? false;
}
}
Loading