Рефактор

This commit is contained in:
zakhy 2025-01-10 10:43:45 +07:00
parent 84fa815d8c
commit 4c82efe290

View File

@ -20,29 +20,29 @@
{% csrf_token %}
<input id="id_acs" type="hidden" value="None" name="id">
<input id="cmd" type="hidden" value="None" name="cmd">
<div class="row">
<div class="col-md-12">
<div class="card card-primary card-outline mt-1">
<div class="card-body">
<div class="tab-content">
<div class="row">
<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 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 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: 75vh; padding-left: 0;">
<div id="map">
<div id="popup"></div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card card-primary card-outline mt-1">
<div class="card-body p-1">
<div class="tab-content">
<div class="row">
<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 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 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: 75vh; padding-left: 0;">
<div id="map">
<div id="popup"></div>
</div>
</div>
</div>
@ -54,6 +54,7 @@
</div>
</div>
</div>
</div>
</form>
</section>
@ -63,49 +64,49 @@
{% 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;
let map, GTOLayer, GTOSource, GTOMarkers, popup, VlocationLayer, VlocationSource, VlocationMarkers = {};
const getGTOMarkerText = function (feature) {
return feature.get('statenum');
};
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'
const createGTOStateNumTextStyle = function (feature, resolution) {
const font = 'bold' + ' ' + '14px' + '/' + '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,
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}),
backgroundFill: new ol.style.Fill({color: '#fff'}),
backgroundStroke: new ol.style.Stroke({color: '#000', width: parseInt('1')}),
padding: [5, 5, 5, 5],
});
};
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, // Масштаб иконки
}),
text: createTextStyle(feature, resolution)
text: createGTOStateNumTextStyle(feature, resolution)
})
}
function VlocationStyleFunction(feature, resolution) {
return new ol.style.Style({
image: new ol.style.Icon({
src: '/static/img/helmet.png',
scale: 0.1, // Масштаб иконки
}),
})
}
@ -142,18 +143,23 @@
requestAnimationFrame(animate);
}
let map, GTOLayer, GTOSource, popup, m_markers = {};
function initializeMap() {
// Источник данных для маркеров
// Источник данных для GTO
GTOSource = new ol.source.Vector();
// Слой для отображения маркеров
// Слой для отображения GTO
GTOLayer = new ol.layer.Vector({
source: GTOSource,
style: pointStyleFunction
style: GTOStyleFunction
});
VlocationSource = new ol.source.Vector();
VlocationLayer = new ol.layer.Vector({
source: VlocationSource,
style: VlocationStyleFunction
})
// Создание карты
map = new ol.Map({
target: 'map', // ID элемента, куда встроится карта
@ -168,6 +174,7 @@
zoom: 14,
}),
});
const element = document.getElementById('popup')
// Всплывающее окно
popup = new ol.Overlay({
@ -232,7 +239,7 @@
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({
@ -243,7 +250,7 @@
statenum: equipment.statenum
});
GTOSource.addFeature(feature);
m_markers[equipment.id] = feature;
GTOMarkers[equipment.id] = feature;
}
function updateMarkers() {
@ -255,8 +262,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]);
@ -266,10 +273,11 @@
}
} else {
// Создаем новый маркер, если его ещё нет
addMarker(equipment);
addGTOMarker(equipment);
}
});
});
// fetch для vlocation/update_object/
}