http://pages.towson.edu/preese/av/multiple_polys_from_xml.html
There are two polygons (Alabama, Arkansas) that I'd like to see on the
map, but instead I only see Arkansas. I've been searching around the
group and figure that this is some sort of "last in a loop" JavaScript
bug (I think Ben Appleton posted this link http://scriptnode.com/article/the-last-in-a-loop-bug/)
but I'm still wrestling with how to fix the problem. Any thoughts?
you have set array of points as global - so you overwrite points last
polygon's data.
Try put var pts = []; to loop instead of making it global, like this:
var pts = [];
for (var i = 0; i < points.length; i++) {
pts[i] = new google.maps.LatLng(parseFloat(points[i].getAttribute
("lat")),
parseFloat(points[i].getAttribute("lng")));
}
Regards,
Michal Biniek
On 22 Sty, 23:56, PhilR8 <phi...@gmail.com> wrote:
> I've been toying around with the XML tutorial written by Pamela
> (http://gmaps-samples-v3.googlecode.com/svn/trunk/xmlparsing/
> downloadurl_info.html) and am trying to do something similar with
> polygons as well as markers. Here's what I've been fooling around
> with so far:
>
> http://pages.towson.edu/preese/av/multiple_polys_from_xml.html
>
> There are two polygons (Alabama, Arkansas) that I'd like to see on the
> map, but instead I only see Arkansas. I've been searching around the
> group and figure that this is some sort of "last in a loop" JavaScript
> bug (I think Ben Appleton posted this linkhttp://scriptnode.com/article/the-last-in-a-loop-bug/)
http://pages.towson.edu/preese/av/point_in_poly_test.html
As you can probably deduce from the URL, I'm trying to do some point-
in-polygon stuff. Specifically, using the click listener to open a
marker infowindow that is inside of the polygon. I have two polygons
in the demo above (Utah and Wyoming) and corresponding markers, but no
matter where I click in either polygon, the Wyoming infowindow is
opened. I used to do this successfully in V2 using Mike Williams'
point in polygon example, but I'm not having any luck figuring out how
to do it in V3 from the examples that I've found. Anyone have any
thoughts? Thanks in advance.
You're not obtaining function closure on the polygons.
Just like you create the markers in a separate function, you need to
do the same with the polygons.
http://econym.org.uk/gmap/closure.htm
--
Marcelo - http://maps.forum.nu
--
http://pages.towson.edu/preese/av/point_in_poly_test.html (same link
as above)
But now the polygons look strange, like there are two or three (or
more) stacked on top of each other. Notice the difference from
before:
http://pages.towson.edu/preese/av/point_in_poly_test_bad.html
What am I doing wrong?
On Feb 27, 1:29 am, Marcelo <marcelo...@hotmail.com> wrote:
> On Feb 27, 12:40 am, PhilR8 <phi...@gmail.com> wrote:
>
> > So, similarly, here's a test map:
>
> >http://pages.towson.edu/preese/av/point_in_poly_test.html
>
> > As you can probably deduce from the URL, I'm trying to do some point-
> > in-polygon stuff. Specifically, using the click listener to open a
> > marker infowindow that is inside of the polygon. I have two polygons
> > in the demo above (Utah and Wyoming) and corresponding markers, but no
> > matter where I click in either polygon, the Wyoming infowindow is
> > opened.
>
> You're not obtaining function closure on the polygons.
> Just like you create the markers in a separate function, you need to
> do the same with the polygons.http://econym.org.uk/gmap/closure.htm
>
> --
> Marcelo -http://maps.forum.nu
You are creating a new polygon for every individual point that you
read.
Indent your code properly and you will see it.
--
Marcelo - http://maps.forum.nu
--
>
On Mar 1, 5:39 pm, Marcelo <marcelo...@hotmail.com> wrote:
> On Mar 1, 11:14 pm, PhilR8 <phi...@gmail.com> wrote:
>
> > But now the polygons look strange, like there are two or three (or
> > more) stacked on top of each other. Notice the difference from
> > before:
>
> You are creating a new polygon for every individual point that you
> read.
> Indent your code properly and you will see it.
>
> --
> Marcelo -http://maps.forum.nu