使用Google Maps API -添加线和实现线的单击事件,( 'clickable' GPolyline & GPolygon option)...

本文介绍了如何在Google Maps API中使用GPolylineOptions和GPolygonOptions设置'clickable'选项来控制多边形是否可点击,并提供了一个示例演示不同设置下的行为表现。

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

转载于:https://www.cnblogs.com/kaixin110/archive/2007/11/06/951161.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值