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 aMapkeyed 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
onClickandonOverlayClick. fillColoris 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.