Отображение popover по кнопке
This commit is contained in:
parent
8dd741e300
commit
3492f34cf9
@ -4,6 +4,7 @@
|
||||
if (executed === 0) {
|
||||
executed = 1
|
||||
let map = {}
|
||||
let popover;
|
||||
let VlocationLayer = {}
|
||||
let VlocationSource = {}
|
||||
let popup = {}
|
||||
@ -39,7 +40,11 @@
|
||||
map.getView().animate({
|
||||
center: featureCoords,
|
||||
zoom: 17,
|
||||
duration: 1000,
|
||||
});
|
||||
setTimeout( () => {
|
||||
showPopover(feature, featureCoords)
|
||||
}, 1001)
|
||||
});
|
||||
tdWorkerCoord.appendChild(showCoordButton)
|
||||
|
||||
@ -49,6 +54,53 @@
|
||||
return tr
|
||||
}
|
||||
|
||||
function showPopover(feature, coordinates) {
|
||||
// Удаление существующего popover
|
||||
disposePopover();
|
||||
|
||||
// Получение контейнера элемента popup
|
||||
const element = document.getElementById('popup'); // Убедитесь, что этот элемент существует в DOM
|
||||
|
||||
// Установка позиции popup на карте
|
||||
popup.setPosition(coordinates);
|
||||
|
||||
// Создание нового popover
|
||||
popover = new bootstrap.Popover(element, {
|
||||
placement: 'top', // Расположение popover
|
||||
html: true, // Поддержка HTML-содержимого
|
||||
content: createPopover(feature),
|
||||
});
|
||||
|
||||
// Отображение popover
|
||||
popover.show();
|
||||
}
|
||||
|
||||
function disposePopover() {
|
||||
if (popover) {
|
||||
popover.dispose();
|
||||
popover = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function createPopover(feature) {
|
||||
const res = document.createElement('div')
|
||||
const properties = feature.getProperties()
|
||||
for (let property in properties) {
|
||||
if (property === 'geometry' || property === 'id') continue
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
strong.textContent = `${propertiesTranslate[property]}: `
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get(property)
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
function VlocationStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon({
|
||||
@ -130,70 +182,27 @@
|
||||
});
|
||||
map.addOverlay(popup);
|
||||
|
||||
let popover;
|
||||
|
||||
function disposePopover() {
|
||||
if (popover) {
|
||||
popover.dispose();
|
||||
popover = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
map.on('movestart', disposePopover);
|
||||
|
||||
// Обработчик клика на карту
|
||||
// Обработка кликов по маркерам
|
||||
map.on('click', function (evt) {
|
||||
// Получение feature по клику
|
||||
const feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
|
||||
return feature;
|
||||
});
|
||||
|
||||
// Удаление существующего popover
|
||||
disposePopover();
|
||||
|
||||
if (!feature) {
|
||||
return; // Если feature не найден, ничего не делаем
|
||||
disposePopover(); // Если feature не найден, закрываем popover
|
||||
return;
|
||||
}
|
||||
|
||||
// Получение координат клика
|
||||
const coordinates = evt.coordinate;
|
||||
|
||||
// Получение контейнера элемента popup
|
||||
const element = document.getElementById('popup'); // Убедитесь, что этот элемент существует в DOM
|
||||
|
||||
// Установка позиции popup на карте
|
||||
popup.setPosition(coordinates);
|
||||
|
||||
function createPopover(feature) {
|
||||
const res = document.createElement('div')
|
||||
const properties = feature.getProperties()
|
||||
for (let property in properties) {
|
||||
if (property === 'geometry' || property === 'id') continue
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
strong.textContent = `${propertiesTranslate[property]}: `
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get(property)
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Создание нового popover
|
||||
popover = new bootstrap.Popover(element, {
|
||||
placement: 'top', // Расположение popover
|
||||
html: true, // Поддержка HTML-содержимого
|
||||
content: createPopover(feature),
|
||||
});
|
||||
|
||||
// Отображение popover
|
||||
popover.show();
|
||||
});
|
||||
// Отображаем popover на фиче
|
||||
showPopover(feature, coordinates);
|
||||
})
|
||||
|
||||
// Загрузка маркеров
|
||||
updateMarkers();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user