JVector映射标记悬停时如何获得动态图像

时间:2016-07-30 09:05:16

标签: javascript jquery jvectormap

您好我正在使用JVector Map并且我之前可能会问过我的问题,而且我也发现了这篇文章jvectormap markers label image但我的问题仍未解决

我想在工具提示中显示每个标记的图片,当鼠标悬停时显示该图片

这是我的代码:

$('#world-map').vectorMap({
    map: 'world_mill',
    backgroundColor: '#fff',
    zoomOnScroll: false,
    regionStyle:{
        initial: {
            fill: '#878787',
            "fill-opacity": 1,
            stroke: '#fff',
            "stroke-width": 1,
            "stroke-opacity": 1
        },
        hover: {
            "fill-opacity": 1,
            cursor: 'pointer',
            fill: '#133060'

        },
        selected: {
            fill: 'yellow'
        },
    },
    markerStyle: {
        initial: {
            fill: '#F8E23B',
            stroke: '#383f47',
            "stroke-width": 3,
            r: 10
        }
    },

  markers: [
  { latLng: [61.524010, 105.318756], name: 'FT 1', imgsrc: 'team1.jpg' },
  { latLng: [60.128161, 18.643501], name: 'FT 2', imgsrc: 'team2.jpg' },
  { latLng: [35.861660, 104.195397], name: 'FT 3', imgsrc: 'team3.jpg' },
  { latLng: [37.090240, -95.712891], name: 'FT 4', imgsrc: 'team4.jpg' },
 { latLng: [56.130366, -106.346771], name: 'FT 5', imgsrc: 'team5.jpg' },
  { latLng: [-25.274398, 133.775136], name: 'FT 6', imgsrc: 'team6.jpg' },
  { latLng: [51.165691, 10.451526], name: 'FT 7', imgsrc: 'team7.jpg' },

  ],

  onRegionTipShow: function (e, el, code) {

      el.html(el.html() + '<p id="popop"></p>').css("fontSize","15px");
  },
  onMarkerTipShow: function (e, el, code) {

      el.html(el.html() + '<br /><img src="../Content/img/' + markers[index].imgsrc + '"/>').css("fontSize", "15px");

      //el.html(el.html() + '<br /><img src="../Content/img/' + "team1.jpg" + '"/>').css("fontSize", "15px");
  },


});

用这个系数可以正常工作

el.html(el.html() + '<br /><img src="../Content/img/' + "team1.jpg" + '"/>').css("fontSize", "15px");

但是根据那篇文章中的指南我使用了这个,因为我需要不同的图片而且它不起作用。

el.html(el.html() + '<br /><img src="../Content/img/' + markers[index].imgsrc + '"/>').css("fontSize", "15px");

如果有人帮助我,请致谢。

1 个答案:

答案 0 :(得分:2)

调用onMarkerTipShow()时,codeindex,但markers不在范围内。您需要处理地图中的markers

onMarkerTipShow: function (e, el, code) {
      var markers = $('#world-map').vectorMap('get', 'mapObject').markers;  
      el.html(el.html() + '<br /><img src="../Content/img/' 
         + markers[code].config.imgsrc 
         + '"/>').css("fontSize", "15px");
  }
相关问题