From 4ddde10213d20b5ce8bdba83e4067a50ffeea6d2 Mon Sep 17 00:00:00 2001 From: Ian G Date: Thu, 24 Feb 2022 02:01:05 -0500 Subject: [PATCH] cleaning mapboxgl support --- src/components/mapboxgl/Line.tsx | 2 +- .../mapboxgl/LocationInformationDialog.tsx | 16 +++++++++--- src/components/mapboxgl/Map.tsx | 5 ++-- .../mapboxgl/{Utility => }/MapContext.ts | 0 src/components/mapboxgl/Marker.tsx | 2 +- src/components/mapboxgl/Utility/Map.ts | 25 ------------------- src/components/mapboxgl/Utility/Point.ts | 8 ++++++ src/components/mapboxgl/Utility/index.ts | 2 ++ src/components/mapboxgl/index.ts | 2 ++ 9 files changed, 29 insertions(+), 33 deletions(-) rename src/components/mapboxgl/{Utility => }/MapContext.ts (100%) delete mode 100644 src/components/mapboxgl/Utility/Map.ts create mode 100644 src/components/mapboxgl/Utility/Point.ts create mode 100644 src/components/mapboxgl/Utility/index.ts diff --git a/src/components/mapboxgl/Line.tsx b/src/components/mapboxgl/Line.tsx index 113a29d..e33edc7 100644 --- a/src/components/mapboxgl/Line.tsx +++ b/src/components/mapboxgl/Line.tsx @@ -1,7 +1,7 @@ import { GeoJSON } from 'geojson' import { Expression, GeoJSONSource, GeoJSONSourceRaw } from 'mapbox-gl' import React, { useContext, useEffect, useState } from 'react' -import { MapContext } from './Utility/MapContext' +import { MapContext } from './MapContext' export interface Coordinates { longitude: number diff --git a/src/components/mapboxgl/LocationInformationDialog.tsx b/src/components/mapboxgl/LocationInformationDialog.tsx index ce637fd..46e1966 100644 --- a/src/components/mapboxgl/LocationInformationDialog.tsx +++ b/src/components/mapboxgl/LocationInformationDialog.tsx @@ -19,7 +19,7 @@ export const LocationInformationDialog = ({ showMouse, mouseLongitude, mouseLatitude, - showForCode, + showForCode }: Props): React.ReactElement => { return (
Longitude: {longitude} | Latitude: {latitude} | Zoom: {zoom}
-
{showForCode ? `- {"longitude": ${longitude}, "latitude": ${latitude}}` : null}
+
+ {showForCode + ? `- {"longitude": ${longitude}, "latitude": ${latitude}}` + : null} +
{showMouse ? (
Mouse ~ Longitude: {mouseLongitude} | Latitude: {mouseLatitude}
-
{showForCode ? `- {"longitude": ${mouseLongitude}, "latitude": ${mouseLatitude}}` : null}
+
+ {showForCode + ? `- {"longitude": ${mouseLongitude}, "latitude": ${mouseLatitude}}` + : null} +
) : null}
diff --git a/src/components/mapboxgl/Map.tsx b/src/components/mapboxgl/Map.tsx index fa7eaa4..7aa0e90 100644 --- a/src/components/mapboxgl/Map.tsx +++ b/src/components/mapboxgl/Map.tsx @@ -10,7 +10,8 @@ import Line from './Line' import LocationInformationDialog from './LocationInformationDialog' import { MarkerMethods } from './Marker' import { MinMax } from './Utility/LngLat' -import { MapContext } from './Utility/MapContext' + +import { MapContext } from './MapContext' interface Props { accessToken: string @@ -53,7 +54,7 @@ export const Map = ({ const [mapStyleIsLoaded, setMapStyleIsLoaded] = useState(false) const [mouseLocation, setMouseLocation] = useState() const [mouseLocationPause, setMouseLocationPause] = useState(false) - // const [markers, setMarkers] = useState({}) + // TODO: only allows for one instance of a map, fix for future usage mapboxgl.accessToken = accessToken diff --git a/src/components/mapboxgl/Utility/MapContext.ts b/src/components/mapboxgl/MapContext.ts similarity index 100% rename from src/components/mapboxgl/Utility/MapContext.ts rename to src/components/mapboxgl/MapContext.ts diff --git a/src/components/mapboxgl/Marker.tsx b/src/components/mapboxgl/Marker.tsx index 85d573e..5ab7de0 100644 --- a/src/components/mapboxgl/Marker.tsx +++ b/src/components/mapboxgl/Marker.tsx @@ -7,7 +7,7 @@ import React, { useState } from 'react' import ReactDOM from 'react-dom' -import { MapContext } from './Utility/MapContext' +import { MapContext } from './MapContext' export interface Coordinates { longitude: number diff --git a/src/components/mapboxgl/Utility/Map.ts b/src/components/mapboxgl/Utility/Map.ts deleted file mode 100644 index faef7d3..0000000 --- a/src/components/mapboxgl/Utility/Map.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { - GeoJSONSourceRaw, - LineLayer, - Marker as MapboxMarker, - SymbolLayer -} from 'mapbox-gl' -import mapboxgl from 'mapbox-gl' - -export type MapboxMarkersStore = Record -interface LinesStoreRecord { - source: GeoJSONSourceRaw - lineLayer: LineLayer - symbolLayer: SymbolLayer | null -} -export type MapboxLinesStore = Record - -export const calculateDistanceSquared = ( - left: mapboxgl.Point, - right: mapboxgl.Point -): number => { - return ( - (left.x - right.x) * (left.x - right.x) + - (left.y - right.y) * (left.y - right.y) - ) -} diff --git a/src/components/mapboxgl/Utility/Point.ts b/src/components/mapboxgl/Utility/Point.ts new file mode 100644 index 0000000..f4a1a38 --- /dev/null +++ b/src/components/mapboxgl/Utility/Point.ts @@ -0,0 +1,8 @@ +import { Point } from 'mapbox-gl' + +export const calculateDistanceSquared = (left: Point, right: Point): number => { + return ( + (left.x - right.x) * (left.x - right.x) + + (left.y - right.y) * (left.y - right.y) + ) +} diff --git a/src/components/mapboxgl/Utility/index.ts b/src/components/mapboxgl/Utility/index.ts new file mode 100644 index 0000000..947ae51 --- /dev/null +++ b/src/components/mapboxgl/Utility/index.ts @@ -0,0 +1,2 @@ +export * from './LngLat' +export * from './Point' diff --git a/src/components/mapboxgl/index.ts b/src/components/mapboxgl/index.ts index 7be93a7..c3851fb 100644 --- a/src/components/mapboxgl/index.ts +++ b/src/components/mapboxgl/index.ts @@ -1,3 +1,5 @@ export { Map } from './Map' export { Marker } from './Marker' export { Line } from './Line' +export { MapContext } from './MapContext' +export * from './Utility'