1

I have seen some examples of this but they are not working for this situation.

What I need to be able to do is when I click on a marker get the index of that marker to write to the console. The reason I need this info is so that I can then go and later update the popup for this marker.

I have a JSBIN of this at http://jsbin.com/hepeli/4/edit?js,console,output

When you create a marker it makes a popup that displays an index, but this is actually just the length of an array that the markers are being pushed into.

When you click a marker with the delete tool it does write to console the index but I can't get it to do this when I just click on the marker.

1
  • are you saying you want to save the index as a property of the marker, not just the popup? just writing the index to the console is not that different from how you are writing it on delete: console.log("added marker_index: " + markerList.indexOf(marker) );
    – toms
    Commented Mar 3, 2015 at 19:11

1 Answer 1

1

Is this what you mean?

starting from your code in onMapClickAddMarker:

markerList.push(marker);     

add this

var marker_index = markerList.indexOf(marker);  
console.log("added marker_index: " + markerList.indexOf(marker) );
marker.myid = marker_index;      
marker.on('click', function(e) {
  console.log("Clicked marker with id: " + marker.myid);
});
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.