remove geoquery when there's a saved location
This commit is contained in:
parent
eb11feb964
commit
c3e38b4077
|
@ -8,9 +8,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|
||||||
const overrides = {};
|
|
||||||
|
|
||||||
let AutoSelectQuery = false;
|
|
||||||
let FullScreenOverride = false;
|
let FullScreenOverride = false;
|
||||||
|
|
||||||
const categories = [
|
const categories = [
|
||||||
|
@ -58,21 +55,12 @@ const init = () => {
|
||||||
maxSuggestions: 10,
|
maxSuggestions: 10,
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
transformResult: (response) => {
|
transformResult: (response) => ({
|
||||||
if (AutoSelectQuery) {
|
suggestions: $.map(response.suggestions, (i) => ({
|
||||||
AutoSelectQuery = false;
|
value: i.text,
|
||||||
window.setTimeout(() => {
|
data: i.magicKey,
|
||||||
$(ac.suggestionsContainer.children[0]).click();
|
})),
|
||||||
}, 1);
|
}),
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
suggestions: $.map(response.suggestions, (i) => ({
|
|
||||||
value: i.text,
|
|
||||||
data: i.magicKey,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
minChars: 3,
|
minChars: 3,
|
||||||
showNoSuggestionNotice: true,
|
showNoSuggestionNotice: true,
|
||||||
noSuggestionNotice: 'No results found. Please try a different search string.',
|
noSuggestionNotice: 'No results found. Please try a different search string.',
|
||||||
|
@ -88,12 +76,11 @@ const init = () => {
|
||||||
|
|
||||||
// Auto load the previous query
|
// Auto load the previous query
|
||||||
const TwcQuery = localStorage.getItem('TwcQuery');
|
const TwcQuery = localStorage.getItem('TwcQuery');
|
||||||
if (TwcQuery) {
|
const TwcLatLong = localStorage.getItem('TwcLatLon');
|
||||||
AutoSelectQuery = true;
|
if (TwcQuery && TwcLatLong) {
|
||||||
const txtAddress = document.getElementById('txtAddress');
|
const txtAddress = document.getElementById('txtAddress');
|
||||||
txtAddress.value = TwcQuery;
|
txtAddress.value = TwcQuery;
|
||||||
txtAddress.blur();
|
LoadTwcData(JSON.parse(TwcLatLong));
|
||||||
txtAddress.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TwcPlay = localStorage.getItem('TwcPlay');
|
const TwcPlay = localStorage.getItem('TwcPlay');
|
||||||
|
@ -118,6 +105,7 @@ const init = () => {
|
||||||
postMessage('navButton', 'play');
|
postMessage('navButton', 'play');
|
||||||
|
|
||||||
localStorage.removeItem('TwcQuery');
|
localStorage.removeItem('TwcQuery');
|
||||||
|
localStorage.removeItem('TwcLatLon');
|
||||||
});
|
});
|
||||||
|
|
||||||
// swipe functionality
|
// swipe functionality
|
||||||
|
@ -129,31 +117,30 @@ const autocompleteOnSelect = async (suggestion, elem) => {
|
||||||
// Do not auto get the same city twice.
|
// Do not auto get the same city twice.
|
||||||
if (elem.previousSuggestionValue === suggestion.value) return;
|
if (elem.previousSuggestionValue === suggestion.value) return;
|
||||||
|
|
||||||
if (overrides[suggestion.value]) {
|
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
||||||
doRedirectToGeometry(overrides[suggestion.value]);
|
data: {
|
||||||
} else {
|
text: suggestion.value,
|
||||||
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
magicKey: suggestion.data,
|
||||||
data: {
|
f: 'json',
|
||||||
text: suggestion.value,
|
},
|
||||||
magicKey: suggestion.data,
|
});
|
||||||
f: 'json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const loc = data.locations[0];
|
const loc = data.locations[0];
|
||||||
if (loc) {
|
if (loc) {
|
||||||
doRedirectToGeometry(loc.feature.geometry);
|
doRedirectToGeometry(loc.feature.geometry);
|
||||||
} else {
|
} else {
|
||||||
console.error('An unexpected error occurred. Please try a different search string.');
|
console.error('An unexpected error occurred. Please try a different search string.');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const doRedirectToGeometry = (geom) => {
|
const doRedirectToGeometry = (geom) => {
|
||||||
const latLon = { lat: Math.round2(geom.y, 4), lon: Math.round2(geom.x, 4) };
|
const latLon = { lat: Math.round2(geom.y, 4), lon: Math.round2(geom.x, 4) };
|
||||||
LoadTwcData(latLon);
|
|
||||||
// Save the query
|
// Save the query
|
||||||
localStorage.setItem('TwcQuery', document.getElementById('txtAddress').value);
|
localStorage.setItem('TwcQuery', document.getElementById('txtAddress').value);
|
||||||
|
localStorage.setItem('TwcLatLon', JSON.stringify(latLon));
|
||||||
|
|
||||||
|
// get the data
|
||||||
|
LoadTwcData(latLon);
|
||||||
};
|
};
|
||||||
|
|
||||||
const btnFullScreenClick = () => {
|
const btnFullScreenClick = () => {
|
||||||
|
|
Loading…
Reference in a new issue