A Pen by Paul Le Cam on CodePen.
Created
October 3, 2020 16:12
-
-
Save jccartwright/ff7f69f4960ce6aa1f0715ec5ed7c2c4 to your computer and use it in GitHub Desktop.
React-Leaflet v2 example
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
<div id="container"></div> |
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
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='© <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')) |
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
<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> |
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
.leaflet-container { | |
height: 400px; | |
width: 100%; | |
} |
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
<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