Removing a Google maps Circle/shape

后端 未结 4 1918
长情又很酷
长情又很酷 2021-02-03 21:40

I am creating a Circle using the google.maps.Circle() method. This all works fine and dandy, but how can I remove said circle?

My code:

var populationOpt         


        
4条回答
  •  盖世英雄少女心
    2021-02-03 22:22

    You need to remove events listeners too, not just hiding the circle, in-fact circle.setMap(null) will just hide the circle

    function remove_circle(circle) {
        // remove event listers
        google.maps.event.clearListeners(circle, 'click_handler_name');
        google.maps.event.clearListeners(circle, 'drag_handler_name');
        circle.setRadius(0);
        // if polygon:
        // polygon_shape.setPath([]); 
        circle.setMap(null);
    }
    

提交回复
热议问题