Ale*_*lex 0 javascript mapbox-gl-js
在我的 Mapbox 上有 3 层。
id: 'Map', id:'Cluster',id: 'Point'
map.on('click', 'Point', function (e) {
$(".page-wrapper").addClass("toggled");/*show sidebar*/
});
Run Code Online (Sandbox Code Playgroud)
此代码意味着当我单击图层上的点时id: 'Point',侧边栏将显示。
$(".page-wrapper").removeClass("toggled");/*hide sidebar*/
Run Code Online (Sandbox Code Playgroud)
添加到事件时,此代码将隐藏侧边栏。
现在,我想点击图层id: 'Point'侧边栏上没有点的任何地方将被隐藏。
我怎样才能做到这一点?
对整个地图和preventDefault函数使用点击事件处理程序:
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');
}
});
Run Code Online (Sandbox Code Playgroud)
[ https://jsfiddle.net/7mfb59qo/2/ ]
| 归档时间: |
|
| 查看次数: |
527 次 |
| 最近记录: |