Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 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. <Marker position={[lat, lng]} icon={customMarker} key={index}>
  75. <div className="leaflet-popup-content">
  76. <Popup maxWidth="1000" maxHeight="auto">
  77. <div className="chart">
  78. <br />
  79. <br />
  80. Температура °C
  81. <ComposedChart
  82. width={400}
  83. height={200}
  84. data={this.loadData(index+1)}
  85. margin={{
  86. top: 20,
  87. right: 0,
  88. left: 0,
  89. bottom: 20
  90. }}
  91. >
  92. <CartesianGrid stroke="#f5f5f5" />
  93. <XAxis dataKey="DATS" />
  94. <YAxis />
  95. <Tooltip />
  96. <Legend />
  97. <Line
  98. type="monotone"
  99. dataKey="TA"
  100. fill="#f70000"
  101. stroke="#f56200"
  102. />
  103. </ComposedChart>
  104. </div>
  105. {index + 1} is for popup with lat: {lat} and lon {lng}
  106. </Popup>
  107. </div>
  108. </Marker>
  109. ))}
  110. </LeafletMap>
  111. );
  112. }
  113. }
  114.  
  115. export default Map;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement