有谁知道传单? 我试图创建一个功能,你点击链接,地图转到一个位置。 我尝试将点域值置于“值” - 属性下面,如下所示:
<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")); ...更多推荐
发布评论