Убрал лишнее с создания слоя

This commit is contained in:
zakhy 2025-03-03 09:10:55 +07:00
parent 2edbab2625
commit 3b09125b60

View File

@ -117,9 +117,7 @@
<script src="{% static 'js/ol/dxf-parser.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.15.0/proj4-src.js"></script>
<script src="{% static 'js/ol/layersStyles.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/mapCommonFuncs.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/timeSliderFuncs.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script>
const filePath = document.getElementById("file_path");
const fileField = document.getElementById("id_layer_file_input");
@ -130,7 +128,6 @@
filePath.textContent = file.name; // Устанавливаем имя файла как текст ссылки
}
});
</script>
<script>
@ -155,10 +152,10 @@
}),
extent: ol.proj.transformExtent(
[
parseFloat('87.889212480'),
parseFloat('53.633875446'),
parseFloat('87.965792495'),
parseFloat('53.713365769')
parseFloat('{{ orth_minLon }}'),
parseFloat('{{ orth_minLat }}'),
parseFloat('{{ orth_maxLon }}'),
parseFloat('{{ orth_maxLat }}')
],
'EPSG:4326', // Исходная проекция
'EPSG:3857' // Целевая проекция
@ -167,10 +164,6 @@
scanLayer.set('name', 'Ортофотоплан')
layers.push(scanLayer)
}
const iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat([centerLon, centerLat])),
name: 'Null Island',
});
function getCoordsByFeature(feature, resoluiton) {
const coords = feature.getGeometry().getCoordinates()
@ -182,44 +175,6 @@
}
}
function iconStyle(feature, resolution) {
return 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,
}),
text: new ol.style.Text({
textAlign: 'center',
textBaseline: 'middle',
text: getCoordsByFeature(feature, resolution).formatted,
fill: new ol.style.Fill({color: '#000'}),
offsetX: 0,
offsetY: -25,
placement: 'point',
maxAngle: '0.7853981633974483',
overflow: 'false',
rotation: parseFloat('0'),
backgroundFill: new ol.style.Fill({color: '#fff'}),
backgroundStroke: new ol.style.Stroke({color: '#000', width: 1}),
padding: [3, 3, 3, 3],
})
});
}
const exampleSource = new ol.source.Vector({
features: [iconFeature],
});
// const exampleLayer = new ol.layer.Vector({
// source: exampleSource,
// style: iconStyle
// });
// layers.push(exampleLayer)
const map = new ol.Map({
target: 'map',
layers: layers,
@ -239,11 +194,6 @@
map.addInteraction(transformInteraction);
let vectorLayer;
// Обработчик клика на карту
map.on('click', function (event) {
const features = map.getFeaturesAtPixel(event.pixel); // Получаем объекты в точке клика
console.log(getCoordsByFeature(features[0]).formatted)
});
// const ctrl = new ol.control.Status();
// map.addControl(ctrl);
// // Show information on each frame
@ -347,6 +297,7 @@
let minY = dxfHeader.$EXTMIN.y;
return entities.map(entity => {
const coords = getCoordinates(entity).map(([x, y]) => {
// Возможно отображение от нулевых координат. Для этого нужно отнимать minX и minY
const normalizedX = x
// - minX;
const normalizedY = y
@ -362,22 +313,31 @@
const normalizedEntities = normalizeCoordinates(dxf.entities, dxf.header);
const features = normalizedEntities.map(entity => {
if (entity.type === 'LINE') {
return createFeature('LineString', entity.normalizedCoords, {color: getColorByColorTable(entity.colorIndex)});
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,
color: getColorByColorTable(entity.colorIndex)
});
return createFeature('Point',
entity.normalizedCoords[0],
{radius: entity.radius, color: getColorByColorTable(entity.colorIndex)}
);
} else if (entity.type === 'ARC') {
return createFeature('LineString', entity.normalizedCoords, {color: getColorByColorTable(entity.colorIndex)});
return createFeature('LineString',
entity.normalizedCoords,
{color: getColorByColorTable(entity.colorIndex)});
} else if (entity.type === 'POINT') {
return createFeature('Point', entity.normalizedCoords[0], {color: getColorByColorTable(entity.colorIndex)});
return createFeature('Point',
entity.normalizedCoords[0],
{color: getColorByColorTable(entity.colorIndex)});
} else if (entity.type === 'SPLINE') {
return createFeature('LineString', entity.normalizedCoords, {color: getColorByColorTable(entity.colorIndex)});
return createFeature('LineString',
entity.normalizedCoords,
{color: getColorByColorTable(entity.colorIndex)});
}
return null;
}).filter(f => f !== null);
@ -467,12 +427,10 @@
});
map.addLayer(vectorLayer);
// Настройка transformInteraction для редактирования
const features = vectorSource.getFeatures();
const group = new ol.Collection(features);
transformInteraction.setSelection(group);
// Обновляем выделение при перемещении мыши
map.on('pointermove', () => {
transformInteraction.setSelection(group);
});
@ -561,6 +519,7 @@
transformInteraction.setSelection(emptyGroup)
}
// Если редактирование слоя
document.addEventListener('DOMContentLoaded', function () {
const fileInput = document.getElementById('id_file');
if (fileInput && fileInput.value) {