简体   繁体   中英

How to get tile for click event in leaflet marker cluster?

Here is my code.

function onMapClick(e) {
    e.originalEvent.defaultPrevented = true;
    var orig = e.originalEvent;
    console.log(orig.target);
}
map.on('click', onMapClick);

console.log will show the tile ie

<img class="leaflet-tile leaflet-tile-loaded" ... />

But i could not able to find the tile when I use leaflet marker cluster. How to get the tile in leaflet marker cluster with map click event?

Best way to get tile is to calculate it from coordinates. There are many calculating implementations on OpenStreetMap wiki .

Here you have working example in JSFiddle . Just use it in map.on event method:

map.on('click', function(e) {
 console.log(getTileURL(e.latlng.lat, e.latlng.lng, map.getZoom()));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM