11import { useState , useRef } from 'react' ;
2- import { Dimensions , StyleSheet , View } from 'react-native' ;
2+ import { Button , Dimensions , StyleSheet , View } from 'react-native' ;
33import {
44 Clusterer ,
55 isClusterFeature ,
66 type Supercluster ,
77} from 'react-native-clusterer' ;
88import MapView , { type Region } from 'react-native-maps' ;
9- import { initialRegion , parsedPlacesData } from './places' ;
9+ import { getRandomData , initialRegion , parsedPlacesData } from './places' ;
1010import { Point } from './Point' ;
1111
1212type IFeature = Supercluster . PointOrClusterFeature < any , any > ;
@@ -17,6 +17,9 @@ const MAP_DIMENSIONS = { width: MAP_WIDTH, height: MAP_HEIGHT };
1717
1818export const Map = ( ) => {
1919 const [ region , setRegion ] = useState < Region > ( initialRegion ) ;
20+ const [ places , setPlaces ] =
21+ useState < Supercluster . PointFeature < any > [ ] > ( parsedPlacesData ) ;
22+ const [ options , setOptions ] = useState ( { radius : 18 } ) ;
2023 const mapRef = useRef < MapView > ( null ) ;
2124
2225 const _handlePointPress = ( point : IFeature ) => {
@@ -35,9 +38,9 @@ export const Map = () => {
3538 style = { MAP_DIMENSIONS }
3639 >
3740 < Clusterer
38- data = { parsedPlacesData }
41+ data = { places }
3942 region = { region }
40- options = { { radius : 18 } }
43+ options = { options }
4144 mapDimensions = { MAP_DIMENSIONS }
4245 renderItem = { ( item ) => {
4346 return (
@@ -54,6 +57,18 @@ export const Map = () => {
5457 } }
5558 />
5659 </ MapView >
60+ < View style = { styles . buttonContainer } >
61+ < Button
62+ title = "Add 1000 points"
63+ onPress = { ( ) =>
64+ setPlaces ( parsedPlacesData . concat ( getRandomData ( 1000 ) ) )
65+ }
66+ />
67+ < Button
68+ title = "Change options"
69+ onPress = { ( ) => setOptions ( { radius : Math . floor ( Math . random ( ) * 18 ) } ) }
70+ />
71+ </ View >
5772 </ View >
5873 ) ;
5974} ;
@@ -62,4 +77,19 @@ const styles = StyleSheet.create({
6277 container : {
6378 flex : 1 ,
6479 } ,
80+ buttonContainer : {
81+ position : 'absolute' ,
82+ bottom : 0 ,
83+ left : 0 ,
84+ right : 0 ,
85+ flexDirection : 'row' ,
86+ justifyContent : 'space-between' ,
87+ width : '100%' ,
88+ backgroundColor : '#ed8e8efd' ,
89+ borderColor : '#ed8e8e' ,
90+ borderWidth : 1 ,
91+ borderRadius : 5 ,
92+ gap : 10 ,
93+ paddingHorizontal : 20 ,
94+ } ,
6595} ) ;
0 commit comments