Leaflet,panTo点击链接时的地图位置?(Leaflet, panTo map location when link is clicked?)

编程入门 行业动态 更新时间:2024-10-27 04:33:04
Leaflet,panTo点击链接时的地图位置?(Leaflet, panTo map location when link is clicked?)

有谁知道传单? 我试图创建一个功能,你点击链接,地图转到一个位置。 我尝试将点域值置于“值” - 属性下面,如下所示:

<a href="#" class="marker" value="{{ mymodel.pt }}">Link</a>

然后我想做这样的事情,但它不起作用:

$("#dialog").on("click", ".marker", function(e) { e.preventDefault(); map.panTo([$(this).attr("value")]); });

任何想法或替代解决方案? 谢谢!

Does anyone know leaflet? Im trying to make a function where you click on a link and the map goes to a location. Im trying with putting a pointfield value under the "value"-attribute like this:

<a href="#" class="marker" value="{{ mymodel.pt }}">Link</a>

And then i want to do something like this but it's not working:

$("#dialog").on("click", ".marker", function(e) { e.preventDefault(); map.panTo([$(this).attr("value")]); });

Any ideas or alternative solutions? Thank you!

最满意答案

Leaflet需要一个LatLng对象或至少一个两元素数组作为panTo函数的第一个参数(参见: http ://leafletjs.com/reference.html#latlng)

我不确定'mymodel.pt'包含什么,但请确保您最终得到类似于此内容的实际值:

<a href="#" class="marker" value="[50,50]">Link</a>

并略微改变JS:

... map.panTo($(this).attr("value")); ...

Leaflet expects a LatLng object or at least a two-element array as the first parameter for the panTo-function (see: http://leafletjs.com/reference.html#latlng)

I'm not sure what 'mymodel.pt' contains, but make sure that you end up with something like this for the actual value:

<a href="#" class="marker" value="[50,50]">Link</a>

And change the JS slightly:

... map.panTo($(this).attr("value")); ...

更多推荐

本文发布于:2023-07-28 08:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1303054.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   链接   地图   panTo   Leaflet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!