Hi Everyone

Following up on Rawans's question and Rosskos' response I have a
question I hope you can help me with.

Unfortunately my site is on an intranet at the moment so cant post a
link however I think my query is relatively simple... (I hope)(please
be kind Im a javascript newbie to say the least!)

I am attempting to attach an onclick event to a number of polylines
each with their own corresponding html variables all loaded from a
mysql database via a php xml generator (based on Google example). Code
snapshot below:

                var linehtml = [];
                var linelocations = 'line.php'
                GDownloadUrl(linelocations, function(linedata) {
                        var linexml = GXml.parse(linedata);
                        var lines = 
linexml.documentElement.getElementsByTagName("line");
                        for (var a = 0; a < lines.length; a++) {
                                var lineid = lines[a].getAttribute("lineid");
                                var linename = 
lines[a].getAttribute("linename");
                                var linetype = 
lines[a].getAttribute("linetype");
                                var linecolour = 
lines[a].getAttribute("linecolour");
                                // read each point on that line
                                var points = 
lines[a].getElementsByTagName("point");
                                var pts = [];
                                for (var i = 0; i < points.length; i++) {
                                   pts[i] = new 
GLatLng(parseFloat(points[i].getAttribute
("lat")),parseFloat(points[i].getAttribute("lng")));
                                }

                        // Create a new instance of PolylineEncoder
                        var polylineEncoder = new PolylineEncoder();

                        // Assign the array to dpEncodeToGPolyline  to get an 
encoded
polyline
                        var line = polylineEncoder.dpEncodeToGPolyline(pts, 
linecolour, 6,
0.7);

                        var html = 'Region ID:' + lineid + '<br />Region Name:' 
+ linename
+ '<br />Area Type: ' + linetype;
                        linehtml.push(html);

                        GEvent.addListener(line, 'click', 
function(overlaylatlng) {
                                //'x' is reference of clicked polyline
                                
map.openInfoWindowHtml(overlaylatlng,linehtml[x])
                        });

                        GEvent.addListener(line, "mouseover", function(){
                                
map.getDragObject().setDraggableCursor("pointer");
                        });

                        GEvent.addListener(line, "mouseout", function(){
                                
map.getDragObject().setDraggableCursor("url(http://maps.google.com/
intl/en_us/mapfiles/openhand.cur),default");
                        });
                        map.addOverlay(line);
                        }
                });

Now I know when the polyline is clicked I need to send the right ID so
that the correct html field is loaded from linehtml[] and attached to
the onclick event. However I am utterly stumped as to how I would
pass / set this?

Any help greatfully received.

Thanks in advance

Pete

On Nov 19, 12:24 pm, Rossko <[email protected]> wrote:
> > My polylines are stored in an array along with all its details (each
> > array element can be identified by thepolylineid)and I want to be
> > able to identify whichpolyline(id) has been clicked to be able to
> > display its corresponding info.
>
> Overlay creation
>   mypolyline = new GPolyine (....);
>   mypolyline.myid = yourindex;
>
> Click event handler ...
>   index = clickedpolyline.myid;
>   mycontent = myarray[index];

--

You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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-api?hl=en.


Reply via email to