This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[google_maps_flutter] add tile overlays #3434
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5ebc39d
platform_interface
e459267
dart
964a5f6
android implemenattion
d6731de
integration_tests
7a7bef2
style fix
040eee6
ios
03390c2
fix no tile return value
5e22757
merge master
5a34d94
fix merge issue
83e10f9
fix with new platform interface api
c4db2c7
Merge branch 'master' into gmap_cutsom_tiles
c09b713
format
b25a00a
minor refactoring
8224d53
minor java code fixes
b9581f9
remove mistake commit
ca69b19
Update packages/google_maps_flutter/google_maps_flutter/android/src/m…
0483931
review
8ceb6a5
revert platform_interface to version dependency
ac26845
update deps to 1.2.0
93808a4
Merge branch 'master' into gmap_cutsom_tiles
4fd5296
Merge branch 'master' into gmap_cutsom_tiles
3d97fd2
rerun ci
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
dart
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
packages/google_maps_flutter/google_maps_flutter/example/lib/tile_overlay.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright 2018 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. | ||
|
|
||
| // ignore_for_file: public_member_api_docs | ||
|
|
||
| import 'dart:typed_data'; | ||
| import 'dart:ui' as ui; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:google_maps_flutter/google_maps_flutter.dart'; | ||
|
|
||
| import 'page.dart'; | ||
|
|
||
| class TileOverlayPage extends GoogleMapExampleAppPage { | ||
| TileOverlayPage() : super(const Icon(Icons.map), 'Tile overlay'); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return const TileOverlayBody(); | ||
| } | ||
| } | ||
|
|
||
| class TileOverlayBody extends StatefulWidget { | ||
| const TileOverlayBody(); | ||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => TileOverlayBodyState(); | ||
| } | ||
|
|
||
| class TileOverlayBodyState extends State<TileOverlayBody> { | ||
| TileOverlayBodyState(); | ||
|
|
||
| GoogleMapController controller; | ||
| TileOverlay _tileOverlay; | ||
|
|
||
| void _onMapCreated(GoogleMapController controller) { | ||
| this.controller = controller; | ||
| } | ||
|
|
||
| @override | ||
| void dispose() { | ||
| super.dispose(); | ||
| } | ||
|
|
||
| void _removeTileOverlay() { | ||
| setState(() { | ||
| _tileOverlay = null; | ||
| }); | ||
| } | ||
|
|
||
| void _addTileOverlay() { | ||
| final TileOverlay tileOverlay = TileOverlay( | ||
| tileOverlayId: TileOverlayId("tile_overlay_1"), | ||
| tileProvider: DebugTileProvider(), | ||
| ); | ||
| setState(() { | ||
| _tileOverlay = tileOverlay; | ||
| }); | ||
| } | ||
|
|
||
| void _clearTileCache() { | ||
| if (_tileOverlay != null && controller != null) { | ||
| controller.clearTileCache(_tileOverlay.tileOverlayId); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Column( | ||
| mainAxisSize: MainAxisSize.min, | ||
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| crossAxisAlignment: CrossAxisAlignment.stretch, | ||
| children: <Widget>[ | ||
| Center( | ||
| child: SizedBox( | ||
| width: 350.0, | ||
| height: 300.0, | ||
| child: GoogleMap( | ||
| initialCameraPosition: const CameraPosition( | ||
| target: LatLng(59.935460, 30.325177), | ||
| zoom: 7.0, | ||
| ), | ||
| tileOverlays: | ||
| _tileOverlay != null ? <TileOverlay>{_tileOverlay} : null, | ||
| onMapCreated: _onMapCreated, | ||
| ), | ||
| ), | ||
| ), | ||
| FlatButton( | ||
| child: const Text('Add tile overlay'), | ||
| onPressed: _addTileOverlay, | ||
| ), | ||
| FlatButton( | ||
| child: const Text('Remove tile overlay'), | ||
| onPressed: _removeTileOverlay, | ||
| ), | ||
| FlatButton( | ||
| child: const Text('Clear tile cache'), | ||
| onPressed: _clearTileCache, | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class DebugTileProvider implements TileProvider { | ||
| DebugTileProvider() { | ||
| boxPaint.isAntiAlias = true; | ||
| boxPaint.color = Colors.blue; | ||
| boxPaint.strokeWidth = 2.0; | ||
| boxPaint.style = PaintingStyle.stroke; | ||
| } | ||
|
|
||
| static const int width = 100; | ||
| static const int height = 100; | ||
| static final Paint boxPaint = Paint(); | ||
| static final TextStyle textStyle = TextStyle( | ||
| color: Colors.red, | ||
| fontSize: 20, | ||
| ); | ||
|
|
||
| @override | ||
| Future<Tile> getTile(int x, int y, int zoom) async { | ||
| final ui.PictureRecorder recorder = ui.PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
| final TextSpan textSpan = TextSpan( | ||
| text: "$x,$y", | ||
| style: textStyle, | ||
| ); | ||
| final TextPainter textPainter = TextPainter( | ||
| text: textSpan, | ||
| textDirection: TextDirection.ltr, | ||
| ); | ||
| textPainter.layout( | ||
| minWidth: 0.0, | ||
| maxWidth: width.toDouble(), | ||
| ); | ||
| final Offset offset = const Offset(0, 0); | ||
| textPainter.paint(canvas, offset); | ||
| canvas.drawRect( | ||
| Rect.fromLTRB(0, 0, width.toDouble(), width.toDouble()), boxPaint); | ||
| final ui.Picture picture = recorder.endRecording(); | ||
| final Uint8List byteData = await picture | ||
| .toImage(width, height) | ||
| .then((ui.Image image) => | ||
| image.toByteData(format: ui.ImageByteFormat.png)) | ||
| .then((ByteData byteData) => byteData.buffer.asUint8List()); | ||
| return Tile(width, height, byteData); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: update to version dep before landing