Skip to content

Commit 5b0a796

Browse files
Merge pull request #72 from MobilityData/copilot/cleanup-remove-leaflet-types
Cleanup: Remove Leaflet, replace with LngLatTuple in [lng, lat] order
2 parents 55f864a + 248ecbe commit 5b0a796

File tree

12 files changed

+48
-48
lines changed

12 files changed

+48
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ next-env.d.ts
3636
.vercel
3737

3838
.vscode/
39+
tsconfig.tsbuildinfo

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"@reduxjs/toolkit": "^1.9.6",
1616
"@sentry/nextjs": "^10.42.0",
1717
"@turf/center": "^6.5.0",
18-
"@types/leaflet": "^1.9.12",
1918
"@types/lodash": "^4.17.20",
2019
"@types/react-map-gl": "^6.1.7",
2120
"@vercel/analytics": "^1.6.1",
@@ -28,7 +27,6 @@
2827
"firebase": "^10.4.0",
2928
"firebase-admin": "^13.0.2",
3029
"formik": "^2.4.5",
31-
"leaflet": "^1.9.4",
3230
"loadashes6": "^1.0.0",
3331
"maplibre-gl": "^5.7.0",
3432
"material-react-table": "^2.13.0",
@@ -42,7 +40,6 @@
4240
"react-draggable": "^4.5.0",
4341
"react-google-recaptcha": "^3.1.0",
4442
"react-hook-form": "^7.52.1",
45-
"react-leaflet": "^4.2.1",
4643
"react-map-gl": "^8.0.4",
4744
"react-redux": "^8.1.3",
4845
"react-router-dom": "^6.16.0",

src/app/components/CoveredAreaMap.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { mapBoxPositionStyle } from '../screens/Feed/Feed.styles';
2020
import dynamic from 'next/dynamic';
2121
import { type GeoJSONData, type GeoJSONDataGBFS } from './MapGeoJSON';
2222
import { useTranslations } from 'next-intl';
23-
import type { LatLngTuple } from 'leaflet';
23+
import { type LngLatTuple } from '../types';
2424
import { useTheme } from '@mui/material/styles';
2525
import {
2626
type GTFSFeedType,
@@ -54,7 +54,7 @@ const Map = dynamic(async () => await import('./Map').then((mod) => mod.Map), {
5454
});
5555

5656
interface CoveredAreaMapProps {
57-
boundingBox?: LatLngTuple[];
57+
boundingBox?: LngLatTuple[];
5858
latestDataset?: LatestDatasetLite;
5959
feed: AllFeedType;
6060
}
@@ -251,14 +251,14 @@ const CoveredAreaMap: React.FC<CoveredAreaMapProps> = ({
251251
);
252252
}
253253
if (config.enableDetailedCoveredArea && geoJsonData != null) {
254-
let gbfsGeoJsonBoundingBox: LatLngTuple[] = [];
254+
let gbfsGeoJsonBoundingBox: LngLatTuple[] = [];
255255
if (feed?.data_type === 'gbfs') {
256256
gbfsGeoJsonBoundingBox = computeBoundingBox(geoJsonData) ?? [];
257257
if (gbfsGeoJsonBoundingBox.length === 0) {
258258
setGeoJsonError(true);
259259
}
260260
}
261-
const feedBoundingBox: LatLngTuple[] =
261+
const feedBoundingBox: LngLatTuple[] =
262262
feed?.data_type === 'gtfs'
263263
? (boundingBox ?? [])
264264
: gbfsGeoJsonBoundingBox;

src/app/components/GtfsVisualizationMap.functions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
type ExpressionSpecification,
1010
type LngLatBoundsLike,
1111
} from 'maplibre-gl';
12-
import { type LatLngTuple } from 'leaflet';
12+
import { type LngLatTuple } from '../types';
1313

1414
export interface LatestDatasetLite {
1515
hosted_url?: string;
@@ -69,14 +69,14 @@ export function generateStopColorExpression(
6969
}
7070

7171
export const getBoundsFromCoordinates = (
72-
coordinates: LatLngTuple[],
72+
coordinates: LngLatTuple[],
7373
): LngLatBoundsLike => {
7474
let minLng = Number.POSITIVE_INFINITY;
7575
let minLat = Number.POSITIVE_INFINITY;
7676
let maxLng = Number.NEGATIVE_INFINITY;
7777
let maxLat = Number.NEGATIVE_INFINITY;
7878

79-
coordinates.forEach(([lat, lng]) => {
79+
coordinates.forEach(([lng, lat]) => {
8080
minLat = Math.min(minLat, lat);
8181
maxLat = Math.max(maxLat, lat);
8282
minLng = Math.min(minLng, lng);

src/app/components/GtfsVisualizationMap.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Map, {
1010
import maplibregl, { type LngLatBoundsLike } from 'maplibre-gl';
1111
import 'maplibre-gl/dist/maplibre-gl.css';
1212
import { Protocol } from 'pmtiles';
13-
import { type LatLngExpression } from 'leaflet';
13+
import { type LngLatTuple, type GtfsRoute } from '../types';
1414
import { Box, useTheme } from '@mui/material';
1515

1616
import {
@@ -20,7 +20,6 @@ import {
2020
type MapElementType,
2121
} from './MapElement';
2222
import { MapDataPopup } from './Map/MapDataPopup';
23-
import type { GtfsRoute } from '../types';
2423
import { createPrecomputation, extendBBoxes } from '../utils/precompute';
2524
import { SelectedRoutesStopsPanel } from './Map/SelectedRoutesStopsPanel';
2625
import { ScanningOverlay } from './Map/ScanningOverlay';
@@ -41,7 +40,7 @@ import {
4140
} from './GtfsVisualizationMap.layers';
4241

4342
export interface GtfsVisualizationMapProps {
44-
polygon: LatLngExpression[];
43+
polygon: LngLatTuple[];
4544
latestDataset?: LatestDatasetLite;
4645
filteredRoutes?: string[];
4746
filteredRouteTypeIds?: string[];
@@ -260,9 +259,7 @@ export const GtfsVisualizationMap = ({
260259
};
261260
}, []);
262261

263-
const bounds: LngLatBoundsLike = getBoundsFromCoordinates(
264-
polygon as Array<[number, number]>,
265-
);
262+
const bounds: LngLatBoundsLike = getBoundsFromCoordinates(polygon);
266263

267264
// route IDs coming from selected route types
268265
const routeIdsFromTypes =

src/app/components/Map.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import MapGL, {
88
MapProvider,
99
} from 'react-map-gl/maplibre';
1010
import 'maplibre-gl/dist/maplibre-gl.css';
11-
import { type LatLngTuple } from 'leaflet';
11+
import { type LngLatTuple } from '../types';
1212
import { useTheme } from '@mui/material/styles';
1313
import { Box } from '@mui/material';
1414
import { getBoundsFromCoordinates } from './GtfsVisualizationMap.functions';
1515

1616
export interface MapProps {
17-
polygon: LatLngTuple[];
17+
polygon: LngLatTuple[];
1818
}
1919

2020
export const Map = (
@@ -26,10 +26,8 @@ export const Map = (
2626
return getBoundsFromCoordinates(props.polygon);
2727
}, [props.polygon]);
2828

29-
// Convert LatLngExpression[] to GeoJSON ring for Source
30-
const coordinates = props.polygon.map((p) => {
31-
return [p[1], p[0]];
32-
});
29+
// Polygon is already in [lng, lat] (GeoJSON) format - no conversion needed
30+
const coordinates: number[][] = [...props.polygon];
3331

3432
// Ensure it's a closed ring for a polygon
3533
if (

src/app/components/MapGeoJSON.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import MapGL, {
88
Popup,
99
} from 'react-map-gl/maplibre';
1010
import 'maplibre-gl/dist/maplibre-gl.css';
11-
import { type LatLngTuple } from 'leaflet';
11+
import { type LngLatTuple } from '../types';
1212
import { useTranslations } from 'next-intl';
1313
import { PopupTable } from './PopupTable';
1414
import { useTheme } from '@mui/material/styles';
@@ -35,7 +35,7 @@ export interface GeoJSONDataGBFS extends GeoJSONData {
3535

3636
export interface MapProps {
3737
geoJSONData: GeoJSONData | null;
38-
polygon: LatLngTuple[];
38+
polygon: LngLatTuple[];
3939
displayMapDetails?: boolean;
4040
}
4141

src/app/screens/Feed/Feed.functions.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import {
55
type GBFSVersionType,
66
type GBFSFeedType,
77
} from '../../services/feeds/utils';
8-
import { type LatLngTuple } from 'leaflet';
9-
import { type GeoJSONData, type GeoJSONDataGBFS } from '../../types';
8+
import {
9+
type LngLatTuple,
10+
type GeoJSONData,
11+
type GeoJSONDataGBFS,
12+
} from '../../types';
1013

1114
export function formatProvidersSorted(provider: string): string[] {
1215
const providers = provider.split(',').filter((n) => n);
@@ -136,7 +139,7 @@ export const sortGbfsVersions = (
136139
/* eslint-disable */
137140
export function computeBoundingBox(
138141
geojson: GeoJSONData | GeoJSONDataGBFS,
139-
): LatLngTuple[] | undefined {
142+
): LngLatTuple[] | undefined {
140143
if (geojson == null) {
141144
return undefined;
142145
}
@@ -187,14 +190,14 @@ export function computeBoundingBox(
187190
}
188191

189192
return [
190-
[minY, minX],
191-
[maxY, maxX],
193+
[minX, minY],
194+
[maxX, maxY],
192195
];
193196
}
194197

195198
export const getBoundingBox = (
196199
feed: GTFSFeedType | GBFSFeedType ,
197-
): LatLngTuple[] | undefined => {
200+
): LngLatTuple[] | undefined => {
198201
if (feed == undefined || feed.data_type === 'gtfs_rt') {
199202
return undefined;
200203
};
@@ -208,20 +211,20 @@ export const getBoundingBox = (
208211
}
209212
return [
210213
[
211-
feed.bounding_box.minimum_latitude,
212214
feed.bounding_box.minimum_longitude,
215+
feed.bounding_box.minimum_latitude,
213216
],
214217
[
215-
feed.bounding_box.minimum_latitude,
216218
feed.bounding_box.maximum_longitude,
219+
feed.bounding_box.minimum_latitude,
217220
],
218221
[
219-
feed.bounding_box.maximum_latitude,
220222
feed.bounding_box.maximum_longitude,
223+
feed.bounding_box.maximum_latitude,
221224
],
222225
[
223-
feed.bounding_box.maximum_latitude,
224226
feed.bounding_box.minimum_longitude,
227+
feed.bounding_box.maximum_latitude,
225228
],
226229
];
227230
};

src/app/store/dataset-selectors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type LatLngExpression } from 'leaflet';
1+
import { type LngLatTuple } from '../types';
22
import { type components, type paths } from '../services/feeds/types';
33
import { type RootState } from './store';
44
import { createSelector } from '@reduxjs/toolkit';
@@ -29,28 +29,28 @@ export const selectHasLoadedAllDatasets = (
2929

3030
export const selectBoundingBoxFromLatestDataset = createSelector(
3131
[selectLatestDatasetsData],
32-
(latestDataset): LatLngExpression[] | undefined => {
32+
(latestDataset): LngLatTuple[] | undefined => {
3333
if (latestDataset === undefined) return undefined;
3434
return latestDataset.bounding_box?.minimum_latitude !== undefined &&
3535
latestDataset.bounding_box?.maximum_latitude !== undefined &&
3636
latestDataset.bounding_box?.minimum_longitude !== undefined &&
3737
latestDataset.bounding_box?.maximum_longitude !== undefined
3838
? [
3939
[
40-
latestDataset.bounding_box?.minimum_latitude,
4140
latestDataset.bounding_box?.minimum_longitude,
41+
latestDataset.bounding_box?.minimum_latitude,
4242
],
4343
[
44-
latestDataset.bounding_box?.minimum_latitude,
4544
latestDataset.bounding_box?.maximum_longitude,
45+
latestDataset.bounding_box?.minimum_latitude,
4646
],
4747
[
48-
latestDataset.bounding_box?.maximum_latitude,
4948
latestDataset.bounding_box?.maximum_longitude,
49+
latestDataset.bounding_box?.maximum_latitude,
5050
],
5151
[
52-
latestDataset.bounding_box?.maximum_latitude,
5352
latestDataset.bounding_box?.minimum_longitude,
53+
latestDataset.bounding_box?.maximum_latitude,
5454
],
5555
]
5656
: undefined;

src/app/store/feed-selectors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
isGtfsRtFeedType,
1111
} from '../services/feeds/utils';
1212
import { type RootState } from './store';
13-
import type { LatLngTuple } from 'leaflet';
13+
import { type LngLatTuple } from '../types';
1414

1515
export const selectFeedData = (state: RootState): BasicFeedType => {
1616
return state.feedProfile.data;
@@ -100,7 +100,7 @@ export const selectRelatedGtfsRTFeedsData = (
100100

101101
export const selectFeedBoundingBox = (
102102
state: RootState,
103-
): LatLngTuple[] | undefined => {
103+
): LngLatTuple[] | undefined => {
104104
if (
105105
!(
106106
isGtfsFeedType(state.feedProfile.data) ||
@@ -120,9 +120,9 @@ export const selectFeedBoundingBox = (
120120
return undefined;
121121
}
122122
return [
123-
[feed.bounding_box.minimum_latitude, feed.bounding_box.minimum_longitude],
124-
[feed.bounding_box.minimum_latitude, feed.bounding_box.maximum_longitude],
125-
[feed.bounding_box.maximum_latitude, feed.bounding_box.maximum_longitude],
126-
[feed.bounding_box.maximum_latitude, feed.bounding_box.minimum_longitude],
123+
[feed.bounding_box.minimum_longitude, feed.bounding_box.minimum_latitude],
124+
[feed.bounding_box.maximum_longitude, feed.bounding_box.minimum_latitude],
125+
[feed.bounding_box.maximum_longitude, feed.bounding_box.maximum_latitude],
126+
[feed.bounding_box.minimum_longitude, feed.bounding_box.maximum_latitude],
127127
];
128128
};

0 commit comments

Comments
 (0)