【问题标题】:Selected countries name in jqvmapjqvmap中选定的国家名称
【发布时间】:2014-03-21 16:12:05
【问题描述】:

我正在使用 jqvmap 显示世界地图并在单击国家/地区时显示适当的电子邮件信息。它工作正常。我只需要显示 6-7 个国家/地区。现在我想将悬停时的国家名称显示为仅选定国家的工具提示。 这是我的地图代码

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('#vmap').vectorMap({
        map: 'world_en',
        backgroundColor: '#fff',
        color: '#87CEEB',
        hoverOpacity: 0.6,
        selectedColor: '#8B0000',
        enableZoom: true,
        showTooltip: true,
        values: sample_data,
        scaleColors: ['#C8EEFF', '#006491'],
        selectedRegion: null,
        normalizeFunction: 'polynomial',
        onRegionClick: function(element, code, region)
        {
            if (region == "United States of America") {
               document.getElementById('mailblock').innerHTML = 'Contact Information for USA (New York) :';
            }

        }
    });
});
</script>

【问题讨论】:

    标签: javascript jqvmap


    【解决方案1】:

    您可以做类似的事情(将您的示例视为理所当然):

    <script type="text/javascript">
    jQuery(document).ready(function() {
        // your defined areas where the label is shown
        var areasWithLabel = ['DE', 'US', 'CA', 'RU'];
    
        jQuery('#vmap').vectorMap({
            // removed your usual settings
            onLabelShow: function(event, label, code) {
                for (area in areasWithLabel  {
                   if (area == code) {
                       event.preventDefault();
                   }
                }
            }
        });
    });
    </script>
    

    您所做的基本上是检查您定义的区域之一当前是否悬停在上方并阻止该事件的默认行为(显示标签)。

    您可以查看documentation page 上的示例之一

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 2014-08-04
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多