Skip to content

google_maps_flutter_web marker too big #73789

@BoHellgren

Description

@BoHellgren

I create a marker for Maps using the code below. When I display it with the GoogleMap widget, the icon displayed on the map is about three times as big on Web compared to Android. I have found a workaround as you can see on the line

if (kIsWeb) markerWidth= 30; else markerWidth = 100;

but this should not be necessary!
Using Flutter 1.25.0-8.2.pre • channel beta and --web-renderer canvaskit

import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

Future<BitmapDescriptor> createCustomMarkerBitmap(int markerNumber, String imageURL) async {
  int markerWidth;
  if (kIsWeb) markerWidth= 30; else markerWidth = 100;
  PictureRecorder recorder = new PictureRecorder();
  Canvas c = Canvas(recorder);

  final data1 = await rootBundle.load(imageURL);
  var markerImage = await decodeImageFromList(data1.buffer.asUint8List());
  c.drawImageRect(markerImage, Rect.fromLTRB(
      0.0, 0.0, markerImage.width.toDouble(), markerImage.height.toDouble()),
      Rect.fromLTRB(0.0, 0.0, markerWidth.toDouble(), markerWidth.toDouble()), Paint());

  TextSpan span = TextSpan(
    style: TextStyle(color: Colors.black,fontSize: markerWidth/3,fontWeight: FontWeight.bold),
    text: markerNumber.toString(),
  );
  TextPainter tp = TextPainter(text: span,textAlign: TextAlign.left,textDirection: TextDirection.ltr);
  tp.layout();
  tp.paint(c, Offset(markerNumber > 9 ? markerWidth/3.5 : markerWidth/2.5, markerWidth/5.5));

  var p = recorder.endRecording();
  ByteData pngBytes =
  await (await p.toImage(markerWidth, markerWidth)).toByteData(format: ImageByteFormat.png);
  Uint8List data = Uint8List.view(pngBytes.buffer);
  return BitmapDescriptor.fromBytes(data);
}

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: new featureNothing broken; request for a new capabilitycustomer: famlfound in release: 1.25Found to occur in 1.25has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions