2012-11-17 19 views
1

我的小册子地图当前完全位于透明画布元素的后面,因此它永远不会直接注册用户的鼠标事件。因此,我需要以编程方式将鼠标事件注册到传单中。如何以编程方式在JQuery中单击/拖动/等单张?

如果我有快速介绍教程代码在我的应用程序运行,又名:

<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 &copy; <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注册,AKA $('#backgroundMap').click(...)?还是应该在其他地方注册?

或者我应该做一些完全不同的事情,当涉及到传单?

回答

0

是否要触发Leaflet中的click/drag/etc事件以及这些事件的监听者?或者你只是想以编程方式移动地图?

如果你想要后者,在How to change the map center in leaflet有各种答案。

这是你真正想要的命令,在这个answer提到:

map.panTo(new L.LatLng(40.737, -73.923)); 
相关问题