Last active
November 18, 2019 22:28
-
-
Save Myrrel/a0d85ac21fd51fd5f301dc958c7f4c30 to your computer and use it in GitHub Desktop.
react leaflet
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
| Para usar leaflet en proyectos de React | |
| ======================================= | |
| + npm install --save leaflet | |
| + npm install --save react-leaflet | |
| ```javascript | |
| import React from 'react'; | |
| import { Map, TileLayer } from 'react-leaflet'; | |
| import L from 'leaflet'; // podria comentarlo funciona igual | |
| import 'leaflet/dist/leaflet.css'; | |
| const styles = { | |
| wrapper: { | |
| height: 400, | |
| width: '80%', | |
| margin: '0 auto', | |
| display: 'flex' | |
| }, | |
| map: { | |
| flex: 1 | |
| } | |
| } | |
| class Mapa extends React.Component { | |
| constructor (props){ | |
| super(props); | |
| this.state = { | |
| center: [27.9361805667694, -15.589599609374998], | |
| zoom: 10, | |
| url: 'https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}{r}.png' | |
| } | |
| } | |
| render(){ | |
| return ( | |
| <div className="container"> | |
| <div style={styles.wrapper}> | |
| <Map style={styles.map} center={this.state.center} zoom={this.state.zoom}> | |
| <TileLayer url={this.state.url} /> | |
| </Map> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Mapa; | |
| ``` | |
| [1]https://leaflet-extras.github.io/leaflet-providers/preview/ | |
| [2]https://react-leaflet.js.org/en/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment