从jVectormap World Map获取国家/地区名称

时间:2013-12-14 17:21:38

标签: javascript jquery jquery-plugins jvectormap

如何从jVectormap获取点击国家/地区的名称?

我使用简单的代码,添加了警告以显示点击的国家/地区的名称但不起作用。

jQuery('#vmap').vectorMap({
    map: 'world_en',
    backgroundColor: '#e9e9e7',
    color: '#dfdfdd',
    hoverOpacity: 0,
    selectedColor: '#5f8b98',
    hoverColor: '#5f8b98',
    enableZoom: true,
    showTooltip: true,
    values: sample_data,
    scaleColors: ['#dfdfdd'],
    onRegionClick: function (event, code) {
    var map = $('#vmap').vectorMap('get', 'mapObject');
    var name = map.getRegionName(code);
    //ADDED ALERT TO SHOW NAME OF CLICKED COUNTRY
    alert(name);
    },
    normalizeFunction: 'polynomial'
});

以下是使用脚本的文档:
http://jvectormap.com/documentation/javascript-api-v1/jvm-worldmap/

2 个答案:

答案 0 :(得分:1)

“它不起作用”是什么意思? 你收到错误了吗?或者你在警报中得到了什么?

未经测试,但您可以尝试这样做:

var mymap = new jvm.WorldMap({
  container: $('#vmap'),
  ...
  onRegionClick: function (event, code) {
    alert(mymap.getRegionName(code));
  }
});

答案 1 :(得分:0)

使用此

$scope.open = function ($timeout, $log, parameter1) {

           var modalInstance = $uibModal.open({
                templateUrl: 'myModalContent.html',
                controller: ModalInstanceCtrl,
                resolve: {
                    items: function ($http) {
                        return "loadind data...";
                    }
                }
            });

            modalInstance.opened.then(function($timeout, $log) {
                $scope.loadData(modalInstance,$timeout, $log);
            }, function() {
                $log.info('Modal dismissed at: ' + new Date());
            });

            $scope.loadData = function(aModalInstance, $timeout, $log) {
                $timeout(function() {
                    aModalInstance.setItems("data loaded...");
                }, 3000);
            };

    };

        var ModalInstanceCtrl = function ($scope, $uibModalInstance, items) {
            $scope.items = items;

            $uibModalInstance.setItems = function(theData) {
                $scope.items = theData;
            };

            $scope.ok = function() {
                $uibModalInstance.close('close');
            };
            $scope.cancel = function() {
                $uibModalInstance.dismiss('cancel');
            };
        };
    });

所有剧本

 onRegionClick:function(event, code) {                        
        var name = (code);                        
        alert(name);                    
        }