简体   繁体   English

标记点击事件以签入传单

[英]Marker click event to check in leaflet

I am using leaflet.js for showing markers on a map. 我正在使用leaflet.js在地图上显示标记。 Onclicking any marker i am adding a property for that marker and setting true. 在单击任何标记时,我正在为该标记添加属性并设置为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'));
       });

The variable m is scoped to the loop where you're assigning properties to the markers. 变量m的作用域是为标记分配属性的循环。 When there's an event, m is undefined - there's no real way for m to be associated with the current clicked marker. 当发生事件时,m是不确定的-没有真正的方法将m与当前单击的标记关联。 You'll need to use the mouse event given as an argument to the mouseover handler in order to determine which layer was clicked. 您需要使用作为mouseover处理程序的参数提供的mouse事件 ,以确定单击了哪个图层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM