still work
This commit is contained in:
parent
072b794ab2
commit
1506ffe098
@ -60,25 +60,25 @@
|
||||
<button id="deleteLayer">Удалить слой</button>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
scanLayer = new ol.layer.Tile({
|
||||
source: new ol.source.XYZ({
|
||||
url: '/media/map/orth/tiles/{z}/{x}/{y}.png',
|
||||
}),
|
||||
extent: ol.proj.transformExtent(
|
||||
[
|
||||
parseFloat('87.889212480'),
|
||||
parseFloat('53.633875446'),
|
||||
parseFloat('87.965792495'),
|
||||
parseFloat('53.713365769')
|
||||
],
|
||||
'EPSG:4326', // Исходная проекция
|
||||
'EPSG:3857' // Целевая проекция
|
||||
)
|
||||
});
|
||||
let i = 0
|
||||
scanLayer = new ol.layer.Tile({
|
||||
source: new ol.source.XYZ({
|
||||
url: '/media/map/orth/tiles/{z}/{x}/{y}.png',
|
||||
}),
|
||||
extent: ol.proj.transformExtent(
|
||||
[
|
||||
parseFloat('87.889212480'),
|
||||
parseFloat('53.633875446'),
|
||||
parseFloat('87.965792495'),
|
||||
parseFloat('53.713365769')
|
||||
],
|
||||
'EPSG:4326', // Исходная проекция
|
||||
'EPSG:3857' // Целевая проекция
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
scanLayer.set('name', 'Ортофотоплан')
|
||||
scanLayer.set('name', 'Ортофотоплан')
|
||||
|
||||
const map = new ol.Map({
|
||||
target: 'map',
|
||||
@ -86,7 +86,7 @@
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
}),
|
||||
scanLayer
|
||||
scanLayer
|
||||
],
|
||||
view: new ol.View({
|
||||
center: ol.proj.fromLonLat([0, 0]),
|
||||
@ -146,34 +146,34 @@
|
||||
}
|
||||
});
|
||||
|
||||
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 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;
|
||||
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
console.log('Min X:', minX, 'Min Y:', minY);
|
||||
console.log('max X:', maxX, 'max Y:', maxY);
|
||||
console.log('Min X:', minX, 'Min Y:', minY);
|
||||
console.log('max X:', maxX, 'max Y:', maxY);
|
||||
|
||||
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 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};
|
||||
});
|
||||
return { ...entity, normalizedCoords: coords };
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getCoordinates(entity) {
|
||||
if (entity.type === 'LINE') return [[entity.start.x, entity.start.y], [entity.end.x, entity.end.y]];
|
||||
@ -205,7 +205,8 @@ function normalizeCoordinates(entities, offsetX = 0, offsetY = 0, scale = 1) {
|
||||
return {type: 'FeatureCollection', features: features};
|
||||
}
|
||||
|
||||
function createFeature(type, coordinates, properties = {}) {
|
||||
function createFeature(type, coordinates, properties = {name: `${i}`}) {
|
||||
i++
|
||||
return {
|
||||
type: 'Feature',
|
||||
geometry: {type, coordinates},
|
||||
@ -286,8 +287,8 @@ function normalizeCoordinates(entities, offsetX = 0, offsetY = 0, scale = 1) {
|
||||
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] += 87.915936 // ДОЛГОТА
|
||||
res[1] += 53.688360 // ШИРОТА
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user