react-native-map-clustering:react-native-map-clustering是一个RN三方库,需要在鸿蒙RN上可用,达到在安卓和IOS上的使用效果,满足应用跨端开发的需求。            

react-native-map-clustering是一个RN三方库,需要在鸿蒙RN上可用,达到在安卓和IOS上的使用效果,满足应用跨端开发的需求。            

Branch5Tags7
FilesLast commitLast update
1 month ago
1 month ago
1 month ago
1 month ago
1 year ago
2 years ago
1 month ago
1 month ago
16 days ago
16 days ago
1 month ago
5 years ago
6 years ago
1 month ago

Document Template: v0.4.2

react-native-map-clustering

This project is based on react-native-map-clustering.

This third-party library has been migrated to AtomGit and is now available for direct download from npm, the new package name is: @react-native-ohos/react-native-map-clustering, the version correspondence details are as follows:

Name Version(Npm Address) Release Information Supported RN Version Supported Autolink Compile API Version Community Baseline Version Source code address
@react-native-ohos/react-native-map-clustering ~ 4.1.0 (In development) AtomGit Releases 0.82.* No API12+ 4.0.0 master
@react-native-ohos/react-native-map-clustering ~ 3.5.0 AtomGit Releases 0.77.* No API12+ 3.4.0 br_rnoh0.77
@react-native-ohos/react-native-map-clustering ~ 3.4.3 AtomGit Releases 0.72.* No API12+ 3.4.0 br_rnoh0.72
@react-native-oh-tpl/react-native-map-clustering <= 3.4.2-0.0.1@deprecated Github Releases(deprecated) 0.72.* No API12+ 3.4.0 sig

Introduction

react-native-map-clustering is a marker clustering library for React Native, built on top of react-native-maps. It provides clustered display for map markers and supports both iOS and Android.

Installation

Go to the project directory and execute the following instruction:

npm

npm install @react-native-ohos/react-native-map-clustering

yarn

yarn add @react-native-ohos/react-native-map-clustering

Dependency Notes

Choose the appropriate third-party library version based on the React Native framework version used in your application. The version mapping is as follows:

RN Framework Version Dependency Library Supported Version Range
0.82 @react-native-ohos/react-native-maps >=1.25.0

The implementation of this library depends on the above-mentioned adapted third-party libraries. If they have already been introduced into your application project, you can skip the steps in this chapter and use them directly.

Ensure that the third-party library versions match the RN framework version used in your project. Mismatched versions may cause compilation or runtime errors.

Constraints

Compatibility

This document is verified based on the following versions:

  1. RNOH: 0.82.7; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 6.0.1.260; ROM: 6.0.0.130 SP15;

Permission Requirements

No special permission is required.

Example

The following code shows the basic use scenario of the repository:

The name of the imported repository remains unchanged.

import React from "react";
import MapView from "react-native-map-clustering";
import { Marker } from "react-native-maps";

function getRandomLatitude(min = 48, max = 56) {
  return Math.random() * (max - min) + min;
}

function getRandomLongitude(min = 14, max = 24) {
  return Math.random() * (max - min) + min;
}

const INITIAL_REGION = {
  latitude: 52.5,
  longitude: 19.2,
  latitudeDelta: 8.5,
  longitudeDelta: 8.5
};

export function MapClusteringExample() {
  const _generateMarkers = (count) => {
    const markers = [];

    for (let i = 0; i < count; i++) {
      markers.push(
        <Marker
          title='456'
          key={i}
          coordinate={{
            latitude: getRandomLatitude(),
            longitude: getRandomLongitude()
          }}
        />
      );
    }

    return markers;
  };

  return (
    <MapView initialRegion={INITIAL_REGION}
      style={{ flex: 1 }}
    >
      {_generateMarkers(200)}
    </MapView>
  );
}

How to Use

Enable/disable clustering

// clusteringEnabled is true by default; set it to false to display markers as they are without clustering
<MapView
  initialRegion={INITIAL_REGION}
  style={{ flex: 1 }}
  clusteringEnabled={false}
>
  {_generateMarkers(200)}
</MapView>

Custom clustering parameters

// radius: clustering radius; minPoints: minimum number of markers required to form a cluster; extent and nodeSize are SuperCluster engine parameters
<MapView
  initialRegion={INITIAL_REGION}
  style={{ flex: 1 }}
  radius={80}
  minPoints={5}
  extent={512}
  nodeSize={64}
>
  {_generateMarkers(200)}
</MapView>

Cluster press event

// When preserveClusterPressBehavior is true, clicking a cluster does not zoom in automatically; handle it in onClusterPress
<MapView
  initialRegion={INITIAL_REGION}
  style={{ flex: 1 }}
  preserveClusterPressBehavior={true}
  onClusterPress={(cluster, markers) => {
    // cluster: the pressed cluster; markers: the markers contained in the cluster
    console.log(`cluster ${cluster.id} pressed, contains ${markers.length} markers`);
  }}
>
  {_generateMarkers(200)}
</MapView>

Listening for clustering results and region changes

<MapView
  initialRegion={INITIAL_REGION}
  style={{ flex: 1 }}
  onMarkersChange={(markers) => {
    // Called when the clustered markers change; returns the current marker data
  }}
  onRegionChangeComplete={(region, markers) => {
    // Called when the map region change completes; returns the current region and marker data
  }}
>
  {_generateMarkers(200)}
</MapView>

Available APIs

The **Platform** column indicates the platform where the properties are supported in the original third-party library.

If the value of **OpenHarmony Platform Support** is **Yes**, it means that the OpenHarmony platform supports this property; **No** means the opposite; **Partially** means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

Components

Name Parameter Type Required Platform OpenHarmony Platform Support Description
MapView MapViewProps Yes All Yes A clustered map component built on top of the MapView of react-native-maps, providing clustered display for map markers

Properties

MapViewProps

Name Parameter Type Default Value Required Platform OpenHarmony Platform Support Description
clusteringEnabled bool true No All Yes Set true to enable and false to disable clustering
spiralEnabled bool true No All No Set true to enable and false to disable spiral view
animationEnabled bool true No iOS No Animate imploding/exploding of clusters' markers and clusters size change. Works only on iOS
preserveClusterPressBehavior bool false No All Yes If set to true, after clicking on cluster it will not be zoomed
tracksViewChanges bool false No All No Sets whether the cluster markers should track view changes. It's turned off by default to improve cluster markers performance
layoutAnimationConf LayoutAnimationConfig LayoutAnimation.Presets.spring No iOS No Layout animation configuration for cluster markers
radius Number Dimensions.get("window").width * 0.06 No All Yes SuperCluster radius
maxZoom Number 20 No All No SuperCluster maxZoom
minZoom Number 1 No All Yes SuperCluster minZoom
extent Number 512 No All Yes SuperCluster extent
nodeSize Number 64 No All Yes SuperCluster node size
minPoints Number 2 No All Yes SuperCluster minPoints
edgePadding Object { top: 50, left: 50, right: 50, bottom: 50 } No All No Edge padding for react-native-maps's fitToCoordinates method, called in onClusterPress for fitting to pressed cluster children
clusterColor String "#00B386" No All No Background color of cluster
clusterTextColor String "#FFFFFF" No All No Color of text in cluster
clusterFontFamily String None No All No Font family of text in cluster
selectedClusterId String None No All No ID of the currently selected cluster
selectedClusterColor String None No All No Color of the currently selected cluster
spiderLineColor String "#FF0000" No All No Color of the spider line which joins spiral location with center location
onClusterPress(cluster, markers) Function None No All Yes Allows you to control cluster on click event. Function returns information about cluster and its markers
onRegionChangeComplete(region, markers) Function None No All Yes Called when map's region changes. In return you get current region and markers data
onMarkersChange(markers) Function None No All Yes Called when markers change. In return you get markers data
superClusterRef MutableRefObject None No All Yes Return reference to supercluster library
mapRef Function None No All Yes Callback that returns the reference of the map component
getClusterEngine Function None No All No Callback that returns the supercluster engine instance (not supported yet)
renderCluster Function None No All No Enables you to render custom cluster with custom styles and logic
width Number None No All Yes Map's width
height Number None No All No Map's height

Known Issues

  • Unsupported property clusterColor: issue#1
  • Unsupported property clusterTextColor: issue#2
  • Unsupported property clusterFontFamily: issue#3
  • Unsupported property tracksViewChanges: issue#4
  • Unsupported property renderCluster: issue#5
  • The height property is currently unsupported, consistent with iOS behavior: issue#273
  • The maxZoom property is currently unsupported, consistent with iOS behavior: issue#274
  • The edgePadding property is currently unsupported, consistent with iOS behavior: issue#221
  • The spiralEnabled property is currently unsupported, consistent with iOS behavior: issue#275
  • The spiderLineColor property is currently unsupported, consistent with iOS behavior: issue#276

Other

None

Directory Structure

/react-native-map-clustering  # Project root directory
├── example                   # Example project
├── index.js                  # Entry file
├── index.d.ts                # Type definition file
├── lib                       # Component source code
│   ├── ClusteredMapView.js   # Clustered map component implementation
│   ├── ClusteredMarker.js    # Clustered marker component implementation
│   ├── ClusterHarmony.js     # HarmonyOS-side clustering implementation
│   └── helpers.js            # Utility functions
├── .npmignore                # npm publish ignore configuration
├── CHANGELOG.md              # Changelog
├── COMMITTERS.md             # Contributors list
├── LICENSE                   # Open source license file
├── OAT.xml                   # OAT self-check configuration
├── README.OpenSource         # Open source information
├── README.md                 # Chinese installation and usage guide
├── README_en.md              # English installation and usage guide
├── buildEnv.sh               # Build environment script
└── package.json              # Package configuration

How to Contribute

If you find any problem when using react-native-map-clustering, submit an issue or a PR.

License

The repository is based on The MIT License (MIT).

Introduction

react-native-map-clustering是一个RN三方库,需要在鸿蒙RN上可用,达到在安卓和IOS上的使用效果,满足应用跨端开发的需求。

Customize your domain