Hi I'm using JVector Map
and I know my question maybe asked before , and also I found this article jvectormap markers label image too but my problem still not solved
I want to show a picture for each marker in the tool-tip which it shows when mouse hover's it
here is my codes:
$('#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");
},
});
with this coe it works fine
el.html(el.html() + '<br /><img src="../Content/img/' + "team1.jpg" + '"/>').css("fontSize", "15px");
but by the guide in that article I used this one insted because I need diffrent pictures and it doesn't work .
el.html(el.html() + '<br /><img src="../Content/img/' + markers[index].imgsrc + '"/>').css("fontSize", "15px");
Appricate if some one help me thanks.
When onMarkerTipShow()
is invoked, the code
is the index
, but markers
are not in scope. You need to get a handle on the markers
in the map:
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");
}
来源:https://stackoverflow.com/questions/38672204/jvector-map-how-to-have-dynamic-images-when-markers-hover