【问题标题】:jvectormap label html markupjvectormap 标签 html 标记
【发布时间】:2012-11-06 15:00:06
【问题描述】:

我正在尝试在标记的翻转状态中添加两条不同的信息。在 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'},
       ],

【问题讨论】:

    标签: javascript jquery jvectormap


    【解决方案1】:

    为什么不直接使用 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
      }
      ...
    });
    

    【讨论】:

    • 谢谢您,bjornd...您的解决方案完全有效!另外,这是一个很棒的图书馆……谢谢!
    • 如果是正确答案,请在此答案上打勾。
    • bjrond,我可以知道onMarkerTipShow和onMarkerLabelShow的区别吗?
    猜你喜欢
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多