-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathperformance.js
95 lines (86 loc) · 2.27 KB
/
performance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// @flow
/**
* <!-- {"order": 8 } -->
*
* # N markers
*
* Example of drawing N React markers.
*
*/
import * as React from 'react';
import { Map, Overlay, Marker } from 'rgm';
import { css } from '@emotion/core';
import { Flex, Box } from 'react-system';
import { useGoogleApiLoader } from '../dev-src/hooks';
import { Ratio, Select } from '../dev-src/controls';
import type { StaticProps } from '../dev-src/doc.js';
// https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
const MAP_OPTIONS = {
zoom: 9,
center: {
lat: 59.936,
lng: 30.314,
},
gestureHandling: 'greedy',
clickableIcons: false,
};
const genRandomMarkers = n =>
Array.from(Array(n), () => {
const r = Math.random() * 2 + 0.05;
const angle = Math.random() * 2 * Math.PI;
return {
lat: MAP_OPTIONS.center.lat + r * Math.cos(angle),
lng: MAP_OPTIONS.center.lng + r * Math.sin(angle),
};
});
export default function Performance(): React.Node {
const api = useGoogleApiLoader();
const INITIAL_MARKERS_COUNT = 200;
const [markers, setMarkers] = React.useState(() =>
genRandomMarkers(INITIAL_MARKERS_COUNT),
);
return (
<div>
<Flex p={3}>
<Box pr={2}>Count:</Box>
<Select
options={['100', '200', '300', '500', '1000', '2000']}
value={`${markers.length}`}
onChange={v => {
setMarkers(genRandomMarkers(Number.parseFloat(v)));
}}
/>
</Flex>
<Ratio value={3 / 4}>
{api && (
<Map api={api} options={MAP_OPTIONS}>
<Overlay>
{markers.map((m, index) => (
<Marker key={index} lat={m.lat} lng={m.lng}>
<CircleMarker />
</Marker>
))}
</Overlay>
</Map>
)}
</Ratio>
</div>
);
}
const CircleMarker = () => (
<div
css={css`
place-self: center center;
width: 10px;
height: 10px;
border-radius: 100%;
background-color: white;
border: 2px solid red;
`}
/>
);
export const getStaticProps = async (): Promise<StaticProps> => {
// The best is to place this method at _app.js but this doesn't work now
const doc = await import('../dev-src/doc');
return doc.getStaticProps();
};