Converting polylines to polygons and vice versa - "Closing" issue with MVCArrays

2,949 views
Skip to first unread message

evilC

unread,
Jan 27, 2010, 8:55:40 AM1/27/10
to Google Maps JavaScript API v3
If you create a polygon from an MVCArray of latlngs, then append nodes
to that MVCArray, the polygon overlay updates to reflect the changes,
all good so far.

However, if you remove the polygon overlay and create a polyline
overlay using the *same MVCArray*, the resultant polyline is "closed"
like a polygon (There is an extra line from the last node to the
first).

There is no duplicate node at the end of the MVCArray to "close" the
polygon, this is not the problem. It is something about the MVCArray -
once you pass it to a Polygon constructor, it "closes" the MVCArray
somehow. If I loop through the MVCArray and extract each latlng to
build a new array, the polygon is not closed.

Does anyone know if there is a way to "un-close" the polyline without
rebuilding the MVCArray?

TIA

Clive

Ben Appleton

unread,
Jan 27, 2010, 9:38:35 PM1/27/10
to google-map...@googlegroups.com
Thanks for the bug report, I've prepared a fix.  This should go live in the next week or two.

As a temporary workaround, 2 different MVCArrays can contain the same JS Array.  For example

var coordinates = [...];  // LatLngs
var polylinePath = new MVCArray(coordinates);
var polygonPath = new MVCArray(coordinates);

Then polylinePath and polygonPath can be passed to Polyline and Polygon instances without accidentally closing your Polylines.


--
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.


evilC

unread,
Jan 29, 2010, 7:48:18 PM1/29/10
to Google Maps JavaScript API v3
Thanks Ben,
I don't actually store the path anywhere else, I have adopted the
MVCArray as my "internal" format...
It's cool, changing from line to poly or whatever is not a common
action, so for now, rebuilding the MVCArray on change of geometry type
will do as a workaround.

If you could be so kind as to post on here when the fix is live, that
would be great - I could then remove the workaround and report back
success or failure ;)

Many thanks

Clive

Ben Appleton

unread,
Jan 31, 2010, 8:00:27 PM1/31/10
to google-map...@googlegroups.com
I've filed a bug in the issue tracker, please track this:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=2135


Clive

Reply all
Reply to author
Forward
0 new messages