Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluding some markers #2

Closed
ScreamZ opened this issue Apr 8, 2022 · 4 comments
Closed

Excluding some markers #2

ScreamZ opened this issue Apr 8, 2022 · 4 comments

Comments

@ScreamZ
Copy link

ScreamZ commented Apr 8, 2022

I'm backporting the original issue because I think this repository might need it aswell.

tomekvenits/react-native-map-clustering#236

@JiriHoffmann
Copy link
Owner

Adding it doesn't make sense. If you don't want markers to be clustered then just keep them in two separate variables, one clustered, one not. Also, you should keep the marker for user location excluded anyways since it should be visually different from all other markers and you wouldn't want to recalculate and rerender all other markers every time user location changes.

@ScreamZ
Copy link
Author

ScreamZ commented Apr 12, 2022

@JiriHoffmann Yes, but how am I supposed to exclude it, I only have one clustered map instance ?

Of course, I want to exclude it and add a specific visual.

Do you have a small example? I might be totally dumb but I don't get how

Thanks :)

@JiriHoffmann
Copy link
Owner

No worries, I don't believe it is possible with the react-native-clustering library because it uses react-native-maps internally. The advantage of this library is that is not dependent on react-native-maps so you can organize your points however you want. Going off the example from the readme you could do something like this:

import { useClusterer } from 'react-native-clusterer';

const MAP_DIMENSIONS =  { width: MAP_WIDTH, height: MAP_HEIGHT }

//...
const [region, setRegion] = useState(initialRegion);
const
const [clusteredPoints, supercluster] = useClusterer(
  markers,
  MAP_DIMENSIONS,
  regions
);

// ...
return (
  <MapView
    onRegionChangeComplete={setRegion}
    // ... other props
  >
    {clusteredPoints.map((point) => (
      <Marker
      // ... marker props
      >
        {/*
                // ... marker children - callout, custom marker, etc.
              */}
      </Marker>
    ))}


    {regularPoints.map((point) => (
      <Marker
      // ... marker props
      >
        {/*
                // ... marker children - callout, custom marker, etc.
              */}
      </Marker>
    ))}


   {/* or even just a single marker with user location*/}
    <Marker
    // ... marker props
    >
      {/*
       ... marker children - callout, custom marker, etc.
       */}
    </Marker>
    />
  </MapView>
);

@ScreamZ
Copy link
Author

ScreamZ commented Apr 13, 2022

Nice, thanks for this :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants