waynegm / imgNotes

Extension of the jQuery imgViewer plugin to add markers and notes to the image
MIT License
99 stars 26 forks source link

How would one be able to add a custom function, that runs when a marker is clicked. #46

Closed Prashanth-Thomas closed 6 years ago

Prashanth-Thomas commented 6 years ago

Personally i think imgNotes is simply brilliant. Now coming to the question, lets say that i have to pass the marker details(x,y,note) that was clicked to a component outside the map. This would require some custom lines of code running when the marker is clicked..... Correct? Is this possible? If so how would one go about achieving it.

waynegm commented 6 years ago

You could define a custom onShow callback that triggers a custom event that your other component has an event handler for. It would look something like this:

$("#other_component").on("imgNotes:show", function(event, note) {
\\ Do something with note.x, note.y and note.note
});
...
var $imgd = $("#image_dynamic").imgNotes({
    onShow: function(ev, elem) {
        var note = $(elem).data("note");
        $("#other_component").trigger("imgNotes:show", [note]);
    }
});