Reputation: 4050
I have set of markers in a map they are named like this ev1, ev2, ev3 etc.
When I click a link i want a popup to be opened from the map, they are triggered like this,
ev1.openPopup();
But because I can't write popup code of each marker I got a jquery code like this
$(document).on('click', '.venname', function () {
var myLinkId = $('.venname').attr('data-mylink');
ev+myLinkId.openPopup();
});
Once a link is clicked it will get an id called data-mylink and will combine it with ev, as an example when I click lick one, it'll have a attribute called 1 and the jquery code will get 1 and make the variavle ev1 and will trigger the popup, but somehow I can't get this thing to work and gets an error ev is not defined.
So how can I combile ev with the variable myLinkID?
Upvotes: 1
Views: 60
Reputation: 8565
You can use primitive objects or arrays to store marker objects:
var markers = {marker1: new Marker(...), marker2: new Marker(...), ... };
and then you can reach Marker objects like that:
markers['marker'+markerId].openPopup();
An array example:
var markers = [new Marker(...), new Marker(...), ...];
markers[markerIndex].openPopup();
Upvotes: 2