Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下,如何在inmap中监听点击事件来区分点击的是地图还是动画圆点呢? #94

Open
xiaoseLibrary opened this issue Aug 26, 2019 · 2 comments

Comments

@xiaoseLibrary
Copy link

inmap.getMap().addEventListener("click",function(e){
// alert(e.point.lng + "," + e.point.lat);
});
监听了地图的点击事件,请问依据哪个字段可以判断当前点击的是地图还是动画圆点呢?

@xianshenglu
Copy link
Contributor

我回头来回答下

inmap.getMap().addEventListener("click",function(e){
// alert(e.point.lng + "," + e.point.lat);
});
监听了地图的点击事件,请问依据哪个字段可以判断当前点击的是地图还是动画圆点呢?

@xianshenglu
Copy link
Contributor

xianshenglu commented Jul 26, 2020

我来给个思路,如果要监听圆点的点击事件,可以直接类似这样

event:{
  onMouseClick(){}
}

如果需要判断用户是点击在圆点以外的地图区域,可以参考下面一段逻辑

let prevClickEvent=null
event:{
  onMouseClick(item,event){
    prevClickEvent= event
  }
}
inmap.getMap().addEventListener("click",function(e){
  if(e===prevClickEvent){
      console.log('点击的是上面的 overlay ')
  } 
  console.log('点击的是上面 overlay 以外的地图区域')
});

我这边测试的结果是,两边用的 event 指向同一个对象,所以可以直接这么判断. @ywj1721158614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants