Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to change default control captions #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ var playback = new L.Playback(map, geoJSON, onPlaybackTimeChange, options);

* `tracksLayer` - Set `true` if you want to show layer control on the map. **Default: `true`**.

* `tracksLayerCaption` - The Name of the tracks layer in the control. **Default: `GPS Tracks`**.

* `playControl` - Set `true` if play button is needed. **Default: `false`**.

* `playCommand` - The caption of the default *PlayControl* play button. **Default: `Play`**.

* `stopCommand` - The caption of the default *PlayControl* stop button. **Default: `Stop`**.

* `dateControl` - Set `true` if date label is needed. **Default: `false`**.

* `sliderControl` - Set `true` if slider control is needed. **Default: `false`**.
Expand Down
26 changes: 15 additions & 11 deletions dist/LeafletPlayback.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ L.Playback.TracksLayer = L.Class.extend({
if (jQuery.isFunction(layer_options)){
layer_options = layer_options(feature);
}


options.tracksLayerCaption = options.tracksLayerCaption || 'GPS Tracks';

if (!layer_options.pointToLayer) {
layer_options.pointToLayer = function (featureData, latlng) {
return new L.CircleMarker(latlng, { radius : 5 });
Expand All @@ -538,9 +540,8 @@ L.Playback.TracksLayer = L.Class.extend({

this.layer = new L.GeoJSON(null, layer_options);

var overlayControl = {
'GPS Tracks' : this.layer
};
var overlayControl = {};
overlayControl[options.tracksLayerCaption] = this.layer;

L.control.layers(null, overlayControl, {
collapsed : false
Expand Down Expand Up @@ -601,10 +602,13 @@ L.Playback.DateControl = L.Control.extend({

L.Playback.PlayControl = L.Control.extend({
options : {
position : 'bottomright'
position : 'bottomright',
playCommand : 'Play',
stopCommand : 'Stop'
},

initialize : function (playback) {
initialize : function (playback, options) {
L.setOptions(this, options);
this.playback = playback;
},

Expand All @@ -619,7 +623,7 @@ L.Playback.PlayControl = L.Control.extend({


this._button = L.DomUtil.create('button', '', playControl);
this._button.innerHTML = 'Play';
this._button.innerHTML = this.options.playCommand;


var stop = L.DomEvent.stopPropagation;
Expand All @@ -634,12 +638,12 @@ L.Playback.PlayControl = L.Control.extend({
function play(){
if (playback.isPlaying()) {
playback.stop();
self._button.innerHTML = 'Play';
self._button.innerHTML = this.options.playCommand;
}
else {
playback.start();
self._button.innerHTML = 'Stop';
}
self._button.innerHTML = this.options.stopCommand;
}
}

return this._container;
Expand Down Expand Up @@ -750,7 +754,7 @@ L.Playback = L.Playback.Clock.extend({


if (this.options.playControl) {
this.playControl = new L.Playback.PlayControl(this);
this.playControl = new L.Playback.PlayControl(this, options);
this.playControl.addTo(map);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/LeafletPlayback.min.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ L.Playback.DateControl = L.Control.extend({

L.Playback.PlayControl = L.Control.extend({
options : {
position : 'bottomright'
position : 'bottomright',
playCommand : 'Play',
stopCommand : 'Stop'
},

initialize : function (playback) {
initialize : function (playback, options) {
L.setOptions(this, options);
this.playback = playback;
},

Expand All @@ -58,7 +61,7 @@ L.Playback.PlayControl = L.Control.extend({


this._button = L.DomUtil.create('button', '', playControl);
this._button.innerHTML = 'Play';
this._button.innerHTML = this.options.playCommand;


var stop = L.DomEvent.stopPropagation;
Expand All @@ -73,12 +76,12 @@ L.Playback.PlayControl = L.Control.extend({
function play(){
if (playback.isPlaying()) {
playback.stop();
self._button.innerHTML = 'Play';
self._button.innerHTML = this.options.playCommand;
}
else {
playback.start();
self._button.innerHTML = 'Stop';
}
self._button.innerHTML = this.options.stopCommand;
}
}

return this._container;
Expand Down
2 changes: 1 addition & 1 deletion src/Playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ L.Playback = L.Playback.Clock.extend({


if (this.options.playControl) {
this.playControl = new L.Playback.PlayControl(this);
this.playControl = new L.Playback.PlayControl(this, options);
this.playControl.addTo(map);
}

Expand Down
9 changes: 5 additions & 4 deletions src/TracksLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ L.Playback.TracksLayer = L.Class.extend({
if (jQuery.isFunction(layer_options)){
layer_options = layer_options(feature);
}


options.tracksLayerCaption = options.tracksLayerCaption || 'GPS Tracks';

if (!layer_options.pointToLayer) {
layer_options.pointToLayer = function (featureData, latlng) {
return new L.CircleMarker(latlng, { radius : 5 });
Expand All @@ -19,9 +21,8 @@ L.Playback.TracksLayer = L.Class.extend({

this.layer = new L.GeoJSON(null, layer_options);

var overlayControl = {
'GPS Tracks' : this.layer
};
var overlayControl = {};
overlayControl[options.tracksLayerCaption] = this.layer;

L.control.layers(null, overlayControl, {
collapsed : false
Expand Down