Исправил баг. Карта не была определена в layersStyles.js

This commit is contained in:
zakhy 2025-03-24 12:43:25 +07:00
parent d5d2a6a2ea
commit 4c8aa8a0f7

View File

@ -158,7 +158,7 @@
масштабирования</label>
</div>
{% if request.user.is_superuser %}
<button id="exportGeoJSON" class="btn btn-info float-right">
<button type="button" id="exportGeoJSON" class="btn btn-info float-right">
Экспортировать GeoJSON
</button>
{% endif %}
@ -207,7 +207,6 @@
const degreesToRadians = (degrees) => (degrees * Math.PI) / 180;
function decodeDXFText(text) {
console.log(text)
// Заменяем Unicode коды на символы
text = text.replace(/\\U\+([\dA-F]{4})/gi, (_, code) =>
String.fromCharCode(parseInt(code, 16))
@ -385,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,
@ -641,7 +705,6 @@
"stroke-width": 1,
}
if (entity.text && !entity.text.includes('<27>')) {
console.log(entity.text, entity.rotation, degreesToRadians(entity.rotation))
figureStyle["text-value"] = entity.type === "TEXT" ? entity.text : decodeDXFText(entity.text)
figureStyle["text-rotation"] = -degreesToRadians(entity.rotation)
}