Skip to content

Commit

Permalink
Merge pull request #2 from mithron/events
Browse files Browse the repository at this point in the history
Events
  • Loading branch information
mithron committed Aug 12, 2014
2 parents e292b83 + 1b70eb2 commit eade212
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ Helpers for arrows - what will be displayed on arrows as popup and if no image s
## Images

Images for arrows are in img folder. They are specified in css, so you can change them into what you want.

## Events
Events are added to interact with control from code. Events are fired on switching to next (the 'next' event) or to previous (the 'prev' event) location. Example shows how to do it.
5 changes: 3 additions & 2 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@

var layer = L.tileLayer(MB_URL, {attribution: MB_ATTR, id: 'examples.map-20v6611k'}).addTo(m);



llist.on('next', function() { console.log("Switched to next!");});
llist.on('prev', function() { console.log("Switched to prev!");});

</script>
</body>
</html>
11 changes: 8 additions & 3 deletions src/leaflet.locationlist.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
L.Control.LocationList = L.Control.extend({

includes: L.Mixin.Events,

options: {
position: 'topright',
showlist: true,
Expand Down Expand Up @@ -69,15 +72,17 @@ L.Control.LocationList = L.Control.extend({
else {
this._currentLocation_index = 0 ;}

this._map.setView(this.options.locationsList[this._currentLocation_index].latlng, this.options.locationsList[this._currentLocation_index].zoom);
this._map.setView(this.options.locationsList[this._currentLocation_index].latlng, this.options.locationsList[this._currentLocation_index].zoom);
this.fire('next');
},
_switchPrev: function (e) {
if (this._currentLocation_index != 0) {
this._currentLocation_index = this._currentLocation_index - 1 ; }
else {
this._currentLocation_index = this.options.locationsList.length - 1 ;}

this._map.setView(this.options.locationsList[this._currentLocation_index].latlng, this.options.locationsList[this._currentLocation_index].zoom);
this._map.setView(this.options.locationsList[this._currentLocation_index].latlng, this.options.locationsList[this._currentLocation_index].zoom);
this.fire('prev');

}

Expand All @@ -87,4 +92,4 @@ L.Control.LocationList = L.Control.extend({

L.control.locationlist = function (options) {
return new L.Control.LocationList(options);
};
};

0 comments on commit eade212

Please sign in to comment.