Skip to content

Instantly share code, notes, and snippets.

@jccartwright
Created October 3, 2020 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jccartwright/ff7f69f4960ce6aa1f0715ec5ed7c2c4 to your computer and use it in GitHub Desktop.
Save jccartwright/ff7f69f4960ce6aa1f0715ec5ed7c2c4 to your computer and use it in GitHub Desktop.
React-Leaflet v2 example
<div id="container"></div>
const { Map: LeafletMap, TileLayer, Marker, Popup } = ReactLeaflet
class SimpleExample extends React.Component {
constructor() {
super()
this.state = {
lat: 51.505,
lng: -0.09,
zoom: 13
}
}
render() {
const position = [this.state.lat, this.state.lng];
return (
<LeafletMap center={position} zoom={this.state.zoom}>
<TileLayer
attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='https://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
<Marker position={position}>
<Popup>
A pretty CSS3 popup. <br/> Easily customizable.
</Popup>
</Marker>
</LeafletMap>
);
}
}
ReactDOM.render(<SimpleExample />, document.getElementById('container'))
<script src="https://unpkg.com/react@16.13.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.13.0/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet-src.js"></script>
<script src="https://unpkg.com/react-leaflet@2.7.0/dist/react-leaflet.js"></script>
.leaflet-container {
height: 400px;
width: 100%;
}
<link href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment