Created
June 18, 2021 20:14
-
-
Save maxwell-oroark/28b5ab966e6c0623dd0517b2ae991e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { GoogleMapsOverlay as DeckOverlay } from "@deck.gl/google-maps"; | |
import { EditableGeoJsonLayer, DrawPolygonMode } from "nebula.gl"; | |
import mapStyle from "./mapStyle"; | |
const myFeatureCollection = { | |
type: "FeatureCollection", | |
features: [ | |
/* insert features here */ | |
], | |
}; | |
const selectedFeatureIndexes = []; | |
class Map extends React.Component { | |
constructor() { | |
super(); | |
this.mapRef = React.createRef(); | |
this.state = { | |
data: myFeatureCollection, | |
}; | |
} | |
componentDidMount() { | |
const map = new window.google.maps.Map(this.mapRef.current, { | |
center: { lat: 40, lng: -100 }, | |
zoom: 5, | |
styles: mapStyle, | |
mapTypeId: "terrain", | |
mapTypeControlOptions: { | |
mapTypeIds: ["roadmap", "terrain"], | |
}, | |
streetViewControl: false, | |
}); | |
const overlay = new DeckOverlay({ | |
layers: [ | |
new EditableGeoJsonLayer({ | |
id: "geojson-layer", | |
data: this.state.data, | |
mode: DrawPolygonMode, | |
selectedFeatureIndexes, | |
onEdit: ({ updatedData }) => { | |
console.log("updating data"); | |
this.setState({ | |
data: updatedData, | |
}); | |
}, | |
}), | |
], | |
}); | |
overlay.setMap(map); | |
} | |
render() { | |
return ( | |
<div style={{ width: "100vw", height: "100vh" }} ref={this.mapRef}></div> | |
); | |
} | |
} | |
export default Map; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment