如何删除谷歌地图中的特定多边形添加事件监听器右键单击

时间:2015-12-24 04:17:50

标签: javascript google-maps google-maps-api-3

我是谷歌地图api的新手,我的地图中有更多的多边形,我尝试使用添加事件监听器右键单击选项删除谷歌地图中的特定多边形,这是我的代码。点击特定的多边形不能startLeScan();

setMap(NULL)

1 个答案:

答案 0 :(得分:1)

删除多边形时,添加其他属性[auto_id]以标识多边形,例如

        polygons.push(new google.maps.Polygon({
            auto_id:i,
            id: idd,
            paths: arr,
            strokeColor: '#BA55D3',
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: '#DA70D6',
            fillOpacity: 0.35
        }));

        polygons[polygons.length-1].addListener('rightclick', function (event) {
           polygons[this.auto_id].setMap(null);
        });