高质量编码-在线Excel经纬度坐标系转换(前端开发)

2021-07-15 11:11:28 浏览数 (1)

前端html和js代码如下:

代码语言:javascript复制
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" crossorigin="anonymous"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="static/lib/ajaxfileupload.js" crossorigin="anonymous"></script>
    <script src="static/lib/ajaxfile.js" crossorigin="anonymous"></script>

</head>

<body>

    <div class="container">

        <div class="bs-docs-section">
            <h1 id="forms" class="page-header">坐标系转换</h1>

            <h2 id="forms-example">功能说明</h2>
            <p>坐标转换

                此功能用于百度坐标系(bd-09)、火星坐标系(国测局坐标系、gcj02)、WGS84坐标系的相互转换</p>
            <div class="bs-example" data-example-id="basic-forms">
                <form>

                    <div class="form-group">
                        <label for="selectTransform">选择转换类型</label>
                        <select class="form-control" id="selectTransform">
                            <option value="gcj02_to_bd09">gcj02到bd09</option>
                            <option value="bd09_to_gcj02">bd09到gcj02</option>
                            <option value="wgs84_to_gcj02">wgs84到gcj02</option>
                            <option value="gcj02_to_wgs84">gcj02到wgs84</option>
                            <option value="bd09_to_wgs84">bd09到wgs84</option>
                            <option value="wgs84_to_bd09">wgs84到bd09</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputFile">上传你的Excel文件(经度列名改为"经度",纬度列名改为"纬度")</label>

                        <input type="file" name="xlsx" id="xlsx" required data-type="xlsx" onchange="javascript:ajaxFileUpload(this)">
                    </div>

                    <button type="submit" class="btn btn-default">提交</button>
                </form>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $('form').submit(function(e) {
            e.preventDefault();
            if (!$('#xlsx').val().endsWith('.xlsx')) {
                alert('必须上传正确的格式为xlsx的Excel文件');
                return false;
            }
            var uid = $('#xlsx').data('value');
            if (!uid) {
                alert('提交之前必须先上传正确的文件');
                return false;
            }
            $.post('/coordTransform', {
                uid: uid,
                transform: $('#selectTransform').val()
            }, function(data) {
                console.log(data);
                if (data['result'] == 1) {
                    alert('开始下载转换坐标后的Excel文件');
                    window.open(`/static/files/xlsx/${uid}_convert.xlsx`);
                }
            })


        });

    </script>

</body>

</html>

0 人点赞