Skip to content

Custom markers are not grouped into a clustering marker #287

@lv2211

Description

@lv2211

I'm testing the library to implement the grouping markers function and I don't see any clustering markers displayed like the demo. I don't know whether anyone has encountered this issue before, please help me with this.

Below is the envrironment and some code snippets

Environments

  • Device: Android Emulator - Pixel_3a_API_36
  • react-native-maps: 1.20.1
  • react-native-map-clustering: ^4.0.0
  • expo: 53.0.22
  • react-native: 0.79.5

Codes

// assign different alias to avoid duplicate name with MapView
import ClusteredMapView from 'react-native-map-clustering'; 
import MapView, { MapPressEvent, PROVIDER_GOOGLE } from 'react-native-maps';

const getMarkersFromVenues = useMemo(() => {
    if (!data) return [];
    const markers = data.map((venue) => {
      const isSelected = selectedVenueDetails?.id === venue.id;
      return (
        <FootprintMapMarker
          key={`${venue.id}${isSelected}`}
          venue={venue}
          isSelected={isSelected}
          handleOnSelect={() => setSelectedVenueDetails(venue)}
        />
      );
    });

    return markers;
  }, [data, selectedVenueDetails]);

return (
    <>
      <ClusteredMapView
        ref={mapRef}
        rotateEnabled={false}
        style={styles.map}
        provider={PROVIDER_GOOGLE}
        initialRegion={{
          latitude: 0,
          longitude: 0,
          latitudeDelta: 0,
          longitudeDelta: 0,
        }}
        toolbarEnabled={false}
        onPress={handleDeselectVenue}
        moveOnMarkerPress={false}
        onMapReady={zoomToFitMarkers}
        clusteringEnabled={true}
      >
        {getMarkersFromVenues}
      </ClusteredMapView>
      {selectedVenueDetails && <FootprintVenueDetail {...selectedVenueDetails} />}
    </>
  );
return (
    <Marker
      identifier={`venue-marker-id-${venue.id}`}
      coordinate={{ latitude: venue.latitude, longitude: venue.longitude }}
      tracksViewChanges={isEnabledTrackChanges}
      onPress={handleOnSelect}
      zIndex={isSelected ? 999 : 1}
    >
      {/* This wrapper is used to avoid flickering issue on Android */}
      <View collapsable={false}>
        <View style={styles.markerContainer}>
          <View
            style={[
              styles.iconContainer,
              {
                backgroundColor: isSelected ? Color.night : Color.white,
              },
            ]}
          >
            {getVenueIcon(venue.venueType, isSelected ? Color.white : Color.night)}
          </View>
          <Triangle width={8} height={8} color={isSelected ? Color.night : Color.white} />
        </View>
      </View>
    </Marker>
  );

Actual

Image

Expected

https://raw.githubusercontent.com/venits/react-native-map-clustering/assets/assets/demo.gif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions