<legend id='3wBdP'><style id='3wBdP'><dir id='3wBdP'><q id='3wBdP'></q></dir></style></legend>

  • <small id='3wBdP'></small><noframes id='3wBdP'>

    • <bdo id='3wBdP'></bdo><ul id='3wBdP'></ul>
    <i id='3wBdP'><tr id='3wBdP'><dt id='3wBdP'><q id='3wBdP'><span id='3wBdP'><b id='3wBdP'><form id='3wBdP'><ins id='3wBdP'></ins><ul id='3wBdP'></ul><sub id='3wBdP'></sub></form><legend id='3wBdP'></legend><bdo id='3wBdP'><pre id='3wBdP'><center id='3wBdP'></center></pre></bdo></b><th id='3wBdP'></th></span></q></dt></tr></i><div id='3wBdP'><tfoot id='3wBdP'></tfoot><dl id='3wBdP'><fieldset id='3wBdP'></fieldset></dl></div>

        <tfoot id='3wBdP'></tfoot>
      1. 在 Leaflet L.Draw 插件中以编程方式添加多边形

        时间:2023-08-09
        <legend id='76uxD'><style id='76uxD'><dir id='76uxD'><q id='76uxD'></q></dir></style></legend>

          1. <tfoot id='76uxD'></tfoot>
            <i id='76uxD'><tr id='76uxD'><dt id='76uxD'><q id='76uxD'><span id='76uxD'><b id='76uxD'><form id='76uxD'><ins id='76uxD'></ins><ul id='76uxD'></ul><sub id='76uxD'></sub></form><legend id='76uxD'></legend><bdo id='76uxD'><pre id='76uxD'><center id='76uxD'></center></pre></bdo></b><th id='76uxD'></th></span></q></dt></tr></i><div id='76uxD'><tfoot id='76uxD'></tfoot><dl id='76uxD'><fieldset id='76uxD'></fieldset></dl></div>

            <small id='76uxD'></small><noframes id='76uxD'>

                <tbody id='76uxD'></tbody>
                  <bdo id='76uxD'></bdo><ul id='76uxD'></ul>
                  本文介绍了在 Leaflet L.Draw 插件中以编程方式添加多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  有没有办法使用 Leaflet 绘图插件以编程方式添加多边形?https://github.com/Leaflet/Leaflet.draw

                  Is there a way to add a polygon programmatically using the Leaflet draw plugin? https://github.com/Leaflet/Leaflet.draw

                  例如:点击一个按钮,添加一个可以被插件编辑的方块.

                  For example: click a button and add a square that can be edited by the plugin.

                  推荐答案

                  您只需将多边形(或任何其他您希望可编辑的图层)添加到您传递给 edit.featureGroup 您的 L.Control.Draw 控件.

                  You just need to add your polygon (or whatever other layer that you want to be editable) to the Feature Group that you pass to the edit.featureGroup option of your L.Control.Draw control.

                  var editableLayers = L.featureGroup().addTo(map);
                  var drawControl = new L.Control.Draw({
                    edit: {
                      featureGroup: editableLayers
                    }
                  });
                  
                  // Add a new editable rectangle when clicking on the button.
                  button.addEventListener('click', function (event) {
                    event.preventDefault();
                  
                    L.rectangle([
                      getRandomLatLng(),
                      getRandomLatLng()
                    ]).addTo(editableLayers); // Add to editableLayers instead of directly to map.
                  });
                  

                  稍后可以通过单击编辑图层"按钮来编辑该功能组中的所有内容(如果启用了该功能).

                  Everything that is in that Feature Group can later be edited by clicking on the "Edit layers" button (if that functionality is enabled).

                  现场演示:

                  var map = L.map('map').setView([48.86, 2.35], 11);
                  
                  var editableLayers = L.featureGroup().addTo(map);
                  var drawControl = new L.Control.Draw({
                    edit: {
                      featureGroup: editableLayers
                    },
                    draw: false
                  }).addTo(map);
                  
                  // Add a new editable rectangle when clicking on the button.
                  button.addEventListener('click', function(event) {
                    event.preventDefault();
                  
                    L.rectangle([
                      getRandomLatLng(),
                      getRandomLatLng()
                    ]).addTo(editableLayers); // Add to editableLayers instead of directly to map.
                  });
                  
                  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                  }).addTo(map);
                  
                  function getRandomLatLng() {
                    return [
                      48.8 + 0.1 * Math.random(),
                      2.25 + 0.2 * Math.random()
                    ];
                  }

                  html,
                  body,
                  #map {
                    height: 100%;
                    margin: 0;
                  }
                  
                  #button {
                    z-index: 1050;
                    position: absolute;
                    top: 10px;
                    left: 50px;
                  }

                  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin="" />
                  <script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet-src.js" integrity="sha512-+ZaXMZ7sjFMiCigvm8WjllFy6g3aou3+GZngAtugLzrmPFKFK7yjSri0XnElvCTu/PrifAYQuxZTybAEkA8VOA==" crossorigin=""></script>
                  
                  <link rel="stylesheet" href="https://unpkg.com/leaflet-draw@1.0.2/dist/leaflet.draw.
                  css" />
                  <script src="https://unpkg.com/leaflet-draw@1.0.2/dist/leaflet.draw-src.js"></script>
                  
                  <div id="map"></div>
                  
                  <button id="button">Add editable rectangle</button>

                  这篇关于在 Leaflet L.Draw 插件中以编程方式添加多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何旋转leaflet.js 地图 下一篇:单击 Leaflet 中的标记时,如何防止显示弹出窗口

                  相关文章

                  最新文章

                  1. <i id='VRa4F'><tr id='VRa4F'><dt id='VRa4F'><q id='VRa4F'><span id='VRa4F'><b id='VRa4F'><form id='VRa4F'><ins id='VRa4F'></ins><ul id='VRa4F'></ul><sub id='VRa4F'></sub></form><legend id='VRa4F'></legend><bdo id='VRa4F'><pre id='VRa4F'><center id='VRa4F'></center></pre></bdo></b><th id='VRa4F'></th></span></q></dt></tr></i><div id='VRa4F'><tfoot id='VRa4F'></tfoot><dl id='VRa4F'><fieldset id='VRa4F'></fieldset></dl></div>

                      • <bdo id='VRa4F'></bdo><ul id='VRa4F'></ul>
                    1. <tfoot id='VRa4F'></tfoot>
                      <legend id='VRa4F'><style id='VRa4F'><dir id='VRa4F'><q id='VRa4F'></q></dir></style></legend>

                      <small id='VRa4F'></small><noframes id='VRa4F'>