mirror of
https://github.com/DerTyp7/leaflet-esri-test.git
synced 2025-10-29 12:32:14 +01:00
hard refresh
This commit is contained in:
6760
package-lock.json
generated
6760
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,8 +6,14 @@
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"esri-leaflet": "^3.0.8",
|
||||
"esri-leaflet-heatmap": "^2.0.1",
|
||||
"leaflet": "^1.9.2",
|
||||
"leaflet.heat": "^0.2.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-esri-leaflet": "^2.0.1",
|
||||
"react-leaflet": "^4.1.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
|
||||
32
src/App.js
32
src/App.js
@@ -1,25 +1,11 @@
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
import React from "react";
|
||||
import Map from "./Map";
|
||||
import "./styles.css";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.js</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
export default function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<Map />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
88
src/Map.jsx
Normal file
88
src/Map.jsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import React from "react";
|
||||
import { MapContainer, TileLayer } from "react-leaflet";
|
||||
import HeatmapLayer from "react-esri-leaflet/plugins/HeatmapLayer";
|
||||
import "leaflet/dist/leaflet.css";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
const urls = [
|
||||
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Earthquakes_Since1970/MapServer/0",
|
||||
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Earthquakes_Since1970/MapServer/0",
|
||||
];
|
||||
|
||||
let index = 0;
|
||||
|
||||
let lastRefreshed = Date.now();
|
||||
let heatmapTurnedOff;
|
||||
let isHeatmapOff = false;
|
||||
function Map() {
|
||||
const [url, setUrl] = useState(
|
||||
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/CommunityAddressing/MapServer/0"
|
||||
);
|
||||
const [refreshHook, setRefreshHook] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
if (Date.now() - lastRefreshed >= 1000) {
|
||||
if (index === 1) {
|
||||
setUrl(urls[index]);
|
||||
index = 0;
|
||||
} else {
|
||||
setUrl(urls[index]);
|
||||
index = 1;
|
||||
}
|
||||
}
|
||||
|
||||
setRefreshHook(Math.random());
|
||||
//console.log(urls[index]);
|
||||
}, 100);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
function renderHeatmap() {
|
||||
//console.log("Render");
|
||||
return (
|
||||
<HeatmapLayer
|
||||
url={url}
|
||||
radius={20}
|
||||
eventHandlers={{
|
||||
loading: () => console.log("loading heatmap"),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function turnOffMap() {
|
||||
//console.log("Turn off");
|
||||
|
||||
if (!isHeatmapOff) {
|
||||
heatmapTurnedOff = Date.now();
|
||||
isHeatmapOff = true;
|
||||
}
|
||||
|
||||
//console.log("heatmapTurnedOff ago: " + (Date.now() - heatmapTurnedOff));
|
||||
|
||||
if (Date.now() - heatmapTurnedOff >= 50) {
|
||||
// Wie lange ist die heatpmap aus???
|
||||
//console.log("Turned off for 500");
|
||||
lastRefreshed = Date.now(); // Mach map wieder an
|
||||
isHeatmapOff = false;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
return (
|
||||
<MapContainer id="mapId" zoom={2} center={[39.759, -88.157]}>
|
||||
{refreshHook ? "" : ""}
|
||||
<TileLayer
|
||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
/>
|
||||
{/*console.log("lastRefreshed ago: " + (Date.now() - lastRefreshed))*/}
|
||||
{Date.now() - lastRefreshed >= 5000 ? turnOffMap() : renderHeatmap()}
|
||||
</MapContainer>
|
||||
);
|
||||
}
|
||||
|
||||
export default Map;
|
||||
25
src/index.js
25
src/index.js
@@ -1,17 +1,12 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
import { StrictMode } from "react";
|
||||
import { render } from "react-dom";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
import App from "./App";
|
||||
|
||||
const rootElement = document.getElementById("root");
|
||||
render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
rootElement
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
|
||||
14
src/styles.css
Normal file
14
src/styles.css
Normal file
@@ -0,0 +1,14 @@
|
||||
.App {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#root,
|
||||
.App,
|
||||
#mapId {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
Reference in New Issue
Block a user