@react-native-ohos/react-native-map-clustering 3.4.1-rc.1 → 3.5.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/COMMITTERS.md +6 -0
- package/LICENSE +21 -21
- package/OAT.xml +57 -57
- package/README.OpenSource +10 -10
- package/README.md +13 -13
- package/example/.eslintrc +19 -0
- package/example/.node-version +6 -0
- package/example/.prettierrc.js +7 -0
- package/example/.watchmanconfig +6 -0
- package/example/app.json +4 -0
- package/example/babel.config.js +6 -0
- package/example/contexts.ts +9 -0
- package/example/harmony/AppScope/app.json5 +10 -0
- package/example/harmony/AppScope/resources/base/element/string.json +8 -0
- package/example/harmony/AppScope/resources/base/media/app_icon.png +0 -0
- package/example/harmony/build-profile.template.json5 +36 -0
- package/example/harmony/codelinter.json +32 -0
- package/example/harmony/entry/build-profile.json5 +22 -0
- package/example/harmony/entry/hvigorfile.ts +8 -0
- package/example/harmony/entry/oh-package.json5 +11 -0
- package/example/harmony/entry/src/main/cpp/CMakeLists.txt +42 -0
- package/example/harmony/entry/src/main/cpp/PackageProvider.cpp +17 -0
- package/example/harmony/entry/src/main/ets/RNPackagesFactory.ets +15 -0
- package/example/harmony/entry/src/main/ets/assets/fonts/Pacifico-Regular.ttf +0 -0
- package/example/harmony/entry/src/main/ets/assets/fonts/StintUltraCondensed-Regular.ttf +0 -0
- package/example/harmony/entry/src/main/ets/entryability/EntryAbility.ets +27 -0
- package/example/harmony/entry/src/main/ets/pages/Index.ets +209 -0
- package/example/harmony/entry/src/main/ets/pages/SurfaceDeadlockTest.ets +135 -0
- package/example/harmony/entry/src/main/ets/pages/TouchDisplayer.ets +44 -0
- package/example/harmony/entry/src/main/module.json5 +72 -0
- package/example/harmony/entry/src/main/resources/base/element/color.json +8 -0
- package/example/harmony/entry/src/main/resources/base/element/string.json +20 -0
- package/example/harmony/entry/src/main/resources/base/media/icon.png +0 -0
- package/example/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
- package/example/harmony/entry/src/main/resources/rawfile/1.txt +1 -0
- package/example/harmony/format.ps1 +18 -0
- package/example/harmony/hvigor/hvigor-config.json5 +21 -0
- package/example/harmony/hvigorfile.ts +9 -0
- package/example/harmony/oh-package.json5 +12 -0
- package/example/index.js +11 -0
- package/example/jest.config.js +11 -0
- package/example/metro.config.js +30 -0
- package/example/package.json +61 -0
- package/example/react-native.config.js +11 -0
- package/example/scripts/create-build-profile.js +46 -0
- package/example/src/App.tsx +186 -0
- package/example/src/Navigation.tsx +163 -0
- package/example/src/index.tsx +59 -0
- package/example/tsconfig.json +14 -0
- package/index.d.ts +40 -40
- package/index.js +2 -2
- package/lib/ClusterHarmony.js +21 -21
- package/lib/ClusteredMapView.js +310 -310
- package/package.json +42 -42
package/lib/ClusteredMapView.js
CHANGED
|
@@ -1,310 +1,310 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
memo,
|
|
3
|
-
useState,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
forwardRef,
|
|
8
|
-
} from "react";
|
|
9
|
-
import { Dimensions, LayoutAnimation, Platform } from "react-native";
|
|
10
|
-
import MapView, { Marker, Polyline } from "react-native-maps";
|
|
11
|
-
import SuperCluster from "supercluster";
|
|
12
|
-
import ClusterMarker from "react-native-map-clustering/lib/ClusteredMarker";
|
|
13
|
-
import {
|
|
14
|
-
isMarker,
|
|
15
|
-
markerToGeoJSONFeature,
|
|
16
|
-
calculateBBox,
|
|
17
|
-
returnMapZoom,
|
|
18
|
-
generateSpiral,
|
|
19
|
-
} from "react-native-map-clustering/lib/helpers";
|
|
20
|
-
import ClusterHarmony from "./ClusterHarmony";
|
|
21
|
-
|
|
22
|
-
const ClusteredMapView = forwardRef(
|
|
23
|
-
(
|
|
24
|
-
{
|
|
25
|
-
radius,
|
|
26
|
-
maxZoom,
|
|
27
|
-
minZoom,
|
|
28
|
-
minPoints,
|
|
29
|
-
extent,
|
|
30
|
-
nodeSize,
|
|
31
|
-
children,
|
|
32
|
-
onClusterPress,
|
|
33
|
-
onRegionChangeComplete,
|
|
34
|
-
onMarkersChange,
|
|
35
|
-
preserveClusterPressBehavior,
|
|
36
|
-
clusteringEnabled,
|
|
37
|
-
clusterColor,
|
|
38
|
-
clusterTextColor,
|
|
39
|
-
clusterFontFamily,
|
|
40
|
-
spiderLineColor,
|
|
41
|
-
layoutAnimationConf,
|
|
42
|
-
animationEnabled,
|
|
43
|
-
renderCluster,
|
|
44
|
-
tracksViewChanges,
|
|
45
|
-
spiralEnabled,
|
|
46
|
-
superClusterRef,
|
|
47
|
-
...restProps
|
|
48
|
-
},
|
|
49
|
-
ref
|
|
50
|
-
) => {
|
|
51
|
-
const [markers, updateMarkers] = useState([]);
|
|
52
|
-
const [spiderMarkers, updateSpiderMarker] = useState([]);
|
|
53
|
-
const [otherChildren, updateChildren] = useState([]);
|
|
54
|
-
const [superCluster, setSuperCluster] = useState(null);
|
|
55
|
-
const [currentRegion, updateRegion] = useState(
|
|
56
|
-
restProps.region || restProps.initialRegion
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const [isSpiderfier, updateSpiderfier] = useState(false);
|
|
60
|
-
const [clusterChildren, updateClusterChildren] = useState(null);
|
|
61
|
-
const mapRef = useRef();
|
|
62
|
-
|
|
63
|
-
const propsChildren = useMemo(
|
|
64
|
-
() => React.Children.toArray(children),
|
|
65
|
-
[children]
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
const rawData = [];
|
|
70
|
-
const otherChildren = [];
|
|
71
|
-
|
|
72
|
-
if (!clusteringEnabled) {
|
|
73
|
-
updateSpiderMarker([]);
|
|
74
|
-
updateMarkers([]);
|
|
75
|
-
updateChildren(propsChildren);
|
|
76
|
-
setSuperCluster(null);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
propsChildren.forEach((child, index) => {
|
|
81
|
-
if (isMarker(child)) {
|
|
82
|
-
rawData.push(markerToGeoJSONFeature(child, index));
|
|
83
|
-
} else {
|
|
84
|
-
otherChildren.push(child);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const superCluster = new SuperCluster({
|
|
89
|
-
radius,
|
|
90
|
-
maxZoom,
|
|
91
|
-
minZoom,
|
|
92
|
-
minPoints,
|
|
93
|
-
extent,
|
|
94
|
-
nodeSize,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
superCluster.load(rawData);
|
|
98
|
-
|
|
99
|
-
const bBox = calculateBBox(currentRegion);
|
|
100
|
-
const zoom = returnMapZoom(currentRegion, bBox, minZoom);
|
|
101
|
-
const markers = superCluster.getClusters(bBox, zoom);
|
|
102
|
-
|
|
103
|
-
updateMarkers(markers);
|
|
104
|
-
updateChildren(otherChildren);
|
|
105
|
-
setSuperCluster(superCluster);
|
|
106
|
-
|
|
107
|
-
superClusterRef.current = superCluster;
|
|
108
|
-
}, [propsChildren, clusteringEnabled]);
|
|
109
|
-
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (!spiralEnabled) return;
|
|
112
|
-
|
|
113
|
-
if (isSpiderfier && markers.length > 0) {
|
|
114
|
-
let allSpiderMarkers = [];
|
|
115
|
-
let spiralChildren = [];
|
|
116
|
-
markers.map((marker, i) => {
|
|
117
|
-
if (marker.properties.cluster) {
|
|
118
|
-
spiralChildren = superCluster.getLeaves(
|
|
119
|
-
marker.properties.cluster_id,
|
|
120
|
-
Infinity
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
let positions = generateSpiral(marker, spiralChildren, markers, i);
|
|
124
|
-
allSpiderMarkers.push(...positions);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
updateSpiderMarker(allSpiderMarkers);
|
|
128
|
-
} else {
|
|
129
|
-
updateSpiderMarker([]);
|
|
130
|
-
}
|
|
131
|
-
}, [isSpiderfier, markers]);
|
|
132
|
-
|
|
133
|
-
const _onRegionChangeComplete = (region, harmonyIn) => {
|
|
134
|
-
if (Platform.OS === "harmony" && !harmonyIn) {
|
|
135
|
-
region = region.nativeEvent.region;
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
_onRegionChangeComplete(region, true);
|
|
138
|
-
}, 100);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (superCluster && region) {
|
|
143
|
-
const bBox = calculateBBox(region);
|
|
144
|
-
const zoom = returnMapZoom(region, bBox, minZoom);
|
|
145
|
-
const markers = superCluster.getClusters(bBox, zoom);
|
|
146
|
-
if (animationEnabled && Platform.OS === "ios") {
|
|
147
|
-
LayoutAnimation.configureNext(layoutAnimationConf);
|
|
148
|
-
}
|
|
149
|
-
if (zoom >= 18 && markers.length > 0 && clusterChildren) {
|
|
150
|
-
if (spiralEnabled) updateSpiderfier(true);
|
|
151
|
-
} else {
|
|
152
|
-
if (spiralEnabled) updateSpiderfier(false);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (Platform.OS === "harmony") {
|
|
156
|
-
for (let index = 0; index < markers.length; index++) {
|
|
157
|
-
const marker = markers[index];
|
|
158
|
-
if (marker.properties.point_count > 0) {
|
|
159
|
-
const children = superCluster.getLeaves(
|
|
160
|
-
marker.properties.cluster_id,
|
|
161
|
-
Infinity
|
|
162
|
-
);
|
|
163
|
-
const itemList = [];
|
|
164
|
-
for (let index = 0; index < children.length; index++) {
|
|
165
|
-
const clusterItem = children[index];
|
|
166
|
-
itemList.push({
|
|
167
|
-
position: {
|
|
168
|
-
longitude: clusterItem.geometry.coordinates[0],
|
|
169
|
-
latitude: clusterItem.geometry.coordinates[1],
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
marker["clusterChildItem"] = itemList;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (markers.length != 0) {
|
|
177
|
-
updateMarkers(markers);
|
|
178
|
-
onMarkersChange(markers);
|
|
179
|
-
onRegionChangeComplete(region, markers);
|
|
180
|
-
updateRegion(region);
|
|
181
|
-
}
|
|
182
|
-
} else {
|
|
183
|
-
updateMarkers(markers);
|
|
184
|
-
onMarkersChange(markers);
|
|
185
|
-
onRegionChangeComplete(region, markers);
|
|
186
|
-
updateRegion(region);
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
onRegionChangeComplete(region);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const _onClusterPress = (cluster) => () => {
|
|
194
|
-
const children = superCluster.getLeaves(cluster.id, Infinity);
|
|
195
|
-
|
|
196
|
-
updateClusterChildren(children);
|
|
197
|
-
|
|
198
|
-
if (preserveClusterPressBehavior) {
|
|
199
|
-
onClusterPress(cluster, children);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const coordinates = children.map(({ geometry }) => ({
|
|
204
|
-
latitude: geometry.coordinates[1],
|
|
205
|
-
longitude: geometry.coordinates[0],
|
|
206
|
-
}));
|
|
207
|
-
|
|
208
|
-
mapRef.current.fitToCoordinates(coordinates, {
|
|
209
|
-
edgePadding: restProps.edgePadding,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
onClusterPress(cluster, children);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
return (
|
|
216
|
-
<MapView
|
|
217
|
-
{...restProps}
|
|
218
|
-
ref={(map) => {
|
|
219
|
-
mapRef.current = map;
|
|
220
|
-
if (ref) ref.current = map;
|
|
221
|
-
restProps.mapRef(map);
|
|
222
|
-
}}
|
|
223
|
-
onRegionChangeComplete={_onRegionChangeComplete}
|
|
224
|
-
>
|
|
225
|
-
{markers.map((marker) =>
|
|
226
|
-
marker.properties.point_count === 0 ? (
|
|
227
|
-
propsChildren[marker.properties.index]
|
|
228
|
-
) : !isSpiderfier ? (
|
|
229
|
-
renderCluster ? (
|
|
230
|
-
renderCluster({
|
|
231
|
-
onPress: _onClusterPress(marker),
|
|
232
|
-
clusterColor,
|
|
233
|
-
clusterTextColor,
|
|
234
|
-
clusterFontFamily,
|
|
235
|
-
...marker,
|
|
236
|
-
})
|
|
237
|
-
) : Platform.OS === "harmony" ? (
|
|
238
|
-
<ClusterHarmony
|
|
239
|
-
key={`cluster-${marker.id}`}
|
|
240
|
-
marker={marker}
|
|
241
|
-
distance={40}
|
|
242
|
-
onPress={_onClusterPress(marker)}
|
|
243
|
-
/>
|
|
244
|
-
) : (
|
|
245
|
-
<ClusterMarker
|
|
246
|
-
key={`cluster-${marker.id}`}
|
|
247
|
-
{...marker}
|
|
248
|
-
onPress={_onClusterPress(marker)}
|
|
249
|
-
clusterColor={
|
|
250
|
-
restProps.selectedClusterId === marker.id
|
|
251
|
-
? restProps.selectedClusterColor
|
|
252
|
-
: clusterColor
|
|
253
|
-
}
|
|
254
|
-
clusterTextColor={clusterTextColor}
|
|
255
|
-
clusterFontFamily={clusterFontFamily}
|
|
256
|
-
tracksViewChanges={tracksViewChanges}
|
|
257
|
-
/>
|
|
258
|
-
)
|
|
259
|
-
) : null
|
|
260
|
-
)}
|
|
261
|
-
{otherChildren}
|
|
262
|
-
{spiderMarkers.map((marker) => {
|
|
263
|
-
return propsChildren[marker.index]
|
|
264
|
-
? React.cloneElement(propsChildren[marker.index], {
|
|
265
|
-
coordinate: { ...marker },
|
|
266
|
-
})
|
|
267
|
-
: null;
|
|
268
|
-
})}
|
|
269
|
-
{spiderMarkers.map((marker, index) => (
|
|
270
|
-
<Polyline
|
|
271
|
-
key={index}
|
|
272
|
-
coordinates={[marker.centerPoint, marker, marker.centerPoint]}
|
|
273
|
-
strokeColor={spiderLineColor}
|
|
274
|
-
strokeWidth={1}
|
|
275
|
-
/>
|
|
276
|
-
))}
|
|
277
|
-
</MapView>
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
ClusteredMapView.defaultProps = {
|
|
283
|
-
clusteringEnabled: true,
|
|
284
|
-
spiralEnabled: true,
|
|
285
|
-
animationEnabled: true,
|
|
286
|
-
preserveClusterPressBehavior: false,
|
|
287
|
-
layoutAnimationConf: LayoutAnimation.Presets.spring,
|
|
288
|
-
tracksViewChanges: false,
|
|
289
|
-
// SuperCluster parameters
|
|
290
|
-
radius: Dimensions.get("window").width * 0.06,
|
|
291
|
-
maxZoom: 20,
|
|
292
|
-
minZoom: 1,
|
|
293
|
-
minPoints: 2,
|
|
294
|
-
extent: 512,
|
|
295
|
-
nodeSize: 64,
|
|
296
|
-
// Map parameters
|
|
297
|
-
edgePadding: { top: 50, left: 50, right: 50, bottom: 50 },
|
|
298
|
-
// Cluster styles
|
|
299
|
-
clusterColor: "#00B386",
|
|
300
|
-
clusterTextColor: "#FFFFFF",
|
|
301
|
-
spiderLineColor: "#FF0000",
|
|
302
|
-
// Callbacks
|
|
303
|
-
onRegionChangeComplete: () => {},
|
|
304
|
-
onClusterPress: () => {},
|
|
305
|
-
onMarkersChange: () => {},
|
|
306
|
-
superClusterRef: {},
|
|
307
|
-
mapRef: () => {},
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
export default memo(ClusteredMapView);
|
|
1
|
+
import React, {
|
|
2
|
+
memo,
|
|
3
|
+
useState,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
forwardRef,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { Dimensions, LayoutAnimation, Platform } from "react-native";
|
|
10
|
+
import MapView, { Marker, Polyline } from "react-native-maps";
|
|
11
|
+
import SuperCluster from "supercluster";
|
|
12
|
+
import ClusterMarker from "react-native-map-clustering/lib/ClusteredMarker";
|
|
13
|
+
import {
|
|
14
|
+
isMarker,
|
|
15
|
+
markerToGeoJSONFeature,
|
|
16
|
+
calculateBBox,
|
|
17
|
+
returnMapZoom,
|
|
18
|
+
generateSpiral,
|
|
19
|
+
} from "react-native-map-clustering/lib/helpers";
|
|
20
|
+
import ClusterHarmony from "./ClusterHarmony";
|
|
21
|
+
|
|
22
|
+
const ClusteredMapView = forwardRef(
|
|
23
|
+
(
|
|
24
|
+
{
|
|
25
|
+
radius,
|
|
26
|
+
maxZoom,
|
|
27
|
+
minZoom,
|
|
28
|
+
minPoints,
|
|
29
|
+
extent,
|
|
30
|
+
nodeSize,
|
|
31
|
+
children,
|
|
32
|
+
onClusterPress,
|
|
33
|
+
onRegionChangeComplete,
|
|
34
|
+
onMarkersChange,
|
|
35
|
+
preserveClusterPressBehavior,
|
|
36
|
+
clusteringEnabled,
|
|
37
|
+
clusterColor,
|
|
38
|
+
clusterTextColor,
|
|
39
|
+
clusterFontFamily,
|
|
40
|
+
spiderLineColor,
|
|
41
|
+
layoutAnimationConf,
|
|
42
|
+
animationEnabled,
|
|
43
|
+
renderCluster,
|
|
44
|
+
tracksViewChanges,
|
|
45
|
+
spiralEnabled,
|
|
46
|
+
superClusterRef,
|
|
47
|
+
...restProps
|
|
48
|
+
},
|
|
49
|
+
ref
|
|
50
|
+
) => {
|
|
51
|
+
const [markers, updateMarkers] = useState([]);
|
|
52
|
+
const [spiderMarkers, updateSpiderMarker] = useState([]);
|
|
53
|
+
const [otherChildren, updateChildren] = useState([]);
|
|
54
|
+
const [superCluster, setSuperCluster] = useState(null);
|
|
55
|
+
const [currentRegion, updateRegion] = useState(
|
|
56
|
+
restProps.region || restProps.initialRegion
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const [isSpiderfier, updateSpiderfier] = useState(false);
|
|
60
|
+
const [clusterChildren, updateClusterChildren] = useState(null);
|
|
61
|
+
const mapRef = useRef();
|
|
62
|
+
|
|
63
|
+
const propsChildren = useMemo(
|
|
64
|
+
() => React.Children.toArray(children),
|
|
65
|
+
[children]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const rawData = [];
|
|
70
|
+
const otherChildren = [];
|
|
71
|
+
|
|
72
|
+
if (!clusteringEnabled) {
|
|
73
|
+
updateSpiderMarker([]);
|
|
74
|
+
updateMarkers([]);
|
|
75
|
+
updateChildren(propsChildren);
|
|
76
|
+
setSuperCluster(null);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
propsChildren.forEach((child, index) => {
|
|
81
|
+
if (isMarker(child)) {
|
|
82
|
+
rawData.push(markerToGeoJSONFeature(child, index));
|
|
83
|
+
} else {
|
|
84
|
+
otherChildren.push(child);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const superCluster = new SuperCluster({
|
|
89
|
+
radius,
|
|
90
|
+
maxZoom,
|
|
91
|
+
minZoom,
|
|
92
|
+
minPoints,
|
|
93
|
+
extent,
|
|
94
|
+
nodeSize,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
superCluster.load(rawData);
|
|
98
|
+
|
|
99
|
+
const bBox = calculateBBox(currentRegion);
|
|
100
|
+
const zoom = returnMapZoom(currentRegion, bBox, minZoom);
|
|
101
|
+
const markers = superCluster.getClusters(bBox, zoom);
|
|
102
|
+
|
|
103
|
+
updateMarkers(markers);
|
|
104
|
+
updateChildren(otherChildren);
|
|
105
|
+
setSuperCluster(superCluster);
|
|
106
|
+
|
|
107
|
+
superClusterRef.current = superCluster;
|
|
108
|
+
}, [propsChildren, clusteringEnabled]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!spiralEnabled) return;
|
|
112
|
+
|
|
113
|
+
if (isSpiderfier && markers.length > 0) {
|
|
114
|
+
let allSpiderMarkers = [];
|
|
115
|
+
let spiralChildren = [];
|
|
116
|
+
markers.map((marker, i) => {
|
|
117
|
+
if (marker.properties.cluster) {
|
|
118
|
+
spiralChildren = superCluster.getLeaves(
|
|
119
|
+
marker.properties.cluster_id,
|
|
120
|
+
Infinity
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
let positions = generateSpiral(marker, spiralChildren, markers, i);
|
|
124
|
+
allSpiderMarkers.push(...positions);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
updateSpiderMarker(allSpiderMarkers);
|
|
128
|
+
} else {
|
|
129
|
+
updateSpiderMarker([]);
|
|
130
|
+
}
|
|
131
|
+
}, [isSpiderfier, markers]);
|
|
132
|
+
|
|
133
|
+
const _onRegionChangeComplete = (region, harmonyIn) => {
|
|
134
|
+
if (Platform.OS === "harmony" && !harmonyIn) {
|
|
135
|
+
region = region.nativeEvent.region;
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
_onRegionChangeComplete(region, true);
|
|
138
|
+
}, 100);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (superCluster && region) {
|
|
143
|
+
const bBox = calculateBBox(region);
|
|
144
|
+
const zoom = returnMapZoom(region, bBox, minZoom);
|
|
145
|
+
const markers = superCluster.getClusters(bBox, zoom);
|
|
146
|
+
if (animationEnabled && Platform.OS === "ios") {
|
|
147
|
+
LayoutAnimation.configureNext(layoutAnimationConf);
|
|
148
|
+
}
|
|
149
|
+
if (zoom >= 18 && markers.length > 0 && clusterChildren) {
|
|
150
|
+
if (spiralEnabled) updateSpiderfier(true);
|
|
151
|
+
} else {
|
|
152
|
+
if (spiralEnabled) updateSpiderfier(false);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (Platform.OS === "harmony") {
|
|
156
|
+
for (let index = 0; index < markers.length; index++) {
|
|
157
|
+
const marker = markers[index];
|
|
158
|
+
if (marker.properties.point_count > 0) {
|
|
159
|
+
const children = superCluster.getLeaves(
|
|
160
|
+
marker.properties.cluster_id,
|
|
161
|
+
Infinity
|
|
162
|
+
);
|
|
163
|
+
const itemList = [];
|
|
164
|
+
for (let index = 0; index < children.length; index++) {
|
|
165
|
+
const clusterItem = children[index];
|
|
166
|
+
itemList.push({
|
|
167
|
+
position: {
|
|
168
|
+
longitude: clusterItem.geometry.coordinates[0],
|
|
169
|
+
latitude: clusterItem.geometry.coordinates[1],
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
marker["clusterChildItem"] = itemList;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (markers.length != 0) {
|
|
177
|
+
updateMarkers(markers);
|
|
178
|
+
onMarkersChange(markers);
|
|
179
|
+
onRegionChangeComplete(region, markers);
|
|
180
|
+
updateRegion(region);
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
updateMarkers(markers);
|
|
184
|
+
onMarkersChange(markers);
|
|
185
|
+
onRegionChangeComplete(region, markers);
|
|
186
|
+
updateRegion(region);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
onRegionChangeComplete(region);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const _onClusterPress = (cluster) => () => {
|
|
194
|
+
const children = superCluster.getLeaves(cluster.id, Infinity);
|
|
195
|
+
|
|
196
|
+
updateClusterChildren(children);
|
|
197
|
+
|
|
198
|
+
if (preserveClusterPressBehavior) {
|
|
199
|
+
onClusterPress(cluster, children);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const coordinates = children.map(({ geometry }) => ({
|
|
204
|
+
latitude: geometry.coordinates[1],
|
|
205
|
+
longitude: geometry.coordinates[0],
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
mapRef.current.fitToCoordinates(coordinates, {
|
|
209
|
+
edgePadding: restProps.edgePadding,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
onClusterPress(cluster, children);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<MapView
|
|
217
|
+
{...restProps}
|
|
218
|
+
ref={(map) => {
|
|
219
|
+
mapRef.current = map;
|
|
220
|
+
if (ref) ref.current = map;
|
|
221
|
+
restProps.mapRef(map);
|
|
222
|
+
}}
|
|
223
|
+
onRegionChangeComplete={_onRegionChangeComplete}
|
|
224
|
+
>
|
|
225
|
+
{markers.map((marker) =>
|
|
226
|
+
marker.properties.point_count === 0 ? (
|
|
227
|
+
propsChildren[marker.properties.index]
|
|
228
|
+
) : !isSpiderfier ? (
|
|
229
|
+
renderCluster ? (
|
|
230
|
+
renderCluster({
|
|
231
|
+
onPress: _onClusterPress(marker),
|
|
232
|
+
clusterColor,
|
|
233
|
+
clusterTextColor,
|
|
234
|
+
clusterFontFamily,
|
|
235
|
+
...marker,
|
|
236
|
+
})
|
|
237
|
+
) : Platform.OS === "harmony" ? (
|
|
238
|
+
<ClusterHarmony
|
|
239
|
+
key={`cluster-${marker.id}`}
|
|
240
|
+
marker={marker}
|
|
241
|
+
distance={40}
|
|
242
|
+
onPress={_onClusterPress(marker)}
|
|
243
|
+
/>
|
|
244
|
+
) : (
|
|
245
|
+
<ClusterMarker
|
|
246
|
+
key={`cluster-${marker.id}`}
|
|
247
|
+
{...marker}
|
|
248
|
+
onPress={_onClusterPress(marker)}
|
|
249
|
+
clusterColor={
|
|
250
|
+
restProps.selectedClusterId === marker.id
|
|
251
|
+
? restProps.selectedClusterColor
|
|
252
|
+
: clusterColor
|
|
253
|
+
}
|
|
254
|
+
clusterTextColor={clusterTextColor}
|
|
255
|
+
clusterFontFamily={clusterFontFamily}
|
|
256
|
+
tracksViewChanges={tracksViewChanges}
|
|
257
|
+
/>
|
|
258
|
+
)
|
|
259
|
+
) : null
|
|
260
|
+
)}
|
|
261
|
+
{otherChildren}
|
|
262
|
+
{spiderMarkers.map((marker) => {
|
|
263
|
+
return propsChildren[marker.index]
|
|
264
|
+
? React.cloneElement(propsChildren[marker.index], {
|
|
265
|
+
coordinate: { ...marker },
|
|
266
|
+
})
|
|
267
|
+
: null;
|
|
268
|
+
})}
|
|
269
|
+
{spiderMarkers.map((marker, index) => (
|
|
270
|
+
<Polyline
|
|
271
|
+
key={index}
|
|
272
|
+
coordinates={[marker.centerPoint, marker, marker.centerPoint]}
|
|
273
|
+
strokeColor={spiderLineColor}
|
|
274
|
+
strokeWidth={1}
|
|
275
|
+
/>
|
|
276
|
+
))}
|
|
277
|
+
</MapView>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
ClusteredMapView.defaultProps = {
|
|
283
|
+
clusteringEnabled: true,
|
|
284
|
+
spiralEnabled: true,
|
|
285
|
+
animationEnabled: true,
|
|
286
|
+
preserveClusterPressBehavior: false,
|
|
287
|
+
layoutAnimationConf: LayoutAnimation.Presets.spring,
|
|
288
|
+
tracksViewChanges: false,
|
|
289
|
+
// SuperCluster parameters
|
|
290
|
+
radius: Dimensions.get("window").width * 0.06,
|
|
291
|
+
maxZoom: 20,
|
|
292
|
+
minZoom: 1,
|
|
293
|
+
minPoints: 2,
|
|
294
|
+
extent: 512,
|
|
295
|
+
nodeSize: 64,
|
|
296
|
+
// Map parameters
|
|
297
|
+
edgePadding: { top: 50, left: 50, right: 50, bottom: 50 },
|
|
298
|
+
// Cluster styles
|
|
299
|
+
clusterColor: "#00B386",
|
|
300
|
+
clusterTextColor: "#FFFFFF",
|
|
301
|
+
spiderLineColor: "#FF0000",
|
|
302
|
+
// Callbacks
|
|
303
|
+
onRegionChangeComplete: () => {},
|
|
304
|
+
onClusterPress: () => {},
|
|
305
|
+
onMarkersChange: () => {},
|
|
306
|
+
superClusterRef: {},
|
|
307
|
+
mapRef: () => {},
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export default memo(ClusteredMapView);
|