We've added a 'clickable' option to GPolylineOptions and
GPolygonOptions (not yet in the reference). The option is designed to
perform just as the 'clickable' option for GMarker, and thus defaults
to true. You can make your polygons not clickable by setting it to
false.
Here's a demo that compares clickable/event listener/non clickable
behavior across polys and markers:
http://gmaps-samples.googlecode.com/svn/trunk/poly/clickable.html
Please let me know if you have any problems with the new option.
我的代码:
function addPolyline(latlon)
{
var points = [];
for(i=0;i<latlon.length-1;i++)
{
var simpleValue = latlon[i].split(",");
var tmp = new String(simpleValue);
var strlatlon = tmp.split(";");
points.push(new GLatLng(strlatlon[1],strlatlon[0]));
}
var polyline = new GPolyline(points, "#FF0000", 3,1,{clickable: true});
map.setCenter(points[0],16);
//add Polyline
GEvent.addListener(map, "click", function(overlay, latlng)
{
window.alert("You clicked the map at latlng: " + latlng + " and on overlay: " + overlay);
});
createPoly(points, true, true, true);
}
function createPoly(latlng, addListener, makePolyline, isClickable)
{
var polyLatLngs = latlng;
if (makePolyline)
{
var poly = new GPolyline(polyLatLngs, '#0000ff',5, .7, {clickable: isClickable});
}else
{
var poly = new GPolygon(polyLatLngs, '#0000ff', 1, 1.0, '#ff0000', .5, {clickable: isClickable});
}
map.addOverlay(poly);
}
More :http://www.handandaily.com/2007/11/06/WebGIS/438.html