BIGEMPA Js API示例中心

经纬度网源代码展示

代码编辑区 运行 下载 还原
<!DOCTYPE html>

<html>

<head>
  <meta charset='UTF-8' />
  <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  <link href='http://www.bigemap.com:9000/bigemap.js/v2.1.0/bigemap.css' rel='stylesheet' />
  <script src='http://www.bigemap.com:9000/bigemap.js/v2.1.0/bigemap.js'></script>
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    #map {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 100%;
    }
    .tools{
        width: 240px;
        height: 40px;
        position: absolute;
        display: flex;
        justify-content: space-between;
        z-index: 999;
        top: 20px;
        right: 100px;
    }
    #itemOne,#itemTwo{
        width: 88px;
       height: 40px;
       line-height: 40px;
       text-align: center;
       background-color: #59acff;
       color: aliceblue;
       font-size: 12px;
       margin-right: 20px;
       border-radius: 4px;
       cursor: pointer;
    }
  </style>
  <title>地图添加经纬度网</title>
</head>

<body>
  <div id='map'>
    <div class="tools">
        <h3 id="itemOne">添加经纬网</h3>
        <h3 id="itemTwo">移除经纬网</h3>
    </div>
  </div>
  <script src="/bigemapGridLines/BMDrawLonlatLine.js"></script>
  <script>
    // 软件配置信息地址,软件安装完成之后使用本地地址,如:http://localhost:9000
    BM.Config.HTTP_URL = 'http://www.bigemap.com:9000';
    //创建地图
    var  map = BM.map('map', 'bigemap.zhongkexingtu', { center: [22.906279484467223, 114.10481473882101], zoom: 16, zoomControl: true, attributionControl: false });
    // 初始化经纬度网
    var lonLatGridLines = new BM.BMDrawLonlatLine(map);
 
    //经纬度线的颜色设置
    lonLatGridLines.setLineColor("#38a4fe");

    //经纬线度数文本颜色调整为红色
    lonLatGridLines.setTextColor("red");

     //经纬线度数文本只显示北边(经度值)和东边(纬度值) , 默认是全显示,有三个可选值 all right left
    lonLatGridLines.setTextPosition("all");

    document.querySelector("#itemOne").addEventListener("click",function(){
        ///初始化话的时候,触发一次绘制
        lonLatGridLines.drawLonlatTileGrid();
        // 添加绘制地图事件(即拖动地图时,清除上一次的图层的同时绘制新的图层)
        lonLatGridLines.addDrawEvent();
    })

    document.querySelector("#itemTwo").addEventListener("click",function(){
        //释放资源,移除经纬线相关图层和地图事件
        lonLatGridLines && lonLatGridLines.removeDrawEvent();
    })
  </script>
</body>

</html>