Merge branch 'dev'
This commit is contained in:
commit
42cc7c28d9
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.env
|
||||
test_data
|
||||
.idea
|
||||
docker-compose.yml
|
||||
media
|
||||
log
|
||||
@ -8,6 +8,10 @@
|
||||
<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' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/create_layer.css' %}?ver={% settings_value 'APP_VER' %}">
|
||||
<style>
|
||||
|
||||
</style>
|
||||
<style>
|
||||
.file-upload-label {
|
||||
cursor: pointer;
|
||||
@ -42,67 +46,97 @@
|
||||
|
||||
<section class="content text-sm p-1">
|
||||
<div class="card" style="height: 90%;">
|
||||
|
||||
<!-- /.card-header -->
|
||||
<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-header">
|
||||
<h3 class="card-title">Общие данные</h3>
|
||||
<div class="col-md-5 col-sm-12">
|
||||
<div class="card card-primary card-outline card-tabs h-100">
|
||||
<div class="card-header p-0 pt-1 border-bottom-0">
|
||||
<ul class="nav nav-tabs" id="custom-tabs-three-tab" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="common-properties-tab" data-toggle="pill"
|
||||
href="#common-properties" role="tab"
|
||||
aria-controls="common-properties" aria-selected="true">
|
||||
Общие данные
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="style-properties-tab" data-toggle="pill"
|
||||
href="#style-properties" role="tab"
|
||||
aria-controls="style-properties" aria-selected="false">
|
||||
Внешний вид
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- form start -->
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label for="name">Наименование</label>
|
||||
{{ form.name }}
|
||||
</div>
|
||||
{% if not layer %}
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<label for="XOffsetField">Xпопр:</label>
|
||||
<input type="number" name="XOffset" id="XOffsetField"
|
||||
class="form-control"
|
||||
min="0" value="0">
|
||||
<div class="tab-content" id="custom-tabs-three-tabContent">
|
||||
<div class="tab-pane fade show active" id="common-properties" role="tabpanel"
|
||||
aria-labelledby="common-properties-tab">
|
||||
<div class="form-group">
|
||||
<label for="name">Наименование</label>
|
||||
{{ form.name }}
|
||||
</div>
|
||||
{% if not layer %}
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<label for="XOffsetField">Xпопр:</label>
|
||||
<input type="number" name="XOffset" id="XOffsetField"
|
||||
class="form-control"
|
||||
min="0" value="0">
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label for="YOffsetField">Yпопр:</label>
|
||||
<input type="number" name="YOffset" id="YOffsetField"
|
||||
class="form-control"
|
||||
min="0" value="0">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label for="YOffsetField">Yпопр:</label>
|
||||
<input type="number" name="YOffset" id="YOffsetField"
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="exampleInputFile">Файл</label>
|
||||
<div class="input-group d-flex flex-column">
|
||||
<label for="id_layer_file_input" class="file-upload-label">Выберите файл
|
||||
с
|
||||
расширением
|
||||
.kml, .json, .geojson, .dxf</label>
|
||||
<span>Сейчас выбран: <span id="file_path"></span></span>
|
||||
<input type="file" name="layer_file_input"
|
||||
class="form-control"
|
||||
min="0" value="0">
|
||||
autofocus=""
|
||||
id="id_layer_file_input"
|
||||
accept=".kml, .json, .geojson, .dxf">
|
||||
{{ form.file.as_hidden }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="exampleInputFile">Файл</label>
|
||||
<div class="input-group d-flex flex-column">
|
||||
<label for="id_layer_file_input" class="file-upload-label">Выберите файл с
|
||||
расширением
|
||||
.kml, .json, .geojson, .dxf</label>
|
||||
<span>Сейчас выбран: <span id="file_path"
|
||||
style="cursor: auto; color: var(--primary);"></span></span>
|
||||
<input type="file" name="layer_file_input"
|
||||
class="form-control"
|
||||
autofocus=""
|
||||
id="id_layer_file_input" style="visibility:hidden; display: none"
|
||||
accept=".kml, .json, .geojson, .dxf">
|
||||
{{ form.file.as_hidden }}
|
||||
<div class="tab-pane fade" id="style-properties" role="tabpanel"
|
||||
aria-labelledby="style-properties-tab">
|
||||
<div id="style-editor-container">
|
||||
<div class="row">
|
||||
<div class="col-5 col-sm-3">
|
||||
<div id="vert-tabs-tab"
|
||||
role="tablist" aria-orientation="vertical">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-7 col-sm-9">
|
||||
<div class="tab-content" id="style-tabContent">
|
||||
<h6
|
||||
>Для стилизации слоя - загрузите файл!</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" 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>
|
||||
<!-- /.card -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8 col-sm-12">
|
||||
<div class="card h-100">
|
||||
<div class="col-md-7 col-sm-12">
|
||||
<div class="card card-primary card-outline h-100">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Предпросмотр</h3>
|
||||
</div>
|
||||
@ -123,9 +157,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 type="button" id="exportGeoJSON" class="btn btn-info float-right">
|
||||
Экспортировать GeoJSON
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -167,6 +204,22 @@
|
||||
});
|
||||
}
|
||||
|
||||
const degreesToRadians = (degrees) => (degrees * Math.PI) / 180;
|
||||
|
||||
function decodeDXFText(text) {
|
||||
// Заменяем Unicode коды на символы
|
||||
text = text.replace(/\\U\+([\dA-F]{4})/gi, (_, code) =>
|
||||
String.fromCharCode(parseInt(code, 16))
|
||||
);
|
||||
|
||||
// Убираем символы \pi и заменяем \P на перенос строки
|
||||
text = text.replace(/\\pi\d+\.\d+/g, ''); // Убираем управляющие коды \pi
|
||||
text = text.replace(/\\P/g, '\n'); // Заменяем \P на перенос строки
|
||||
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
let previousChoice;
|
||||
let isDrawing = false; // Флаг для отслеживания состояния рисования
|
||||
|
||||
@ -294,6 +347,7 @@
|
||||
let vectorSource = {}
|
||||
let vectorLayer = {}
|
||||
let group = {}
|
||||
const DXFLayersList = []
|
||||
layers = [
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
@ -330,6 +384,71 @@
|
||||
}
|
||||
}
|
||||
|
||||
const createStyleFromFeature = function (feature, resolution) {
|
||||
// Получаем стили из feature
|
||||
const styleProperties = feature.get("style");
|
||||
|
||||
// Если стили заданы, создаем стиль на их основе
|
||||
if (styleProperties) {
|
||||
const stroke = styleProperties["stroke-color"] || styleProperties["stroke-width"]
|
||||
? new ol.style.Stroke({
|
||||
color: styleProperties["stroke-color"] || "blue",
|
||||
width: styleProperties["stroke-width"] || 2,
|
||||
lineDash: styleProperties['stroke-line-dash']
|
||||
})
|
||||
: null;
|
||||
|
||||
const fill = styleProperties["fill-color"] ? new ol.style.Fill({
|
||||
color: styleProperties["fill-color"]
|
||||
}) : null;
|
||||
|
||||
const zoom = map.getView().getZoom();
|
||||
const text = zoom > 12
|
||||
? new ol.style.Text({
|
||||
text: styleProperties["text-value"],
|
||||
font: styleProperties["text-font"] || "14px Calibri,sans-serif",
|
||||
fill: new ol.style.Fill({
|
||||
color: styleProperties["text-color"] || styleProperties["stroke-color"] || "white"
|
||||
}),
|
||||
scale: 1,
|
||||
offsetX: styleProperties["text-offset-x"] || 0,
|
||||
offsetY: styleProperties["text-offset-y"] || 0,
|
||||
textAlign: styleProperties["text-align"] || "center",
|
||||
textBaseline: styleProperties["text-baseline"] || "middle",
|
||||
rotation: styleProperties['text-rotation'] || 0
|
||||
})
|
||||
: null;
|
||||
|
||||
return new ol.style.Style({
|
||||
stroke: stroke,
|
||||
fill: fill,
|
||||
text: text
|
||||
});
|
||||
}
|
||||
// Дефолтный стиль
|
||||
return new ol.style.Style({
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(255, 0, 0, 0.5)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'blue',
|
||||
width: 2
|
||||
}),
|
||||
text: new ol.style.Text({
|
||||
// text: 'Hello, OpenLayers!',
|
||||
font: '14px Calibri,sans-serif',
|
||||
fill: new ol.style.Fill({
|
||||
color: 'white'
|
||||
}),
|
||||
offsetX: 0,
|
||||
offsetY: -20,
|
||||
textAlign: 'center',
|
||||
textBaseline: 'middle'
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const map = new ol.Map({
|
||||
target: 'map',
|
||||
layers: layers,
|
||||
@ -360,24 +479,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();
|
||||
}
|
||||
@ -394,22 +510,40 @@
|
||||
}
|
||||
|
||||
// Функция для создания формы на основе свойств стиля
|
||||
function createStyleForm(feature) {
|
||||
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";
|
||||
|
||||
function createStyleForm(feature, layerName = "0") {
|
||||
// Список свойств стиля для отображения в форме
|
||||
const styleProperties = Object.keys(DEFAULT_STYLE);
|
||||
const style = feature.get("style") || DEFAULT_STYLE; // Используем стиль из фичи или по умолчанию
|
||||
|
||||
const row = document.createElement("div");
|
||||
row.className = "row";
|
||||
const container = document.getElementById("style-editor-container");
|
||||
|
||||
const tabContent = document.getElementById('style-tabContent')
|
||||
const tabList = document.getElementById('vert-tabs-tab')
|
||||
|
||||
// Элемент списка слева
|
||||
const tabLink = document.createElement('a')
|
||||
tabLink.className = 'nav-link'
|
||||
tabLink.id = `layer_${layerName}-tab`
|
||||
tabLink.href = `#layer_${layerName}`
|
||||
tabLink.role = 'tab'
|
||||
tabLink.setAttribute('data-toggle', "pill")
|
||||
tabLink.setAttribute('aria-controls', `layer_${layerName}`)
|
||||
tabLink.ariaSelected = 'false'
|
||||
tabLink.textContent = `Слой ${layerName}`
|
||||
|
||||
tabList.appendChild(tabLink)
|
||||
|
||||
|
||||
// Заголовок
|
||||
|
||||
const tabPane = document.createElement('div')
|
||||
tabPane.className = 'tab-pane text-left fade'
|
||||
tabPane.id = `layer_${layerName}`
|
||||
tabPane.role = 'tabpanel'
|
||||
tabPane.ariaLabelledBy = `layer_${layerName}-tab`
|
||||
|
||||
const row = document.createElement('div')
|
||||
row.className = 'row'
|
||||
|
||||
// Динамически создаем поля для каждого свойства стиля
|
||||
styleProperties.forEach((property) => {
|
||||
@ -425,7 +559,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;
|
||||
@ -433,13 +568,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";
|
||||
}
|
||||
@ -448,25 +585,35 @@
|
||||
col.appendChild(input);
|
||||
row.appendChild(col);
|
||||
});
|
||||
form.appendChild(row)
|
||||
tabPane.appendChild(row)
|
||||
tabContent.appendChild(tabPane)
|
||||
// Добавляем форму в контейнер
|
||||
container.appendChild(form);
|
||||
|
||||
// Добавляем обработчики событий для полей ввода
|
||||
form.querySelectorAll("input").forEach((input) => {
|
||||
tabContent.querySelectorAll("input").forEach((input) => {
|
||||
input.addEventListener("input", updateLayerStyle);
|
||||
});
|
||||
}
|
||||
|
||||
// Функция для инициализации формы при загрузке
|
||||
function initializeForm() {
|
||||
const features = vectorSource.getFeatures();
|
||||
function initializeForm(dxfLayers = undefined) {
|
||||
document.getElementById("style-tabContent").innerHTML = "";
|
||||
document.getElementById("vert-tabs-tab").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);
|
||||
createStyleForm(firstFeature, firstFeature.get('layer'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -482,7 +629,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);
|
||||
}
|
||||
@ -509,6 +660,174 @@
|
||||
}
|
||||
});
|
||||
|
||||
function processBlockInsert(entity, dxf) {
|
||||
const blockName = entity.name;
|
||||
const block = dxf.blocks[blockName];
|
||||
|
||||
if (!block) {
|
||||
console.warn(`Block ${blockName} not found`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const features = [];
|
||||
const x = entity.position.x;
|
||||
const y = entity.position.y;
|
||||
const rotation = entity.rotation || 0;
|
||||
const scale = entity.scale || {x: 1, y: 1, z: 1};
|
||||
|
||||
// Обрабатываем каждую сущность в блоке
|
||||
block.entities.forEach(blockEntity => {
|
||||
// Копируем сущность, чтобы не модифицировать оригинал
|
||||
const entityCopy = JSON.parse(JSON.stringify(blockEntity));
|
||||
let feature = null;
|
||||
let coords = [];
|
||||
|
||||
// Устанавливаем слой из INSERT, если он не наследуется
|
||||
if (!entityCopy.layer || entityCopy.layer === '0') {
|
||||
entityCopy.layer = entity.layer;
|
||||
}
|
||||
|
||||
// Обрабатываем каждый тип сущности и сразу создаем фичу
|
||||
if (entityCopy.type === 'CIRCLE') {
|
||||
// Применяем трансформации
|
||||
entityCopy.radius *= scale.x;
|
||||
const centerX = x + (entityCopy.center.x * scale.x);
|
||||
const centerY = y + (entityCopy.center.y * scale.y);
|
||||
|
||||
// Создаем фичу
|
||||
const normalizedCoords = convertToLonLat([centerX, centerY]);
|
||||
feature = createFeature('Point', normalizedCoords, {
|
||||
style: getStyleFromDXFEntity(entityCopy, dxf.tables.lineType?.lineTypes),
|
||||
layer: entityCopy.layer
|
||||
});
|
||||
} else if (entityCopy.type === 'LINE') {
|
||||
// Применяем трансформации и создаем координаты
|
||||
coords = entityCopy.vertices.map(vertex => {
|
||||
let vx = vertex.x * scale.x;
|
||||
let vy = vertex.y * scale.y;
|
||||
|
||||
if (rotation !== 0) {
|
||||
const angle = (rotation * Math.PI) / 180;
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
vx = vx * cos - vy * sin;
|
||||
vy = vx * sin + vy * cos;
|
||||
}
|
||||
|
||||
return [x + vx, y + vy];
|
||||
});
|
||||
|
||||
// Создаем фичу
|
||||
const normalizedCoords = coords.map(coord => convertToLonLat(coord));
|
||||
feature = createFeature('LineString', normalizedCoords, {
|
||||
style: getStyleFromDXFEntity(entityCopy, dxf.tables.lineType?.lineTypes),
|
||||
layer: entityCopy.layer
|
||||
});
|
||||
} else if (entityCopy.type === 'LWPOLYLINE' || entityCopy.type === 'POLYLINE') {
|
||||
// Применяем трансформации и создаем координаты
|
||||
coords = entityCopy.vertices.map(vertex => {
|
||||
let vx = vertex.x * scale.x;
|
||||
let vy = vertex.y * scale.y;
|
||||
|
||||
if (rotation !== 0) {
|
||||
const angle = (rotation * Math.PI) / 180;
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
vx = vx * cos - vy * sin;
|
||||
vy = vx * sin + vy * cos;
|
||||
}
|
||||
|
||||
return [x + vx, y + vy];
|
||||
});
|
||||
|
||||
// Создаем фичу
|
||||
const normalizedCoords = coords.map(coord => convertToLonLat(coord));
|
||||
feature = createFeature(
|
||||
entityCopy.closed ? 'Polygon' : 'LineString',
|
||||
entityCopy.closed ? [normalizedCoords] : normalizedCoords,
|
||||
{
|
||||
style: getStyleFromDXFEntity(entityCopy, dxf.tables.lineType?.lineTypes),
|
||||
layer: entityCopy.layer
|
||||
}
|
||||
);
|
||||
} else if (entityCopy.type === 'ARC') {
|
||||
// Применяем трансформации
|
||||
const centerX = x + (entityCopy.center.x * scale.x);
|
||||
const centerY = y + (entityCopy.center.y * scale.y);
|
||||
entityCopy.radius *= scale.x;
|
||||
entityCopy.center = {x: centerX, y: centerY};
|
||||
|
||||
if (rotation !== 0) {
|
||||
entityCopy.startAngle += rotation;
|
||||
entityCopy.endAngle += rotation;
|
||||
}
|
||||
|
||||
// Создаем фичу
|
||||
const arcCoords = arcToLine(entityCopy);
|
||||
const normalizedCoords = arcCoords.map(coord => convertToLonLat(coord));
|
||||
feature = createFeature('LineString', normalizedCoords, {
|
||||
style: getStyleFromDXFEntity(entityCopy, dxf.tables.lineType?.lineTypes),
|
||||
layer: entityCopy.layer
|
||||
});
|
||||
} else if (entityCopy.type === 'POINT') {
|
||||
// Применяем трансформации
|
||||
const pointX = x + (entityCopy.position.x * scale.x);
|
||||
const pointY = y + (entityCopy.position.y * scale.y);
|
||||
|
||||
// Создаем фичу
|
||||
const normalizedCoords = convertToLonLat([pointX, pointY]);
|
||||
feature = createFeature('Point', normalizedCoords, {
|
||||
style: getStyleFromDXFEntity(entityCopy, dxf.tables.lineType?.lineTypes),
|
||||
layer: entityCopy.layer
|
||||
});
|
||||
} else if (entityCopy.type === 'SPLINE') {
|
||||
// Применяем трансформации и создаем координаты
|
||||
coords = entityCopy.controlPoints.map(point => {
|
||||
let px = point.x * scale.x;
|
||||
let py = point.y * scale.y;
|
||||
|
||||
if (rotation !== 0) {
|
||||
const angle = (rotation * Math.PI) / 180;
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
px = px * cos - py * sin;
|
||||
py = px * sin + py * cos;
|
||||
}
|
||||
|
||||
return [x + px, y + py];
|
||||
});
|
||||
|
||||
// Создаем фичу
|
||||
const normalizedCoords = coords.map(coord => convertToLonLat(coord));
|
||||
feature = createFeature('LineString', normalizedCoords, {
|
||||
style: getStyleFromDXFEntity(entityCopy, dxf.tables.lineType?.lineTypes),
|
||||
layer: entityCopy.layer
|
||||
});
|
||||
} else if (entityCopy.type === 'TEXT' || entityCopy.type === 'MTEXT') {
|
||||
// Применяем трансформации
|
||||
const textX = x + (entityCopy.position.x * scale.x);
|
||||
const textY = y + (entityCopy.position.y * scale.y);
|
||||
|
||||
if (rotation !== 0) {
|
||||
entityCopy.rotation = (entityCopy.rotation || 0) + rotation;
|
||||
}
|
||||
|
||||
// Создаем фичу
|
||||
const normalizedCoords = convertToLonLat([textX, textY]);
|
||||
feature = createFeature('Point', normalizedCoords, {
|
||||
style: getStyleFromDXFEntity(entityCopy),
|
||||
layer: entityCopy.layer
|
||||
});
|
||||
}
|
||||
|
||||
if (feature) {
|
||||
features.push(feature);
|
||||
}
|
||||
});
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
function getCoordinates(entity) {
|
||||
if (entity.type === 'LINE') {
|
||||
return [[entity.vertices[0].x, entity.vertices[0].y], [entity.vertices[1].x, entity.vertices[1].y]];
|
||||
@ -528,15 +847,18 @@
|
||||
if (entity.type === 'SPLINE') {
|
||||
return entity.controlPoints.map(v => [v.x, v.y]);
|
||||
}
|
||||
if (entity.type === 'TEXT') {
|
||||
return [[entity.startPoint.x, entity.startPoint.y]]
|
||||
}
|
||||
if (entity.type === 'MTEXT') {
|
||||
return [[entity.position.x, entity.position.y]]
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function normalizeCoordinates(entities, dxfHeader) {
|
||||
let minX = dxfHeader.$EXTMIN.x;
|
||||
let minY = dxfHeader.$EXTMIN.y;
|
||||
return entities.map(entity => {
|
||||
const coords = getCoordinates(entity).map(([x, y]) => {
|
||||
// Возможно отображение от нулевых координат. Для этого нужно отнимать minX и minY
|
||||
const XOffset = parseInt(document.getElementById("XOffsetField").value)
|
||||
const YOffset = parseInt(document.getElementById("YOffsetField").value)
|
||||
return convertToLonLat([x, y], XOffset, YOffset);
|
||||
@ -545,65 +867,122 @@
|
||||
});
|
||||
}
|
||||
|
||||
function getStyleFromDXFEntity(entity, lineTypes = undefined) {
|
||||
const figureStyle = {
|
||||
"stroke-color": getColorByColorTable(entity.colorIndex),
|
||||
"stroke-width": 1,
|
||||
}
|
||||
if (entity.text && !entity.text.includes('<27>')) {
|
||||
figureStyle["text-value"] = entity.type === "TEXT" ? entity.text : decodeDXFText(entity.text)
|
||||
figureStyle["text-rotation"] = -degreesToRadians(entity.rotation)
|
||||
}
|
||||
if (lineTypes && entity.lineType) {
|
||||
if (lineTypes[entity.lineType] && (entity.lineType !== "Continuous" && entity.lineType !== 'HIDDEN')) {
|
||||
figureStyle["stroke-line-dash"] = lineTypes[entity.lineType].pattern.map(num => Math.abs(num) * 10)
|
||||
}
|
||||
}
|
||||
return figureStyle
|
||||
}
|
||||
|
||||
function dxfToGeoJSON(dxf) {
|
||||
console.log(dxf);
|
||||
const normalizedEntities = normalizeCoordinates(dxf.entities, dxf.header);
|
||||
let features = [];
|
||||
|
||||
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
|
||||
if (entity.type === 'LINE') {
|
||||
return createFeature('LineString',
|
||||
entity.normalizedCoords,
|
||||
{
|
||||
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
|
||||
});
|
||||
} else if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
|
||||
const coords = entity.normalizedCoords;
|
||||
return createFeature(entity.closed ? 'Polygon' : 'LineString',
|
||||
entity.closed ? [coords] : coords,
|
||||
{
|
||||
style: {
|
||||
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1
|
||||
normalizedEntities.forEach(entity => {
|
||||
DXFLayersList.push(entity.layer);
|
||||
|
||||
if (entity.type === 'INSERT') {
|
||||
// Обрабатываем блоки
|
||||
const blockFeatures = processBlockInsert(entity, dxf);
|
||||
console.log(blockFeatures);
|
||||
if (blockFeatures && blockFeatures.length > 0) {
|
||||
features.push(...blockFeatures);
|
||||
}
|
||||
} else {
|
||||
// Обрабатываем обычные сущности
|
||||
let feature = null;
|
||||
|
||||
if (entity.type === 'LINE') {
|
||||
feature = createFeature('LineString',
|
||||
entity.normalizedCoords,
|
||||
{
|
||||
style: {
|
||||
"stroke-color": getColorByColorTable(entity.colorIndex),
|
||||
"stroke-width": 1,
|
||||
},
|
||||
"layer": entity.layer
|
||||
});
|
||||
} else if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
|
||||
const coords = entity.normalizedCoords;
|
||||
// Для замкнутых полилиний добавляем первую точку в конец
|
||||
if (entity.shape && coords.length > 0) {
|
||||
coords.push(coords[0]); // Замыкаем полигон
|
||||
}
|
||||
console.log(entity)
|
||||
feature = createFeature(
|
||||
entity.shape ? 'Polygon' : 'LineString',
|
||||
entity.shape ? [coords] : coords,
|
||||
{
|
||||
style: {
|
||||
...getStyleFromDXFEntity(entity, dxf.tables.lineType?.lineTypes),
|
||||
},
|
||||
"layer": entity.layer
|
||||
}
|
||||
});
|
||||
} else if (entity.type === 'CIRCLE') {
|
||||
return createFeature('Point',
|
||||
entity.normalizedCoords[0],
|
||||
{
|
||||
style: {
|
||||
"circle-radius": entity.radius,
|
||||
"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1
|
||||
}
|
||||
});
|
||||
} else if (entity.type === 'ARC') {
|
||||
return createFeature('LineString',
|
||||
entity.normalizedCoords,
|
||||
{
|
||||
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
|
||||
});
|
||||
} else if (entity.type === 'POINT') {
|
||||
return createFeature('Point',
|
||||
entity.normalizedCoords[0],
|
||||
{
|
||||
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
|
||||
});
|
||||
} else if (entity.type === 'SPLINE') {
|
||||
return createFeature('LineString',
|
||||
entity.normalizedCoords,
|
||||
{
|
||||
style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1}
|
||||
});
|
||||
);
|
||||
} else if (entity.type === 'TEXT' || entity.type === 'MTEXT') {
|
||||
feature = createFeature('Point',
|
||||
entity.normalizedCoords[0],
|
||||
{
|
||||
style: {
|
||||
...getStyleFromDXFEntity(entity)
|
||||
},
|
||||
"layer": entity.layer
|
||||
});
|
||||
} else if (entity.type === 'CIRCLE') {
|
||||
feature = createFeature('Point',
|
||||
entity.normalizedCoords[0],
|
||||
{
|
||||
style: {
|
||||
...getStyleFromDXFEntity(entity, dxf.tables.lineType?.lineTypes)
|
||||
},
|
||||
"layer": entity.layer
|
||||
});
|
||||
} else if (entity.type === 'ARC') {
|
||||
feature = createFeature('LineString',
|
||||
entity.normalizedCoords,
|
||||
{
|
||||
style: {
|
||||
...getStyleFromDXFEntity(entity, dxf.tables.lineType?.lineTypes)
|
||||
},
|
||||
"layer": entity.layer
|
||||
});
|
||||
} else if (entity.type === 'POINT') {
|
||||
feature = createFeature('Point',
|
||||
entity.normalizedCoords[0],
|
||||
{
|
||||
style: {
|
||||
...getStyleFromDXFEntity(entity, dxf.tables.lineType?.lineTypes)
|
||||
},
|
||||
"layer": entity.layer
|
||||
});
|
||||
} else if (entity.type === 'SPLINE') {
|
||||
feature = createFeature('LineString',
|
||||
entity.normalizedCoords,
|
||||
{
|
||||
style: {
|
||||
...getStyleFromDXFEntity(entity, dxf.tables.lineType?.lineTypes)
|
||||
},
|
||||
"layer": entity.layer
|
||||
});
|
||||
}
|
||||
|
||||
if (feature) {
|
||||
features.push(feature);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}).filter(f => f !== null);
|
||||
console.log(features)
|
||||
});
|
||||
|
||||
return {type: 'FeatureCollection', features: features};
|
||||
}
|
||||
|
||||
@ -636,10 +1015,14 @@
|
||||
if (vectorLayer) {
|
||||
map.removeLayer(vectorLayer);
|
||||
}
|
||||
const kmlFeatures = new ol.format.KML({extractStyles: false}).readFeatures(kml, {
|
||||
featureProjection: 'EPSG:3857',
|
||||
})
|
||||
kmlFeatures.forEach(feature => {
|
||||
feature.set('layer', 'kml')
|
||||
})
|
||||
vectorSource = new ol.source.Vector({
|
||||
features: new ol.format.KML({extractStyles: false}).readFeatures(kml, {
|
||||
featureProjection: 'EPSG:3857',
|
||||
})
|
||||
features: kmlFeatures
|
||||
});
|
||||
// Подписываемся на событие добавления фичи
|
||||
vectorSource.on("addfeature", (event) => {
|
||||
@ -664,23 +1047,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
function addGeoJSONToMap(geojson) {
|
||||
function addGeoJSONToMap(geojson, dxfLayers = undefined) {
|
||||
if (vectorLayer) {
|
||||
map.removeLayer(vectorLayer);
|
||||
}
|
||||
const geoJSONFeatures = new ol.format.GeoJSON().readFeatures(geojson, {
|
||||
featureProjection: 'EPSG:3857'
|
||||
})
|
||||
geoJSONFeatures.forEach(feature => {
|
||||
if (!feature.get('layer')) {
|
||||
feature.set('layer', 'geojson')
|
||||
}
|
||||
})
|
||||
vectorSource = new ol.source.Vector({
|
||||
features: new ol.format.GeoJSON().readFeatures(geojson, {
|
||||
featureProjection: 'EPSG:3857'
|
||||
})
|
||||
features: geoJSONFeatures
|
||||
});
|
||||
|
||||
// Подписываемся на событие добавления фичи
|
||||
vectorSource.on("addfeature", (event) => {
|
||||
createStyleForm(event.feature);
|
||||
});
|
||||
|
||||
// Инициализируем форму стилем из первой фичи
|
||||
initializeForm();
|
||||
initializeForm(dxfLayers);
|
||||
|
||||
vectorLayer = new ol.layer.Vector({
|
||||
source: vectorSource,
|
||||
|
||||
@ -166,6 +166,70 @@
|
||||
return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
const createStyleFromFeature = function (feature, resolution) {
|
||||
// Получаем стили из feature
|
||||
const styleProperties = feature.get("style");
|
||||
|
||||
// Если стили заданы, создаем стиль на их основе
|
||||
if (styleProperties) {
|
||||
const stroke = styleProperties["stroke-color"] || styleProperties["stroke-width"]
|
||||
? new ol.style.Stroke({
|
||||
color: styleProperties["stroke-color"] || "blue",
|
||||
width: styleProperties["stroke-width"] || 2,
|
||||
lineDash: styleProperties['stroke-line-dash']
|
||||
})
|
||||
: null;
|
||||
|
||||
const fill = styleProperties["fill-color"] ? new ol.style.Fill({
|
||||
color: styleProperties["fill-color"]
|
||||
}) : null;
|
||||
|
||||
const zoom = map.getView().getZoom();
|
||||
const text = zoom > 12
|
||||
? new ol.style.Text({
|
||||
text: styleProperties["text-value"],
|
||||
font: styleProperties["text-font"] || "14px Calibri,sans-serif",
|
||||
fill: new ol.style.Fill({
|
||||
color: styleProperties["text-color"] || styleProperties["stroke-color"] || "white"
|
||||
}),
|
||||
scale: 1,
|
||||
offsetX: styleProperties["text-offset-x"] || 0,
|
||||
offsetY: styleProperties["text-offset-y"] || 0,
|
||||
textAlign: styleProperties["text-align"] || "center",
|
||||
textBaseline: styleProperties["text-baseline"] || "middle",
|
||||
rotation: styleProperties['text-rotation'] || 0
|
||||
})
|
||||
: null;
|
||||
|
||||
return new ol.style.Style({
|
||||
stroke: stroke,
|
||||
fill: fill,
|
||||
text: text
|
||||
});
|
||||
}
|
||||
// Дефолтный стиль
|
||||
return new ol.style.Style({
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(255, 0, 0, 0.5)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'blue',
|
||||
width: 2
|
||||
}),
|
||||
text: new ol.style.Text({
|
||||
// text: 'Hello, OpenLayers!',
|
||||
font: '14px Calibri,sans-serif',
|
||||
fill: new ol.style.Fill({
|
||||
color: 'white'
|
||||
}),
|
||||
offsetX: 0,
|
||||
offsetY: -20,
|
||||
textAlign: 'center',
|
||||
textBaseline: 'middle'
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
// Инициализация слайдера
|
||||
function initTimeSlider() {
|
||||
const dayMilliseconds = 24 * 60 * 60 * 1000;
|
||||
|
||||
14
static/css/create_layer.css
Normal file
14
static/css/create_layer.css
Normal file
@ -0,0 +1,14 @@
|
||||
#vert-tabs-tab {
|
||||
overflow-y: scroll;
|
||||
max-height: 500px;
|
||||
}
|
||||
|
||||
#file_path {
|
||||
cursor: auto;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
#id_layer_file_input {
|
||||
visibility: hidden;
|
||||
display: none
|
||||
}
|
||||
@ -119,64 +119,3 @@ function polygonBrownStyleFunction(feature, resolution) {
|
||||
text: createGTOZoneNameTextStyle(feature, resolution)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const createStyleFromFeature = function (feature, resolution) {
|
||||
// Получаем стили из feature
|
||||
const styleProperties = feature.get("style");
|
||||
|
||||
// Если стили заданы, создаем стиль на их основе
|
||||
if (styleProperties) {
|
||||
const stroke = styleProperties["stroke-color"] || styleProperties["stroke-width"]
|
||||
? new ol.style.Stroke({
|
||||
color: styleProperties["stroke-color"] || "blue",
|
||||
width: styleProperties["stroke-width"] || 2
|
||||
})
|
||||
: null;
|
||||
|
||||
const fill = styleProperties["fill-color"] ? new ol.style.Fill({
|
||||
color: styleProperties["fill-color"]
|
||||
}) : null;
|
||||
|
||||
const text = styleProperties["text-value"]
|
||||
? new ol.style.Text({
|
||||
text: styleProperties["text-value"],
|
||||
font: styleProperties["text-font"] || "14px Calibri,sans-serif",
|
||||
fill: new ol.style.Fill({
|
||||
color: styleProperties["text-color"] || "white"
|
||||
}),
|
||||
offsetX: styleProperties["text-offset-x"] || 0,
|
||||
offsetY: styleProperties["text-offset-y"] || -20,
|
||||
textAlign: styleProperties["text-align"] || "center",
|
||||
textBaseline: styleProperties["text-baseline"] || "middle"
|
||||
})
|
||||
: null;
|
||||
|
||||
return new ol.style.Style({
|
||||
stroke: stroke,
|
||||
fill: fill,
|
||||
text: text
|
||||
});
|
||||
}
|
||||
// Дефолтный стиль
|
||||
return new ol.style.Style({
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(255, 0, 0, 0.5)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'blue',
|
||||
width: 2
|
||||
}),
|
||||
text: new ol.style.Text({
|
||||
// text: 'Hello, OpenLayers!',
|
||||
font: '14px Calibri,sans-serif',
|
||||
fill: new ol.style.Fill({
|
||||
color: 'white'
|
||||
}),
|
||||
offsetX: 0,
|
||||
offsetY: -20,
|
||||
textAlign: 'center',
|
||||
textBaseline: 'middle'
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user