Problem with Polygons while migrating from 3.3 to 3.5

47 views
Skip to first unread message

Andre Tannus

unread,
Jun 8, 2011, 11:15:17 AM6/8/11
to google-map...@googlegroups.com
Hi folks,

A while back I had some trouble with Polygons nor rendering from one day to the next.

Uncaught TypeError: Cannot set property 'Lb' of undefined

I've been investigating this on and off for a few weeks now, and I have found the problem.

It happens when you try to instantiate a new google.maps.Polygon() passing in {paths: []}. This used to work on 3.3, but on 3.5 (and perhaps 3.4?), paths cannot be an empty array. The odd thing is that it CAN be an array of empty arrays!

bad for > 3.4:
new google.maps.Polygon({
  paths: []
})

good for all:
new google.maps.Polygon({
  paths: [[]]
})

Although this isn't too big an issue, it does seem like a bug since the documentation for google.maps.PolygonOptions says:

Paths: The ordered sequence of coordinates that designates a closed loop. Unlike polylines, a polygon may consist of one or more paths. As a result, the paths property may specify one or more arrays ofLatLng coordinates. Simple polygons may be defined using a single array of LatLngs. More complex polygons may specify an array of arrays. Any simple arrays are convered into MVCArrays. Inserting or removing LatLngs from the MVCArray will automatically update the polygon on the map.
Here, Yellow is clearly stating ONE OR MORE, but Red steps back and says a SINGLE ARRAY OF LATLNGS may be used. This is at least inconsistent: If you are able to use an array of empty arrays for complex polygons, you should be able to use an empty array for simple polygons imho.

If the desired behavior is to enforce a non-empty Paths array, I suggest changing the docs sentence to 
Paths: The ordered sequence of coordinates that designates a closed loop. Unlike polylines, a polygon may consist of one or more paths. As a result, the paths property should specify one or more arrays of LatLng coordinates. Simple polygons may be defined using a single array of one or more LatLngs. More complex polygons may specify an array of arrays. Any simple arrays are convered into MVCArrays. Inserting or removing LatLngs from the MVCArray will automatically update the polygon on the map.
I hope I'm not being obtuse here. I really did look for info on this in the forum, but this issue might be too old, and nothing surfaced.

Thanks,

André.

Andrew Leach

unread,
Jun 8, 2011, 11:24:17 AM6/8/11
to google-map...@googlegroups.com
On 8 June 2011 16:15, Andre Tannus <andre....@gmail.com> wrote:
> Hi folks,
> A while back I had some trouble with Polygons nor rendering from one day to
> the next.
> Uncaught TypeError: Cannot set property 'Lb' of undefined
> I've been investigating this on and off for a few weeks now, and I have
> found the problem.
> It happens when you try to instantiate a new google.maps.Polygon() passing
> in {paths: []}. This used to work on 3.3, but on 3.5 (and perhaps 3.4?),
> paths cannot be an empty array. The odd thing is that it CAN be an array of
> empty arrays!

> Although this isn't too big an issue, it does seem like a bug since the


> documentation for google.maps.PolygonOptions says:
>
> Paths: The ordered sequence of coordinates that designates a closed loop.
> Unlike polylines, a polygon may consist of one or more paths. As a result,
> the paths property may specify one or more arrays ofLatLng coordinates.
> Simple polygons may be defined using a single array of LatLngs. More complex
> polygons may specify an array of arrays. Any simple arrays are convered
> into MVCArrays. Inserting or removing LatLngs from the MVCArray will
> automatically update the polygon on the map.

I don't think it's a bug. The documentation clearly says that at least
one array of points is needed, and supplying an empty array doesn't
provide anything. Nowehere does it say that you can start with no
points; indeed, it implies that you must start with a real polygon.

An error caused by [] is not a bug. The fact that [[]] doesn't cause
an error is a bonus.

Andre Tannus

unread,
Jun 8, 2011, 2:41:22 PM6/8/11
to google-map...@googlegroups.com
Thanks for the input.


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.




--
--
A ciência consiste em perturbar um sistema e analisar sua reação. Eu, sou uma perturbação.

André Tannús
Chef, Cook, Solution Designer and Developer at Epungo
+55 11 8053-7636

"Somewhere, something incredible is waiting to be known."
Carl Sagan



Chris Broadfoot

unread,
Jun 8, 2011, 8:42:05 PM6/8/11
to google-map...@googlegroups.com
You should probably be looking at using the setPath method (or path option in PolygonOptions)

I've filed a bug internally - this is a pretty easy fix.

panu

unread,
Jul 20, 2011, 3:16:38 PM7/20/11
to google-map...@googlegroups.com
Is the path option of PolygonOptions a part of the public API? I don't see it in the API reference.

I came across of this same bug when migrating my map application from API version 3.3 to 3.4. I see that the bug has now been fixed in API version 3.5 but it still exists in API version 3.4. This is really troubling because on the one hand Google encourages to develop the map applications using the latest API version but makes it impossible because trivial regressions like this happen all the time (I mean, isn't an empty path like the first test case you come up when testing a polygon API). On the other hand using the released version of the API is not much better if bugs like this will not fixed in that API version.

Rossko

unread,
Jul 20, 2011, 3:22:21 PM7/20/11
to Google Maps JavaScript API v3
> Is the path option of PolygonOptions a part of the public API? I don't see
> it in the API reference.

Well, 'paths' strictly speaking
http://code.google.com/apis/maps/documentation/javascript/reference.html#PolygonOptions
It is there in the english language version, you may be getting
redirected to a different language version which aren't always as
complete it seems.

panu

unread,
Jul 25, 2011, 4:26:24 PM7/25/11
to google-map...@googlegroups.com
Yes, I know that "paths" is a property of PolygonOptions but I indeed meant "path". There seems to be a property of that name. In the polygon example:

http://code.google.com/apis/maps/documentation/javascript/examples/polygon-simple.html

you can change this line:

      paths: triangleCoords,

to this:

      path: triangleCoords,

and it still works. Also, if you add to that example these lines before the bermudaTriangle:

    var emptyTriangle = new google.maps.Polygon({paths: []});
    emptyTriangle.setMap(map);

you can reproduce the problem with API version 3.4. If you change "paths" to "path" then there will be no error.
Reply all
Reply to author
Forward
0 new messages