Skip to content

Commit c121014

Browse files
committed
Only call digitransit api when the layer is visible
1 parent 7011fec commit c121014

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

web/src/components/Map.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
100100
LayerId.DigiTransitPoint,
101101
{
102102
url: "https://api.digitransit.fi/routing/v1/routers/waltti/index/graphql",
103+
tarmo_category: "Pysäkit",
103104
zoomThreshold: 12,
104105
reload: true,
105106
gqlQuery: `{
@@ -123,6 +124,7 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
123124
LayerId.DigiTransitBikePoint,
124125
{
125126
url: "https://api.digitransit.fi/routing/v1/routers/waltti/index/graphql",
127+
tarmo_category: "Pysäkit",
126128
zoomThreshold: 12,
127129
reload: false,
128130
gqlQuery: `{
@@ -157,6 +159,12 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
157159
"User-Agent": "TARMO - Tampere Mobilemap",
158160
};
159161
externalSources.forEach((value, key) => {
162+
// Do not reload if data is not visible
163+
if (
164+
mapFiltersContext.getVisibilityValue(value.tarmo_category) == "none"
165+
) {
166+
return;
167+
}
160168
// Do not reload if data does not need to be updated
161169
if (!value.reload && externalData && externalData.get(key)) {
162170
return;
@@ -192,7 +200,7 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
192200
useEffect(() => {
193201
loadExternalData();
194202
// eslint-disable-next-line
195-
}, [bounds]);
203+
}, [bounds, mapFiltersContext]);
196204

197205
// TODO: at the moment, the user can only select points on the search layer.
198206
// Another way of implementing this would be to zoom in when selected, and

web/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LayerId } from "./components/style";
22
import { GeoJsonProperties } from "geojson";
3+
import { CategoryFilters } from "./contexts/MapFiltersContext";
34

45
export interface PopupInfo {
56
layerId: LayerId;
@@ -11,6 +12,7 @@ export interface PopupInfo {
1112

1213
export interface ExternalSource {
1314
url: string;
15+
tarmo_category: keyof CategoryFilters;
1416
zoomThreshold: number;
1517
gqlQuery?: string;
1618
reload?: boolean;

0 commit comments

Comments
 (0)