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

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

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

    2. Leaflet.js - 点击时设置标记,拖动时更新位置

      时间:2023-08-09

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

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

              <bdo id='nuBw3'></bdo><ul id='nuBw3'></ul>
              <tfoot id='nuBw3'></tfoot>
              • 本文介绍了Leaflet.js - 点击时设置标记,拖动时更新位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                对于我正在处理的一个小项目,我需要能够在 Leaflet.js 驱动的图像地图上放置一个标记,并在它被拖动时更新该标记的位置.我使用下面的代码来尝试这个,但它失败了.我收到错误未定义标记".我不知道为什么它不起作用 - 也许你们可以帮助我?;)

                for a small project I am working on, I need to be able to place a marker on a leaflet.js powered image-map and update the position of this marker, if it gets dragged. I use the following code to try this, but it fails. I get the error 'marker not defined'. I don't know why it's not working - maybe you guys could help me out? ;)

                function onMapClick(e) {
                    gib_uni();
                    marker = new L.marker(e.latlng, {id:uni, icon:redIcon, draggable:'true'};
                    map.addLayer(marker);
                };
                
                marker.on('dragend', function(event){
                    var marker = event.target;
                    var position = marker.getLatLng();
                    alert(position);
                    marker.setLatLng([position],{id:uni,draggable:'true'}).bindPopup(position).update();
                });
                

                推荐答案

                在上面的代码片段中,在添加事件处理程序时没有定义标记.在创建标记后立即添加 dragend 侦听器,请尝试以下操作:

                In the code snippet above, marker is not defined at the time the event handler is added. Try the following where the dragend listener is added immediately following the creation of the Marker:

                function onMapClick(e) {
                    gib_uni();
                    marker = new L.marker(e.latlng, {id:uni, icon:redIcon, draggable:'true'});
                    marker.on('dragend', function(event){
                            var marker = event.target;
                            var position = marker.getLatLng();
                            console.log(position);
                            marker.setLatLng(position,{id:uni,draggable:'true'}).bindPopup(position).update();
                    });
                    map.addLayer(marker);
                };
                

                您的新 L.Marker() 行末尾还缺少一个括号.

                You were also missing a bracket at the end of your new L.Marker() line.

                您还在 setLatLng 调用中将 position 放入了一个数组中,但它已经是一个 LatLng 对象.

                You also put position into an array in the call to setLatLng but it is already a LatLng object.

                这篇关于Leaflet.js - 点击时设置标记,拖动时更新位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在传单中批量添加标记? 下一篇:在 Leaflet 中获取当前地图范围内的标记/图层列表

                相关文章

                最新文章

                <small id='5gH73'></small><noframes id='5gH73'>

              • <legend id='5gH73'><style id='5gH73'><dir id='5gH73'><q id='5gH73'></q></dir></style></legend>
                  <bdo id='5gH73'></bdo><ul id='5gH73'></ul>

                  <tfoot id='5gH73'></tfoot>

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