-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[google_maps_flutter_platform_interface] Platform interface changes to support heatmaps #7312
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
Merged
auto-submit
merged 8 commits into
flutter:main
from
Rexios80:feature/heatmaps-platform-interface
Aug 5, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6875cee
Platform interface changes to support heatmaps
Rexios80 17433ea
Merge branch 'main' into feature/heatmaps-platform-interface
Rexios80 bff33a2
Make this a major version change
Rexios80 252d050
Remove extraneous heatmaps parameters
Rexios80 6edb095
Revert major version change
Rexios80 cac2a4b
Add deprecation annotations
Rexios80 9bca29b
Merge branch 'main' into feature/heatmaps-platform-interface
Rexios80 51232da
Remove deprecation comments
Rexios80 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
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md
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
159 changes: 159 additions & 0 deletions
159
..._flutter/google_maps_flutter_platform_interface/lib/src/method_channel/serialization.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,159 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import '../../google_maps_flutter_platform_interface.dart'; | ||
|
||
String _objectsToAddKey(String name) => '${name}sToAdd'; | ||
String _objectsToChangeKey(String name) => '${name}sToChange'; | ||
String _objectIdsToRemoveKey(String name) => '${name}IdsToRemove'; | ||
const String _heatmapIdKey = 'heatmapId'; | ||
const String _heatmapDataKey = 'data'; | ||
const String _heatmapDissipatingKey = 'dissipating'; | ||
const String _heatmapGradientKey = 'gradient'; | ||
const String _heatmapMaxIntensityKey = 'maxIntensity'; | ||
const String _heatmapOpacityKey = 'opacity'; | ||
const String _heatmapRadiusKey = 'radius'; | ||
const String _heatmapMinimumZoomIntensityKey = 'minimumZoomIntensity'; | ||
const String _heatmapMaximumZoomIntensityKey = 'maximumZoomIntensity'; | ||
const String _heatmapGradientColorsKey = 'colors'; | ||
const String _heatmapGradientStartPointsKey = 'startPoints'; | ||
const String _heatmapGradientColorMapSizeKey = 'colorMapSize'; | ||
|
||
void _addIfNonNull(Map<String, Object?> map, String fieldName, Object? value) { | ||
if (value != null) { | ||
map[fieldName] = value; | ||
} | ||
} | ||
|
||
/// Serialize [MapsObjectUpdates] | ||
Object serializeMapsObjectUpdates<T extends MapsObject<T>>( | ||
MapsObjectUpdates<T> updates, | ||
Object Function(T) serialize, | ||
) { | ||
final Map<String, Object> json = <String, Object>{}; | ||
|
||
_addIfNonNull( | ||
json, | ||
_objectsToAddKey(updates.objectName), | ||
updates.objectsToAdd.map(serialize).toList(), | ||
); | ||
_addIfNonNull( | ||
json, | ||
_objectsToChangeKey(updates.objectName), | ||
updates.objectsToChange.map(serialize).toList(), | ||
); | ||
_addIfNonNull( | ||
json, | ||
_objectIdsToRemoveKey(updates.objectName), | ||
updates.objectIdsToRemove | ||
.map<String>((MapsObjectId<T> m) => m.value) | ||
.toList(), | ||
); | ||
|
||
return json; | ||
} | ||
|
||
/// Serialize [Heatmap] | ||
Object serializeHeatmap(Heatmap heatmap) { | ||
final Map<String, Object> json = <String, Object>{}; | ||
|
||
_addIfNonNull(json, _heatmapIdKey, heatmap.heatmapId.value); | ||
_addIfNonNull( | ||
json, | ||
_heatmapDataKey, | ||
heatmap.data.map(serializeWeightedLatLng).toList(), | ||
); | ||
_addIfNonNull(json, _heatmapDissipatingKey, heatmap.dissipating); | ||
|
||
final HeatmapGradient? gradient = heatmap.gradient; | ||
if (gradient != null) { | ||
_addIfNonNull( | ||
json, _heatmapGradientKey, serializeHeatmapGradient(gradient)); | ||
} | ||
_addIfNonNull(json, _heatmapMaxIntensityKey, heatmap.maxIntensity); | ||
_addIfNonNull(json, _heatmapOpacityKey, heatmap.opacity); | ||
_addIfNonNull(json, _heatmapRadiusKey, heatmap.radius.radius); | ||
_addIfNonNull( | ||
json, _heatmapMinimumZoomIntensityKey, heatmap.minimumZoomIntensity); | ||
_addIfNonNull( | ||
json, _heatmapMaximumZoomIntensityKey, heatmap.maximumZoomIntensity); | ||
|
||
return json; | ||
} | ||
|
||
/// Serialize [WeightedLatLng] | ||
Object serializeWeightedLatLng(WeightedLatLng wll) { | ||
return <Object>[serializeLatLng(wll.point), wll.weight]; | ||
} | ||
|
||
/// Deserialize [WeightedLatLng] | ||
WeightedLatLng? deserializeWeightedLatLng(Object? json) { | ||
if (json == null) { | ||
return null; | ||
} | ||
assert(json is List && json.length == 2); | ||
final List<dynamic> list = json as List<dynamic>; | ||
final LatLng latLng = deserializeLatLng(list[0])!; | ||
return WeightedLatLng(latLng, weight: list[1] as double); | ||
} | ||
|
||
/// Serialize [LatLng] | ||
Object serializeLatLng(LatLng latLng) { | ||
return <Object>[latLng.latitude, latLng.longitude]; | ||
} | ||
|
||
/// Deserialize [LatLng] | ||
LatLng? deserializeLatLng(Object? json) { | ||
if (json == null) { | ||
return null; | ||
} | ||
assert(json is List && json.length == 2); | ||
final List<Object?> list = json as List<Object?>; | ||
return LatLng(list[0]! as double, list[1]! as double); | ||
} | ||
|
||
/// Serialize [HeatmapGradient] | ||
Object serializeHeatmapGradient(HeatmapGradient gradient) { | ||
final Map<String, Object> json = <String, Object>{}; | ||
|
||
_addIfNonNull( | ||
json, | ||
_heatmapGradientColorsKey, | ||
gradient.colors.map((HeatmapGradientColor e) => e.color.value).toList(), | ||
); | ||
_addIfNonNull( | ||
json, | ||
_heatmapGradientStartPointsKey, | ||
gradient.colors.map((HeatmapGradientColor e) => e.startPoint).toList(), | ||
); | ||
_addIfNonNull(json, _heatmapGradientColorMapSizeKey, gradient.colorMapSize); | ||
|
||
return json; | ||
} | ||
|
||
/// Deserialize [HeatmapGradient] | ||
HeatmapGradient? deserializeHeatmapGradient(Object? json) { | ||
if (json == null) { | ||
return null; | ||
} | ||
assert(json is Map); | ||
final Map<String, Object?> map = (json as Map<Object?, Object?>).cast(); | ||
final List<Color> colors = (map[_heatmapGradientColorsKey]! as List<Object?>) | ||
.whereType<int>() | ||
.map((int e) => Color(e)) | ||
.toList(); | ||
final List<double> startPoints = | ||
(map[_heatmapGradientStartPointsKey]! as List<Object?>) | ||
.whereType<double>() | ||
.toList(); | ||
final List<HeatmapGradientColor> gradientColors = <HeatmapGradientColor>[]; | ||
for (int i = 0; i < colors.length; i++) { | ||
gradientColors.add(HeatmapGradientColor(colors[i], startPoints[i])); | ||
} | ||
return HeatmapGradient( | ||
gradientColors, | ||
colorMapSize: map[_heatmapGradientColorMapSizeKey] as int? ?? 256, | ||
); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.