0
function addDoctorLocation(options) 
{
    var gm = Ext.getCmp('mygooglemap');
    var mpoint = new google.maps.LatLng(options.lat,options.lng);
    var marker = gm.addMarker(mpoint,options.marker,false,false, options.listeners);
    infoBubble = new InfoBubble({maxWidth: 300});
}

tree.on('checkchange', function(node){
    var data = node.data;

    if (data.checked == true){
        var options = {
            lat:3.951941,
            lng:102.052002,
            marker: {title:"Hello World!"},
            listeners: {
                click: function(e){

                }
            }     
        }     
        addDoctorLocation(options);           
    }

    Ext.MessageBox.show({
        title: 'Changed checkbox status',
        msg: 'MainID: ' + data.MainID + ' <br /> Checkbox status: ' + data.checked,
        icon: Ext.MessageBox.INFO
    });
})

问题

此代码在选中复选框时成功添加标记,但是,当未选中复选框时如何删除标记?
我需要为标记分配一个ID吗?取消选中时,我应该删除 id 的标记吗?附加:一张地图有多个标记,而不仅仅是1个标记

4

1 回答 1

2

创建标记结构作为全局变量。添加标记时,也将它们添加到结构中,根据复选框键入独特的内容。因此,您可以稍后使用它来识别要隐藏的标记。如果 data.checked != true 然后marker.setMap(null);用来摆脱它。

就像是:

var markers = {};

function addDoctorLocation(options) 
{
    var gm = Ext.getCmp('mygooglemap');
    var mpoint = new google.maps.LatLng(options.lat,options.lng);
    var marker = gm.addMarker(mpoint,options.marker,false,false, options.listeners);
    infoBubble = new InfoBubble({maxWidth: 300});

    // assign it into the structure
    markers[options.MainID] = marker;
}

tree.on('checkchange', function(node){
    var data = node.data;

    if (data.checked == true){
        var options = {
            lat:3.951941,
            lng:102.052002,
            marker: {title:"Hello World!"},
            listeners: {
                click: function(e){

                }
            },
            MainID: data.MainID
        };     
        addDoctorLocation(options);           
    } else {
        markers[data.MainID].setMap(null);
    }

    Ext.MessageBox.show({
        title: 'Changed checkbox status',
        msg: 'MainID: ' + data.MainID + ' <br /> Checkbox status: ' + data.checked,
        icon: Ext.MessageBox.INFO
    });
});
于 2013-02-25T09:41:03.817 回答