• <bdo id='IOw9k'></bdo><ul id='IOw9k'></ul>
        <tfoot id='IOw9k'></tfoot>

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

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

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

        使传单工具提示可点击

        时间:2023-08-08

          <legend id='67iRg'><style id='67iRg'><dir id='67iRg'><q id='67iRg'></q></dir></style></legend>
            <tfoot id='67iRg'></tfoot>

            <small id='67iRg'></small><noframes id='67iRg'>

              <tbody id='67iRg'></tbody>
              <bdo id='67iRg'></bdo><ul id='67iRg'></ul>
                1. <i id='67iRg'><tr id='67iRg'><dt id='67iRg'><q id='67iRg'><span id='67iRg'><b id='67iRg'><form id='67iRg'><ins id='67iRg'></ins><ul id='67iRg'></ul><sub id='67iRg'></sub></form><legend id='67iRg'></legend><bdo id='67iRg'><pre id='67iRg'><center id='67iRg'></center></pre></bdo></b><th id='67iRg'></th></span></q></dt></tr></i><div id='67iRg'><tfoot id='67iRg'></tfoot><dl id='67iRg'><fieldset id='67iRg'></fieldset></dl></div>
                  本文介绍了使传单工具提示可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在 Leaflet 地图(不带标记)上添加 工具提示 并使其可点击.以下代码添加了一个工具提示,但它不可点击:

                  I want to add tooltips on a Leaflet map (without markers) and make them clickable. The following code adds a tooltip but it's not clickable:

                  var tooltip = L.tooltip({
                          direction: 'center',
                          permanent: true,
                          interactive: true,
                          noWrap: true,
                          opacity: 0.9
                      });
                  tooltip.setContent( "Example" );
                  tooltip.setLatLng(new L.LatLng(someLat, someLon));
                  tooltip.addTo(myLayer);
                  tooltip.on('click', function(event) {
                      console.log("Click!");
                  });
                  

                  我怎样才能让它工作?

                  推荐答案

                  要接收对 L.Tooltip 对象的点击,您需要:

                  To receive clicks on a L.Tooltip object, you'll need to :

                  • 在关联的 DOM 对象上设置监听器:

                  • set up a listener on the associated DOM object :

                  var el = tooltip.getElement();
                  el.addEventListener('click', function() {
                     console.log("click");
                  });
                  

                2. 删除 pointer-events: none 在该元素上设置的属性:

                3. remove the pointer-events: none property set on that element:

                  var el = tooltip.getElement();
                  el.style.pointerEvents = 'auto';
                  

                4. 到目前为止的演示

                  var map = L.map(document.getElementById('map')).setView([48.8583736, 2.2922926], 4);
                  L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                  }).addTo(map);
                  
                  var tooltip = L.tooltip({
                      direction: 'center',
                      permanent: true,
                      interactive: true,
                      noWrap: true,
                      opacity: 0.9
                  });
                  tooltip.setContent( "Example" );
                  tooltip.setLatLng(new L.LatLng(48.8583736, 2.2922926));
                  tooltip.addTo(map);
                  
                  var el = tooltip.getElement();
                  el.addEventListener('click', function() {
                      console.log("click");
                  });
                  el.style.pointerEvents = 'auto';

                  html, body {
                    height: 100%;
                    margin: 0;
                  }
                  #map {
                    width: 100%;
                    height: 180px;
                  }

                  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.css"/>
                  <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script>
                     
                  <div id='map'></div>

                  如果您想创建组件或直接监听工具提示对象,您可以扩展 L.Tooltip 以将这些更改直接烘焙到定义中:

                  If you want to create a component or listen directly to a tooltip object, you can extend L.Tooltip to bake those alterations directly into the definition:

                  L.ClickableTooltip = L.Tooltip.extend({
                      onAdd: function (map) {
                          L.Tooltip.prototype.onAdd.call(this, map);
                  
                          var el = this.getElement(),
                              self = this;
                  
                          el.addEventListener('click', function() {
                              self.fire("click");
                          });
                          el.style.pointerEvents = 'auto';
                      }
                  });
                  
                  var tooltip = new L.ClickableTooltip({
                      direction: 'center',
                      permanent: true,
                      noWrap: true,
                      opacity: 0.9
                  });
                  tooltip.setContent( "Example" );
                  tooltip.setLatLng(new L.LatLng(48.8583736, 2.2922926));
                  tooltip.addTo(map);
                  
                  tooltip.on('click', function(e) {
                      console.log("clicked", JSON.stringify(e.target.getLatLng()));
                  });
                  

                  还有一个演示

                  L.ClickableTooltip = L.Tooltip.extend({
                  
                      onAdd: function (map) {
                          L.Tooltip.prototype.onAdd.call(this, map);
                  
                          var el = this.getElement(),
                              self = this;
                  
                          el.addEventListener('click', function() {
                              self.fire("click");
                          });
                          el.style.pointerEvents = 'auto';
                      }
                  });
                  
                  
                  var map = L.map(document.getElementById('map')).setView([48.8583736, 2.2922926], 4);
                  L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                  }).addTo(map);
                  
                  var tooltip = new L.ClickableTooltip({
                      direction: 'center',
                      permanent: true,
                      noWrap: true,
                      opacity: 0.9
                  });
                  tooltip.setContent( "Example" );
                  tooltip.setLatLng(new L.LatLng(48.8583736, 2.2922926));
                  tooltip.addTo(map);
                  
                  tooltip.on('click', function(e) {
                      console.log("clicked", JSON.stringify(e.target.getLatLng()));
                  });

                  html, body {
                    height: 100%;
                    margin: 0;
                  }
                  #map {
                    width: 100%;
                    height: 180px;
                  }

                  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.css"/>
                  <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script>
                     
                  <div id='map'></div>

                  这篇关于使传单工具提示可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:传单圆圈绘图/编辑问题 下一篇:如何包含“leaflet.css"在带有 webpack 的 React 应

                  相关文章

                  最新文章

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

                      <bdo id='r0gRC'></bdo><ul id='r0gRC'></ul>

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

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