|
@@ -0,0 +1,56 @@
|
|
|
+import React, {Profiler} from "react";
|
|
|
+import Pigeon from "./../Pigeon";
|
|
|
+
|
|
|
+import {calcDistance} from './../helpers/distance';
|
|
|
+import {measureTime} from './../helpers/measureTime';
|
|
|
+import {longitude, latitude, mapWidth, mapHeight} from "./../config/variables";
|
|
|
+
|
|
|
+
|
|
|
+export default class Pigeons extends React.Component{
|
|
|
+ constructor(props) {
|
|
|
+ super(props)
|
|
|
+ this.metricsRef = React.createRef()
|
|
|
+
|
|
|
+ this.state = {
|
|
|
+ mapConfig: {
|
|
|
+ zoom: 15,
|
|
|
+ path: [],
|
|
|
+ coords: [latitude, longitude],
|
|
|
+ width: mapWidth,
|
|
|
+ height: mapHeight,
|
|
|
+ defaultZoom: 15,
|
|
|
+ distance: 0,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateMapState = (key, value) => {
|
|
|
+ let mapConfigCopy = JSON.parse(JSON.stringify(this.state.mapConfig));
|
|
|
+ mapConfigCopy[key] = value;
|
|
|
+ this.setState({mapConfig: mapConfigCopy})
|
|
|
+ }
|
|
|
+
|
|
|
+ getDistance = () => {
|
|
|
+ let dst = calcDistance(this.state.mapConfig.path)
|
|
|
+ this.updateMapState("distance", dst)
|
|
|
+ }
|
|
|
+
|
|
|
+ render(){
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <div ref={this.metricsRef} className="mapTime" >
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <Profiler id="pigeons" onRender={measureTime(this)}>
|
|
|
+ { Array.from({length:200}, (_, index) => <Pigeon
|
|
|
+ mapConfig={this.state.mapConfig}
|
|
|
+ updateMapState={this.updateMapState}
|
|
|
+ getDistance={this.getDistance}
|
|
|
+ key={index}
|
|
|
+ />) }
|
|
|
+ </Profiler>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|