Убрал карту с страницы GTO
This commit is contained in:
parent
779bf755e9
commit
6c371ebf7d
@ -30,9 +30,9 @@
|
||||
<div class="col-md-12">
|
||||
<ul class="nav nav-tabs" id="custom-content-above-tab" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="custom-content-above-home-tab"
|
||||
<a class="nav-link active" id="custom-content-above-home-tab"
|
||||
data-toggle="pill" href="#custom-content-above-home" role="tab"
|
||||
aria-controls="custom-content-above-home" aria-selected="false">Оборудование
|
||||
aria-controls="custom-content-above-home" aria-selected="true">Оборудование
|
||||
в работе ( {{ clients_count }} шт. )</a>
|
||||
</li>
|
||||
{% if user.profile.role == 1 %}
|
||||
@ -44,14 +44,9 @@
|
||||
( {{ clients_count_block }} шт. )</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active " id="custom-content-above-profile-tab"
|
||||
data-toggle="pill" href="#custom-content-map" role="tab"
|
||||
aria-controls="custom-content-map" aria-selected="true">Карта</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="custom-content-above-tabContent">
|
||||
<div class="tab-pane fade" id="custom-content-above-home"
|
||||
<div class="tab-pane fade active show" id="custom-content-above-home"
|
||||
role="tabpanel" aria-labelledby="custom-content-above-home-tab">
|
||||
<div class="card">
|
||||
<div class="card-header text-sm">
|
||||
@ -367,21 +362,9 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="tab-pane fade active show" id="custom-content-map"
|
||||
role="tabpanel" aria-labelledby="custom-content-map-tab">
|
||||
<div class="card">
|
||||
<div class="card-body table-responsive p-0"
|
||||
style="height: 80vh; padding-left: 0;">
|
||||
<div id="map">
|
||||
<div id="popup"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -396,218 +379,4 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block script_footer %}
|
||||
<script src="{% static 'js/ol/lib/OpenLayers.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
<script>
|
||||
const getText = function (feature) {
|
||||
let text = feature.get('statenum');
|
||||
return text;
|
||||
};
|
||||
const createTextStyle = function (feature, resolution) {
|
||||
const size = '14px';
|
||||
const height = '1';
|
||||
const weight = 'bold';
|
||||
const font = weight + ' ' + size + '/' + height + ' ' + 'Arial';
|
||||
const fillColor = '#000';
|
||||
const borderWidth = parseInt('0.1', 10);
|
||||
|
||||
const backgroundFill = '#fff'
|
||||
const backgroundStroke = '#000'
|
||||
|
||||
|
||||
return new ol.style.Text({
|
||||
textAlign: 'center',
|
||||
textBaseline: 'middle',
|
||||
font: font,
|
||||
text: getText(feature, resolution),
|
||||
fill: new ol.style.Fill({color: fillColor}),
|
||||
offsetX: 0,
|
||||
offsetY: -30,
|
||||
placement: 'point',
|
||||
maxAngle: '0.7853981633974483',
|
||||
overflow: 'false',
|
||||
rotation: parseFloat('0'),
|
||||
|
||||
backgroundFill: new ol.style.Fill({color: backgroundFill}),
|
||||
backgroundStroke: new ol.style.Stroke({color: backgroundStroke, width: borderWidth}),
|
||||
padding: [5,5,5,5],
|
||||
});
|
||||
};
|
||||
function pointStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon({
|
||||
src: '/static/img/belaz.png',
|
||||
scale: 0.1, // Масштаб иконки
|
||||
}),
|
||||
text: createTextStyle(feature, resolution)
|
||||
})
|
||||
}
|
||||
|
||||
function moveMarker(marker, newCoordinates) {
|
||||
const duration = 2000; // Длительность анимации в миллисекундах
|
||||
const startCoordinates = marker.getGeometry().getCoordinates();
|
||||
|
||||
// Начало анимации
|
||||
const startTime = performance.now();
|
||||
|
||||
function animate(currentTime) {
|
||||
// Вычисление прошедшего времени
|
||||
const elapsed = currentTime - startTime;
|
||||
|
||||
// Вычисление доли анимации (от 0 до 1)
|
||||
const fraction = Math.min(elapsed / duration, 1);
|
||||
|
||||
// Интерполяция координат
|
||||
const interpolatedCoordinates = [
|
||||
startCoordinates[0] + fraction * (newCoordinates[0] - startCoordinates[0]),
|
||||
startCoordinates[1] + fraction * (newCoordinates[1] - startCoordinates[1]),
|
||||
];
|
||||
|
||||
// Устанавливаем новые координаты для маркера
|
||||
marker.getGeometry().setCoordinates(interpolatedCoordinates);
|
||||
|
||||
// Продолжаем анимацию, если она еще не завершена
|
||||
if (fraction < 1) {
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
}
|
||||
|
||||
// Запуск анимации
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
let map, GTOLayer, GTOSource, popup, m_markers = {};
|
||||
|
||||
function initializeMap() {
|
||||
// Источник данных для маркеров
|
||||
GTOSource = new ol.source.Vector();
|
||||
|
||||
// Слой для отображения маркеров
|
||||
GTOLayer = new ol.layer.Vector({
|
||||
source: GTOSource,
|
||||
style: pointStyleFunction
|
||||
});
|
||||
|
||||
// Создание карты
|
||||
map = new ol.Map({
|
||||
target: 'map', // ID элемента, куда встроится карта
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.OSM(), // Open street Map
|
||||
}),
|
||||
GTOLayer,
|
||||
],
|
||||
view: new ol.View({
|
||||
center: ol.proj.fromLonLat(['{{lon}}', '{{lat}}']), // Центр карты
|
||||
zoom: 14,
|
||||
}),
|
||||
});
|
||||
const element = document.getElementById('popup')
|
||||
// Всплывающее окно
|
||||
popup = new ol.Overlay({
|
||||
element: element,
|
||||
positioning: 'bottom-center',
|
||||
{#autoPan: true,#}
|
||||
});
|
||||
map.addOverlay(popup);
|
||||
|
||||
let popover;
|
||||
|
||||
function disposePopover() {
|
||||
if (popover) {
|
||||
popover.dispose();
|
||||
popover = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Обработка кликов по маркерам
|
||||
map.on('click', function (evt) {
|
||||
// Получение feature по клику
|
||||
const feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
|
||||
return feature;
|
||||
});
|
||||
|
||||
// Удаление существующего popover
|
||||
disposePopover();
|
||||
|
||||
if (!feature) {
|
||||
return; // Если feature не найден, ничего не делаем
|
||||
}
|
||||
|
||||
// Получение координат клика
|
||||
const coordinates = evt.coordinate;
|
||||
|
||||
// Получение контейнера элемента popup
|
||||
const element = document.getElementById('popup'); // Убедитесь, что этот элемент существует в DOM
|
||||
|
||||
// Установка позиции popup на карте
|
||||
popup.setPosition(coordinates);
|
||||
|
||||
// Создание нового popover
|
||||
popover = new bootstrap.Popover(element, {
|
||||
placement: 'top', // Расположение popover
|
||||
html: true, // Поддержка HTML-содержимого
|
||||
content: `
|
||||
<div>
|
||||
<span><strong>Имя: </strong>${feature.get('name') || 'Нет имени'}</span><br>
|
||||
<span><strong>Координаты: </strong>${feature.get('lat')} ${feature.get('lon')}</span><br>
|
||||
<span><strong>Время координат: </strong>${feature.get('time') || 'Нет времени'}</span>
|
||||
</div>
|
||||
`,
|
||||
});
|
||||
|
||||
// Отображение popover
|
||||
popover.show();
|
||||
});
|
||||
map.on('movestart', disposePopover);
|
||||
|
||||
// Загрузка маркеров
|
||||
updateMarkers();
|
||||
setInterval(updateMarkers, 5000)
|
||||
}
|
||||
|
||||
function addMarker(equipment) {
|
||||
const point = new ol.geom.Point(ol.proj.fromLonLat([equipment.lon, equipment.lat]));
|
||||
const feature = new ol.Feature(point);
|
||||
feature.setProperties({
|
||||
name: equipment.name,
|
||||
time: equipment.time,
|
||||
lat: equipment.lat,
|
||||
lon: equipment.lon,
|
||||
statenum: equipment.statenum
|
||||
});
|
||||
GTOSource.addFeature(feature);
|
||||
m_markers[equipment.id] = feature;
|
||||
}
|
||||
|
||||
function updateMarkers() {
|
||||
fetch('update_object/', {
|
||||
method: 'POST',
|
||||
headers: {'X-CSRFToken': csrftoken},
|
||||
mode: 'same-origin',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
data.forEach(equipment => {
|
||||
if (m_markers[equipment.id]) {
|
||||
const marker = m_markers[equipment.id];
|
||||
const currentCoordinates = marker.getGeometry().getCoordinates();
|
||||
const newCoordinates = ol.proj.fromLonLat([equipment.lon, equipment.lat]);
|
||||
|
||||
// Проверяем, изменились ли координаты
|
||||
if (currentCoordinates[0] !== newCoordinates[0] || currentCoordinates[1] !== newCoordinates[1]) {
|
||||
moveMarker(marker, newCoordinates); // Плавное перемещение
|
||||
}
|
||||
} else {
|
||||
// Создаем новый маркер, если его ещё нет
|
||||
addMarker(equipment);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
window.onload = initializeMap;
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock script_footer %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user