下面是我添加信息气泡的代码。我想在单击(点击)不同的标记后删除当前的信息气泡。
function addInfoBubble(map)
{
var group = new H.map.Group();
map.addObject(group);
// add 'tap' event listener, that opens info bubble, to the group
group.addEventListener('tap', function(evt) {
// event target is the marker itself, group is a parent event target
// for all objects that it contains
var bubble = new H.ui.InfoBubble(evt.target.getPosition(), {
// read custom data
content: evt.target.getData()
});
// show info bubble
ui.addBubble(bubble);
}, false);
}
我应该在哪里放置代码行ui.removeBubble(bubble)
如果我点击不同的标记?
您可以在添加新信息之前从用户界面中删除所有信息气泡。如果您不介意删除当前显示的所有气泡,则类似以下内容应该有效:
ui.getBubbles().forEach(bub => ui.removeBubble(bub));
将其合并到您的代码中:
function addInfoBubble(map) {
var group = new H.map.Group();
map.addObject(group);
// add 'tap' event listener, that opens info bubble, to the group
group.addEventListener('tap', function(evt) {
// event target is the marker itself, group is a parent event target
// for all objects that it contains
var bubble = new H.ui.InfoBubble(evt.target.getPosition(), {
// read custom data
content: evt.target.getData()
});
//remove infobubbles
ui.getBubbles().forEach(bub => ui.removeBubble(bub));
// show info bubble
ui.addBubble(bubble);
}, false);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)