Skip to content

Commit fad3a35

Browse files
ditmancylyl
authored and
Egor
committed
[google_maps_flutter_web] First version of the plugin. (flutter#2933)
This package introduces the first version of the google_maps_flutter_web plugin. See README for installation instructions. Co-authored-by: chung2012 <[email protected]>
1 parent e2b27c1 commit fad3a35

37 files changed

+3558
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0
2+
3+
* First open-source version
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2017, the Flutter project authors. All rights reserved.
2+
Redistribution and use in source and binary forms, with or without
3+
modification, are permitted provided that the following conditions are
4+
met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# google_maps_flutter_web
2+
3+
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.
4+
5+
## Usage
6+
7+
### Depend on the package
8+
9+
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:
10+
11+
```yaml
12+
dependencies:
13+
google_maps_flutter: ^0.5.28
14+
google_maps_flutter_web: ^0.1.0
15+
```
16+
17+
### Modify web/index.html
18+
19+
Get an API Key for Google Maps JavaScript API. Get started [here](https://developers.google.com/maps/documentation/javascript/get-api-key).
20+
21+
Modify the `<head>` tag of your `web/index.html` to load the Google Maps JavaScript API, like so:
22+
23+
```html
24+
<head>
25+
26+
<!-- // Other stuff -->
27+
28+
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
29+
</head>
30+
```
31+
32+
Now you should be able to use the Google Maps plugin normally.
33+
34+
## Limitations of the web version
35+
36+
The following map options are not available in web, because the map doesn't rotate there:
37+
38+
* `compassEnabled`
39+
* `rotateGesturesEnabled`
40+
* `tiltGesturesEnabled`
41+
42+
There's no "Map Toolbar" in web, so the `mapToolbarEnabled` option is unused.
43+
44+
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:
45+
46+
* `myLocationButtonEnabled`
47+
* `myLocationEnabled`
48+
49+
There's no `defaultMarkerWithHue` in web. If you need colored pins/markers, you may need to use your own asset images.
50+
51+
Indoor and building layers are still not available on the web. Traffic is.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This is a temporary file to allow us to unblock the flutter/plugins repo CI.
2+
# It disables some of lints that were disabled inline. Disabling lints inline
3+
# is no longer possible, so this file is required.
4+
# TODO(ditman) https://github.com/flutter/flutter/issues/55000 (clean this up)
5+
6+
include: ../../../analysis_options.yaml
7+
8+
analyzer:
9+
errors:
10+
undefined_prefixed_name: ignore
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
3+
# Run `pod lib lint google_maps_flutter_web.podspec' to validate before publishing.
4+
#
5+
Pod::Spec.new do |s|
6+
s.name = 'google_maps_flutter_web'
7+
s.version = '0.1.0'
8+
s.summary = 'No-op implementation of google maps flutter web plugin to avoid build issues on iOS'
9+
s.description = <<-DESC
10+
temp fake google_maps_flutter_web plugin
11+
DESC
12+
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_web'
13+
s.license = { :file => '../LICENSE' }
14+
s.author = { 'Flutter Team' => '[email protected]' }
15+
s.source = { :path => '.' }
16+
s.source_files = 'Classes/**/*'
17+
s.dependency 'Flutter'
18+
s.platform = :ios, '8.0'
19+
20+
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
21+
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
22+
s.swift_version = '5.0'
23+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
library google_maps_flutter_web;
6+
7+
import 'dart:async';
8+
import 'dart:html';
9+
import 'dart:ui' as ui;
10+
import 'dart:convert';
11+
12+
import 'package:flutter/rendering.dart';
13+
import 'package:flutter/widgets.dart';
14+
import 'package:flutter/material.dart';
15+
import 'package:flutter/foundation.dart';
16+
import 'package:flutter/services.dart';
17+
import 'package:flutter/gestures.dart';
18+
19+
import 'package:sanitize_html/sanitize_html.dart';
20+
21+
import 'package:stream_transform/stream_transform.dart';
22+
23+
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
24+
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
25+
import 'package:google_maps/google_maps.dart' as gmaps;
26+
27+
import 'src/types.dart';
28+
29+
part 'src/google_maps_flutter_web.dart';
30+
part 'src/google_maps_controller.dart';
31+
part 'src/circle.dart';
32+
part 'src/circles.dart';
33+
part 'src/polygon.dart';
34+
part 'src/polygons.dart';
35+
part 'src/polyline.dart';
36+
part 'src/polylines.dart';
37+
part 'src/marker.dart';
38+
part 'src/markers.dart';
39+
part 'src/convert.dart';
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
part of google_maps_flutter_web;
6+
7+
/// The `CircleController` class wraps a [gmaps.Circle] and its `onTap` behavior.
8+
class CircleController {
9+
gmaps.Circle _circle;
10+
11+
final bool _consumeTapEvents;
12+
13+
/// Creates a `CircleController`, which wraps a [gmaps.Circle] object and its `onTap` behavior.
14+
CircleController({
15+
@required gmaps.Circle circle,
16+
bool consumeTapEvents = false,
17+
ui.VoidCallback onTap,
18+
}) : _circle = circle,
19+
_consumeTapEvents = consumeTapEvents {
20+
if (onTap != null) {
21+
circle.onClick.listen((_) {
22+
onTap.call();
23+
});
24+
}
25+
}
26+
27+
/// Returns the wrapped [gmaps.Circle]. Only used for testing.
28+
@visibleForTesting
29+
gmaps.Circle get circle => _circle;
30+
31+
/// Returns `true` if this Controller will use its own `onTap` handler to consume events.
32+
bool get consumeTapEvents => _consumeTapEvents;
33+
34+
/// Updates the options of the wrapped [gmaps.Circle] object.
35+
void update(gmaps.CircleOptions options) {
36+
_circle.options = options;
37+
}
38+
39+
/// Disposes of the currently wrapped [gmaps.Circle].
40+
void remove() {
41+
_circle.visible = false;
42+
_circle.radius = 0;
43+
_circle.map = null;
44+
_circle = null;
45+
}
46+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
part of google_maps_flutter_web;
6+
7+
/// This class manages all the [CircleController]s associated to a [GoogleMapController].
8+
class CirclesController extends GeometryController {
9+
// A cache of [CircleController]s indexed by their [CircleId].
10+
final Map<CircleId, CircleController> _circleIdToController;
11+
12+
// The stream over which circles broadcast their events
13+
StreamController<MapEvent> _streamController;
14+
15+
/// Initialize the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers.
16+
CirclesController({
17+
@required StreamController<MapEvent> stream,
18+
}) : _streamController = stream,
19+
_circleIdToController = Map<CircleId, CircleController>();
20+
21+
/// Returns the cache of [CircleController]s. Test only.
22+
@visibleForTesting
23+
Map<CircleId, CircleController> get circles => _circleIdToController;
24+
25+
/// Adds a set of [Circle] objects to the cache.
26+
///
27+
/// Wraps each [Circle] into its corresponding [CircleController].
28+
void addCircles(Set<Circle> circlesToAdd) {
29+
circlesToAdd?.forEach((circle) {
30+
_addCircle(circle);
31+
});
32+
}
33+
34+
void _addCircle(Circle circle) {
35+
if (circle == null) {
36+
return;
37+
}
38+
39+
final populationOptions = _circleOptionsFromCircle(circle);
40+
gmaps.Circle gmCircle = gmaps.Circle(populationOptions);
41+
gmCircle.map = googleMap;
42+
CircleController controller = CircleController(
43+
circle: gmCircle,
44+
consumeTapEvents: circle.consumeTapEvents,
45+
onTap: () {
46+
_onCircleTap(circle.circleId);
47+
});
48+
_circleIdToController[circle.circleId] = controller;
49+
}
50+
51+
/// Updates a set of [Circle] objects with new options.
52+
void changeCircles(Set<Circle> circlesToChange) {
53+
circlesToChange?.forEach((circleToChange) {
54+
_changeCircle(circleToChange);
55+
});
56+
}
57+
58+
void _changeCircle(Circle circle) {
59+
final circleController = _circleIdToController[circle?.circleId];
60+
circleController?.update(_circleOptionsFromCircle(circle));
61+
}
62+
63+
/// Removes a set of [CircleId]s from the cache.
64+
void removeCircles(Set<CircleId> circleIdsToRemove) {
65+
circleIdsToRemove?.forEach((circleId) {
66+
final CircleController circleController = _circleIdToController[circleId];
67+
circleController?.remove();
68+
_circleIdToController.remove(circleId);
69+
});
70+
}
71+
72+
// Handles the global onCircleTap function to funnel events from circles into the stream.
73+
bool _onCircleTap(CircleId circleId) {
74+
// Have you ended here on your debugging? Is this wrong?
75+
// Comment here: https://github.com/flutter/flutter/issues/64084
76+
_streamController.add(CircleTapEvent(mapId, circleId));
77+
return _circleIdToController[circleId]?.consumeTapEvents ?? false;
78+
}
79+
}

0 commit comments

Comments
 (0)