BIGEMPA Js API示例中心

编辑线,面源代码展示

代码编辑区 运行 下载 还原
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>绘制</title>
    <script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
    <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>
    <link href="http://www.bigemap.com/Public/css/button.min.css" rel="stylesheet">
    <!--
     以下CSS地址请在安装软件了替换成本地的地址
     CSS地址请使用:
     http://localhost:9000/bigemap.js/v2.1.0/bigemap.css
     JS地址请使用:
     http://localhost:9000/bigemap.js/v2.1.0/bigemap.js
     软件下载地址 http://www.bigemap.com/reader/download/detail201802017.html
    -->
    <!--<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>-->
    <!--引入鼠标绘制的JS+CSS-->
    <!--对应下面的CSS+JS的下载地址 请直接访问 http://bigemap.com/Public/mouse_draw/mouse_draw.zip 来下载-->
    <link rel="stylesheet" href="http://www.bigemap.com/Public/mouse_draw/Bigemap.draw.css"/>
    <script src="http://www.bigemap.com/Public/js/bm.draw.min.js"></script>
</head>
<style type="text/css">
    * {
        padding: 0;
        margin: 0;
    }

    html, body, #map {
        width: 100%;
        height: 100%;
    }

    #edit_line {
        position: absolute;
        z-index: 10;
        right: 20px;
        top: 23px;
        display: inline-block;
        width: 150px;
    }

    #edit_area {
        position: absolute;
        z-index: 10;
        right: 20px;
        top: 50px;
        display: inline-block;
        width: 150px;
    }

    #edit_area button {
        display: inline-block;
        width: 150px;
    }

    #edit_poly {
        position: absolute;
        z-index: 10;
        right: 20px;
        top: 50px;
        display: inline-block;
        width: 150px;
    }

    .info {
        position: fixed;
        top: 0;
        color: #8a6d3b;
        z-index: 99;
        margin: 0;
        background-color: #fcf8e3;
        border-color: #faebcc;
        left: 0;
        right: 0;
        text-align: center;
    }
</style>
<body>
<p class="info">
    右键可以停止 编辑
</p>
<div id="edit_area">
    <button data-type="polyline" class="button button-tiny button-rounded button-primary">编辑线段</button>
    <button data-type="polygon" class="button button-tiny button-rounded button-primary">编辑多边形</button>
    <button data-type="circle" class="button button-tiny button-rounded button-primary">编辑圆</button>
</div>

<div id="map">

</div>
<script>
    BM.Config.HTTP_URL = 'http://www.bigemap.com:9000';
    var overlay = {}, current = '';
    // 在ID为map的元素中实例化一个地图,并设置地图的ID号为 bigemap.zhongkexingtu,ID号程序自动生成,无需手动配置,并设置地图的投影为百度地图 ,中心点,默认的级别和显示级别控件
    var map = BM.map('map', 'bigemap.zhongkexingtu', {
        center: [30, 104],
        zoom: 7,
        zoomControl: true,
        attributionControl: false
    });

    overlay.polyline = new BM.Polyline([
        {lat: 30.325204431530345, lng: 107.60390873998405},
        {lat: 29.669469569529078, lng: 107.32571404427291},
        {lat: 28.667997369204706, lng: 106.05318825691938},
        {lat: 28.432166294982455, lng: 104.6611174196005},
        {lat: 28.40607779623456, lng: 103.55960089713336}
    ]).addTo(map);
    overlay.polygon = new BM.Polygon([
        {lat: 30.280196656341005, lng: 101.70201860368253},
        {lat: 31.17443221616588, lng: 102.44943223893644},
        {lat: 31.612013574947458, lng: 105.5988347902894},
        {lat: 30.606585065678747, lng: 105.95238883048297},
        {lat: 29.78231117982432, lng: 105.75116749852897},
        {lat: 29.212533460366416, lng: 104.35137156397104},
        {lat: 28.97377253153283, lng: 102.9155958071351},
        {lat: 29.17605844636225, lng: 101.755267996341}
    ]).addTo(map);
    overlay.circle=BM.circle({lat: 28.40607779623456, lng: 103.55960089713336},{radius:50000}).addTo(map);
    map.on('contextmenu', function (e) {
        if (!current) return;
        //停止编辑。这里可以进行保存数据库的操作
        switch (current) {
            case 'polygon':
            case 'polyline':
                console.log(overlay[current].getLatLngs());
                overlay[current].editing.disable();
                break;
            case 'circle':
                console.log(overlay[current].getLatLng());
                console.log(overlay[current].getRadius());
                overlay[current].editing.disable();
                break;
        }
    });
    [...document.querySelectorAll('.button')].map(v=>{
        v.onclick=function (){
            overlay[current]&&overlay[current].editing.disable();
            var c=this.dataset;
            current=c['type'];
            overlay[current].editing.enable();
        }
    });


    map.on(BM.Draw.Event.EDITVERTEX,function (e){
        console.log('edit');
        console.log(e.poly);
    }).on(BM.Draw.Event.EDITMOVE,function (e){
        console.log('move');
        console.log(e.poly);
    }).on(BM.Draw.Event.EDITRESIZE,function (e){
        console.log('resize');
        console.log(e.layer);
    });
</script>
</body>
</html>