pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    • <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="v7z37lt" 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="5vz7nxl" 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="tx5flld" 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>
                            主站蜘蛛池模板: 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 微型气象仪_气象传感器_防爆气象传感器-天合传感器大全 | 学叉车培训|叉车证报名|叉车查询|叉车证怎么考-工程机械培训网 | 顶呱呱交易平台-行业领先的公司资产交易服务平台 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 引领中高档酒店加盟_含舍·美素酒店品牌官网 | 水平垂直燃烧试验仪-灼热丝试验仪-漏电起痕试验仪-针焰试验仪-塑料材料燃烧检测设备-IP防水试验机 | 菏泽商标注册_菏泽版权登记_商标申请代理_菏泽商标注册去哪里 | 电液推杆生产厂家|电动推杆|液压推杆-扬州唯升机械有限公司 | FFU_空气初效|中效|高效过滤器_空调过滤网-广州梓净净化设备有限公司 | 乙炔气体报警装置|固定式氯化氢检测仪|河南驰诚电气百科 | 广东泵阀展|阀门展-广东国际泵管阀展览会 | 家德利门业,家居安全门,别墅大门 - 安徽家德利门业有限公司 | 骁龙云呼电销防封号系统-axb电销平台-外呼稳定『免费试用』 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 据信,上课带着跳 D 体验-别样的课堂刺激感受引发网友热议 | 厦门ISO认证|厦门ISO9001认证|厦门ISO14001认证|厦门ISO45001认证-艾索咨询专注ISO认证行业 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 刚性-柔性防水套管-橡胶伸缩接头-波纹管补偿器-启腾供水材料有限公司 | 生鲜配送系统-蔬菜食材配送管理系统-连锁餐饮订货配送软件-挪挪生鲜供应链管理软件 | 纸塑分离机-纸塑分离清洗机设备-压力筛-碎浆机厂家金双联环保 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 飞歌臭氧发生器厂家_水处理臭氧发生器_十大臭氧消毒机品牌 | 高效节能电机_伺服主轴电机_铜转子电机_交流感应伺服电机_图片_型号_江苏智马科技有限公司 | 日本细胞免疫疗法_肿瘤免疫治疗_NK细胞疗法 - 免疫密码 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 油液红外光谱仪-油液监测系统-燃油嗅探仪-上海冉超光电科技有限公司 | 玄米影院| 山东活动策划|济南活动公司|济南公关活动策划-济南锐嘉广告有限公司 | 精益专家 - 设备管理软件|HSE管理系统|设备管理系统|EHS安全管理系统 | 茅茅虫AI论文写作助手-免费AIGC论文查重_写毕业论文降重 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | Magnescale探规,Magnescale磁栅尺,Magnescale传感器,Magnescale测厚仪,Mitutoyo光栅尺,笔式位移传感器-苏州连达精密量仪有限公司 | 防火卷帘门价格-聊城一维工贸特级防火卷帘门厂家▲ | 粘度计NDJ-5S,粘度计NDJ-8S,越平水分测定仪-上海右一仪器有限公司 | 网站seo优化_seo云优化_搜索引擎seo_启新网络服务中心 | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 气力输送设备_料封泵_仓泵_散装机_气化板_压力释放阀-河南锐驰机械设备有限公司 | 对夹式止回阀厂家,温州对夹式止回阀制造商--永嘉县润丰阀门有限公司 |