我的传单 map 目前完全位于透明 Canvas 元素后面,因此它永远不会直接注册来自用户的鼠标事件。因此,我需要以编程方式将鼠标事件注册到传单中。
如果我在我的应用程序中运行快速入门教程代码,又名:
<div id="backgroundMap"></div>
<script>
$("#backgroundMap").css("width",$(window).width()).css("height",$(window).height());
var map = L.map('backgroundMap').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.cloudmade.com/API-Key/997/256/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
maxZoom: 18
}).addTo(map);
map.on('click', onMapClick);
</script>
我是否需要在 div backgroundMap 中注册鼠标事件,又名 $('#backgroundMap').click(...)
?还是应该在其他地方注册?
或者,在传单方面我应该做一些完全不同的事情吗?
最佳答案
您想触发 Leaflet 中的单击/拖动/等事件以及这些事件的任何监听器吗?或者您只是想以编程方式移动 map ?
如果您想要后者,How to change the map center in leaflet 有多种答案。 .
这是你真正想要的命令,在answer中提到过:
map.panTo(new L.LatLng(40.737, -73.923));
关于jquery - 如何使用 JQuery 以编程方式在传单中单击/拖动/等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13435900/