1

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?

2
  • I don't think you can do this. You are trying to variabilize variable name. Commented Sep 26, 2013 at 8:04
  • Serially named variables is a strong indication of a flawed data structure. In this case you obviously need an array. Commented Sep 26, 2013 at 8:12

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.