Browse Source

动态变化

gesofts 3 years ago
parent
commit
0ef682e16f
1 changed files with 63 additions and 0 deletions
  1. 63 0
      1.html

+ 63 - 0
1.html

@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="utf-8">
+    <title>地图单击拾取经纬度</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
+    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
+    <style>
+        body,
+        html,
+        #container {
+            overflow: hidden;
+            width: 100%;
+            height: 100%;
+            margin: 0;
+            font-family: "微软雅黑";
+        }
+        .info {
+            z-index: 999;
+            width: auto;
+            min-width: 22rem;
+            padding: .75rem 1.25rem;
+            margin-left: 1.25rem;
+            position: fixed;
+            top: 1rem;
+            background-color: #fff;
+            border-radius: .25rem;
+            font-size: 14px;
+            color: #666;
+            box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
+        }
+    </style>
+    <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=94iK6uYDWx7AV4FbrPaQDtRp8uBHWIoA"></script>
+</head>
+<body>
+<div id="container"></div>
+<div class = "info">
+<input name="content" id="content"> <button onclick="funJs()">检索</button>
+<span id="lanlng"></span>
+</div>
+</body>
+</html>
+<script>
+    var map = new BMapGL.Map('container');
+    map.centerAndZoom(new BMapGL.Point(118.8660, 31.96949), 15);
+    map.enableScrollWheelZoom(true);
+    map.addEventListener('click', function (e) {
+        document.getElementById("lanlng").innerText=e.latlng.lng.toFixed(6) + ',' + e.latlng.lat.toFixed(6);
+        //alert('点击位置经纬度:' + e.latlng.lng + ',' + e.latlng.lat);
+    });
+
+    function funJs() {
+
+        map.clearOverlays();
+        var local = new BMapGL.LocalSearch(map, {
+            renderOptions:{map: map}
+        });
+        local.search(document.getElementById("content").value);
+    }
+
+
+</script>