Skip to content

Instantly share code, notes, and snippets.

@uccmen
Created July 19, 2019 09:20
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 uccmen/1c3f39419c388b10d6ea985dc4121b72 to your computer and use it in GitHub Desktop.
Save uccmen/1c3f39419c388b10d6ea985dc4121b72 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.8.6/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js"></script>
<script src="https://unpkg.com/react-leaflet@2.4.0/dist/react-leaflet.js"></script>
.leaflet-container {
height: 400px;
width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment