@react-native-ohos/react-native-map-clustering 3.4.1-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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Tony Arrived
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/OAT.xml ADDED
@@ -0,0 +1,57 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <configuration>
3
+ <oatconfig>
4
+ <licensefile>LICENSE</licensefile>
5
+ <policylist>
6
+ <policy name="projectPolicy" desc="">
7
+ <policyitem type="license" name="MIT" path=".*" desc="license under the MIT"/>
8
+ </policy>
9
+ <policy name="projectPolicy" desc="">
10
+ <policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="Process that runs independently, invoked by the X process."/>
11
+ <policyitem type="compatibility" name="Apache-2.0" path=".*" desc="不影响兼容性"/>
12
+ <policyitem type="compatibility" name="BSDStyleLicense" path=".*" desc="不影响兼容性" />
13
+ <policyitem type="compatibility" name="MIT" path=".*" desc="不影响兼容性" />
14
+ <policyitem type="compatibility" name="GPLStyleLicense" path=".*" desc="不影响兼容性" />
15
+ </policy>
16
+ </policylist>
17
+ <filefilterlist>
18
+ <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
19
+ <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
20
+ <filteritem type="filename" name="*/*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
21
+ <filteritem type="filename" name="LICENSE" desc="版权文件,不添加许可证头"/>
22
+ <filteritem type="filepath" name="hvigorw" desc="工程模板,不添加许可证头"/>
23
+ <filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不添加许可证头"/>
24
+ <filteritem type="filepath" name="js/*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
25
+ <filteritem type="filepath" name="js/*.ts" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
26
+ <filteritem type="filepath" name="src/*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
27
+ <filteritem type="filepath" name="src/*.ts" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
28
+ <filteritem type="filepath" name="*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
29
+ <filteritem type="filepath" name="*.ts" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
30
+ <filteritem type="filepath" name="index.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
31
+ <filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
32
+ <filteritem type="filepath" name="hvigor/hvigor-config.json5" desc="工程模板,不修改版权头,以防有修改版权风险"/>
33
+ <filteritem type="filepath" name="lib/ClusteredMapView.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
34
+ </filefilter>
35
+ <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
36
+ <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
37
+ <filteritem type="filename" name="*/*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
38
+ <filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/>
39
+ <filteritem type="filepath" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
40
+ <filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
41
+ <filteritem type="filepath" name="js/*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
42
+ <filteritem type="filepath" name="js/*.ts" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
43
+ <filteritem type="filepath" name="src/*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
44
+ <filteritem type="filepath" name="src/*.ts" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
45
+ <filteritem type="filepath" name="*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
46
+ <filteritem type="filepath" name="*.ts" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
47
+ <filteritem type="filepath" name="index.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
48
+ <filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
49
+ <filteritem type="filepath" name="hvigor/hvigor-config.json5" desc="工程模板,不修改版权头,以防有修改版权风险"/>
50
+ <filteritem type="filepath" name="lib/ClusteredMapView.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
51
+ </filefilter>
52
+ <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
53
+ </filefilter>
54
+
55
+ </filefilterlist>
56
+ </oatconfig>
57
+ </configuration>
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "Name": "react-native-map-clustering",
4
+ "License": "MIT License",
5
+ "License File": "https://github.com/react-native-oh-library/react-native-map-clustering/blob/sig/LICENSE",
6
+ "Version Number": "3.4.2-0.0.1",
7
+ "Owner" : "xiafeng@huawei.com",
8
+ "Upstream URL": "https://github.com/react-native-oh-library/react-native-map-clustering",
9
+ "Description": "React Native Map Clustering both for Android and iOS"
10
+ }
11
+ ]
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @react-native-oh-tpl/react-native-map-clustering
2
+
3
+ This project is based on [react-native-map-clustering](https://github.com/venits/react-native-map-clustering)
4
+
5
+ ## Documentation
6
+
7
+ - [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-map-clustering.md)
8
+
9
+ - [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-map-clustering.md)
10
+
11
+ ## License
12
+
13
+ This library is licensed under [The MIT License (MIT)](https://github.com/react-native-oh-library/react-native-map-clustering/blob/sig/LICENSE)
package/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ declare module "react-native-map-clustering" {
2
+ import * as React from "react";
3
+ import { LayoutAnimationConfig } from "react-native";
4
+ import Map, { MapViewProps, Marker } from "react-native-maps";
5
+
6
+ export type Cluster = {};
7
+
8
+ interface MapClusteringProps {
9
+ clusteringEnabled?: boolean;
10
+ spiralEnabled?: boolean;
11
+ animationEnabled?: boolean;
12
+ preserveClusterPressBehavior?: boolean;
13
+ tracksViewChanges?: boolean;
14
+ layoutAnimationConf?: LayoutAnimationConfig;
15
+ radius?: number;
16
+ maxZoom?: number;
17
+ minZoom?: number;
18
+ extent?: number;
19
+ nodeSize?: number;
20
+ minPoints?: number;
21
+ edgePadding?: { top: number; left: number; right: number; bottom: number };
22
+ clusterColor?: string;
23
+ clusterTextColor?: string;
24
+ clusterFontFamily?: string;
25
+ selectedClusterId?: string;
26
+ selectedClusterColor?: string;
27
+ spiderLineColor?: string;
28
+ superClusterRef?: React.MutableRefObject<any>;
29
+ mapRef?: (ref: React.Ref<Map>) => void;
30
+ onClusterPress?: (cluster: Marker, markers?: Marker[]) => void;
31
+ getClusterEngine?: (ref: any) => void;
32
+ onMarkersChange?: (markers?: Marker[]) => void;
33
+ renderCluster?: (cluster: any) => React.ReactNode;
34
+ }
35
+
36
+ export default class MapView extends React.Component<
37
+ MapViewProps & MapClusteringProps,
38
+ any
39
+ > {}
40
+ }
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import * as MapView from "./lib/ClusteredMapView";
2
+ module.exports = MapView;
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import React, { memo } from "react";
8
+ import { Cluster } from "react-native-maps";
9
+
10
+ const ClusterHarmony = ({ marker, distance, onPress }) => {
11
+ return (
12
+ <Cluster
13
+ clusterItems={marker.clusterChildItem}
14
+ distance={distance ? distance : 40}
15
+ onPress={onPress}
16
+ style={{ zIndex: marker.properties.point_count + 1 }}
17
+ ></Cluster>
18
+ );
19
+ };
20
+
21
+ export default memo(ClusterHarmony);
@@ -0,0 +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);
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-map-clustering",
3
+ "harmony": {
4
+ "alias": "react-native-map-clustering",
5
+ "redirectInternalImports": true
6
+ },
7
+ "version": "3.4.1-rc.1",
8
+ "description": "React Native Map Clustering both for Android and iOS",
9
+ "types": "index.d.ts",
10
+ "main": "index.js",
11
+ "scripts": {
12
+ "test": "jest"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/venits/react-native-map-clustering.git"
17
+ },
18
+ "keywords": [
19
+ "react-native",
20
+ "react",
21
+ "cluster",
22
+ "android",
23
+ "iOS",
24
+ "map",
25
+ "clustering"
26
+ ],
27
+ "author": "Venits",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/venits/react-native-map-clustering/issues"
31
+ },
32
+ "homepage": "https://github.com/venits/react-native-map-clustering#readme",
33
+ "dependencies": {
34
+ "supercluster": "^7.1.0",
35
+ "@mapbox/geo-viewport": "^0.4.1"
36
+ },
37
+ "peerDependencies": {
38
+ "react-native-maps": "*",
39
+ "react-native-map-clustering": "3.4.0",
40
+ "react-native": "*"
41
+ }
42
+ }