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

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

      2. 传单事件:如何传播到重叠层

        时间:2023-05-28
          <tfoot id='fHtKC'></tfoot>

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

            <legend id='fHtKC'><style id='fHtKC'><dir id='fHtKC'><q id='fHtKC'></q></dir></style></legend>

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

                  本文介绍了传单事件:如何传播到重叠层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  假设我有一些重叠的图层,每个图层都有一个点击事件.当我点击地图时,我想知道点击了哪些图层,尽管点击事件在第一层之后停止并且不会传播到其底层.我怎样才能做到这一点?

                  Let's say I have some overlapping layers and each layer has a click event. When I click on the map, I'd like to know which layers are clicked on, though the click event stops after the first layer and does not propagate to its underlying layers. How can I achieve this?

                  这是一个示例小提琴及其代码:https://jsfiddle.net/r0r0xLoc/

                  Here's a sample fiddle and its code: https://jsfiddle.net/r0r0xLoc/

                  <div id="mapid" style="width: 600px; height: 400px;"></div>
                  
                  <script>
                    var mymap = L.map('mapid').setView([51.505, -0.09], 13);
                  
                    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
                      maxZoom: 18,
                      attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
                        '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
                        'Imagery © <a href="http://mapbox.com">Mapbox</a>',
                      id: 'mapbox.streets'
                    }).addTo(mymap);
                  
                    L.polygon([
                      [51.509, -0.08],
                      [51.503, -0.06],
                      [51.51, -0.047]
                    ]).addTo(mymap).on('click', function() {
                      console.log('clicked on 1st polygon')
                    });
                  
                    L.polygon([
                      [51.609, -0.1],
                      [51.503, -0.06],
                      [51.51, -0.047]
                    ]).addTo(mymap).on('click', function() {
                      console.log('clicked on 2nd polygon')
                    });
                  
                  </script>
                  

                  如果您单击每个多边形,您会看到其相关消息.如果单击重叠部分,您只会看到第二个多边形的消息.

                  If you click on each polygon, you see its related message. If you click on the overlapping part, you only see the message for the second polygon.

                  推荐答案

                  您必须直接监听地图 "click" 事件并手动"确定哪些图层包含点击位置.

                  You have to listen directly to the map "click" event and to "manually" determine which layers contain the clicked position.

                  您可以使用 leaflet-pip 插件(点在多边形中)例如进行此确定:

                  You can use leaflet-pip plugin (point in polygon) for example for this determination:

                  map.on("click", function (event) {
                    var clickedLayers = leafletPip.pointInLayer(event.latlng, geoJSONlayerGroup);
                    // Do something with clickedLayers
                  });
                  

                  演示:https://jsfiddle.net/ve2huzxw/526/(听"mousemove" 而不是 "click")

                  Demo: https://jsfiddle.net/ve2huzxw/526/ (listening to "mousemove" instead of "click")

                  这篇关于传单事件:如何传播到重叠层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我可以防止将传单地图平移出世界边缘吗? 下一篇:如何在 180° 子午线附近显示传单标记?

                  相关文章

                  最新文章

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

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

                      <tfoot id='UOmqs'></tfoot>

                    2. <legend id='UOmqs'><style id='UOmqs'><dir id='UOmqs'><q id='UOmqs'></q></dir></style></legend>