From f5f164fbc0fc6e1670ee853db55c6622a1a86efb Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 29 Aug 2022 17:31:26 +0300 Subject: Initial Map conversion --- src/Map.tsx | 117 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 48 deletions(-) (limited to 'src/Map.tsx') diff --git a/src/Map.tsx b/src/Map.tsx index c39e1ac..011d5c8 100644 --- a/src/Map.tsx +++ b/src/Map.tsx @@ -1,5 +1,6 @@ -import React, { Fragment, useState } from "react"; -import ReactMapboxGl, { Layer, Source } from "react-mapbox-gl"; +import React, { Fragment, useState, useEffect, useRef } from "react"; +// @ts-ignore +import { mapboxgl, LngLatLike } from '!mapbox-gl'; // eslint-disable-line import/no-webpack-loader-syntax import { MAPBOX_ACCESS_TOKEN, @@ -9,57 +10,77 @@ import { import "mapbox-gl/dist/mapbox-gl.css"; -const Mapbox = ReactMapboxGl({ - accessToken: MAPBOX_ACCESS_TOKEN, - minZoom: 5, - maxZoom: 10, - hash: false -}); +interface MapProps { + slider: number, + images: string[], +} -function Map(props) { - const [center] = useState([35, 31.9]); +function Map({ slider, images }: MapProps) { + const mapContainer = useRef(null); + const map = useRef(null); + const [center] = useState([35, 31.9]); const [zoom] = useState([6.3]); + useEffect(() => { + if (map.current) return; // initialize map only once + map.current = new mapboxgl({ + accessToken: MAPBOX_ACCESS_TOKEN, + container: mapContainer.current, + style: 'mapbox://styles/mapbox/streets-v11', + center, + zoom, + minZoom: 5, + maxZoom: 10, + hash: false, + }); + }); + return ( - - {props.images.map((img, i) => { - const id = `radar-280-${i}`; - return ( - - - - - ); - })} - +
+
+
); + + // return ( + // + // {images.map((img, i) => { + // const id = `radar-280-${i}`; + // return ( + // + // {/* + // */} + // + // ); + // })} + // + // ); } export default Map; -- cgit v1.3.1