javascript - Click outside the mark (or point) to close something on Mapbox - Stack Overflow

On my Mapbox have 3 layers.id: 'Map', id:'Cluster', id: 'Point'map.on(&#

On my Mapbox have 3 layers. id: 'Map', id:'Cluster', id: 'Point'

map.on('click', 'Point', function (e) {
    $(".page-wrapper").addClass("toggled");/*show sidebar*/
  });

This code mean when I click point on layer id: 'Point', sidebar will show.

$(".page-wrapper").removeClass("toggled");/*hide sidebar*/ 

And this code will hide sidebar when add to event.

Now, I want click any where without point on layer id: 'Point' sidebar will hidden.

How can I do that?

On my Mapbox have 3 layers. id: 'Map', id:'Cluster', id: 'Point'

map.on('click', 'Point', function (e) {
    $(".page-wrapper").addClass("toggled");/*show sidebar*/
  });

This code mean when I click point on layer id: 'Point', sidebar will show.

$(".page-wrapper").removeClass("toggled");/*hide sidebar*/ 

And this code will hide sidebar when add to event.

Now, I want click any where without point on layer id: 'Point' sidebar will hidden.

How can I do that?

Share Improve this question asked Jan 26, 2019 at 8:26 AlexAlex 8271 gold badge15 silver badges39 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Use the click event handler for the entire map and the preventDefault function:

  map.on('click', 'point', function(e) {
    e.preventDefault();
    console.log('show sidebar');
  });

  map.on('click', function(e) {
    if (e.defaultPrevented === false) {
      console.log('hide taskbar');
    }
  });

[ https://jsfiddle/7mfb59qo/2/ ]

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744316348a4568203.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信