Обновление свойств маркера в динамике

This commit is contained in:
zakhy 2025-03-05 08:58:14 +07:00
parent 353e280c05
commit b324556fca
3 changed files with 45 additions and 16 deletions

View File

@ -720,6 +720,9 @@
data.forEach(equipment => {
if (GTOMarkers[equipment.id]) {
const marker = GTOMarkers[equipment.id];
updateMarkerProperties(marker, equipment)
const currentCoordinates = marker.getGeometry().getCoordinates();
const newCoordinates = ol.proj.fromLonLat([equipment.lon, equipment.lat]);
@ -745,6 +748,12 @@
window.onload = initializeMap;
function updateMarkerProperties(marker, properties) {
for (let property in properties) {
marker.set(property, properties[property])
}
}
</script>
{% endblock script_footer %}

View File

@ -523,21 +523,21 @@
}
layersBtn.classList.toggle("selected")
})
layerSwitcher.addControl(
new ol.control.Button({
html: "Создать слой",
handleClick: function () {
window.location.href = '{% url 'create_layer' %}'
}
}), 'bottom');
layerSwitcher.addControl(
new ol.control.Button({
html: "Редактировать слои",
handleClick: function () {
window.location.href = '{% url 'layers_list' %}'
}
}), 'bottom'
);
layerSwitcher.addControl(
new ol.control.Button({
html: "Создать слой",
handleClick: function () {
window.location.href = '{% url 'create_layer' %}'
}
}), 'bottom');
layerSwitcher.addControl(
new ol.control.Button({
html: "Редактировать слои",
handleClick: function () {
window.location.href = '{% url 'layers_list' %}'
}
}), 'bottom'
);
map.addControl(layerSwitcher)
@ -801,6 +801,9 @@
data.forEach(equipment => {
if (GTOMarkers[equipment.id]) {
const marker = GTOMarkers[equipment.id];
updateMarkerProperties(marker, equipment)
const currentCoordinates = marker.getGeometry().getCoordinates();
const newCoordinates = ol.proj.fromLonLat([equipment.lon, equipment.lat]);
@ -820,6 +823,9 @@
data.forEach(worker => {
if (VlocationMarkers[worker.id]) {
const marker = VlocationMarkers[worker.id]
updateMarkerProperties(marker, worker)
const currentCoordinates = marker.getGeometry().getCoordinates();
const newCoordinates = ol.proj.fromLonLat([worker.lon, worker.lat]);
if (currentCoordinates[0] !== newCoordinates[0] || currentCoordinates[1] !== newCoordinates[1]) {
@ -887,6 +893,11 @@
await initializeMap();
})
function updateMarkerProperties(marker, properties) {
for (let property in properties) {
marker.set(property, properties[property])
}
}
</script>

View File

@ -165,7 +165,7 @@
}
// Обработка кликов по маркерам
map.on('click', function (evt) {
map.on('click', function (evt) {
// Получение feature по клику
const feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
return feature;
@ -358,6 +358,9 @@
workersTableBody.appendChild(tableRow)
if (VlocationMarkers[worker.id]) {
const marker = VlocationMarkers[worker.id];
updateMarkerProperties(marker, worker)
const currentCoordinates = marker.getGeometry().getCoordinates();
const newCoordinates = ol.proj.fromLonLat([worker.lon, worker.lat]);
@ -375,6 +378,12 @@
window.onload = initializeMap;
function updateMarkerProperties(marker, properties) {
for (let property in properties) {
marker.set(property, properties[property])
}
}
</script>