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="https://cdn.bootcss.com/Buttons/2.0.0/css/buttons.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="/Public/mouse_draw/Bigemap.draw.css"/>
    <script src="/Public/mouse_draw/Bigemap.draw.js"></script>
    <script src="/Public/mouse_draw/Bigemap.Draw.Event.js"></script>
    
    <script src="/Public/mouse_draw/draw/handler/Draw.Feature.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.Polyline.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.Polygon.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.SimpleShape.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.Rectangle.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.Circle.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.Marker.js"></script>
    <script src="/Public/mouse_draw/draw/handler/Draw.CircleMarker.js"></script>

    <script src="/Public/mouse_draw/edit/handler/Edit.Poly.js"></script>
    <script src="/Public/mouse_draw/edit/handler/Edit.SimpleShape.js"></script>
    <script src="/Public/mouse_draw/edit/handler/Edit.Rectangle.js"></script>
    <script src="/Public/mouse_draw/edit/handler/Edit.Marker.js"></script>
    <script src="/Public/mouse_draw/edit/handler/Edit.CircleMarker.js"></script>
    <script src="/Public/mouse_draw/edit/handler/Edit.Circle.js"></script>



    <script src="/Public/mouse_draw/ext/TouchEvents.js"></script>
    <script src="/Public/mouse_draw/ext/LatLngUtil.js"></script>
    <script src="/Public/mouse_draw/ext/GeometryUtil.js"></script>
    <script src="/Public/mouse_draw/ext/LineUtil.Intersect.js"></script>
    <script src="/Public/mouse_draw/ext/Polyline.Intersect.js"></script>
    <script src="/Public/mouse_draw/ext/Polygon.Intersect.js"></script>

    <script src="/Public/mouse_draw/Control.Draw.js"></script>
    <script src="/Public/mouse_draw/Tooltip.js"></script>
    <script src="/Public/mouse_draw/Toolbar.js"></script>

    <script src="/Public/mouse_draw/draw/DrawToolbar.js"></script>
    <script src="/Public/mouse_draw/edit/EditToolbar.js"></script>
    <script src="/Public/mouse_draw/edit/handler/EditToolbar.Edit.js"></script>
    <script src="/Public/mouse_draw/edit/handler/EditToolbar.Delete.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_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>
<button id="edit_line" class="button button-tiny button-rounded button-primary">编辑线段</button>
<button id="edit_poly" class="button button-tiny button-rounded button-primary">编辑多边形</button>
<div id="map">

</div>
<script>
    BM.Config.HTTP_URL = 'http://www.bigemap.com:9000';

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

    var 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}
    ]);
    polyline.addTo(map);
    
        var 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}
    ]);
    polygon.addTo(map);
    map.on('contextmenu',function (e) {
        //停止编辑。这里可以进行保存数据库的操作
        console.log(polyline.getLatLngs());
        console.log(polygon.getLatLngs());
        polyline.editing.disable();
        polygon.editing.disable();
    });
    
    document.querySelector('#edit_line').onclick=function () {
        polyline.editing.enable();
    }
    document.querySelector('#edit_poly').onclick=function () {
        polygon.editing.enable();
    }
</script>
</body>
</html>