A Pen by Ucchishta Sivaguru on CodePen.
Created
July 19, 2019 09:20
-
-
Save uccmen/1c3f39419c388b10d6ea985dc4121b72 to your computer and use it in GitHub Desktop.
React-Leaflet v2 example
This file contains hidden or 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 hidden or 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 hidden or 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/[email protected]/umd/react.development.js"></script> | |
| <script src="https://unpkg.com/[email protected]/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/[email protected]/dist/react-leaflet.js"></script> |
This file contains hidden or 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 hidden or 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://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