开发者

Hiding & showing markers on event

开发者 https://www.devze.com 2023-02-25 00:47 出处:网络
google.maps.Marker.prototype.hide = function()开发者_如何学Go { if (this.div_) { this.div_.style.visibility = \"hidden\";
google.maps.Marker.prototype.hide = function()开发者_如何学Go 
{
    if (this.div_) 
    {
        this.div_.style.visibility = "hidden";
    }
};
google.maps.Marker.prototype.show = function() 
{
    if (this.div_) {
        this.div_.style.visibility = "visible";
    }
};

It doesnt cause any error. But it doesnt work while Im using it:

marker = new google.maps.Marker({
                map: map,
                draggable: false,
                position: latlng,
                title: 'some title'
            });

And now if someone change the zoom I want to trigger hiding marker:

google.maps.event.addListener(map, 'zoom_changed', function() {
            marker.hide();
});

But it doesnt work. Could someone help me resolve the problem?


to hide a marker use marker.setMap(null);

to show again use marker.setMap(mymap);

EDIT:

forgot about setvisible. here's a working example: http://jsfiddle.net/herostwist/v9nmQ/1/


The API already contains such a method: setVisible. Either pass true or false.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号