On Wed, Nov 25, 2009 at 3:32 AM, arclyte <[email protected]> wrote: > Thanks for the help, Ben. I've been moving brackets, commas and > parentheses around like mad for an hour or two now but am still having > trouble. I tried your suggestion and got it working, but the trouble > comes in when I try to specify a polygon with an inner ring/ > exclusion. Let me detail it a bit... > > poly = new google.maps.Polygon({}); > > path = new google.maps.MVCArray([new google.maps.LatLng > (40.79607046969819, -74.03931065508519),new google.maps.LatLng > (40.79594051506491, -73.99828358599339),new google.maps.LatLng > (40.77033449116813, -73.99845524737034),new google.maps.LatLng > (40.77072450463922, -74.03828068682347)]); > > poly.setPaths(path); > > This code works fine. It creates a square(ish) polygon over West New > York, NJ. If I try to add another path... > > path = new google.maps.MVCArray([new google.maps.LatLng > (40.787492918244446, -74.03089924761449),new google.maps.LatLng > (40.78879261847979, -74.007038316218),new google.maps.LatLng > (40.77657443199805, -74.00652333208714),new google.maps.LatLng > (40.777484374404445, -74.03038426348363)]); > > poly.setPaths(path); > > ... it creates a second, smaller rectangle inside the first. As > expected, they are separate polygons. What I'd like to do is specify > these as a singly polygon with the smaller rectangle as an exclusion > of the larger. Here is what I tried: > > path = new google.maps.MVCArray([new google.maps.LatLng > (40.79607046969819, -74.03931065508519),...],[new google.maps.LatLng > (40.787492918244446, -74.03089924761449),...]); > > The method works but only adds the first polygon to the map, ignoring > the rest of the array. > > > path = new google.maps.MVCArray([[new google.maps.LatLng > (40.79607046969819, -74.03931065508519),...], [new google.maps.LatLng > (40.787492918244446, -74.03089924761449),...]]); > > This method doesn't work and gives the invalid constructor (object) > error. >
Try: var outer = new google.maps.MVCArray([new google.maps.LatLng (40.79607046969819, -74.03931065508519),...]); var inner = new google.maps.MVCArray([new google.maps.LatLng (40.787492918244446, -74.03089924761449),...]); var paths = new MVCArray([outer, inner]); poly.setPaths(paths); I've also tried manually adding points to the sub-arrays... path[0][1] > = new LatLng(); but couldn't get that going either. > > I'm hoping this is just my lack of understanding about the MVCArray... > Is it possible to properly structure a multidimensional array as input > for the MVCArray such that it will produce polygons with inner > rings? > > I've looked at the pentagon example (http://gmaps-samples- > v3.googlecode.com/svn/trunk/poly/pentagon.html) but that is using a > regular multi-dim array, which is basically what I'm doing now. I'd > really like to have it as an MVCArray so I can trigger the updates > automatically. > In that demo I've used a feature of setPaths(), which is that it will automagically convert JS Arrays to MVCArrays, even converting nested JS Arrays to nested MVCArrays. So rather than creating MVCArrays manually above, another possibility would be to feed .setPaths() a multi-dim JS Array, then .getPaths() to retrieve the nested MVCArray and edit that. By the way, note that in Safari and Chrome, inner exclusions have to be specified in reverse order compared to the outer boundary. So if the outer boundary is clockwise, the inner boundary has to be counter-clockwise. This is because Safari and Chrome render with Canvas, which does not implement the usual even-odd winding rule for polygon rendering, but implements a non-zero winding rule instead. - Jim > > > On Nov 24, 12:58 am, Ben Appleton <[email protected]> wrote: > > On Tue, Nov 24, 2009 at 6:05 AM, arclyte <[email protected]> wrote: > > > Can anyone (Ben?) provide an example of how I can prepopulate an > > > MVCArray? I think that's my problem. > > > > If you write > > new MVCArray([... your points here ...]); > > then the MVCArray adopts the given array for its internal storage. The > > .setAt(), .insertAt(), .deleteAt() methods will modify the given array, > and > > fire change events so the polygon knows to redraw. > > > > Ben, the example you provide instantiates an empty array and fill it > > > > > on click. I'm doing that in my script, but it must also pre-load some > > > stored polygons. I'm trying to get away from the way we used to do it > > > in v2 with a thousand lines of pushing points. If I could construct > > > the array of points and define it in the constructor that'd be much > > > better, to my eyes anyway. I've tested and can manually push (.setAt) > > > points into the path/poly but any time I've tried to pre-define it I > > > get the constructor errors I've mentioned. Thanks! > > > > > - Jim > > > > > On Nov 23, 12:45 pm, arclyte <[email protected]> wrote: > > > > I kind of hacked this together based on a prototype, so it's gone > > > > through a few different versions. I had tried to simplify things and > > > > ended up changing path from an MVCArray to just an array. It looks > > > > like that's probably my downfall, forcing me to update the polygon in > > > > order to see the changes that were made in the path. > > > > > > I did that, though, because I've had some trouble getting MVCArray > > > > working correctly. I keep getting errors like this: "Invalid value > > > > for constructor parameter 0: [object Object] > > >http://maps.gstatic.com/intl/en_us/mapfiles/api-3/22a/main.jsLine > > > > 52". I'm guessing it's just syntax, but I'm not familiar enough with > > > > the MVCArray to figure it out in this context. > > > > > > Back to fiddling with it I suppose... Thanks for the response! > > > > > > On Nov 22, 7:34 pm, Ben Appleton <[email protected]> wrote: > > > > > > > On Sat, Nov 21, 2009 at 5:49 AM, arclyte <[email protected]> > wrote: > > > > > > I'm guessing that this is a bug in my code somewhere, but I > haven't > > > > > > been able to figure out where just yet. > > > > > > > > Here is the sample for my current code: > > > > > >http://arclyte.netdojo.com/geo/polyDraw.php > > > > > > > > If you click on the map you'll start placing markers, or you can > > > click > > > > > > on the color box next to a polygon to load markers for that > polygon > > > > > > and edit it. > > > > > > > > My polygon is defined as an array of polygons, so the new (green) > > > > > > polygon is in poly[2]. If you click and add points to the > polygon > > > you > > > > > > can see that the points actually are contained within the object > but > > > > > > the polygon display is not being updated. > > > > > > > > I've found that if I call poly[n].setMaps(map) on the polygon I'm > > > > > > editing it will redraw and show the new/edited points. But that > > > means > > > > > > redrawing the polygon each time... I'm afraid that won't scale > very > > > > > > well if we get very large polygons. It also gives a nice flicker > > > > > > every time you draw a point which I'd rather avoid. > > > > > > > I see you've tried MVCArray's .insertAt(), which notifies the > polygon > > > of a > > > > > change in its coordinates. But that code is currently commented > out. > > > Did > > > > > that not work? > > > > > > > For reference, I use MVCArray's .insertAt() in this polygon editing > > > demo: > http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/poly_edit.html > > > > > > > -- > > > > > > > > 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 > > > > > > [email protected]. > > > > > > To unsubscribe from this group, send email to > > > > > > [email protected]<google-maps-js-api-v3%[email protected]> > <google-maps-js-api-v3%[email protected]<google-maps-js-api-v3%[email protected]> > > > > > <google-maps-js-api-v3%[email protected]<google-maps-js-api-v3%[email protected]> > <google-maps-js-api-v3%[email protected]<google-maps-js-api-v3%[email protected]> > > > > > > > > > > . > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/google-maps-js-api-v3?hl=. > > > > > -- > > > > > 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 > > > [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<google-maps-js-api-v3%[email protected]> > <google-maps-js-api-v3%[email protected]<google-maps-js-api-v3%[email protected]> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/google-maps-js-api-v3?hl=. > > -- > > 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 > [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-maps-js-api-v3%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-maps-js-api-v3?hl=en. > > > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
