ebrelsford / Leaflet.loading

A simple loading control for Leaflet
MIT License
143 stars 49 forks source link

Usage with zoomcontrol in non-default position #7

Closed ajhodges closed 11 years ago

ajhodges commented 11 years ago

Hey, I like the idea of putting the loading indicator in the zoom control. The issue that I am having is that because I want my zoom control positioned in the top right corner, I have to set zoomControl=false; in the map initialization, and then add the control later.

i.e.

var map = L.map('map', {
  'zoomControl': false,
});

map.addControl(L.control.zoom({position: 'topright'}));
map.addControl(new L.Control.Loading());

This breaks your code since you are checking map.zoomControl, which doesn't reflect whether the zoomControl has been added or not, just if it was initialized.

Also, your code requires the zoomControl to be added to the map prior to the Loading control... this might be something to note in the readme. Or is there some way you could have the Loading control hook in to leaflet so it can tell when a zoom control is added? I don't know much about the internal workings of leaflet.

ebrelsford commented 11 years ago

Good point! I've added a zoomControl option. It is difficult to find a non-default zoom control in Leaflet, and no events are currently emitted when controls are added, so this might be the best we can do for now.

I've added an example of how to use this, too. Let me know if it works out.

ajhodges commented 11 years ago

Works great! Thank you. Nice work.