【问题标题】:jvectormap: How to implement HTML instead of simple string in the markers label/tooltip?jvectormap:如何在标记标签/工具提示中实现 HTML 而不是简单的字符串?
【发布时间】:2012-10-07 22:12:12
【问题描述】:

我刚刚实现了 jQuery 插件 jvectormap,用于世界地图。一切都很好,除了这个可能.. 我添加了一些标记,并一直在尝试将 HTML 实现到标记标签/工具提示中。 因此,当悬停标记时,我希望显示图像/html,而不仅仅是“blabla”。

我怎样才能达到这个结果?

这里是初始化 JS:

$('#map').vectorMap({
    markerStyle: {
      initial: {
        fill: '#F8E23B',
        stroke: '#383f47'
      }
    },
    backgroundColor: '#383f47',
    markers: [
      {latLng: [46.90, 8.45], name: "<img src=\"img/logo.png\">"}
    ],
...(other code isn't important)...

重要的部分是name: "&lt;img src=\"img/logo.png\"&gt;"

感谢您的帮助!

【问题讨论】:

    标签: jquery jquery-plugins plugins tooltip jvectormap


    【解决方案1】:

    如果您想自定义鼠标悬停在标记上时显示的标签/工具提示,您应该为 onMarkerLabelShow 提供一个函数。

    onMarkerLabelShow函数(Event e, Object label, String code)将在标记标签显示之前被调用。

    例如:

    $('#map').vectorMap({
        markerStyle: {
          initial: {
            fill: '#F8E23B',
            stroke: '#383f47'
          }
        },
        backgroundColor: '#383f47',
        markers: [
          {latLng: [46.90, 8.45], name: "My marker name"}
        ],
        onMarkerLabelShow: function(event, label, code) {
         label.html("<img src=\"img/logo.png\"><br>"+ label.html());                
        }
    });
    

    【讨论】:

    • 非常好,它适用于 1 个标签! :) 那么如何区分“onMarkerLabelShow”函数中的两个标签?
    • code 将在onMarkerLabelShow() 函数中为该标记返回name。查看此示例,了解如何在将鼠标悬停在区域上时显示国旗图像,可以将相同的技术应用于标记:stackoverflow.com/a/12769847/14419
    • onMarkerLabelShow 目前已弃用,取而代之的是具有相同参数的 onMarkerTipShow 函数。
    • 很好@MadsHansen。如何在标签中显示数据库值?当我点击国家?我尝试了过去两周我无法得到答案请帮助我
    • @Thennarasu 理想情况下,尝试通过 onMarkerLabelShow 函数中的 AJAX 调用检索数据库值。你需要这样的东西:var dbValue; $.ajax({ url: "database.php", success: function(data) { dbValue = data; } });
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 2011-01-13
    • 2016-11-17
    相关资源
    最近更新 更多