грамотное вытягивание стиля
This commit is contained in:
parent
3b09125b60
commit
1390d0f1c2
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user