gistda-sphere-react

Delivery zones

Find which delivery zone a point falls in, with polygon refs and spatial tests

Click the map or drag the pin to see whether a place is inside a delivery zone, and what delivery costs there:

Click the map to check a delivery address.

How it works

  • Each zone is a <Polygon>. A callback ref keeps every zone's ref in a Map keyed by name, and removes it when the zone unmounts.
  • contains(location) on a polygon ref tells whether a point lies inside the zone. Spatial analysis covers the other tests.
  • A click on a zone is an overlay click, so the map handles both onClick and onOverlayClick.
  • fillColor is a live prop, so highlighting the matching zone updates the polygon without re-creating it.

To check an address that users type, find it with useSearch or useSuggest, then pass its { lon, lat } to the same check.

On this page