From 552dbb4789b229a7420eb20d9285a141f2e1bc67 Mon Sep 17 00:00:00 2001 From: 7c00 Date: Tue, 14 Dec 2021 10:39:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E8=81=9A=E5=90=88=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A8=E6=80=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/screens/cluster.tsx | 22 +++++++++++++++------- lib/src/cluster/index.tsx | 3 +++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/example/screens/cluster.tsx b/example/screens/cluster.tsx index 8d5b6c30..f6e71a69 100644 --- a/example/screens/cluster.tsx +++ b/example/screens/cluster.tsx @@ -8,12 +8,7 @@ export default class Clustering extends Component { status?: CameraEvent; cluster?: Cluster | null; mapView?: MapView | null; - markers = Array(1000) - .fill(0) - .map((_, i) => ({ - position: { latitude: 39.5 + Math.random(), longitude: 116 + Math.random() }, - properties: { key: `Marker${i}` }, - })); + state = { markers: generateMarkers() }; render() { return ( @@ -24,6 +19,10 @@ export default class Clustering extends Component { this.status = nativeEvent; this.cluster?.update(nativeEvent); }} + onLongPress={() => { + this.setState({ markers: generateMarkers() }); + setTimeout(() => this.cluster?.update(this.status!), 0); + }} > { @@ -36,7 +35,7 @@ export default class Clustering extends Component { ); }} ref={(ref) => (this.cluster = ref)} - points={this.markers} + points={this.state.markers} renderMarker={(item) => ( ({ + position: { latitude: 39.5 + Math.random(), longitude: 116 + Math.random() }, + properties: { key: `Marker${i}` }, + })); +} diff --git a/lib/src/cluster/index.tsx b/lib/src/cluster/index.tsx index a0e66ef7..6a22fe9e 100644 --- a/lib/src/cluster/index.tsx +++ b/lib/src/cluster/index.tsx @@ -64,6 +64,9 @@ export default class Cluster extends React.PureComponent { }, 0); } + /** + * 需要在 MapView.onCameraIdle({ nativeEvent }) 回调里调用,参数为 nativeEvent + */ update({ cameraPosition, latLngBounds }: CameraEvent) { setTimeout(() => { const { southwest, northeast } = latLngBounds;