diff --git a/justice40-frontend/src/components/mapboxmap.js b/justice40-frontend/src/components/mapboxmap.js deleted file mode 100644 index c90344bc..00000000 --- a/justice40-frontend/src/components/mapboxmap.js +++ /dev/null @@ -1,22 +0,0 @@ -import React, { useRef, useEffect, useState } from 'react'; -import ReactMapGL from 'react-map-gl'; - -const MapboxMap = () => { - const [viewport, setViewport] = useState({ - latitude: 39.289444, - longitude: -76.615278, - zoom: 8 - }); - - return ( - setViewport(viewport)} - /> - ); -} - -export default MapboxMap; \ No newline at end of file diff --git a/justice40-frontend/src/pages/mapbox.js b/justice40-frontend/src/pages/mapbox.js index 4ce4bdb0..82a9c733 100644 --- a/justice40-frontend/src/pages/mapbox.js +++ b/justice40-frontend/src/pages/mapbox.js @@ -1,68 +1,92 @@ import React, { useRef, useEffect, useState } from 'react'; import Layout from '../components/layout'; -import MapboxMap from '../components/mapboxmap' +import ReactMapGL, {Layer, Source} from 'react-map-gl'; import * as mapboxStyles from "./mapbox.module.css"; -// mapboxgl.workerClass = MapboxWorker; -// markup +const xyzSource = { + name: "public.maryland", + scheme: 'xyz', + tilejson: "2.0.0", + minzoom: 0, + maxzoom: 22, + prefetchable: true, + tiles: ["http://localhost:7800/public.maryland/{z}/{x}/{y}.mvt"], + type: 'vector' +}; + +const layerStyle = { + id: 'public.maryland.MultiPolygon.fill', + type: 'fill', + source: "public.maryland", + "source-layer": "public.maryland", + paint: { + "fill-color": [ + "interpolate", + ["linear"], + ["get", "lowincpct"], + 0, + "white", + 1, + "rgb(0,94,162)" + ], + "fill-opacity": 0.5 + } +}; + +const mapStyle = { + 'version': 8, + 'sources': { + 'carto-light': { + 'type': 'raster', + 'tiles': [ + "https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png", + "https://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png", + "https://c.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png", + "https://d.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png" + ] + } + }, + 'layers': [{ + 'id': 'carto-light-layer', + 'source': 'carto-light', + 'type': 'raster', + 'minzoom': 0, + 'maxzoom': 22 + }] +}; + +const MapboxMap = () => { + const [viewport, setViewport] = useState({ + latitude: 39.289444, + longitude: -76.615278, + zoom: 8 + }); + + return ( + setViewport(viewport)} + mapStyle={mapStyle} + > + + + + + ); +} + const MapboxPage = () => { - // const mapContainer = useRef(); - // const [lng, setLng] = useState(-76.615278); - // const [lat, setLat] = useState(39.289444); - // const [zoom, setZoom] = useState(9); - - // useEffect(() => { - // const map = new mapboxgl.Map({ - // container: mapContainer.current, - // style: 'mapbox://styles/mapbox/streets-v11', - // center: [lng, lat], - // zoom: zoom - // }); - - // map.on('load', () => { - // map.resize(); - // }); - - // map.on('load', () => { - // map.on("load", function() { - // map.addSource("public.maryland", { - // "type": "vector", - // "tiles": ["http://localhost:7800/public.maryland/{z}/{x}/{y}.mvt"], - // "minzoom": 0, - // "maxzoom": 22 - // }); - - // map.addLayer({ - // "id": "public.maryland.MultiPolygon.fill", - // "source": "public.maryland", - // "source-layer": "public.maryland", - // "type": "fill", - // "paint": { - // "fill-color": [ - // "interpolate", - // ["linear"], - // ["get", "lowincpct"], - // 0, - // "white", - // 1, - // "black" - // ], - // "fill-opacity": 0.5 - // } - // }); - // }); - // }); - - // return () => map.remove(); - // }, []); - return ( - +
+ +
); - }; export default MapboxPage