jvectormap标签html标记

时间:2012-11-06 15:00:06

标签: javascript jquery jvectormap

我试图在标记的翻转状态下添加两个不同的信息。在 markers.html 中,我为每个城市添加了一些数字,但我想将这些数字设置为与城市名称不同。

如何将html标记添加到标签中。我可以通过在 world-map.js 中添加其他路径来添加数字:

this.container.delegate("[class~='jvectormap-element']", 'mouseover mouseout', function(e){
    var path = this,
      type = jvm.$(this).attr('class').indexOf('jvectormap-region') === -1 ? 'marker' : 'region',
      code = type == 'region' ? jvm.$(this).attr('data-code') : jvm.$(this).attr('data-index'),
      element = type == 'region' ? map.regions[code].element : map.markers[code].element,
      labelText = type == 'region' ? map.mapData.paths[code].name : (map.markers[code].config.name || ''),
      labelShowEvent = jvm.$.Event(type+'LabelShow.jvectormap'),
      overEvent = jvm.$.Event(type+'Over.jvectormap');

    var path2 = this,
      type = jvm.$(this).attr('class').indexOf('jvectormap-region') === -1 ? 'marker' : 'region',
      code = type == 'region' ? jvm.$(this).attr('data-code') : jvm.$(this).attr('data-index'),
      element = type == 'region' ? map.regions[code].element : map.markers[code].element,
      labelNumber = type == 'region' ? map.mapData.paths[code].number : (map.markers[code].config.number || ''),
      labelShowEvent = jvm.$.Event(type+'LabelShow.jvectormap'),
      overEvent = jvm.$.Event(type+'Over.jvectormap');


    if (e.type == 'mouseover') {
        map.container.trigger(overEvent, [code]);
    if (!overEvent.isDefaultPrevented()) {
        element.setHovered(true);
    }

    if(labelNumber!= undefined){
        map.label.text(labelText+ "  " +labelNumber);
    }

    else{
        map.label.text(labelText);
    }
    map.container.trigger(labelShowEvent, [map.label, code]);
    if (!labelShowEvent.isDefaultPrevented()) {
        map.label.show();
        map.labelWidth = map.label.width();
        map.labelHeight = map.label.height();
        }
    } 
    else {
        element.setHovered(false);
        map.label.hide();
        map.container.trigger(type+'Out.jvectormap', [code]);
  }
});

这是我在markers.html中的结构:

 var markers = [ 
        {latLng: [33.57, -86.75], name: 'Birmingham,AL', number: '$34,000'},
        {latLng: [35.22, -92.38], name: 'Little Rock,AR', number: '$34,000'},
       ],

1 个答案:

答案 0 :(得分:14)

为什么不使用API​​:

$('#map').vectorMap({
  ...
  onMarkerTipShow: function(e, label, code){
    label.html('Anything you want');
    //or do what you want with label, it's just a jQuery object
  }
  ...
});