久久久久久久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 抓取一系列標(biāo)記?

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

          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 抓取一系列標(biāo)記?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  上下文:

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

                  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.

                  問(wèn)題

                  如何獲取落入已繪制的 leaflet.draw 形狀內(nèi)的標(biāo)記的傳單標(biāo)記對(duì)象,以便編輯它們?我似乎無(wú)法進(jìn)行選擇,它要么不選擇任何標(biāo)記,要么全部選擇.

                  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 的實(shí)用方法可以很容易地完成大部分您想要的事情.如果你想用像 L.Polygon 這樣的復(fù)雜形狀來(lái)做到這一點(diǎn),你需要像 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

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

                  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();
                  

                  對(duì)于 L.Rectangle 你需要獲取它的邊界對(duì)象并使用 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());
                  

                  正如對(duì)于復(fù)雜多邊形所說(shuō),我使用的是 Turf,但那里有更多的庫(kù)和插件.這是一個(gè)使用 Turf 的 inside 方法的示例.它采用 GeoJSON 點(diǎn)和多邊形特征作為參數(shù),因此請(qǐng)注意轉(zhuǎn)換:

                  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());
                  

                  您可以將它們包裝到每個(gè)相應(yīng)類的便利方法中:

                  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());
                  

                  請(qǐng)注意,如果您實(shí)現(xiàn)了多邊形方法,則不需要矩形方法.由于矩形是從多邊形擴(kuò)展而來(lái)的,它將繼承該方法.我把它放在那里是為了完成.

                  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.

                  現(xiàn)在迭代你的標(biāo)記并比較它們很容易:

                  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();
                          }
                      });
                  });
                  

                  希望對(duì)您有所幫助,這是一個(gè)有效的片段:

                  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>

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

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

                  相關(guān)文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個(gè)多邊形點(diǎn)是否在傳單中的另一個(gè)內(nèi)部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標(biāo)記群集圖標(biāo)顏色,繼承其余默認(rèn) CSS 屬性)
                  Trigger click on leaflet marker(觸發(fā)點(diǎn)擊傳單標(biāo)記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認(rèn)加載磁貼顏色?)
                  Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側(cè)邊欄)
                  <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>
                            主站蜘蛛池模板: 欧美一区二区三区在线 | 欧美黄在线观看 | 97人人澡人人爽91综合色 | 成人影音| 免费成人av网站 | 欧美中文字幕一区 | 淫片专区| 日韩理论电影在线观看 | av中文在线 | 可以在线看的黄色网址 | 国产区在线 | a在线观看 | 国产精品一区二区欧美 | 成人欧美 | 欧美精品一区二区三区在线播放 | 日本免费在线 | 久久青视频| 亚洲成人一区二区 | 亚洲精品女优 | 亚洲欧美日韩在线不卡 | 日韩福利在线 | 久久丁香 | 成人三级网址 | 美女视频h | 欧美三区 | 日韩精品极品视频在线观看免费 | 国产精品乱码一区二区三区 | 日韩精品一区二区在线观看 | 2018天天干天天操 | 日韩av在线中文字幕 | 久久精品中文 | 国产精品免费大片 | 久久精品一区二区三区四区 | 免费黄色大片 | 欧美视频一区二区三区 | 久久综合香蕉 | 精品国产免费人成在线观看 | 成年人在线播放 | jizz在线看片 | 欧美成人h版在线观看 | 亚洲一区久久久 |