a14n / dart-google-maps

A library to use Google Maps JavaScript API v3 from Dart scripts.
Apache License 2.0
130 stars 66 forks source link

map.projection.fromPointToLatLng not correctly bound to projection object? #87

Closed ditman closed 4 years ago

ditman commented 4 years ago

I'm trying to use the fromPointToLatLng method of the default projection of the map, but I'm getting an error:

TypeError: Cannot read property 'y' of undefined.

when I call it like this:

// original JS by: Byron Singh (https://stackoverflow.com/a/30541162)
gmaps.LatLng _pixelToLatLng(gmaps.GMap map, int x, int y) {
  final ne = map.bounds.northEast;
  final sw = map.bounds.southWest;
  final projection = map.projection;

  final topRight = projection.fromLatLngToPoint(ne);   //
  final bottomLeft = projection.fromLatLngToPoint(sw); // <- This two calls work

  final scale = 1 << map.zoom; // 2 ^ zoom

  final point = gmaps.Point((x / scale) + bottomLeft.x, (y / scale) + topRight.y);

  return projection.fromPointToLatLng(point); // <- This blows up!
}

Digging in the JS code a little bit, it seems that when I call the method, this.H is undefined:

Screen Shot 2020-08-15 at 9 21 35 PM

And this is the Window object (from other successful calls of that method, this seems to be an instance of a Projection object).

That this is Window made me suspect that fromPointToLatLng is not correctly bound to the projection object (but my knowledge of this lib is not enough to locate the exact error in Dart :S)

I'm using v3.4.4 of google_maps, according to my pubspec.lock:

  google_maps:
    dependency: transitive
    description:
      name: google_maps
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.4.4"
a14n commented 4 years ago

Sorry for the delay.

It looks really close to #81 . I'll try to fix that.

ditman commented 4 years ago

Ouch! Sorry I didn't find #81, I would have reopened it (x_x)

a14n commented 4 years ago

no, no, it is another issue but with the same behaviour.

The 3.4.5 version should fix this issue.