1

我有一个 JQVmap,它突出显示基于类的悬停链接上的国家/地区。我也想使用同一个类来触发工具提示。知道怎么做吗?如果我添加mapObj.label.show();到悬停状态,它将触发地图上使用的最新工具提示,我当然想从悬停元素上的类触发它。

片段:

        jQuery('#vmap').vectorMap({
            map: 'world_en',
onLabelShow: function (event, label, code) {
        
                if (code == 'se') {
                var countryName = label[0].innerHTML;
          var html = ['<span class="tooltip-up arrow-down-center">',
           countryName,
': 50% of production',
          '</span>'
          ].join("");
          label[0].innerHTML = html;
                }
        },
            backgroundColor: '#fff',
            enableZoom: false,
            color: '#ffffff',
            hoverOpacity: 0.7,
            selectedColor: '#666666',
            showTooltip: true,
            values: sample_data,
            scaleColors: ['#C8EEFF', '#006491'],
            normalizeFunction: 'polynomial',                     
            pinMode: 'content',
            regionsSelectableOne: false,
                regionsSelectable: false,
                series: {
                regions: [{
                  scale: ['#C8EEFF', '#0071A4'],
                  normalizeFunction: 'polynomial'
               }]
             }
        });

 var mapObj = jQuery('#vmap').data('mapObject');

 jQuery('#countries').on('mouseover mouseout', 'a:first-child', function (event) {
  var elem = event.target;
  var countryCodes = jQuery(elem).attr('class').split(/\s+/);

  evtype = event.type;

  if (evtype === 'mouseover') {
    jQuery.each(countryCodes, function(index, code) {
       mapObj.select(code);
    });
  } else {
    jQuery.each(countryCodes, function(index, code) {
      if (mapObj.isSelected(code)) {
        mapObj.deselect(code);
      } else {
        mapObj.select(code);
        mapObj.deselect(code);
      }
    });
  };
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqvmap/1.5.1/jqvmap.css" media="screen" rel="stylesheet" type="text/css">
<script src="https://www.10bestdesign.com/jqvmap/assets/jqvmaps/jquery.vmap.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jqvmap/1.5.1/maps/jquery.vmap.world.js"></script>
        <script src="https://www.10bestdesign.com/jqvmap/assets/jqvmaps/jquery.vmap.sampledata.js"></script>
        
        
<ul id="countries">
  <li><a class="SE" href="">Sweden</a></li>
  <li><a class="DK" href="">Denmark</a></li>
 <li><a class="SE DK" href="">Sweden and Denmark</a></li>
</ul>
 
         
        <div id="vmap" style="width: 1000px; height: 600px;"></div>

4

0 回答 0