Skip to content

Commit

Permalink
Actually var -> let
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Aug 1, 2024
1 parent 000a60c commit a80a23f
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 141 deletions.
38 changes: 19 additions & 19 deletions js/dataController.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var osmEntityCache = {};
var osmEntityMembershipCache = {};
var osmChangesetCache = {};
let osmEntityCache = {};
let osmEntityMembershipCache = {};
let osmChangesetCache = {};

function cacheEntities(elements, full) {
for (var i in elements) {
var element = elements[i];
var type = element.type;
var id = element.id;
var key = type[0] + id;
for (let i in elements) {
let element = elements[i];
let type = element.type;
let id = element.id;
let key = type[0] + id;

osmEntityCache.full = full;

Expand All @@ -16,27 +16,27 @@ function cacheEntities(elements, full) {
}

async function fetchOsmEntity(type, id) {
var key = type[0] + id;
let key = type[0] + id;
if (!osmEntityCache[key] || !osmEntityCache[key].full) {
var url = `https://api.openstreetmap.org/api/0.6/${type}/${id}`;
let url = `https://api.openstreetmap.org/api/0.6/${type}/${id}`;
if (type !== 'node') {
url += '/full';
}
url += '.json';
var response = await fetch(url);
var json = await response.json();
let response = await fetch(url);
let json = await response.json();
cacheEntities(json && json.elements || [], true);
}
return osmEntityCache[key];
}

async function fetchOsmEntityMemberships(type, id) {
var key = type[0] + id;
let key = type[0] + id;

if (!osmEntityMembershipCache[key]) {
var response = await fetch(`https://api.openstreetmap.org/api/0.6/${type}/${id}/relations.json`);
var json = await response.json();
var rels = json && json.elements || [];
let response = await fetch(`https://api.openstreetmap.org/api/0.6/${type}/${id}/relations.json`);
let json = await response.json();
let rels = json && json.elements || [];

osmEntityMembershipCache[key] = [];
rels.forEach(function(rel) {
Expand All @@ -59,9 +59,9 @@ async function fetchOsmEntityMemberships(type, id) {

async function fetchOsmChangeset(id) {
if (!osmChangesetCache[id]) {
var url = `https://api.openstreetmap.org/api/0.6/changeset/${id}.json`;
var response = await fetch(url);
var json = await response.json();
let url = `https://api.openstreetmap.org/api/0.6/changeset/${id}.json`;
let response = await fetch(url);
let json = await response.json();
osmChangesetCache[id] = json && json.elements && json.elements.length && json.elements[0];
}
return osmChangesetCache[id];
Expand Down
18 changes: 9 additions & 9 deletions js/hashController.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
function setHashParameters(params) {
var searchParams = new URLSearchParams(window.location.hash.slice(1));
for (var key in params) {
let searchParams = new URLSearchParams(window.location.hash.slice(1));
for (let key in params) {
if (params[key]) {
searchParams.set(key, params[key]);
} else if (searchParams.has(key)) {
searchParams.delete(key);
}
}
var hash = "#" + decodeURIComponent(searchParams.toString());
let hash = "#" + decodeURIComponent(searchParams.toString());
if (hash !== window.location.hash) {
window.location.hash = hash;
}
}

function hashValue(key) {
var searchParams = new URLSearchParams(window.location.hash.slice(1));
let searchParams = new URLSearchParams(window.location.hash.slice(1));
if (searchParams.has(key)) return searchParams.get(key);
return null;
}

function parseEntityInfoFromString(string) {
var components = string.split("/");
let components = string.split("/");
if (components.length == 2) {
var type = components[0];
var id = parseInt(components[1]);
let type = components[0];
let id = parseInt(components[1]);
if (["node", "way", "relation"].includes(type)) {
return {
type: type,
Expand All @@ -34,13 +34,13 @@ function parseEntityInfoFromString(string) {
}

function focusedEntityInfoFromHash() {
var value = hashValue("focus");
let value = hashValue("focus");
if (value) return parseEntityInfoFromString(value);
return null;
}

function selectedEntityInfoFromHash() {
var value = hashValue("selected");
let value = hashValue("selected");
if (value) return parseEntityInfoFromString(value);
return null;
}
Expand Down
62 changes: 31 additions & 31 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var map;
let map;

var lensStrings = {
let lensStrings = {
access: {
label: "Access"
},
Expand Down Expand Up @@ -230,13 +230,13 @@ const waterwayOnlyLenses = [
];
const defaultTravelMode = "all";
const defaultLens= "";
var travelMode = defaultTravelMode;
var lens = defaultLens;
var lastLens = defaultLens;
let travelMode = defaultTravelMode;
let lens = defaultLens;
let lastLens = defaultLens;

var focusedEntityInfo;
var selectedEntityInfo;
var hoveredEntityInfo;
let focusedEntityInfo;
let selectedEntityInfo;
let hoveredEntityInfo;

function isValidEntityInfo(entityInfo) {
return ["node", "way", "relation"].includes(entityInfo?.type) &&
Expand All @@ -245,7 +245,7 @@ function isValidEntityInfo(entityInfo) {

function compositeGeoJson(features) {
if (!features.length) return;
var coordinates = [];
let coordinates = [];
features.forEach(function(feature) {
if (feature.geometry.type === 'Polygon') {
coordinates.push(feature.geometry.coordinates);
Expand All @@ -263,14 +263,14 @@ function compositeGeoJson(features) {
};
}

var focusAreaGeoJson;
var focusAreaGeoJsonBuffered;
var focusAreaBoundingBox;
let focusAreaGeoJson;
let focusAreaGeoJsonBuffered;
let focusAreaBoundingBox;

function buildFocusAreaGeoJson() {
if (!focusedEntityInfo) return null;
var id = omtId(focusedEntityInfo.id, focusedEntityInfo.type);
var results = map.querySourceFeatures('openmaptiles', {
let id = omtId(focusedEntityInfo.id, focusedEntityInfo.type);
let results = map.querySourceFeatures('openmaptiles', {
filter: [
"==", ["id"], id,
],
Expand All @@ -286,10 +286,10 @@ function buildFocusAreaGeoJson() {
sourceLayer: "landcover",
});
}
var geoJson = compositeGeoJson(results);
let geoJson = compositeGeoJson(results);
if (!geoJson.properties.name) {
// park names are on a different layer for some reason
var poiResults = map.querySourceFeatures('openmaptiles', {
let poiResults = map.querySourceFeatures('openmaptiles', {
filter: ["==", ["id"], id],
sourceLayer: "poi",
});
Expand All @@ -301,12 +301,12 @@ function loadFocusArea() {
focusAreaGeoJson = buildFocusAreaGeoJson();
focusAreaGeoJsonBuffered = focusAreaGeoJson?.geometry?.coordinates?.length ? turfBuffer.buffer(focusAreaGeoJson, 0.25, {units: 'kilometers'}) : focusAreaGeoJson;
focusAreaBoundingBox = bboxOfGeoJson(focusAreaGeoJson);
var maxBbox = focusAreaBoundingBox;
var fitBbox = focusAreaBoundingBox;
let maxBbox = focusAreaBoundingBox;
let fitBbox = focusAreaBoundingBox;
if (focusAreaBoundingBox) {
var width = focusAreaBoundingBox[2] - focusAreaBoundingBox[0];
var height = focusAreaBoundingBox[3] - focusAreaBoundingBox[1];
var maxExtent = Math.max(width, height);
let width = focusAreaBoundingBox[2] - focusAreaBoundingBox[0];
let height = focusAreaBoundingBox[3] - focusAreaBoundingBox[1];
let maxExtent = Math.max(width, height);
maxBbox = extendBbox(focusAreaBoundingBox, maxExtent);
fitBbox = extendBbox(focusAreaBoundingBox, maxExtent / 16);
}
Expand All @@ -323,8 +323,8 @@ function focusEntity(entityInfo) {

focusedEntityInfo = entityInfo;

var type = focusedEntityInfo?.type;
var entityId = focusedEntityInfo?.id;
let type = focusedEntityInfo?.type;
let entityId = focusedEntityInfo?.id;

setHashParameters({
focus: focusedEntityInfo ? type + "/" + entityId : null
Expand Down Expand Up @@ -355,8 +355,8 @@ function selectEntity(entityInfo) {

selectedEntityInfo = entityInfo;

var type = selectedEntityInfo?.type;
var entityId = selectedEntityInfo?.id;
let type = selectedEntityInfo?.type;
let entityId = selectedEntityInfo?.id;

setHashParameters({
selected: selectedEntityInfo ? type + "/" + entityId : null
Expand All @@ -377,21 +377,21 @@ function selectEntity(entityInfo) {
}
}
function updateLensControl() {
var html = "";
var items = lensOptionsByMode[travelMode];
let html = "";
let items = lensOptionsByMode[travelMode];

html += '<option value="">General</option>';
items.forEach(function(item) {
if (item.subitems) {
html += '<optgroup label="' + item.label + '">';
item.subitems.forEach(function(item) {
var label = item.label ? item.label : lensStrings[item].label;
let label = item.label ? item.label : lensStrings[item].label;
html += '<option value="' + item + '">' + label + '</option>';
})
html += '</optgroup>';
}
});
var lensElement = document.getElementById("lens");
let lensElement = document.getElementById("lens");
lensElement.innerHTML = html;
lensElement.value = lens;
}
Expand Down Expand Up @@ -500,8 +500,8 @@ window.onload = function(event) {
'waterfall-landmark',
];

for (var i in imageToLoad) {
var img = imageToLoad[i];
for (let i in imageToLoad) {
let img = imageToLoad[i];
map.loadImage('img/map/' + img + '.png').then(function(resp) {
return map.addImage(img, resp.data, { pixelRatio: 2 });
});
Expand Down
Loading

0 comments on commit a80a23f

Please sign in to comment.