Remove tooltip when mouse leaves map or is over control is examples
This commit is contained in:
@@ -69,10 +69,12 @@ const tooltip = new bootstrap.Tooltip(info, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let currentFeature;
|
let currentFeature;
|
||||||
const displayFeatureInfo = function (pixel) {
|
const displayFeatureInfo = function (pixel, target) {
|
||||||
const feature = map.forEachFeatureAtPixel(pixel, function (feature) {
|
const feature = target.closest('.ol-control')
|
||||||
return feature;
|
? undefined
|
||||||
});
|
: map.forEachFeatureAtPixel(pixel, function (feature) {
|
||||||
|
return feature;
|
||||||
|
});
|
||||||
if (feature) {
|
if (feature) {
|
||||||
info.style.left = pixel[0] + 'px';
|
info.style.left = pixel[0] + 'px';
|
||||||
info.style.top = pixel[1] + 'px';
|
info.style.top = pixel[1] + 'px';
|
||||||
@@ -97,9 +99,14 @@ map.on('pointermove', function (evt) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const pixel = map.getEventPixel(evt.originalEvent);
|
const pixel = map.getEventPixel(evt.originalEvent);
|
||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel, evt.originalEvent.target);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('click', function (evt) {
|
map.on('click', function (evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel, evt.originalEvent.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
map.getTargetElement().addEventListener('pointerleave', function () {
|
||||||
|
tooltip.hide();
|
||||||
|
currentFeature = undefined;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -93,10 +93,12 @@ const tooltip = new bootstrap.Tooltip(info, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let currentFeature;
|
let currentFeature;
|
||||||
const displayFeatureInfo = function (pixel) {
|
const displayFeatureInfo = function (pixel, target) {
|
||||||
const feature = map.forEachFeatureAtPixel(pixel, function (feature) {
|
const feature = target.closest('.ol-control')
|
||||||
return feature;
|
? undefined
|
||||||
});
|
: map.forEachFeatureAtPixel(pixel, function (feature) {
|
||||||
|
return feature;
|
||||||
|
});
|
||||||
if (feature) {
|
if (feature) {
|
||||||
info.style.left = pixel[0] + 'px';
|
info.style.left = pixel[0] + 'px';
|
||||||
info.style.top = pixel[1] + 'px';
|
info.style.top = pixel[1] + 'px';
|
||||||
@@ -121,9 +123,14 @@ map.on('pointermove', function (evt) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const pixel = map.getEventPixel(evt.originalEvent);
|
const pixel = map.getEventPixel(evt.originalEvent);
|
||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel, evt.originalEvent.target);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('click', function (evt) {
|
map.on('click', function (evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel, evt.originalEvent.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
map.getTargetElement().addEventListener('pointerleave', function () {
|
||||||
|
tooltip.hide();
|
||||||
|
currentFeature = undefined;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user