prudvi raju
prudvi raju

Reputation: 505

Marker click event to check in leaflet

I am using leaflet.js for showing markers on a map. Onclicking any marker i am adding a property for that marker and setting true. But if i am accessing that property on mouse over i am getting undefined..

How to check whether the marker is clicked or not By mouse over on marker.

       var _vmarkers = list of Markers;
          vm.marker().on('click', function() {
          //initially making all false
          this._vmarkers.forEach(function (m) {
               m.set('isClicked', false);
          });
             m.set('isClicked', true);
        });

       vm.marker().on('mouseover', function() {
           //printing undefined value even after clicking marker
           console.log(m.get('isClicked'));
       });

Upvotes: 0

Views: 1188

Answers (1)

tmcw
tmcw

Reputation: 11882

The variable m is scoped to the loop where you're assigning properties to the markers. When there's an event, m is undefined - there's no real way for m to be associated with the current clicked marker. You'll need to use the mouse event given as an argument to the mouseover handler in order to determine which layer was clicked.

Upvotes: 1

Related Questions