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

[google_maps_flutter_web] Render custom Marker icons. #3273

Merged
merged 7 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,3 +1,8 @@
## 0.1.0+8

* Update `package:google_maps_flutter_platform_interface` to `^1.0.5`.
* Add support for `fromBitmap` BitmapDescriptors. [Issue](https://github.com/flutter/flutter/issues/66622).

## 0.1.0+7

* Substitute `undefined_prefixed_name: ignore` analyzer setting by a `dart:ui` shim with conditional exports. [Issue](https://github.com/flutter/flutter/issues/69309).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Set<Marker> _rawOptionsToInitialMarkers(Map<String, dynamic> rawOptions) {
Offset offset;
LatLng position;
InfoWindow infoWindow;
BitmapDescriptor icon;
if (rawMarker['anchor'] != null) {
offset = Offset((rawMarker['anchor'][0]), (rawMarker['anchor'][1]));
}
Expand All @@ -280,15 +281,17 @@ Set<Marker> _rawOptionsToInitialMarkers(Map<String, dynamic> rawOptions) {
);
}
}
if (rawMarker['icon'] != null) {
icon = BitmapDescriptor.fromJson(rawMarker['icon']);
}
return Marker(
markerId: MarkerId(rawMarker['markerId']),
alpha: rawMarker['alpha'],
anchor: offset,
consumeTapEvents: rawMarker['consumeTapEvents'],
draggable: rawMarker['draggable'],
flat: rawMarker['flat'],
// TODO: Doesn't this support custom icons?
icon: BitmapDescriptor.defaultMarker,
icon: icon,
infoWindow: infoWindow,
position: position ?? _nullLatLng,
rotation: rawMarker['rotation'],
Expand Down Expand Up @@ -432,6 +435,11 @@ gmaps.MarkerOptions _markerOptionsFromMarker(
..size = size
..scaledSize = size;
}
} else if (iconConfig[0] == 'fromBytes') {
// Grab the bytes, and put them into a blob
List<int> bytes = iconConfig[1];
final blob = Blob([bytes]); // Let the browser figure out the encoding
icon = gmaps.Icon()..url = Url.createObjectUrlFromBlob(blob);
}
}
return gmaps.MarkerOptions()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
version: 0.1.0+7
version: 0.1.0+8

flutter:
plugin:
Expand All @@ -16,14 +16,15 @@ dependencies:
flutter_web_plugins:
sdk: flutter
meta: ^1.1.7
google_maps_flutter_platform_interface: ^1.0.4
google_maps_flutter_platform_interface: ^1.0.5
google_maps: ^3.4.5
stream_transform: ^1.2.0
sanitize_html: ^1.4.1

dev_dependencies:
flutter_test:
sdk: flutter
http: ^0.12.2
url_launcher: ^5.2.5
pedantic: ^1.8.0
mockito: ^4.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

import 'package:integration_test/integration_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

import 'package:integration_test/integration_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

import 'package:integration_test/integration_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

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

import 'package:http/http.dart' as http;
import 'package:integration_test/integration_test.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
import 'package:flutter_test/flutter_test.dart';

import 'resources/icon_image_base64.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -141,6 +147,30 @@ void main() {
expect(controller.markers[MarkerId('1')].marker.icon, isNull);
});

//
testWidgets('markers with custom bitmap icon work',
(WidgetTester tester) async {
final bytes = Base64Decoder().convert(iconImageBase64);
final markers = {
Marker(
markerId: MarkerId('1'), icon: BitmapDescriptor.fromBytes(bytes)),
};

controller.addMarkers(markers);

expect(controller.markers.length, 1);
expect(controller.markers[MarkerId('1')].marker.icon, isNotNull);
expect(controller.markers[MarkerId('1')].marker.icon.url,
startsWith('blob:'));

final blobUrl = controller.markers[MarkerId('1')].marker.icon.url;
final response = await http.get(blobUrl);

expect(response.bodyBytes, bytes,
reason:
'Bytes from the Icon blob must match bytes used to create Marker');
});

// https://github.com/flutter/flutter/issues/67854
testWidgets('InfoWindow snippet can have links',
(WidgetTester tester) async {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
final iconImageBase64 =
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAIRlWElmTU'
'0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIA'
'AIdpAAQAAAABAAAAWgAAAAAAAABIAAAAAQAAAEgAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQ'
'AAABCgAwAEAAAAAQAAABAAAAAAx28c8QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlpVFh0WE1M'
'OmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIH'
'g6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8v'
'd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcm'
'lwdGlvbiByZGY6YWJ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nZLVsglaMECW+YmMSj9M3SrC6Lg71CMiqWfUrJ6ywzefhnZ+G69BaKdB'
'WhXQAn6wzDUpfUPw7MrmX/WhbfmKblw+AAAAAElFTkSuQmCC';
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'dart:async';

import 'package:integration_test/integration_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:ui';

Expand Down