Skip to content

Commit

Permalink
FIX: Auto-locate me button multiple spinners (#234)
Browse files Browse the repository at this point in the history
* FIX: Auto-locate me button multiple spinners

Resolves publiclab/plots2#7305

* FIX: Issue with Travis
  • Loading branch information
VladimirMikulic authored Feb 9, 2020
1 parent ce01bb9 commit 7e8d181
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 62 deletions.
103 changes: 62 additions & 41 deletions dist/Leaflet.BlurredLocation.js

Large diffs are not rendered by default.

61 changes: 40 additions & 21 deletions src/core/Geocoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function Geocoding(options) {
}

function panMapToGeocodedLocation(selector) {

var input = document.getElementById(selector);

var autocomplete = new google.maps.places.Autocomplete(input);
Expand All @@ -83,29 +83,48 @@ module.exports = function Geocoding(options) {
};

function geocodeWithBrowser(success) {
if(success) {
var label = document.createElement("label");
label.classList.add("spinner");
var i = document.createElement("i");
i.classList.add("fa");
i.classList.add("fa-spinner");
i.classList.add("fa-spin");
label.appendChild(i);
var element = document.getElementById(options.geocodeButtonId);
element.appendChild(label);
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
options.goTo(position.coords.latitude, position.coords.longitude,options.zoom);
i.classList.remove("fa") ;
i.classList.remove("fa-spinner") ;
i.classList.remove("fa-spin") ;
}, function(error) {
console.log(error);
});
}
if (!success) return;

if (!isSpinnerPresent(options.geocodeButtonId))
renderSpinner(options.geocodeButtonId);

if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function (position) {
options.goTo(position.coords.latitude, position.coords.longitude, options.zoom);
removeSpinner(options.geocodeButtonId);
}, function (error) {
console.log(error);
removeSpinner(options.geocodeButtonId);
});
}
}

function isSpinnerPresent(elementID) {
var spinner = document.querySelector("#" + elementID + " .spinner");

if (spinner) return true;
return false;
}

function renderSpinner(elementID) {
var element = document.getElementById(elementID);
var label = document.createElement("label");
label.classList.add("spinner");

var i = document.createElement("i");
i.classList.add("fa");
i.classList.add("fa-spinner");
i.classList.add("fa-spin");

label.appendChild(i);
element.appendChild(label);
}

function removeSpinner(elementID) {
var spinner = document.querySelector("#" + elementID + " .spinner");
spinner.remove();
}

function geocodeStringAndPan(string, onComplete) {
if(geocoder) {
if(typeof map.spin == 'function'){
Expand Down

0 comments on commit 7e8d181

Please sign in to comment.