Skip to main content
MAPBOX & SPATIAL UI//7 MIN READ

The Case of the 3 Invisible Artisans: Fixing Map-to-List Desync, FNV-1a Privacy Pins & 64-Vertex GeoJSON Rings

How I architected our Mapbox GL discovery experience—solving why 3 backend matches rendered 0 pins, spreading overlapping neighborhood pins with FNV-1a hashing, and drawing geodesic coverage circles.

if the list says 4 artisans and the map shows 0 pins, the user trusts neither.

Nothing makes a user question their sanity faster than a split-brain discovery screen: the search badge at the top says `'3 artisans found'`, the list view shows three profiles, and then you toggle over to the **Map** tab—and stare at an empty ocean.

While building `DiscoverMapbox.tsx` and `discovery-geo.ts` for our public (`/discover`) and signed-in (`/customer/discover`) marketplace search, I had to solve three competing problems at once: **1-to-1 pin synchronization** between the list and the map, **pre-booking home-address privacy** for artisans, and **visualizing each artisan's actual service radius** (from 5 km to 50 km) without cluttering the screen.

Discover Mapbox view over Lagos showing '4 artisans · Tap a pin to see service area' badge, 'Search this area' floating trigger, and price/name pins
The unified DiscoverMapbox view over Lagos: price/trade pins, single-source-of-truth filter pills, and the drag-activated 'Search this area' trigger.

1. Solving the '3 Results Returned, 0 Shown' Mystery

When we inspected why valid artisans returned by `/api/v1/profiles/artisans/search/` were vanishing on the signed-in discover screen, we found two overly aggressive client-side gates:

  • The District Substring Trap (`matchesDistrict`): The client filter was checking whether the artisan's free-text address contained the customer's exact district substring. If the backend matched an artisan 1.2 km away by PostGIS coordinates across a neighborhood boundary (say, Lekki Phase 1 vs. Victoria Island), the string check rejected them! Bypassing the text-district gate whenever coordinate search (`Boolean(userCoords)`) is active fixed it immediately.
  • Honoring the Artisan's Own Service Radius (`matchesDistance`): An electrician based 8 km away who explicitly configured a `10 km serviceRadius` is a valid match even if the default search slider is at 5 km. Updating the distance check to evaluate `Math.max(radiusKm, artisan.serviceRadius)` made sure mobile professionals covering wide areas weren't filtered out.
Selected artisan card on Discover Map showing Misan Wellington (electrical, 5.0 stars, ₦14,000) and a 10 km translucent blue GeoJSON service-area circle
Tapping an artisan pin draws their 64-vertex geodesic coverage polygon (10 km radius) and slides up the 'View profile & hire' summary sheet.

2. The 3-Tier Coordinate Pipeline (Why Every Listed Artisan Gets a Pin)

Previously, if an artisan registered with a text address like `'Admiralty Way, Lekki'` but hadn't saved numeric `lat`/`lng` coordinates yet, `parseCoordinates()` returned `null` and `DiscoverMapbox` silently skipped them. To guarantee **1-to-1 parity** between the list count and the map pins, every artisan now resolves through a three-tier pipeline:

  • Tier 1 — Saved Coordinates + Deterministic Privacy Offset: If the profile has valid `lat`/`lng`, we pass them through `approximateAreaPoint(coords, artisan.id)` to shift the pin by 0.25–0.5 km.
  • Tier 2 — Cached Forward Geocoding (`geocodeArea`): If the profile only has a text address, we asynchronously query Mapbox Geocoding v6 (`country=ng`) and cache the resolved coordinates so subsequent renders are instant.
  • Tier 3 — Immediate Search-Ring Fallback: While async geocoding is in flight (or if a text address is too vague to geocode), the artisan is placed on a deterministic ring around the active search center—so the map pin count *always* equals the list count.

3. FNV-1a Hashing: Protecting Privacy & Unstacking Overlapping Pins

Plotting raw home coordinates on a public discovery map creates two problems: first, it leaks an artisan's exact house before a customer even books them. Second, if three plumbers in Surulere all typed `'Surulere, Lagos'` as their address, their pins stack on the exact same pixel and only the top pin is clickable!

"Random jitter makes pins jump around on every page refresh. Deterministic FNV-1a hashing keeps every pin private, spread out, and rock-steady across reloads."

In `discovery-geo.ts`, `approximateAreaPoint()` computes an **FNV-1a 32-bit hash** of `artisan.id` to derive a deterministic polar angle and a `0.25–0.5 km` radius offset. That single pure function hides exact street addresses prior to booking *and* fans out artisans in the same neighborhood into distinct, clickable pins that never jump around when you refresh.

Selected artisan card on Discover Map showing Tunde Adeleke (Mobile service) with a tighter 5 km approximate service-area circle over Victoria Island
Comparing coverage rings: a 5 km mobile service radius over Victoria Island / Eko Atlantic vs. the 10 km ring above.

4. 64-Vertex GeoJSON Coverage Circles & Smarter Camera Framing

  • Geodesic Coverage Polygons (`circlePolygonGeoJson`): Mapbox GL markers don't scale with map zoom in real kilometers. So `circlePolygonGeoJson()` computes 64-vertex spherical GeoJSON polygons rendered as native Mapbox fill + dashed-line layers—one for the customer's search radius (`search-radius`) and a highlighted ring for the selected artisan's `serviceRadius` (`1–50 km`).
  • Pin-First Camera Bounds: Earlier, fitting the camera to a 50 km search circle zoomed the map out to show half of Lagos State even when all 4 matching artisans were within 3 km of the user. Now, camera framing fits the matched artisan pins first, only falling back to the search-radius polygon bounds when 0 artisans are in range.
  • 'Search This Area' & Single-Source-of-Truth Filters: Panning the map (`dragstart`) reveals the floating `'Search this area'` pill, which reverse-geocodes the new viewport center via `nearbyPlaceNames` and re-queries the backend. And by stripping out duplicate in-map filter inputs, the page header filters remain the single source of truth.
my take ↓

Anyway, that's what I've been thinking about lately. Back to building.

From the archive

Read something else.