久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

        <i id='KjDGh'><tr id='KjDGh'><dt id='KjDGh'><q id='KjDGh'><span id='KjDGh'><b id='KjDGh'><form id='KjDGh'><ins id='KjDGh'></ins><ul id='KjDGh'></ul><sub id='KjDGh'></sub></form><legend id='KjDGh'></legend><bdo id='KjDGh'><pre id='KjDGh'><center id='KjDGh'></center></pre></bdo></b><th id='KjDGh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='KjDGh'><tfoot id='KjDGh'></tfoot><dl id='KjDGh'><fieldset id='KjDGh'></fieldset></dl></div>

        如何使用 Leaflet.draw 抓取一系列標記?

        How can I grab a selection of markers with Leaflet.draw?(如何使用 Leaflet.draw 抓取一系列標記?)

          1. <tfoot id='trs8Y'></tfoot>
            • <bdo id='trs8Y'></bdo><ul id='trs8Y'></ul>

                    <tbody id='trs8Y'></tbody>
                  <legend id='trs8Y'><style id='trs8Y'><dir id='trs8Y'><q id='trs8Y'></q></dir></style></legend>
                  <i id='trs8Y'><tr id='trs8Y'><dt id='trs8Y'><q id='trs8Y'><span id='trs8Y'><b id='trs8Y'><form id='trs8Y'><ins id='trs8Y'></ins><ul id='trs8Y'></ul><sub id='trs8Y'></sub></form><legend id='trs8Y'></legend><bdo id='trs8Y'><pre id='trs8Y'><center id='trs8Y'></center></pre></bdo></b><th id='trs8Y'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='trs8Y'><tfoot id='trs8Y'></tfoot><dl id='trs8Y'><fieldset id='trs8Y'></fieldset></dl></div>

                1. <small id='trs8Y'></small><noframes id='trs8Y'>

                  本文介紹了如何使用 Leaflet.draw 抓取一系列標記?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  上下文:

                  我制作了一張地圖,并在其中填充了大約 300 個隨機標記.我可以通過單擊彈出窗口中的鏈接來選擇"標記并激活選擇以顯示數據.我還有 Leaflet.draw 插件來繪制圓形、矩形和自定義形狀等形狀,我想用它來選擇"幾個標記.

                  I've made a map, and populated it with around 300 random markers. I can 'select' the markers by clicking on a link in the popup and activate a selection to display data from. I also have the Leaflet.draw plugin to draw shapes like circles, rectangles and custom shapes, and I would like to use it to 'select' a couple of markers.

                  問題

                  如何獲取落入已繪制的 leaflet.draw 形狀內的標記的傳單標記對象,以便編輯它們?我似乎無法進行選擇,它要么不選擇任何標記,要么全部選擇.

                  How can I grab the leaflet marker object of the markers that fall inside a drawn leaflet.draw shape so I can edit them? I cannot seem to make a selection, It either selects none of the markers, or all of them.

                  代碼片段,從不必要的代碼中剝離:

                  Code snippet, stripped from unnecessary code:

                  const drawControl = new L.Control.Draw({
                      draw: {
                          marker   : false,
                          polygon  : true,
                          polyline : false,
                          rectangle: true,
                          circle   : {
                              metric: 'metric'
                          }
                      },
                      edit: false
                  });
                  
                  const map = L.map('map', {
                      layers: [streets, light]
                  }).setView([CONFIG.MAP.LATITUDE, CONFIG.MAP.LONGITUDE], CONFIG.MAP.ZOOMLEVEL)
                  
                  map.addControl(drawControl);
                  
                  map.on(L.Draw.Event.DRAWSTOP, e => {
                  
                      const hello = e.target;
                  
                      console.log(hello);
                      e.target.eachLayer(layer => {
                          if (layer.options.icon) {
                              console.log(layer);
                          }
                      });
                  
                  });
                  

                  推薦答案

                  使用 Leaflet 的實用方法可以很容易地完成大部分您想要的事情.如果你想用像 L.Polygon 這樣的復雜形狀來做到這一點,你需要像 TurfJS 這樣的東西

                  Most of what you want can quite easily be done using Leaflet's utility methods. If you want to do this with a complex shape like L.Polygon you're going to need something like TurfJS

                  對于L.Circle,您需要計算圓心之間的距離并將其與半徑進行比較:

                  For L.Circle you need to calculate the distance between the circle's center and compare it to the radius:

                  var marker = new L.Marker(...),
                      circle = new L.Circle(...);
                  
                  var contains = circle.getLatLng().distanceTo(marker.getLatLng()) < circle.getRadius();
                  

                  對于 L.Rectangle 你需要獲取它的邊界對象并使用 contains 方法:

                  For L.Rectangle you need to fetch it's bounds object and use the contains method:

                  var marker = new L.Marker(...),
                      rectangle = new L.Rectangle(...);
                  
                  var contains = rectangle.getBounds().contains(marker.getLatLng());
                  

                  正如對于復雜多邊形所說,我使用的是 Turf,但那里有更多的庫和插件.這是一個使用 Turf 的 inside 方法的示例.它采用 GeoJSON 點和多邊形特征作為參數,因此請注意轉換:

                  As said for complex polygons i'de use Turf but there are more libraries and plugins out there. Here's an example using Turf's inside method. It take a GeoJSON point and polygon feature as parameters so mind the conversion:

                  var marker = new L.Marker(...),
                      polygon = new L.Polygon(...);
                  
                  var contains = turf.inside(marker.toGeoJSON(), polygon.toGeoJSON());
                  

                  您可以將它們包裝到每個相應類的便利方法中:

                  You could wrap those into convenience methods for each respective class:

                  L.Polygon.include({
                      contains: function (latLng) {
                          return turf.inside(new L.Marker(latLng).toGeoJSON(), this.toGeoJSON());
                      } 
                  });
                  
                  L.Rectangle.include({
                      contains: function (latLng) {
                          return this.getBounds().contains(latLng);
                      }
                  });
                  
                  L.Circle.include({
                      contains: function (latLng) {
                          return this.getLatLng().distanceTo(latLng) < this.getRadius();
                      }
                  });
                  
                  var marker = new L.Marker(...),
                      polygon = new L.Polygon(...),
                      rectangle = new L.Rectangle(...),
                      circle = new L.Circle(...);
                  
                  polygon.contains(marker.getLatLng());
                  rectangle.contains(marker.getLatLng());
                  circle.contains(marker.getLatLng());
                  

                  請注意,如果您實現了多邊形方法,則不需要矩形方法.由于矩形是從多邊形擴展而來的,它將繼承該方法.我把它放在那里是為了完成.

                  Note that if you implement the polygon method that there is no need for the rectangle method. Since rectangle is extended from polygon it will inherit the method. I left it in there to be complete.

                  現在迭代你的標記并比較它們很容易:

                  Now iterating your markers and comparing them is easy:

                  map.on(L.Draw.Event.CREATED, function (e) {
                      markers.eachLayer(function (marker) {
                          if (!e.layer.contains(marker.getLatLng())) {
                              marker.remove();
                          }
                      });
                  });
                  

                  希望對您有所幫助,這是一個有效的片段:

                  Hope that helps, here's a working snippet:

                  var map = new L.Map('leaflet', {
                      'center': [0, 0],
                      'zoom': 0
                  });
                  
                  var markers = new L.LayerGroup().addTo(map);
                  
                  for (var i = 0; i < 300; i++) {
                      var marker = new L.Marker([
                          (Math.random() * (90 - -90) + -90).toFixed(5) * 1,
                          (Math.random() * (180 - -180) + -180).toFixed(5) * 1
                      ]).addTo(markers);
                  }
                  
                  new L.Control.Draw({
                      draw: {
                          marker   : false,
                          polygon  : true,
                          polyline : false,
                          rectangle: true,
                          circle   : {
                              metric: 'metric'
                          }
                      },
                      edit: false
                  }).addTo(map);
                  
                  L.Polygon.include({
                      contains: function (latLng) {
                          return turf.inside(new L.Marker(latLng).toGeoJSON(), this.toGeoJSON());
                      } 
                  });
                  
                  L.Rectangle.include({
                      contains: function (latLng) {
                          return this.getBounds().contains(latLng);
                      }
                  });
                  
                  L.Circle.include({
                      contains: function (latLng) {
                          return this.getLatLng().distanceTo(latLng) < this.getRadius();
                      }
                  });
                  
                  map.on(L.Draw.Event.CREATED, function (e) {
                      markers.eachLayer(function (marker) {
                          if (!e.layer.contains(marker.getLatLng())) {
                              marker.remove();
                          }
                      });
                  });

                  body {
                      margin: 0;
                  }
                  
                  html, body, #leaflet {
                      height: 100%;
                  }

                  <!DOCTYPE html>
                  <html>
                    <head>
                      <title>Leaflet 1.0.3</title>
                      <meta charset="utf-8" />
                      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                      <link type="text/css" rel="stylesheet"  />
                      <link type="text/css" rel="stylesheet"  />
                    </head>
                    <body>
                      <div id="leaflet"></div>
                      <script type="application/javascript" src="http://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
                      <script type="application/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.9/leaflet.draw.js"></script>
                      <script type="application/javascript" src="http://unpkg.com/@turf/turf@latest/turf.min.js"></script>
                    </body>
                  </html>

                  這篇關于如何使用 Leaflet.draw 抓取一系列標記?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                  Trigger click on leaflet marker(觸發點擊傳單標記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                  Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)
                  <legend id='Gg0cr'><style id='Gg0cr'><dir id='Gg0cr'><q id='Gg0cr'></q></dir></style></legend>

                    <bdo id='Gg0cr'></bdo><ul id='Gg0cr'></ul>
                          <i id='Gg0cr'><tr id='Gg0cr'><dt id='Gg0cr'><q id='Gg0cr'><span id='Gg0cr'><b id='Gg0cr'><form id='Gg0cr'><ins id='Gg0cr'></ins><ul id='Gg0cr'></ul><sub id='Gg0cr'></sub></form><legend id='Gg0cr'></legend><bdo id='Gg0cr'><pre id='Gg0cr'><center id='Gg0cr'></center></pre></bdo></b><th id='Gg0cr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Gg0cr'><tfoot id='Gg0cr'></tfoot><dl id='Gg0cr'><fieldset id='Gg0cr'></fieldset></dl></div>

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

                          • <tfoot id='Gg0cr'></tfoot>

                              <tbody id='Gg0cr'></tbody>
                            主站蜘蛛池模板: 国产精品福利视频 | 久婷婷 | 日韩少妇视频 | 一区二区中文 | 一级片欧美 | 在线观看的av | 精产国产伦理一二三区 | 国产精品久久久久久久 | 欧美精品系列 | 日韩免费观看 | 国产伦精品一区二区 | 精品一区二区三区中文字幕 | 欧美黄网站| 久久99久久久 | 国产精品国产三级国产 | 亚洲国产精品一区二区三区 | 亚洲视频一区二区三区 | 国产激情一区二区三区 | 国产午夜免费视频 | av入口| 一级理论片 | 欧美 日韩 国产 成人 在线 | 日韩毛片在线观看 | 欧美久久网 | 国产精品一区二区三区四区五区 | 亚洲精品一区二区三 | 91黄色免费视频 | 午夜亚洲精品 | 国产午夜精品一区二区三区嫩草 | 国产一区二区精品丝袜 | 51成人网 | 国产高清一区二区三区 | 午夜无遮挡| 波多野结衣视频一区 | 国产成人免费观看 | 国产在线一 | 免费特级毛片 | www.麻豆av | 欧美一级在线观看 | 欧美在线亚洲 | 色综合视频在线观看 |