This commit is contained in:
zakhy 2025-02-14 14:18:03 +07:00
parent 1506ffe098
commit 84e8ddbb9a

View File

@ -9,6 +9,7 @@
<script src="/static/js/ol/ol-ext/ol-ext.min.js"></script>
<link rel="stylesheet" href="/static/js/ol/ol-ext/ol-ext.min.css">
<script src="/static/js/ol/dxf-parser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nurbs/dist/nurbs.min.js"></script>
<style>
#map {
@ -146,64 +147,62 @@
}
});
function normalizeCoordinates(entities, offsetX = 0, offsetY = 0, scale = 1) {
let minX = Infinity, minY = Infinity;
let maxX = 0, maxY = 0
entities.forEach(entity => {
const coords = getCoordinates(entity);
coords.forEach(([x, y]) => {
if (x < minX) minX = x;
if (y < minY) minY = y;
function getCoordinates(entity) {
if (entity.type === 'LINE') {
return [[entity.vertices[0].x, entity.vertices[0].y], [entity.vertices[1].x, entity.vertices[1].y]];
}
if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
return entity.vertices.map(v => [v.x, v.y]);
}
if (entity.type === 'CIRCLE') {
return [[entity.center.x, entity.center.y]];
}
if (entity.type === 'ARC') {
return arcToLine(entity);
}
if (entity.type === 'POINT') {
return [[entity.position.x, entity.position.y]];
}
return [];
}
if (x > maxX) maxX = x;
if (y > maxY) maxY = y;
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]) => {
const normalizedX = x - minX;
const normalizedY = y - minY;
return convertToLonLat([normalizedX, normalizedY]);
});
return { ...entity, normalizedCoords: coords };
});
}
console.log('Min X:', minX, 'Min Y:', minY);
console.log('max X:', maxX, 'max Y:', maxY);
function dxfToGeoJSON(dxf) {
console.log(dxf);
const normalizedEntities = normalizeCoordinates(dxf.entities, dxf.header);
const features = normalizedEntities.map(entity => {
if (entity.type === 'LINE') {
return createFeature('LineString', entity.normalizedCoords);
} else if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
const coords = entity.normalizedCoords;
return createFeature(entity.closed ? 'Polygon' : 'LineString', entity.closed ? [coords] : coords);
} else if (entity.type === 'CIRCLE') {
return createFeature('Point', entity.normalizedCoords[0], { radius: entity.radius });
} else if (entity.type === 'ARC') {
return createFeature('LineString', entity.normalizedCoords);
} else if (entity.type === 'POINT') {
return createFeature('Point', entity.normalizedCoords[0]);
} else if (entity.type === 'SPLINE') {
return createFeature('LineString', entity.normalizedCoords);
}
return null;
}).filter(f => f !== null);
return entities.map(entity => {
const coords = getCoordinates(entity).map(([x, y]) => {
const normalizedX = (x - minX + offsetX) * scale;
const normalizedY = (y - minY + offsetY) * scale;
console.log('Original:', [x, y], 'Normalized:', [normalizedX, normalizedY]);
return convertToLonLat([normalizedX, normalizedY]);
});
return {...entity, normalizedCoords: coords};
});
}
function getCoordinates(entity) {
if (entity.type === 'LINE') return [[entity.start.x, entity.start.y], [entity.end.x, entity.end.y]];
if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') return entity.vertices.map(v => [v.x, v.y]);
if (entity.type === 'CIRCLE') return [[entity.center.x, entity.center.y]];
if (entity.type === 'ARC') return arcToLine(entity);
if (entity.type === 'POINT') return [[entity.position.x, entity.position.y]];
return [];
}
function dxfToGeoJSON(dxf) {
console.log(dxf)
const normalizedEntities = normalizeCoordinates(dxf.entities);
const features = normalizedEntities.map(entity => {
if (entity.type === 'LINE') {
return createFeature('LineString', entity.normalizedCoords);
} else if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
const coords = entity.normalizedCoords;
return createFeature(entity.closed ? 'Polygon' : 'LineString', entity.closed ? [coords] : coords);
} else if (entity.type === 'CIRCLE') {
return createFeature('Point', entity.normalizedCoords[0], {radius: entity.radius});
} else if (entity.type === 'ARC') {
return createFeature('LineString', entity.normalizedCoords);
} else if (entity.type === 'POINT') {
return createFeature('Point', entity.normalizedCoords[0]);
}
return null;
}).filter(f => f !== null);
return {type: 'FeatureCollection', features: features};
}
return { type: 'FeatureCollection', features: features };
}
function createFeature(type, coordinates, properties = {name: `${i}`}) {
i++
@ -284,11 +283,15 @@
}
function convertToLonLat([x, y]) {
const kx = 1.676;
const ky = 1.001;
console.log(`Координаты до конвертации [${x},${y}]`)
res = ol.proj.transform([x, y], 'EPSG:3857', 'EPSG:4326')
console.log(`Координаты после конвертации [${res[0]},${res[1]}]`)
res[0] += 87.915936 // ДОЛГОТА
res[1] += 53.688360 // ШИРОТА
res[0] = kx * res[0] + 87.915936 // ДОЛГОТА
res[1] = ky * res[1] + 53.688360 // ШИРОТА
return res;
}