Не работает изменение цвета

This commit is contained in:
zakhy 2025-03-21 08:31:41 +07:00
parent 941a721903
commit 9903a3ebcb

View File

@ -8,6 +8,15 @@
<link rel="stylesheet" href="{% static 'js/ol/ol-ext/ol-ext.min.css' %}?ver={% settings_value 'APP_VER' %}">
<link rel="stylesheet" href="{% static 'js/ol/ol-ext/ol-layer-theme.css' %}?ver={% settings_value 'APP_VER' %}">
<link rel="stylesheet" href="{% static 'css/main_page.css' %}?ver={% settings_value 'APP_VER' %}">
<style>
.main-data-card {
max-height: 320px;
}
.style-card {
max-height: 300px;
overflow-y: scroll;
}
</style>
<style>
.file-upload-label {
cursor: pointer;
@ -47,12 +56,12 @@
<form enctype="multipart/form-data" method="post" class="card-body">
<div class="row h-100">
<div class="col-md-4 col-sm-12">
<div class="card">
<div class="card p-0 main-data-card">
<div class="card-header">
<h3 class="card-title">Общие данные</h3>
</div>
<!-- form start -->
<div class="card-body">
<div class="card-body p-2">
<div class="form-group">
<label for="name">Наименование</label>
{{ form.name }}
@ -93,12 +102,12 @@
</div>
</div>
</div>
<div class="card" id="style-editor-card">
<div class="card p-0 style-card mb-0" id="style-editor-card">
<div class="card-header">
<h3 class="card-title">Стиль слоя</h3>
</div>
<!-- form start -->
<div id="style-editor-container" class="card-body"></div>
<div id="style-editor-container" class="card-body p-2"></div>
</div>
</div>
<div class="col-md-8 col-sm-12">
@ -123,9 +132,12 @@
<label for="modeChangeRadio1" class="custom-control-label">Режим
масштабирования</label>
</div>
<button id="exportGeoJSON" class="btn btn-info float-right d-none">
Экспортировать GeoJSON
</button>
{% if request.user.is_superuser %}
<button id="exportGeoJSON" class="btn btn-info float-right d-none">
Экспортировать GeoJSON
</button>
{% endif %}
</div>
</div>
</div>
@ -294,6 +306,7 @@
let vectorSource = {}
let vectorLayer = {}
let group = {}
const DXFLayersList = []
layers = [
new ol.layer.Tile({
source: new ol.source.OSM()
@ -394,13 +407,10 @@
}
// Функция для создания формы на основе свойств стиля
function createStyleForm(feature) {
function createStyleForm(feature, layerName = undefined) {
const style = feature.get("style") || DEFAULT_STYLE; // Используем стиль из фичи или по умолчанию
const container = document.getElementById("style-editor-container");
// Очищаем контейнер
container.innerHTML = "";
// Создаем форму
const form = document.createElement("form");
form.id = "style-editor";
@ -408,8 +418,16 @@
// Список свойств стиля для отображения в форме
const styleProperties = Object.keys(DEFAULT_STYLE);
// Заголовок
const titleCol = document.createElement('div')
titleCol.className = 'col-12'
const titleH = document.createElement('h6')
titleH.textContent = layerName ? `Слой: ${layerName}` : "Слой"
titleCol.appendChild(titleH)
const row = document.createElement("div");
row.className = "row";
row.appendChild(titleCol)
// Динамически создаем поля для каждого свойства стиля
styleProperties.forEach((property) => {
@ -459,13 +477,24 @@
}
// Функция для инициализации формы при загрузке
function initializeForm() {
function initializeForm(dxfLayers = undefined) {
const container = document.getElementById("style-editor-container");
// Очищаем контейнер
container.innerHTML = "";
const features = vectorSource.getFeatures();
if (dxfLayers) {
for (let layer in dxfLayers) {
const byLayer = features.filter((feature) => feature.get('layer') === layer)
const firstFeatureInLayer = byLayer[0]
if (firstFeatureInLayer !== undefined) {
createStyleForm(firstFeatureInLayer, layer);
}
}
return
}
// Если фичи уже есть, создаем форму для первой фичи
if (features.length > 0) {
const firstFeature = features[0];
const style = firstFeature.get("style") || DEFAULT_STYLE; // Используем стиль из фичи или по умолчанию
createStyleForm(firstFeature);
}
}
@ -482,7 +511,11 @@
const dxf = parser.parseSync(e.target.result);
const geojson = dxfToGeoJSON(dxf);
clearVectorLayer();
addGeoJSONToMap(geojson);
if (dxf.tables.layer) {
addGeoJSONToMap(geojson, dxf.tables.layer.layers);
} else {
addGeoJSONToMap(geojson);
}
} catch (error) {
console.error('DXF Parsing Error:', error);
}
@ -549,20 +582,16 @@
console.log(dxf);
const normalizedEntities = normalizeCoordinates(dxf.entities, dxf.header);
let prevLayer = null
let manyLayers = false
const features = normalizedEntities.map(entity => {
let currentLayer = entity.layer
if (prevLayer && (currentLayer !== prevLayer) && manyLayers === false) {
manyLayers = true
document.getElementById("style-editor-card").style.display = 'none'
}
prevLayer = currentLayer
DXFLayersList.push(entity.layer)
if (entity.type === 'LINE') {
return createFeature('LineString',
entity.normalizedCoords,
{
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
style: {
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1,
},
"layer": entity.layer
});
} else if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
const coords = entity.normalizedCoords;
@ -570,8 +599,9 @@
entity.closed ? [coords] : coords,
{
style: {
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1
}
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1,
},
"layer": entity.layer
});
} else if (entity.type === 'CIRCLE') {
return createFeature('Point',
@ -579,31 +609,40 @@
{
style: {
"circle-radius": entity.radius,
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1
}
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1,
},
"layer": entity.layer
});
} else if (entity.type === 'ARC') {
return createFeature('LineString',
entity.normalizedCoords,
{
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
style: {
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1,
},
"layer": entity.layer
});
} else if (entity.type === 'POINT') {
return createFeature('Point',
entity.normalizedCoords[0],
{
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
style: {
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1,
},
"layer": entity.layer
});
} else if (entity.type === 'SPLINE') {
return createFeature('LineString',
entity.normalizedCoords,
{
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
style: {
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1,
},
"layer": entity.layer
});
}
return null;
}).filter(f => f !== null);
console.log(features)
return {type: 'FeatureCollection', features: features};
}
@ -664,7 +703,7 @@
}
}
function addGeoJSONToMap(geojson) {
function addGeoJSONToMap(geojson, dxfLayers = undefined) {
if (vectorLayer) {
map.removeLayer(vectorLayer);
}
@ -674,13 +713,11 @@
})
});
// Подписываемся на событие добавления фичи
vectorSource.on("addfeature", (event) => {
createStyleForm(event.feature);
});
// Инициализируем форму стилем из первой фичи
initializeForm();
initializeForm(dxfLayers);
vectorLayer = new ol.layer.Vector({
source: vectorSource,