-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoBoundaries.tsx
42 lines (36 loc) · 1.5 KB
/
DemoBoundaries.tsx
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
//
// Demonstrates the computation of the boundary line(s) of the max cluster.
//
import { Polyline, Rectangle } from 'react-leaflet'
import { cluster2boundaries, tiles2clusters, TileSet } from 'tiles-math'
import { OSMContainer } from './OSMContainer'
import { sampleCoords } from './sample-coords'
const tileZoom = 14 // VeloViewer and others use zoom-level 14 tiles
const mapZoom = 13
const tiles = new TileSet(tileZoom).addCoords(sampleCoords)
const { detachedTiles, minorClusters, maxCluster } = tiles2clusters(tiles)
const nonCluster = detachedTiles.merge(minorClusters) // Do not distinguish between normal tiles and smaller clusters
const boundaries = cluster2boundaries(maxCluster)
// Displays all tiles, the max cluster, and the boundary line around the max cluster.
const TileContainer = () => (
<div>
<>
{nonCluster.map((tile, index) => (
<Rectangle key={index} bounds={tile.bounds()} pathOptions={{ color: 'red', weight: 0.5 }} />
))}
</>
<>
{maxCluster.map((tile, index) => (
<Rectangle key={index} bounds={tile.bounds()} pathOptions={{ color: 'blue', weight: 0.5 }} />
))}
</>
<>
{boundaries.map((line, index) => (
<Polyline key={index} positions={line.positions()} pathOptions={{ color: 'blue', weight: 4 }} />
))}
</>
</div>
)
export const DemoBoundaries = () => (
<OSMContainer tileContainer={<TileContainer />} mapZoom={mapZoom} />
)