<tfoot id='WZoX6'></tfoot>

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

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

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

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

      在 Leaflet 弹出窗口中添加按钮

      时间:2023-08-09
      • <bdo id='bGoMv'></bdo><ul id='bGoMv'></ul>

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

                  <tbody id='bGoMv'></tbody>
                <legend id='bGoMv'><style id='bGoMv'><dir id='bGoMv'><q id='bGoMv'></q></dir></style></legend>

                本文介绍了在 Leaflet 弹出窗口中添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                当我尝试在 Leaflet 弹出窗口中添加按钮时遇到问题.单击地图时会生成弹出窗口.

                I got a problem when I try to add buttons inside a Leaflet popup. The popup is generated when you click on the map.

                理想情况下,我想弹出 2 个按钮:

                Ideally I want to popuo to show 2 buttons:

                • 从这里开始
                • 然后去这个位置

                这个草图是我想要的结果的一个例子:

                This sketch is an example of the result I want:

                 ________________________________________________
                |You clicked the map at LatLng(XXXXX,XXXXX)      |
                |  ---------------    -------------------        |
                | |Start from here|  |Go to this location|       |
                |  ---------------    -------------------        |
                |___________________  ___________________________|
                                   /
                

                这是我在弹出窗口中看到的内容:您在 LatLng(XXXXX,XXXX) [object HTMLButtonElement] 处单击了地图

                this is what I get inside my popUp : You clicked the map at LatLng(XXXXX,XXXX) [object HTMLButtonElement]

                我正在尝试使用 L.domUtil 创建按钮

                I am trying to create the buttons using L.domUtil

                defineYourWaypointOnClick(e: any) {
                
                var choicePopUp = L.popup();
                var container = L.DomUtil.create('div'),
                  startBtn = this.createButton('Start from this location', container),
                  destBtn = this.createButton('Go to this location', container);
                
                choicePopUp
                  .setLatLng(e.latlng)
                  .setContent('You clicked the map at ' + e.latlng.toString() + '<br>' + startBtn)
                  .openOn(this.map);
                
                L.DomEvent.on(startBtn, 'click', () => {
                  alert("toto");
                });
                
                L.DomEvent.on(destBtn, 'click', () => {
                  alert("tata");
                });
                }
                
                createButton(label: string, container: any) {
                    var btn = L.DomUtil.create('button', '', container);
                    btn.setAttribute('type', 'button');
                    btn.innerHTML = label;
                    return btn;
                }
                

                我从这里调用我的方法:

                I call my method from here :

                this.map.on('click', (e: any) => {
                  this.defineYourWaypointOnClick(e);
                });
                

                提前感谢您能给我的任何帮助:)

                Thank you in advance for any help you can give me :)

                推荐答案

                您应该使用 innerHTML 向您的传单添加按钮,如下所示

                You should be using innerHTML to add buttons to your leaflet as below

                defineYourWaypointOnClick(e: any) {
                
                var choicePopUp = L.popup();
                var container = L.DomUtil.create('div');
                //////////////////////////////////////////////////////////////////////////////////////////////
                ///////////modified here
                startBtn = this.createButton('Start from this location', container),
                destBtn = this.createButton('Go to this location', container);
                div.innerHTML = ''+startBtn+ '&nbsp;&nbsp;&nbsp;&nbsp;' + destBtn ; 
                //////////////////////////////////////////////////////////////////////////////////////////////
                
                choicePopUp
                  .setLatLng(e.latlng)
                  .setContent('You clicked the map at ' + e.latlng.toString() + '<br>' + startBtn)
                  .openOn(this.map);
                
                L.DomEvent.on(startBtn, 'click', () => {
                  alert("toto");
                });
                
                L.DomEvent.on(destBtn, 'click', () => {
                  alert("tata");
                });
                }
                
                createButton(label: string, container: any) {
                var btn = L.DomUtil.create('button', '', container);
                btn.setAttribute('type', 'button');
                btn.innerHTML = label;
                return btn;
                }
                

                这篇关于在 Leaflet 弹出窗口中添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 Leaflet 中显示超出特定缩放级别的标签? 下一篇:单击传单标记会将您带到 URL

                相关文章

                最新文章

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

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

                    <bdo id='vWHcd'></bdo><ul id='vWHcd'></ul>
                  <tfoot id='vWHcd'></tfoot>
                  <legend id='vWHcd'><style id='vWHcd'><dir id='vWHcd'><q id='vWHcd'></q></dir></style></legend>