diff --git a/README.md b/README.md index 2dd6f06..4ec6281 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/index.html b/examples/index.html index c21e388..556ffce 100644 --- a/examples/index.html +++ b/examples/index.html @@ -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!");}); + diff --git a/src/leaflet.locationlist.js b/src/leaflet.locationlist.js index c0b5fac..182be5f 100644 --- a/src/leaflet.locationlist.js +++ b/src/leaflet.locationlist.js @@ -1,4 +1,7 @@ L.Control.LocationList = L.Control.extend({ + + includes: L.Mixin.Events, + options: { position: 'topright', showlist: true, @@ -69,7 +72,8 @@ 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) { @@ -77,7 +81,8 @@ L.Control.LocationList = L.Control.extend({ 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'); } @@ -87,4 +92,4 @@ L.Control.LocationList = L.Control.extend({ L.control.locationlist = function (options) { return new L.Control.LocationList(options); -}; \ No newline at end of file +};