MCPcopy Create free account
hub / github.com/developmentseed/stac-react / Map

Function Map

example/src/pages/Main/Map.jsx:38–106  ·  view source on GitHub ↗
({ className, isBboxDrawEnabled, handleDrawComplete, items })

Source from the content-addressed store, hash-verified

36};
37
38function Map({ className, isBboxDrawEnabled, handleDrawComplete, items }) {
39 const mapContainerRef = useRef();
40 const drawControleRef = useRef();
41 const [map, setMap] = useState();
42
43 useEffect(() => {
44 const m = new mapbox.Map({
45 container: mapContainerRef.current,
46 style: 'mapbox://styles/mapbox/dark-v10',
47 center: [-99.31640625, 40.04443758460856],
48 zoom: 3,
49 dragRotate: false,
50 touchZoomRotate: false,
51 attributionControl: true,
52 });
53
54 const onLoad = () => {
55 setMap(m);
56 m.addSource('items', {
57 type: 'geojson',
58 data: { type: 'FeatureCollection', features: [] },
59 });
60
61 m.addLayer({
62 id: 'items',
63 type: 'line',
64 source: 'items',
65 layout: {},
66 paint: {
67 'line-color': '#0080ff',
68 'line-width': 1,
69 },
70 });
71 };
72 m.on('load', onLoad);
73 drawControleRef.current = addDrawControl(m, handleDrawComplete);
74
75 return () => {
76 m.off('load', onLoad);
77 if (map) {
78 map.remove();
79 }
80 };
81 }, []);
82
83 useEffect(() => {
84 if (isBboxDrawEnabled) {
85 drawControleRef.current.deleteAll();
86 drawControleRef.current.changeMode('draw_rectangle');
87 map.getCanvas().style.cursor = 'crosshair';
88 }
89 }, [isBboxDrawEnabled, map]);
90
91 useEffect(() => {
92 if (map) {
93 if (items) {
94 map.getSource('items').setData(items);
95 } else {

Callers

nothing calls this directly

Calls 1

addDrawControlFunction · 0.85

Tested by

no test coverage detected