fix (Сохранение состояние вкладки на ГТО)
This commit is contained in:
parent
b4bf943c8f
commit
47f12a4c74
@ -25,7 +25,7 @@
|
||||
<div class="col-md-12">
|
||||
<div class="card card-primary card-outline ">
|
||||
<div class="card-header text-sm">
|
||||
<a href="/gto/reports/">Отчеты</a>
|
||||
<a href="/gto/reports/">Отчеты</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="tab-content">
|
||||
@ -35,22 +35,30 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" 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">Оборудование
|
||||
в работе ( {{ clients_count }} шт. )</a>
|
||||
aria-controls="custom-content-above-home" aria-selected="false"
|
||||
onclick="switchTab('#custom-content-above-home')">
|
||||
Оборудование в работе ({{ clients_count }} шт.)
|
||||
</a>
|
||||
</li>
|
||||
{% if user.profile.role == 1 %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="custom-content-above-profile-tab"
|
||||
data-toggle="pill" href="#custom-content-above-profile"
|
||||
role="tab" aria-controls="custom-content-above-profile"
|
||||
aria-selected="false">Заблокированное оборудование
|
||||
( {{ clients_count_block }} шт. )</a>
|
||||
role="tab"
|
||||
aria-controls="custom-content-above-profile"
|
||||
aria-selected="false"
|
||||
onclick="switchTab('#custom-content-above-profile')">
|
||||
Заблокированное оборудование ({{ clients_count_block }} шт.)
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active " id="custom-content-above-profile-tab"
|
||||
<a class="nav-link" id="custom-content-map-tab"
|
||||
data-toggle="pill" href="#custom-content-map" role="tab"
|
||||
aria-controls="custom-content-map" aria-selected="true">Карта</a>
|
||||
aria-controls="custom-content-map" aria-selected="false"
|
||||
onclick="switchTab('#custom-content-map')">
|
||||
Карта
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="custom-content-above-tabContent">
|
||||
@ -196,38 +204,10 @@
|
||||
id="mypaginator_next">
|
||||
<a class="page-link" href="?page=
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{{ start_page_list_block|add:-1}}"
|
||||
aria-controls="mypaginator"
|
||||
data-dt-idx="
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{{ start_page_list_block|add:-1}}"
|
||||
style="padding: .3rem .5rem;"><span>..</span></a>
|
||||
</li>
|
||||
@ -259,38 +239,10 @@
|
||||
id="mypaginator_next">
|
||||
<a class="page-link" href="?page=
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{{ end_page_list_block|add:1}}"
|
||||
aria-controls="mypaginator"
|
||||
data-dt-idx="
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{{ end_page_list_block|add:1}}"
|
||||
style="padding: .3rem .5rem;"><span>..</span></a>
|
||||
</li>
|
||||
@ -376,6 +328,10 @@
|
||||
<div class="card-body table-responsive p-0"
|
||||
style="height: 80vh; padding-left: 0;">
|
||||
<div id="map">
|
||||
<button type="button" id="toStart" class="btn"
|
||||
style="position: absolute; top: .5em; left: .5em; z-index: 999; background-color: rgba(255,255,255, 0.5); border: 1px solid #e2c4b0">
|
||||
Вернуться на разрез
|
||||
</button>
|
||||
<div id="popup"></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -401,47 +357,70 @@
|
||||
{% 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);
|
||||
function switchTab(tabHref) {
|
||||
// Находим элемент вкладки по href
|
||||
var tabElement = document.querySelector(`a[href="${tabHref}"]`);
|
||||
if (tabElement) {
|
||||
var tab = new bootstrap.Tab(tabElement);
|
||||
tab.show();
|
||||
|
||||
const backgroundFill = '#fff'
|
||||
const backgroundStroke = '#000'
|
||||
// Сохраняем выбранную вкладку в localStorage
|
||||
localStorage.setItem('gto_selectedTab', tabHref);
|
||||
} else {
|
||||
console.error('Вкладка с href ' + tabHref + ' не найдена.');
|
||||
}
|
||||
}
|
||||
|
||||
function restoreTab() {
|
||||
var gto_selectedTab = localStorage.getItem('gto_selectedTab');
|
||||
|
||||
if (gto_selectedTab) {
|
||||
switchTab(gto_selectedTab);
|
||||
}
|
||||
}
|
||||
|
||||
// Восстанавливаем вкладку при загрузке страницы
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
restoreTab();
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function getGTOMarkerText(feature) {
|
||||
const statemum = feature.get('garagenum')
|
||||
if (statemum) {
|
||||
return statemum;
|
||||
}
|
||||
return feature.get('name')
|
||||
}
|
||||
|
||||
function createGTOStateNumTextStyle(feature, resolution) {
|
||||
const font = 'bold' + ' ' + '12px' + '/' + '1' + ' ' + 'Arial';
|
||||
return new ol.style.Text({
|
||||
textAlign: 'center',
|
||||
textBaseline: 'middle',
|
||||
font: font,
|
||||
text: getText(feature, resolution),
|
||||
fill: new ol.style.Fill({color: fillColor}),
|
||||
text: getGTOMarkerText(feature, resolution),
|
||||
fill: new ol.style.Fill({color: '#000'}),
|
||||
offsetX: 0,
|
||||
offsetY: -30,
|
||||
offsetY: -25,
|
||||
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],
|
||||
backgroundFill: new ol.style.Fill({color: '#fff'}),
|
||||
backgroundStroke: new ol.style.Stroke({color: '#000', width: 1}),
|
||||
padding: [3, 3, 3, 3],
|
||||
});
|
||||
};
|
||||
function pointStyleFunction(feature, resolution) {
|
||||
}
|
||||
|
||||
function GTOStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon({
|
||||
src: '/static/img/belaz.png',
|
||||
scale: 0.1, // Масштаб иконки
|
||||
src: feature.get('icon') ? feature.get('icon') : "/static/img/belaz.png",
|
||||
width: 30,
|
||||
height: 20
|
||||
}),
|
||||
text: createTextStyle(feature, resolution)
|
||||
text: createGTOStateNumTextStyle(feature, resolution)
|
||||
})
|
||||
}
|
||||
|
||||
@ -478,17 +457,22 @@
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
let map, GTOLayer, GTOSource, popup, m_markers = {};
|
||||
let map = {}
|
||||
let popup = {}
|
||||
let GTOMarkers = {}
|
||||
let GTOSource = {}
|
||||
let GTOLayer = {}
|
||||
let centerLat = '{{lon}}'
|
||||
let centerLon = '{{lat}}'
|
||||
|
||||
function initializeMap() {
|
||||
// Источник данных для маркеров
|
||||
GTOSource = new ol.source.Vector();
|
||||
|
||||
// Слой для отображения маркеров
|
||||
// Слой для отображения GTO
|
||||
GTOLayer = new ol.layer.Vector({
|
||||
source: GTOSource,
|
||||
style: pointStyleFunction
|
||||
style: GTOStyleFunction
|
||||
});
|
||||
GTOLayer.set('name', 'Горнотранспортное оборудование')
|
||||
|
||||
// Создание карты
|
||||
map = new ol.Map({
|
||||
@ -500,7 +484,7 @@
|
||||
GTOLayer,
|
||||
],
|
||||
view: new ol.View({
|
||||
center: ol.proj.fromLonLat(['{{lon}}', '{{lat}}']), // Центр карты
|
||||
center: ol.proj.fromLonLat([centerLat, centerLon]), // Центр карты
|
||||
zoom: 12,
|
||||
}),
|
||||
});
|
||||
@ -545,30 +529,170 @@
|
||||
// Установка позиции popup на карте
|
||||
popup.setPosition(coordinates);
|
||||
|
||||
function createPopover(feature) {
|
||||
const res = document.createElement('div')
|
||||
const properties = feature.getProperties()
|
||||
for (let property in properties) {
|
||||
switch (property) {
|
||||
case 'name': {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Имя: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('name')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case 'lat': {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Координаты: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('lat') + ' ' + feature.get('lon')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case 'time': {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Время координаты: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('time')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case 'statenum': {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Госномер: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('statenum')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case 'garagenum': {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Гаражный номер: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('garagenum')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case "depth": {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Глубина: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('depth') + " км."
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case "magnitude": {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Магнитуда: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('magnitude')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case "region": {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Регион: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('region')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
case "source": {
|
||||
let div = document.createElement('div')
|
||||
let span = document.createElement('span')
|
||||
let strong = document.createElement('strong')
|
||||
|
||||
strong.textContent = "Источник: "
|
||||
div.appendChild(strong)
|
||||
|
||||
span.textContent = feature.get('source')
|
||||
div.appendChild(span)
|
||||
|
||||
res.appendChild(div)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Создание нового 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>
|
||||
`,
|
||||
content: createPopover(feature),
|
||||
});
|
||||
|
||||
// Отображение popover
|
||||
popover.show();
|
||||
});
|
||||
map.on('movestart', disposePopover);
|
||||
map.on("pointermove", function (evt) {
|
||||
var hit = this.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
|
||||
return true;
|
||||
});
|
||||
if (hit) {
|
||||
this.getTargetElement().style.cursor = 'pointer';
|
||||
} else {
|
||||
this.getTargetElement().style.cursor = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Загрузка маркеров
|
||||
updateMarkers();
|
||||
setInterval(updateMarkers, 5000)
|
||||
}
|
||||
|
||||
function addMarker(equipment) {
|
||||
function addGTOMarker(equipment) {
|
||||
const point = new ol.geom.Point(ol.proj.fromLonLat([equipment.lon, equipment.lat]));
|
||||
const feature = new ol.Feature(point);
|
||||
feature.setProperties({
|
||||
@ -576,14 +700,17 @@
|
||||
time: equipment.time,
|
||||
lat: equipment.lat,
|
||||
lon: equipment.lon,
|
||||
statenum: equipment.statenum
|
||||
statenum: equipment.statenum,
|
||||
garagenum: equipment.garagenum,
|
||||
model: equipment.model,
|
||||
icon: equipment.icon
|
||||
});
|
||||
GTOSource.addFeature(feature);
|
||||
m_markers[equipment.id] = feature;
|
||||
GTOMarkers[equipment.id] = feature;
|
||||
}
|
||||
|
||||
function updateMarkers() {
|
||||
fetch('update_object/', {
|
||||
fetch('/gto/update_object/', {
|
||||
method: 'POST',
|
||||
headers: {'X-CSRFToken': csrftoken},
|
||||
mode: 'same-origin',
|
||||
@ -591,8 +718,8 @@
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
data.forEach(equipment => {
|
||||
if (m_markers[equipment.id]) {
|
||||
const marker = m_markers[equipment.id];
|
||||
if (GTOMarkers[equipment.id]) {
|
||||
const marker = GTOMarkers[equipment.id];
|
||||
const currentCoordinates = marker.getGeometry().getCoordinates();
|
||||
const newCoordinates = ol.proj.fromLonLat([equipment.lon, equipment.lat]);
|
||||
|
||||
@ -602,12 +729,19 @@
|
||||
}
|
||||
} else {
|
||||
// Создаем новый маркер, если его ещё нет
|
||||
addMarker(equipment);
|
||||
addGTOMarker(equipment);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let toStart = document.querySelector('#toStart')
|
||||
toStart.addEventListener('click', ev => {
|
||||
map.setView(new ol.View({
|
||||
center: ol.proj.fromLonLat([centerLat, centerLon]), // Центр карты
|
||||
zoom: 12,
|
||||
}))
|
||||
})
|
||||
|
||||
window.onload = initializeMap;
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
<div class="card-body table-responsive p-0"
|
||||
style="height: 75vh; padding-left: 0;">
|
||||
<div id="map">
|
||||
<button type="button" id="test" class="btn"
|
||||
<button type="button" id="toStart" class="btn"
|
||||
style="position: absolute; top: .5em; left: .5em; z-index: 999; background-color: rgba(255,255,255, 0.5); border: 1px solid #e2c4b0">
|
||||
Вернуться на разрез
|
||||
</button>
|
||||
@ -741,8 +741,8 @@
|
||||
{# });#}
|
||||
}
|
||||
|
||||
let test = document.querySelector('#test')
|
||||
test.addEventListener('click', ev => {
|
||||
let toStart = document.querySelector('#toStart')
|
||||
toStart.addEventListener('click', ev => {
|
||||
map.setView(new ol.View({
|
||||
center: ol.proj.fromLonLat([centerLat, centerLon]), // Центр карты
|
||||
zoom: 12,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user