Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. import React from "react";
  2. import { Map as LeafletMap, TileLayer, Marker, Popup } from "react-leaflet";
  3. import L from "leaflet";
  4. import {
  5. ComposedChart,
  6. Bar,
  7. Area,
  8. Line,
  9. XAxis,
  10. YAxis,
  11. CartesianGrid,
  12. Tooltip,
  13. Legend
  14. } from "recharts";
  15. import "./App.css";
  16.  
  17. const customMarker = new L.Icon({
  18. iconUrl:
  19. "https://unpkg.com/browse/leaflet@1.5.1/dist/images/marker-shadow.png",
  20. iconSize: [25, 41],
  21. iconAnchor: [10, 41],
  22. popupAnchor: [2, -40]
  23. });
  24.  
  25. class Map extends React.Component {
  26. state = {
  27. date: new Date()
  28. };
  29.  
  30. constructor() {
  31. super();
  32. this.state = {
  33. coords: [
  34. { lat: 41.19197, lng: 25.33719 },
  35. { lat: 41.26352, lng: 25.1471 }
  36. ],
  37. zoom: 8,
  38. minZoom: 7,
  39. maxZoom: 9,
  40. dats: null,
  41. loading: true,
  42. dataAPI: null,
  43. temp: null
  44. };
  45. this.getURL = this.getURL.bind(this);
  46. this.loadData = this.loadData.bind(this);
  47. }
  48.  
  49. getURL = id =>
  50. `http://192.168.0.1:8000/?date=2019-10-20&id=${id}&daysForward=2`;
  51.  
  52. loadData = async id => {
  53. const response = await fetch(this.getURL(id));
  54. const data = await response.json();
  55. return data.aladinModel[0];
  56. };
  57.  
  58. render() {
  59. const { coords, zoom } = this.state;
  60. return (
  61. <LeafletMap
  62. center={[42.733883, 25.48583]}
  63. zoom={zoom}
  64. minZoom={this.state.minZoom}
  65. maxZoom={this.state.maxZoom}
  66. style={{ height: "100vh", width: "100vw" }}
  67. >
  68. <TileLayer
  69. attribution='&copy; <a href="http://plovdiv.meteo.bg">НИМХ - Пловдив</a> '
  70. url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
  71. />
  72.  
  73. {coords.map(({ lat, lng }, index) => {
  74. let charData = this.loadData(index + 1);
  75. return (
  76. <Marker position={[lat, lng]} icon={customMarker} key={index}>
  77. <div className="leaflet-popup-content">
  78. <Popup maxWidth="1000" maxHeight="auto">
  79. <div className="chart">
  80. <br />
  81. <br />
  82. Температура °C
  83. <ComposedChart
  84. width={400}
  85. height={200}
  86. data={charData}
  87. margin={{
  88. top: 20,
  89. right: 0,
  90. left: 0,
  91. bottom: 20
  92. }}
  93. >
  94. <CartesianGrid stroke="#f5f5f5" />
  95. <XAxis dataKey="DATS" />
  96. <YAxis />
  97. <Tooltip />
  98. <Legend />
  99. <Line
  100. type="monotone"
  101. dataKey="TA"
  102. fill="#f70000"
  103. stroke="#f56200"
  104. />
  105. </ComposedChart>
  106. </div>
  107. {index + 1} is for popup with lat: {lat} and lon {lng}
  108. </Popup>
  109. </div>
  110. </Marker>
  111. );
  112. })}
  113. </LeafletMap>
  114. );
  115. }
  116. }
  117.  
  118. export default Map;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement