Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import React, { Component, createRef } from 'react';
  2. import { makeStyles } from "@material-ui/core/styles";
  3. import Leaflet from 'leaflet';
  4. import { Map, TileLayer, Marker, Popup, MapControl, withLeaflet } from 'react-leaflet';
  5. import { Apps, CloudDownload } from "@material-ui/icons";
  6. import ExampleIcon from "@material-ui/icons/AddToQueue";
  7. import 'leaflet/dist/leaflet.css';
  8.  
  9. export default class EventMap extends React.Component {
  10. state = {
  11. center: {
  12. lat: 31.698956,
  13. lng: 76.732407,
  14. },
  15. marker: {
  16. lat: 31.698956,
  17. lng: 76.732407,
  18. },
  19. zoom: 13,
  20. draggable: true,
  21. };
  22.  
  23. constructor(props) {
  24. super(props);
  25. this.map_bounds = {
  26. dsf: 123
  27. };
  28. this.componentDidMount = this.componentDidMount.bind(this);
  29. };
  30.  
  31.  
  32. componentDidMount(){
  33. let mapInst = this.refs.map.leafletElement;
  34. console.log()
  35. mapInst.on('moveend', function () {
  36. console.log(mapInst.getBounds())
  37. });
  38.  
  39. mapInst.on('dragend', function () {
  40. console.log(this.props)
  41. });
  42. }
  43.  
  44. updateParent = (newBounds) => {
  45. this.props.parentCallback({'bounds': newBounds});
  46. }
  47.  
  48.  
  49. refmarker = createRef(this.state.marker);
  50.  
  51. render() {
  52. const position = [this.state.center.lat, this.state.center.lng];
  53.  
  54. return (
  55. <div>
  56. <Map ref='map' center={position} zoom={this.state.zoom} style={{height:"500px", width:"500px"}}>
  57. <TileLayer
  58. attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  59. url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
  60. />
  61. {this.props.tournament_data.map(mark =>
  62. <Marker
  63. ref={this.refmarker}
  64. draggable={false}
  65. position={mark.coord}
  66. >
  67. <Popup minWidth={90}>
  68. <span>
  69. {mark.id}
  70. </span>
  71. </Popup>
  72. </Marker>
  73. )}
  74. </Map>
  75. </div>
  76. );
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement