jVectorMap change/refresh 地图与新的参考地图?

jVectorMap change/refresh map with new reference map?

我有一个包含地图的 div,但是,我想更改一个 属性,它会依次更新地图以对应于对 [=18= 所做的更改].更具体地说,当我更改地图名称时,我希望 div 更改以反映这个新地图名称。如果我绘制了智利地图并将地图名称更改为巴西,我希望绘制巴西地图。请参阅下面的更多上下文。我已经尝试了 .reset().updateSize() 和其他一些建议的调整……没有任何效果。

app.directive('countrymap', ['$rootScope', function($rootScope) 
{
    return {
        link: function(scope, element, attrs) {
            $(element).width('auto'),
            $(element).height(500),
            $rootScope.$watch("countryMap", function (newCountry, oldCountry) 
            {
                setTimeout( function() 
                { 
                    var map = new jvm.Map(
                    {
                        container: $(element),
                        map: newCountry,
                        backgroundColor: 'transparent',
                        regionsSelectable: true,
                        regionsSelectableOne: true,
                        zoomButtons : false,
                        regionStyle: 
                        {
                            selected:
                            { fill: 'Red' }
                        }
                    });
                }, 100);
            })
        }
    };  
}]);

我想我会 post 为那些遇到同样挫折的人找到解决这个问题的方法。我决定使用 .remove() 摆脱旧地图并绘制一张新地图。修改后的代码见下文。

app.directive('countrymap', ['$rootScope', function($rootScope) 
{
    return {
        link: function(scope, element, attrs) {
            $(element).width('auto'),
            $(element).height(500),
            $rootScope.$watch("countryMap", function (newCountry, oldCountry) 
            {
                setTimeout( function() 
                { 
                    try { $(element).vectorMap('get', 'mapObject').remove(); }
                    catch(err) {}
                    var map = new jvm.Map(
                    {
                        container: $(element),
                        map: newCountry,
                        backgroundColor: 'transparent',
                        regionsSelectable: true,
                        regionsSelectableOne: true,
                        zoomButtons : false,
                        regionStyle: 
                        {
                            selected:
                            { fill: 'Red' }
                        }
                    });
                }, 100);
            })
        }
    };  
}]);