Despite adding all necessary scripts and configuring my API_KEY in config.js, I keep getting an error message saying "Uncaught SyntaxError: Unexpected token." I have double-checked my API key multiple times, and it seems to be correct.
Here is a snippet from my Python file:
app.route("/")
def index():
"""Return the homepage."""
return render_template("index.html", cities=cities, aqi=aqi, CO=CO, NO2=NO2, SO2=SO2, PM25=pm25)
if __name__ == "__main__":
app.run()
The variables cities, aqi, etc., are lists that I am passing to index.html.
This is my index.html file:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Air-Quality</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="../static/css/style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.9.2/d3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js"></script>
<!-- Other script tags -->
<script>
var cities = {{cities|tojson}};
var aqi = {{aqi|tojson}};
var CO = {{CO|tojson}};
var NO2 = {{NO2|tojson}};
var SO2 = {{SO2|tojson}};
var PM25 = {{PM25|tojson}};
</script>
</head>
<body>
<div class="text-center main globe">
</div>
In addition to this, there is JavaScript code that is invoking leaflet:
var myMap = L.map('globe', {
center:[45.5017, -73.5673],
zoom:1
});
L.tileLayer("https://{API_URL}/{z}/{x}/{y}.png?access_token={accessToken}", {
maxZoom: 18,
id: "mapbox.streets-basic",
accessToken: API_KEY
}).addTo(myMap);
All the file paths are correct. I am puzzled about what could be going wrong. Thank you in advance.
Below is the full error message:
leaflet.css:3 Uncaught SyntaxError: Unexpected token .
leaflet.js:5 Uncaught Error: Map container not found.
at i._initContainer (leaflet.js:5)
at initialize (leaflet.js:5)
at new i (leaflet.js:5)
at Object.t.map (leaflet.js:5)
at draw_globe.js:3