utm 转 经纬度坐标 cesium Ue4 CityEngine

utm 转 经纬度坐标|

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <title>UTM to LatLng Conversion</title>
    <meta charset="utf-8" />
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }

        h1 {
            font-size: 24px;
            margin-bottom: 20px;
            text-align: center;
        }

        form {
            max-width: 400px;
            margin: 0 auto;
            background-color: #ffffff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        p {
            font-size: 18px;
            margin-bottom: 10px;
        }

        label {
            display: inline-block;
            width: 120px;
            font-weight: bold;
        }

        input[type="number"] {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }

        button {
            display: block;
            width: 100%;
            padding: 10px;
            font-size: 16px;
            font-weight: bold;
            color: #fff;
            background-color: #007bff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        #result {
            font-weight: bold;
            font-size: 20px;
            margin-top: 20px;
            text-align: center;
        }

        #saveButton {
            margin-top: 20px;
            background-color: #28a745;
        }
    </style>
    </style>
    <script src="https://cdn.bootcdn.net/ajax/libs/proj4js/2.9.0/proj4-src.js"></script>
</head>

<body>
    <h1>UTM to LatLng Conversion</h1>
    <form>
        <p>
            <label for="utmX">UTM X-coordinate:</label>
            <input type="number" id="utmX" step="any" />
        </p>
        <p>
            <label for="utmY">UTM Y-coordinate:</label>
            <input type="number" id="utmY" step="any" />
        </p>
        <button type="button" onclick="convertUTMToLatLng()">Convert</button>
    </form>

    <p>Converted LatLng:</p>
    <p id="result"></p>

    <button id="saveButton" type="button" onclick="saveToLocalStorage()">Save Coordinates</button>

    <script>
        const utmProjection = '+proj=utm +zone=49 +datum=WGS84 +units=m +no_defs';

        const utmXInput = document.getElementById('utmX');
        const utmYInput = document.getElementById('utmY');
        const resultElement = document.getElementById('result');

        // Load coordinates from local storage if available
        window.onload = function () {
            if (localStorage.getItem('utmX') && localStorage.getItem('utmY')) {
                utmXInput.value = localStorage.getItem('utmX');
                utmYInput.value = localStorage.getItem('utmY');
            }
        }
        let latLngRes = ''
        const convertUTMToLatLng = () => {
            const utmX = parseFloat(utmXInput.value);
            const utmY = parseFloat(utmYInput.value);

            if (isNaN(utmX) || isNaN(utmY)) {
                alert('Please enter valid UTM coordinates.');
                return;
            }

            // Define UTM projection object
            const utm = proj4(utmProjection);

            // Perform projection conversion
            const latLng = utm.inverse([utmX, utmY]);
            console.log(latLng,'latLng');
            latLngRes = `${latLng[0]}, ${latLng[1]}`
            // Update the displayed result
            resultElement.textContent = `${latLng[0]}, ${latLng[1]}`;

            // Save coordinates to local storage
            localStorage.setItem('utmX', utmX);
            localStorage.setItem('utmY', utmY);
        };
        const saveToLocalStorage = () => {
            const utmX = parseFloat(utmXInput.value);
            const utmY = parseFloat(utmYInput.value);

            if (isNaN(utmX) || isNaN(utmY)) {
                alert('Please enter valid UTM coordinates.');
                return;
            }

            // Save coordinates to local storage
            localStorage.setItem('utmX', utmX);
            localStorage.setItem('utmY', utmY);
            // 创建一个辅助元素用于复制文本
            var tempElement = document.createElement("textarea");
            tempElement.value = latLngRes;
            document.body.appendChild(tempElement);

            // 选择辅助元素的文本并复制
            tempElement.select();
            document.execCommand("copy");

            // 移除辅助元素
            document.body.removeChild(tempElement);
            alert("Text copied!");
        };
    </script>
相关推荐
LIUAWEIO9 小时前
vue里面下载配置使用zepto vue中怎样使用zepto
javascript·vue.js·es6·zepto
lantian9 小时前
TypeScript 三斜线指令完全指南:从入门到理解为什么不再需要它
前端·javascript·vue.js
用户938515635079 小时前
从"用栈实现队列"说起:深入理解 JavaScript 原型式面向对象
javascript
ZengLiangYi10 小时前
AI 编程工具的数据格式为什么不能统一
javascript·后端·架构
陈_杨10 小时前
鸿蒙APP开发-带你走进旧物集的时间线与收藏管理
前端·javascript
尼斯湖皮皮怪10 小时前
iceCoder双模详解
javascript
小雨下雨的雨10 小时前
月相分析工具鸿蒙PC Electron框架技术实现详解
前端·javascript·华为·electron
布依前端10 小时前
基于 Vue 3 的 Tiptap 富文本编辑器实践:tiptap-editor-vue3 项目介绍
前端·javascript·vue.js
奥利奥夹心脆芙10 小时前
OTel / Logstash / Fluentd 全维对比,及统一日志与指标管道的 AWS ECS 落地
javascript
zithern_juejin11 小时前
手写函数组合compose
javascript