/
BELEGO
/
GIS_APPLICATION
Обзор
Документация
Войти
/
BELEGO
/
GIS_APPLICATION
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Front/src/utils/mapUtils.js
62 строки
3 KB
HACKER_LAPTOP
fix camera position, del buttons cesium
13 окт 2025, 00:49
13 окт 2025, 00:49
45617e9
Код
Авторство
О чём код?
import { fromLonLat } from 'ol/proj' /** * Перемещает карту к фиче * @param {import("ol/Map").default} map - объект карты * @param {import("ol/Feature").default} feature - фича */ export function moveToFeature(map, feature) { if (!map || !feature) return try { const geometry = feature.getGeometry() if (!geometry) { console.warn("⚠️ У фичи нет геометрии:", feature) return } map.getView().fit(geometry.getExtent(), { padding: [40, 40, 40, 40], maxZoom: 12, duration: 500 }) } catch (e) { console.error("❌ Ошибка при перемещении к фиче:", e) } } /** * Конвертирует уровень приближения OpenLayers (zoom) в высоту камеры Cesium. * * OL zoom 0 соответствует обзору всей планеты, zoom 18 — максимальное приближение на уровне улицы. * Формула: высота уменьшается экспоненциально с увеличением zoom. * * @param {number} zoom - Уровень zoom OpenLayers (обычно 0–18) * @returns {number} safeHeight - Высота камеры в Cesium в метрах, безопасная для установки */ export function olZoomToCesiumHeight(zoom) { const maxZoom = 18; const maxHeight = 150000000; // Height for zoom 0 (entire globe) const minHeight = 1000; // Height for zoom 18 (close-up) const height = maxHeight / Math.pow(2, zoom); const safeHeight = Math.max(minHeight, Math.min(height, maxHeight)); console.log(`[Convert] OL zoom ${zoom} → Cesium height ${safeHeight}`); return safeHeight; } /** * Конвертирует высоту камеры Cesium в уровень приближения OpenLayers * @param {number} height - высота камеры Cesium в метрах * @returns {number} zoom - уровень zoom OpenLayers (0–18) */ export function cesiumHeightToOlZoom(height) { const maxZoom = 18; const maxHeight = 150000000; // Высота для zoom 0 const minHeight = 1000; // Высота для zoom 18 const clampedHeight = Math.max(minHeight, Math.min(height, maxHeight)); const zoom = Math.log2(maxHeight / clampedHeight); const safeZoom = Math.max(0, Math.min(zoom, maxZoom)); console.log(`[Convert] Cesium height ${height} → OL zoom ${safeZoom}`); return safeZoom; }