Ворую стиль с dxf

This commit is contained in:
zakhy 2025-02-20 14:17:18 +07:00
parent 85a05f729f
commit 99168c0ada
2 changed files with 1112 additions and 24 deletions

View File

@ -16,6 +16,10 @@
border-radius: .25rem;
font-weight: normal !important;
}
.ol-status.ol-unselectable.ol-control.ol-visible {
background-color: rgba(0, 0, 0, 0.2) !important
}
</style>
{% endblock %}
{% block content %}
@ -119,7 +123,6 @@
let centerLon = parseFloat('{{lon}}')
let transformInteraction = {}
let translateInteraction = {}
console.log(centerLat)
let i = 0
const scanLayerExists = Boolean(parseInt('{{ scan_layer_enable }}'))
@ -147,8 +150,34 @@
scanLayer.set('name', 'Ортофотоплан')
layers.push(scanLayer)
}
const iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat([centerLon, centerLat])),
name: 'Null Island',
population: 4000,
rainfall: 500,
});
const iconStyle = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: '/static/img/earthquake.png',
width: 20,
height: 20,
}),
});
iconFeature.setStyle(iconStyle);
const exampleSource = new ol.source.Vector({
features: [iconFeature],
});
const exampleLayer = new ol.layer.Vector({
source: exampleSource,
});
layers.push(exampleLayer)
const map = new ol.Map({
target: 'map',
layers: layers,
@ -162,10 +191,29 @@
// Добавляем возможность масштабирования и перемещения с помощью маркеров
transformInteraction = new ol.interaction.Transform({
addCondition: ol.events.condition.shiftKeyOnly
addCondition: ol.events.condition.shiftKeyOnly,
});
map.addInteraction(transformInteraction);
let vectorLayer;
// const ctrl = new ol.control.Status();
// map.addControl(ctrl);
// // Show information on each frame
// map.on('postrender', function (e) {
// console.log(ol.coordinate)
// // console.log(e)
// var c = map.getView().getCenter();
// ctrl.status({
// center: [Math.round(c[0]), Math.round(c[1])],
// lonlat: ol.coordinate.toStringXY(ol.proj.toLonLat(c), 7),
// zoom: map.getView().getZoom(),
// resolution: map.getView().getResolution().toFixed(4),
// angle: Math.round(map.getView().getRotation() * 180 / Math.PI * 100) / 100,
// size: map.getSize(),
// animate: e.frameState.animate
// });
// });
document.getElementById('id_layer_file_input').addEventListener('change', function (event) {
const file = event.target.files[0];
if (file) {
@ -201,6 +249,15 @@
}
});
const createDXFStyle = function (feature, resolution) {
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: feature.get("color"),
width: 1,
}),
});
};
function getCoordinates(entity) {
if (entity.type === 'LINE') {
return [[entity.vertices[0].x, entity.vertices[0].y], [entity.vertices[1].x, entity.vertices[1].y]];
@ -217,13 +274,19 @@
if (entity.type === 'POINT') {
return [[entity.position.x, entity.position.y]];
}
if (entity.type === 'SPLINE') {
return entity.controlPoints.map(v => [v.x, v.y]);
}
if (entity.type === "INSERT") {
{#const type = #}
console.log(entity)
}
return [];
}
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;
@ -239,22 +302,25 @@
const normalizedEntities = normalizeCoordinates(dxf.entities, dxf.header);
const features = normalizedEntities.map(entity => {
if (entity.type === 'LINE') {
return createFeature('LineString', entity.normalizedCoords);
return createFeature('LineString', entity.normalizedCoords, {color: getColorByColorTable(entity.colorIndex)});
} else if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
const coords = entity.normalizedCoords;
return createFeature(entity.closed ? 'Polygon' : 'LineString', entity.closed ? [coords] : coords);
return createFeature(entity.closed ? 'Polygon' : 'LineString', entity.closed ? [coords] : coords,
{color: getColorByColorTable(entity.colorIndex)});
} else if (entity.type === 'CIRCLE') {
return createFeature('Point', entity.normalizedCoords[0], {radius: entity.radius});
return createFeature('Point', entity.normalizedCoords[0], {
radius: entity.radius,
color: getColorByColorTable(entity.colorIndex)
});
} else if (entity.type === 'ARC') {
return createFeature('LineString', entity.normalizedCoords);
return createFeature('LineString', entity.normalizedCoords, {color: getColorByColorTable(entity.colorIndex)});
} else if (entity.type === 'POINT') {
return createFeature('Point', entity.normalizedCoords[0]);
return createFeature('Point', entity.normalizedCoords[0], {color: getColorByColorTable(entity.colorIndex)});
} else if (entity.type === 'SPLINE') {
return createFeature('LineString', entity.normalizedCoords);
return createFeature('LineString', entity.normalizedCoords, {color: getColorByColorTable(entity.colorIndex)});
}
return null;
}).filter(f => f !== null);
return {type: 'FeatureCollection', features: features};
}
@ -336,16 +402,7 @@
});
vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'red',
width: 2
}),
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({color: 'blue'})
})
})
style: createDXFStyle
});
map.addLayer(vectorLayer);
@ -380,9 +437,7 @@
function downloadGeoJSON(geojson) {
const blob = new Blob([geojson], {type: 'application/json'});
console.log(blob)
const url = URL.createObjectURL(blob);
console.log(url)
const a = document.createElement('a');
a.href = url;
a.download = 'export.geojson';
@ -413,7 +468,6 @@
}
}).then(response => {
if (response.ok) {
console.log('Файл успешно сохранен!');
window.location.href = '/main/'
} else {
console.error('Ошибка при сохранении файла.');
@ -438,7 +492,6 @@
document.addEventListener('DOMContentLoaded', function () {
const fileInput = document.getElementById('id_file');
console.log(fileInput.value)
if (fileInput && fileInput.value) {
const fileUrl = "/media/" + fileInput.value; // URL файла
const fileExtension = fileUrl.split('.').pop().toLowerCase();

File diff suppressed because one or more lines are too long