Skip to content

Commit

Permalink
Moved url to getter function
Browse files Browse the repository at this point in the history
- Use old url as fallback when no API key is found
  • Loading branch information
JusticeV452 committed Jun 27, 2024
1 parent 1b3346d commit 6ce8e19
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/components/ParisMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export const DEFAULT_MAP_CENTER_LAT = 48.858859;
export const DEFAULT_MAP_CENTER_LNG = 2.3470599;
const API_KEY = process.env.REACT_APP_STADIA_API_KEY;


function getTilesUrl() {
if (!API_KEY) {
return "http://stamen-tiles-a.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.png";
}
return `https://tiles.stadiamaps.com/tiles/stamen_toner_lite/{z}/{x}/{y}.png?api_key=${API_KEY}`;
}

export class ParisMap extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -88,7 +96,7 @@ export class ParisMap extends React.Component {
// Retrieves Map image

// HOT option
url={`https://tiles.stadiamaps.com/tiles/stamen_toner_lite/{z}/{x}/{y}.png?api_key=${API_KEY}`}
url={getTilesUrl()}
/>

{Object.keys(this.props.layers)
Expand Down

0 comments on commit 6ce8e19

Please sign in to comment.