• <bdo id='on9Mq'></bdo><ul id='on9Mq'></ul>

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

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

    2. 传单在按钮单击时打开特定标记弹出窗口

      时间:2023-08-08
    3. <small id='5eASh'></small><noframes id='5eASh'>

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

                  <tbody id='5eASh'></tbody>
                <legend id='5eASh'><style id='5eASh'><dir id='5eASh'><q id='5eASh'></q></dir></style></legend>

              • 本文介绍了传单在按钮单击时打开特定标记弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试在某些事件(例如,按钮单击)上打开特定标记的弹出窗口.为此,我将 id 属性添加到标记并将所有标记存储在数组中.但是由于某种原因,当我尝试访问数组内的标记的 id 属性时,它是未定义的.

                I'm trying to open a specific marker's popup on some event(say, button click). In order to do so I add an id property to a marker and store all markers in an array. But for some reason, the id property of a marker inside of an array is undefined when I try to access it.

                var map = L.map('map').setView([51.505, -0.09], 13);
                var markers = [];
                var marker = L.marker([51.5, -0.09]);
                marker["id"]="0";
                marker.bindPopup('!');
                marker.addTo(map);
                markers.push(marker);
                
                openPopupById("0");
                
                function openPopupById(id) {
                    for(var marker in markers) {
                        alert("Marker's id " + marker["id"] + " target id " + id );
                        if (marker["id"] === id) {
                            //marker.openPopup();
                            alert("opening " + id);
                        }
                    }
                    alert(id);
                }
                

                更新好的,我找到了解决方案:我应该将 for 替换为

                UPDATE Ok, I found the solution: I should replace for with

                for(var i = 0; i < markers.length; ++i)
                

                并以 markers[i]["id"]

                但是谁能解释一下为什么第一个版本不起作用?

                But can someone explain me why the first version doesn't work?

                推荐答案

                我认为你的错误是使用push(在markers.push(marker)中)

                I think your mistake is the use of push (in markers.push(marker))

                要存储标记,您应该使用

                To store the markers, you should use

                markers["id"] = marker;
                

                你可以这样打开你的弹出窗口

                You can open your popup like that

                markers["id"].openPopup();
                

                让标记知道他们的 id

                For the markers to know their id

                marker.id = "id";
                

                这篇关于传单在按钮单击时打开特定标记弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将谷歌折线图放在传单弹出窗口中 下一篇:Leaflet js:如何在地图上绘制任何标记结束时获取

                相关文章

                最新文章

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

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

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

                  <tfoot id='yPKIO'></tfoot>
                    <legend id='yPKIO'><style id='yPKIO'><dir id='yPKIO'><q id='yPKIO'></q></dir></style></legend>