【问题标题】:unable to dispaly polygon on the map using Leaflet draw plugin无法使用 Leaflet draw 插件在地图上显示多边形
【发布时间】:2017-04-22 01:37:01
【问题描述】:

我正在尝试从这里使用绘图插件http://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw

并尝试在本地使用它,如下所示

<html>
<head>

    <title>A Leaflet map!</title>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"/>
    <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.css"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.js"></script>
    <style>
        #map{ height: 100% }
    </style>
</head>
<body>

<div id="map"></div>

<script>

    var map = L.map('map').setView([51.505, -0.09], 13);
    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);

   var  drawControl = new L.Control.Draw({
        draw : {
            position : 'topleft',
            polygon : true,
            polyline : false,
            rectangle : true,
            circle : false

        },
        edit : false
    });

    map.addControl(drawControl);

</script>
</body>
</html>

我正在获取绘图控件和地图,但绘制完成后不显示多边形绘图不知道该怎么做

请帮助在地图上绘制多边形,如本演示所示

http://leaflet.github.io/Leaflet.draw/docs/examples/full.html

【问题讨论】:

    标签: leaflet display polygons leaflet.draw


    【解决方案1】:

    您必须创建一个要素组并在创建图层时添加它们...

       var drawnItems = L.featureGroup().addTo(map);
    
       map.on(L.Draw.Event.CREATED, function (event) {
            var layer = event.layer;
    
            drawnItems.addLayer(layer);
        });
    

    查看http://leaflet.github.io/Leaflet.draw/docs/examples/full.html的来源

    【讨论】:

    • 你能指出一些例子,我可以得到绘制的多边形的坐标和其他操作
    • Draw 插件正在创建此处记录的图层:leafletjs.com/reference.html。因此,当调用 Draw.Event.CREATED 时,您可以从图层中获取所有值。例如,如果您绘制一个矩形,它将是leafletjs.com/reference.html#rectangle
    猜你喜欢
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多