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>
相关推荐
AAA阿giao1 分钟前
拼乐高式开发:深入剖析 React 组件通信、弹窗设计与样式管理
开发语言·前端·javascript·react.js·前端框架·props·components
Rysxt_15 分钟前
Vue 3 项目核心:App.vue 文件的作用与配置详解
前端·javascript·vue.js
imkaifan25 分钟前
10、vue3中针对图片的处理
前端·javascript·vue.js
invicinble35 分钟前
对于使用html去进行前端开发的全面认识,以及过度到vue开发
前端·javascript·vue.js
csdn_aspnet36 分钟前
C# 结合 JavaScript 实现手写板签名并上传到服务器
javascript·c#
watersink37 分钟前
Agent 设计模式
开发语言·javascript·设计模式
han_41 分钟前
前端性能优化之性能瓶颈点,Web 页面加载全流程解析
前端·javascript·性能优化
C_心欲无痕42 分钟前
vue3 - toRefs将响应式对象转换为普通对象
前端·javascript·vue.js
小oo呆43 分钟前
【自然语言处理与大模型】LangChainV1.0入门指南:AgentState介绍
前端·javascript·easyui
我是伪码农1 小时前
电子时钟案例
javascript·css·css3