Рефакторинг.
Убрал функции добавления маркеров, объединив их в одну
This commit is contained in:
parent
66b8a1f003
commit
209f01c8cc
@ -100,7 +100,6 @@
|
||||
<script src="{% static 'js/ol/ol-ext/ol-ext.min.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
<script src="{% static 'js/ol/layersStyles.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
<script src="{% static 'js/ol/mapCommonFuncs.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
<script src="{% static 'js/ol/timeSliderFuncs.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
|
||||
@ -296,71 +295,7 @@
|
||||
|
||||
// Добавление новых маркеров
|
||||
filteredEarthquakes.forEach(earthquake => {
|
||||
addSPMarker(earthquake);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function GTOStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon({
|
||||
src: feature.get('icon') ? feature.get('icon') : "/static/img/belaz.png",
|
||||
width: 30,
|
||||
height: 20
|
||||
}),
|
||||
text: createGTOStateNumTextStyle(feature, resolution)
|
||||
})
|
||||
}
|
||||
|
||||
function createHatchPattern() {
|
||||
// Создаем элемент canvas для шаблона штриховки
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 10; // Ширина шаблона
|
||||
canvas.height = 10; // Высота шаблона
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.strokeStyle = 'rgba(125, 105, 49, 0.1)'; // Цвет штриховки
|
||||
ctx.lineWidth = 2;
|
||||
|
||||
// Рисуем диагональные линии для штриховки
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, 10);
|
||||
ctx.lineTo(10, 0);
|
||||
ctx.stroke();
|
||||
|
||||
// Создаем паттерн из канваса
|
||||
return ctx.createPattern(canvas, 'repeat');
|
||||
}
|
||||
|
||||
function VlocationStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon({
|
||||
src: '/static/img/worker.png',
|
||||
width: 25,
|
||||
height: 30
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function SPStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon({
|
||||
src: '/static/img/earthquake_yellow.png',
|
||||
width: 25,
|
||||
height: 30
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function polygonStyleFunction(feature, resolution) {
|
||||
return new ol.style.Style({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'rgb(0,117,217)',
|
||||
width: 2,
|
||||
}),
|
||||
fill: new ol.style.Fill({
|
||||
color: createHatchPattern(),
|
||||
}),
|
||||
addMarker(earthquake, SPSource, SPMarkers);
|
||||
});
|
||||
}
|
||||
|
||||
@ -757,28 +692,12 @@
|
||||
setInterval(updateMarkers, 3000)
|
||||
}
|
||||
|
||||
function addGTOMarker(equipment) {
|
||||
const point = new ol.geom.Point(ol.proj.fromLonLat([equipment.lon, equipment.lat]));
|
||||
function addMarker(obj, source, markersStorage) {
|
||||
const point = new ol.geom.Point(ol.proj.fromLonLat([obj.lon, obj.lat]));
|
||||
const feature = new ol.Feature(point);
|
||||
updateMarkerProperties(feature, equipment)
|
||||
GTOSource.addFeature(feature);
|
||||
GTOMarkers[equipment.id] = feature;
|
||||
}
|
||||
|
||||
function addVlocationMarker(worker) {
|
||||
const point = new ol.geom.Point(ol.proj.fromLonLat([worker.lon, worker.lat]));
|
||||
const feature = new ol.Feature(point);
|
||||
updateMarkerProperties(feature, worker)
|
||||
VlocationSource.addFeature(feature)
|
||||
VlocationMarkers[worker.id] = feature
|
||||
}
|
||||
|
||||
function addSPMarker(earthquake) {
|
||||
const point = new ol.geom.Point(ol.proj.fromLonLat([earthquake.lon, earthquake.lat]));
|
||||
const feature = new ol.Feature(point);
|
||||
updateMarkerProperties(feature, earthquake)
|
||||
SPSource.addFeature(feature)
|
||||
SPMarkers[earthquake.id] = feature
|
||||
updateMarkerProperties(feature, obj)
|
||||
source.addFeature(feature);
|
||||
markersStorage[obj.id] = feature;
|
||||
}
|
||||
|
||||
function updateMarkers() {
|
||||
@ -804,7 +723,7 @@
|
||||
}
|
||||
} else {
|
||||
// Создаем новый маркер, если его ещё нет
|
||||
addGTOMarker(equipment);
|
||||
addMarker(equipment, GTOSource, GTOMarkers);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -823,7 +742,7 @@
|
||||
moveMarker(marker, newCoordinates); // Плавное перемещение
|
||||
}
|
||||
} else {
|
||||
addVlocationMarker(worker)
|
||||
addMarker(worker, VlocationSource, VlocationMarkers)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user