Стилизация каждого слоя в DXF
This commit is contained in:
parent
9903a3ebcb
commit
b99311fb70
@ -9,13 +9,14 @@
|
||||
<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;
|
||||
}
|
||||
.main-data-card {
|
||||
max-height: 320px;
|
||||
}
|
||||
|
||||
.style-card {
|
||||
max-height: 300px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
.file-upload-label {
|
||||
@ -373,24 +374,21 @@
|
||||
};
|
||||
|
||||
// Функция для обновления стиля слоя
|
||||
function updateLayerStyle() {
|
||||
function updateLayerStyle(event) {
|
||||
const form = document.getElementById("style-editor");
|
||||
const inputs = form.querySelectorAll("input");
|
||||
|
||||
const input = event.target
|
||||
// Обновляем стиль для всех фич в слое
|
||||
vectorSource.getFeatures().forEach((feature) => {
|
||||
const currentStyle = feature.get("style") || {};
|
||||
vectorSource.getFeatures()
|
||||
.filter((feature) => feature.get('layer') === input.dataset.layer)
|
||||
.forEach((feature) => {
|
||||
const currentStyle = feature.get("style") || {};
|
||||
const property = input.id.split('_')[0];
|
||||
currentStyle[property] = input.type === "number" ? parseFloat(input.value) : input.value;
|
||||
|
||||
inputs.forEach((input) => {
|
||||
const property = input.id;
|
||||
const value = input.type === "number" ? parseFloat(input.value) : input.value;
|
||||
currentStyle[property] = value;
|
||||
// Устанавливаем обновленный стиль
|
||||
feature.set("style", currentStyle);
|
||||
});
|
||||
|
||||
// Устанавливаем обновленный стиль
|
||||
feature.set("style", currentStyle);
|
||||
});
|
||||
|
||||
// Обновляем слой
|
||||
vectorLayer.changed();
|
||||
}
|
||||
@ -407,7 +405,7 @@
|
||||
}
|
||||
|
||||
// Функция для создания формы на основе свойств стиля
|
||||
function createStyleForm(feature, layerName = undefined) {
|
||||
function createStyleForm(feature, layerName = "0") {
|
||||
const style = feature.get("style") || DEFAULT_STYLE; // Используем стиль из фичи или по умолчанию
|
||||
const container = document.getElementById("style-editor-container");
|
||||
|
||||
@ -422,7 +420,7 @@
|
||||
const titleCol = document.createElement('div')
|
||||
titleCol.className = 'col-12'
|
||||
const titleH = document.createElement('h6')
|
||||
titleH.textContent = layerName ? `Слой: ${layerName}` : "Слой"
|
||||
titleH.textContent = layerName
|
||||
titleCol.appendChild(titleH)
|
||||
|
||||
const row = document.createElement("div");
|
||||
@ -443,7 +441,8 @@
|
||||
if (property === "stroke-width") {
|
||||
input = document.createElement("input");
|
||||
input.type = "number";
|
||||
input.id = property;
|
||||
input.id = layerName ? `${property}_${layerName}` : property;
|
||||
input.dataset.layer = layerName
|
||||
input.value = style[property] || DEFAULT_STYLE[property];
|
||||
input.className = "form-control";
|
||||
input.min = 1;
|
||||
@ -451,13 +450,15 @@
|
||||
} else if (property === "stroke-color") {
|
||||
input = document.createElement("input");
|
||||
input.type = "color";
|
||||
input.id = property;
|
||||
input.id = `${property}_${layerName}`
|
||||
input.dataset.layer = layerName
|
||||
input.value = rgbToHex(style[property]) || DEFAULT_STYLE[property];
|
||||
input.className = "form-control";
|
||||
} else if (property === "fill-color") {
|
||||
input = document.createElement("input");
|
||||
input.type = "color";
|
||||
input.id = property;
|
||||
input.id = `${property}_${layerName}`
|
||||
input.dataset.layer = layerName
|
||||
input.value = rgbToHex(style[property]) || DEFAULT_STYLE[property];
|
||||
input.className = "form-control";
|
||||
}
|
||||
@ -492,10 +493,9 @@
|
||||
}
|
||||
return
|
||||
}
|
||||
// Если фичи уже есть, создаем форму для первой фичи
|
||||
if (features.length > 0) {
|
||||
const firstFeature = features[0];
|
||||
createStyleForm(firstFeature);
|
||||
createStyleForm(firstFeature, firstFeature.get('layer'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user