Skip to content
This repository was archived by the owner on Jun 10, 2023. It is now read-only.
This repository was archived by the owner on Jun 10, 2023. It is now read-only.

click event for custom markers #53

Description

@mg1075

Thanks for writing this directive.
My question is about adding a click event to custom markers, where the array of markers gets attached to the gl-markers attribute.

A mapbox tutorial shows that they manually add event listeners to custom markers.
https://www.mapbox.com/help/tutorials/building-a-store-locator/#add-new-event-listeners

I am able to do similar inside an angularjs controller using the "element" property of the markers api.

My concerns here are:
(1) Is there a different or recommended way of adding a click event using your plugin? (It seems the answer here is "no").
(2) If I have a function in the angular controller to add an event listener to each marker,
do I have to worry about somehow destroying these event listeners in the angular controller's $destroy event? If yes, then how best to remove the listeners added to the custom markers?

function createElementForDivMarker(m_marker, m_index) {
     var el = document.createElement('div');
    el.id = "marker-" + m_index;
    el.className = 'marker marker-' + m_marker.properties.map_marker_class;  
        el.addEventListener('click', function(e) {
            console.log(m_marker.properties);
        }); 
    return el;
 }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions