Убрал отрисовку блоков

This commit is contained in:
zakhy 2025-03-25 09:23:28 +07:00
parent 31b8058082
commit 2f44dd6596

View File

@ -660,174 +660,6 @@
}
});
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]];
@ -891,96 +723,86 @@
normalizedEntities.forEach(entity => {
DXFLayersList.push(entity.layer);
// Обрабатываем обычные сущности
let feature = null;
if (entity.type === 'INSERT') {
// Обрабатываем блоки
const blockFeatures = processBlockInsert(entity, dxf);
console.log(blockFeatures);
if (blockFeatures && blockFeatures.length > 0) {
features.push(...blockFeatures);
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]); // Замыкаем полигон
}
} 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]); // Замыкаем полигон
feature = createFeature(
entity.shape ? 'Polygon' : 'LineString',
entity.shape ? [coords] : coords,
{
style: {
...getStyleFromDXFEntity(entity, dxf.tables.lineType?.lineTypes),
},
"layer": entity.layer
}
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 === '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);
}
);
} 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 {type: 'FeatureCollection', features: features};