Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mdouchin/443e098466bf78eb5fbdd4dc7bf2bf88 to your computer and use it in GitHub Desktop.
Save mdouchin/443e098466bf78eb5fbdd4dc7bf2bf88 to your computer and use it in GitHub Desktop.
Lizmap geolocation - Control GPS auto-center duration
lizMap.events.on({
'uicreated': function(e) {
// Re-Center frequency in ms
var autoCenterTimeout = 10000;
// Do not edit after this line
var autoCenterStatus = false;
var autoCenterTm = null;
function toggleAutoCenter(toggle) {
var geolocate = lizMap.controls.geolocation;
if (toggle) {
setAutoCenter()
} else {
clearAutoCenter();
}
}
function setAutoCenter() {
autoCenterTm = setTimeout(
function() {
autoCenterStatus = true;
// Zoom
$('#geolocation-center').click();
console.log('center = ' + (new Date()).getSeconds());
// Re-run
setAutoCenter();
},
autoCenterTimeout
);
}
function clearAutoCenter() {
console.log('deactivate');
autoCenterStatus = false;
clearTimeout(autoCenterTm);
}
function replaceGeolocationAutoCenterButton() {
// Run only if needed
if (!('geolocation' in lizMap.controls)) {
return false;
}
// Hide Lizmap original auto center button
$('#geolocation-bind').hide();
// Replace with new button
var but = '&nbsp;<button id="geolocation-auto-center" class="btn btn-small btn-primary start"><span class="icon"></span>&nbsp;Rester centré</button>';
$('#geolocation-center').after(but);
$('#geolocation-auto-center').click(function(){
if ($(this).hasClass('start')) {
$(this).removeClass('start');
var set_active = true;
} else {
var set_active = !autoCenterStatus;
}
$(this)
.toggleClass('btn-success', set_active)
.toggleClass('btn-primary', !set_active);
toggleAutoCenter(set_active);
});
}
// Run
replaceGeolocationAutoCenterButton();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment