From 1390d0f1c2287d1a31697208af8bfdbb7537d822 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Mon, 3 Mar 2025 10:27:48 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BC=D0=BE=D1=82=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B2=D1=8B=D1=82=D1=8F=D0=B3=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=B8=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/main/templates/create_layer.html | 95 +++++++++++++++++++++------ 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/apps/main/templates/create_layer.html b/apps/main/templates/create_layer.html index 7491b34..ff7e19b 100644 --- a/apps/main/templates/create_layer.html +++ b/apps/main/templates/create_layer.html @@ -251,22 +251,63 @@ } }); - const createDXFStyle = function (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: feature.get("color"), - width: 1, + color: 'blue', + width: 2 }), - image: new ol.style.Circle({ - radius: 10, // Размер точки + text: new ol.style.Text({ + text: 'Hello, OpenLayers!', + font: '14px Calibri,sans-serif', fill: new ol.style.Fill({ - color: 'red', // Цвет заливки + color: 'white' }), - stroke: new ol.style.Stroke({ - color: 'white', // Цвет обводки - width: 2, // Толщина обводки - }), - }), + offsetX: 0, + offsetY: -20, + textAlign: 'center', + textBaseline: 'middle' + }) }); }; @@ -315,29 +356,45 @@ if (entity.type === 'LINE') { return createFeature('LineString', entity.normalizedCoords, - {color: getColorByColorTable(entity.colorIndex)}); + { + 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, - {color: getColorByColorTable(entity.colorIndex)}); + { + style: { + "stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1 + } + }); } else if (entity.type === 'CIRCLE') { return createFeature('Point', entity.normalizedCoords[0], - {radius: entity.radius, color: getColorByColorTable(entity.colorIndex)} - ); + { + style: { + "circle-radius": entity.radius, + "stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1 + } + }); } else if (entity.type === 'ARC') { return createFeature('LineString', entity.normalizedCoords, - {color: getColorByColorTable(entity.colorIndex)}); + { + style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1} + }); } else if (entity.type === 'POINT') { return createFeature('Point', entity.normalizedCoords[0], - {color: getColorByColorTable(entity.colorIndex)}); + { + style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1} + }); } else if (entity.type === 'SPLINE') { return createFeature('LineString', entity.normalizedCoords, - {color: getColorByColorTable(entity.colorIndex)}); + { + style: {"stroke-color": getColorByColorTable(entity.colorIndex), "stroke-width": 1} + }); } return null; }).filter(f => f !== null); @@ -423,7 +480,7 @@ }); vectorLayer = new ol.layer.Vector({ source: vectorSource, - style: createDXFStyle + style: createStyleFromFeature }); map.addLayer(vectorLayer);