Map Overlays
How the search map draws overlay layers — schools, neighborhoods, postal codes, school districts — on top of the listings, and how selection/popups work. For the broader map/search anatomy see Property Search — How it works.
Overlays are extra, config-driven layers of geographic data (from the LiveBy
source). Each overlay is a plain data object — an OverlayLayerDefinition — so a
tenant enables, reorders, restyles, or hides overlays entirely through config,
without touching the map code. The default set is defined in
src/configs/defaults/overlays/liveBy.ts and gated on features.liveBy.

Key files
| File | Role |
|---|---|
src/configs/defaults/overlays/liveBy.ts | The overlay definitions (livebyNeighborhood, livebyPostalCode, livebySchoolDistrict, livebySchool) + the exported overlayLayers array. |
src/configs/defaults/overlays/parcels.ts | The public-record parcels overlay (parcelsLayers), gated on features.publicRecord. |
src/configs/defaults/map.ts | OverlayLayerDefinition type + the overlays: { layers, persistSelection } config block. |
src/components/shared/Map/OverlayLayersController.tsx | Leaf that runs the sync hooks (renders nothing). |
.../hooks/useOverlayLayers/useOverlayLayers.ts | The per-overlay sync engine: fetch → render polygons (GL) + markers (DOM). |
.../hooks/useOverlayLayers/layers.ts | Add/update/remove an overlay’s GL polygons through the shared renderer. |
src/utils/map/polygons.ts + resolvePolygonStyle.ts | The single polygon renderer (one GeoJSON source + fill/line layer pair per overlay, setData on re-sync) and its feature-state paint. |
.../hooks/useOverlayMarkers/renderMarkers.ts | Render overlay point features as DOM markers + client-side clustering. |
.../hooks/useOverlaySelectsLocation.ts | Wires marker/polygon clicks → location selection (search map only). |
.../Map/markerElement.ts | Builds the marker DOM element (shared by listing + overlay markers). |
.../Map/OverlayMarkerPopup/ | Popup host + per-overlay tooltip cards (tooltipRegistry.ts). |
src/utils/map/overlays.ts | fetchLocations (direct) and fetchDedupedLocations (through the filtering route) — the two fetchData implementations. |
src/app/api/overlay-locations/ | Server route that re-fetches and drops empty locations (route.ts + filterLocationsByCounts in utils.ts). |
GL vs DOM
Mapbox is used two ways on this map — know which is which:
- Listing markers → DOM. Search-result markers are plain DOM nodes built by
createMarkerElement(markerElement.ts) and driven byuseListingMarkers. Cheap: ~100 markers created in well under a frame, no per-marker React root. - Overlay point markers → DOM (current reality). School, neighborhood, and
postal-code point/cluster markers are also DOM markers, rendered by
renderOverlayMarkers(useOverlayMarkers/renderMarkers.ts) via the samecreateMarkerElementpath. They were previously GL circle layers — that path is gone. Clustering is done client-side incluster.ts(not by a GLcluster: truesource). - Overlay polygons → GL. Boundaries and catchments render as GL fill + line
layers (
addOverlayPolygons→addPolygonToMap). Polygons must stay GL — DOM can’t draw arbitrary geometry.
A single overlay commonly renders both: DOM markers and a GL polygon
(e.g. a school marker with a showOnMarkerHover catchment polygon). Polygons
render data-driven — whenever the fetched data contains polygon features —
the polygon config only tunes how (colour/style/hover behaviour).
How it works
- Definition — each overlay in
overlayLayersdeclares itslabel,color,fetchData(bounds → GeoJSON),activationMinZoom, and how it’sselectable('marker'|'polygon'| none). - Toggle menu — the search map’s
MapLayersMenulists overlays whereshowOn.searchis truthy (andshowOn.menu !== false); toggling one flipsactiveLayersinMapOptionsProvider. Overlays whoseshowOn.searchis{ active: true }are seeded intoactiveLayerson first load — the search page computes them withdefaultActiveLayerIds(utils/map/overlays) and passes them as the provider’slayersprop; the PDP map does the same viaNeighborhoodSectionforshowOn.listing. - Sync —
useOverlayLayersreacts toactiveLayers+ viewport changes: for each enabled layer it fetches data for the current bounds, adds the GL polygon layer, and renders DOM markers. Layers below theiractivationMinZoomare removed and re-fetched once zoomed back in. - Selection → popup — on the search map,
useOverlaySelectsLocationturns a marker/polygon click into a location selection (MapOptionsProvider.locations- the
locationIdfilter). Hovering shows a popup:OverlayMarkerPopuprenders the React card looked up by overlay id intooltipRegistry.
- the
Configuration
@configs/overlays(overlays/liveBy.ts) — the overlay definitions. Add, reorder, restyle, or drop layers here; tenants override the file.@configs/map→overlays—{ layers: overlayLayers, persistSelection }.layersis the ordered list;persistSelection: false(default) drops a layer’s selected locations when it’s hidden.- Per-layer availability & default-active —
showOncontrols where an overlay appears and whether it starts enabled.search(opt-in) lists it in the search map’sMapLayersMenu;listing(opt-out) shows it on the PDP map;menu: falsehides the row so a standaloneOverlayToggleButton(wired inMapControls) controls it instead. On either surface a value of{ active: true }also seeds the overlay into the initialactiveLayersset — enabled at map load. A baretrueshows the overlay but leaves it off: default-active is explicit opt-in, never implicit. - Location types —
locationTypeslists everyApiLocation.typea layer requests and selects; selection, deselection on hide, the polygon guard and the neighbourhood button (includes('neighborhood')) all read the whole list. SERHANT’s neighbourhoods ask for['neighborhood', 'neighborhood-alternate'], so LiveBy’s micro-neighbourhoods (Turtle Bay inside Midtown East) draw with them; nested polygons overlap. - Tooltips — register a card component per overlay id in
OverlayMarkerPopup/tooltipRegistry.ts(override via_<tenant>/tooltipRegistry.tsx).tooltipLayerIdpoints the polygon-hover tooltip at another layer’s fill, so an overlay can expose only a subset of its polygons to hover. - Render floor —
renderMinZoom(defaults toactivationMinZoom) is the zoom below which an active layer stops drawing; set it lower to let the user zoom out a step without the layer vanishing (bounded by the API’s 300-per-page cap). - Polygon paint —
polygon.casingdraws a wider line under the outline so a pale outline still reads over a pale basemap;listingPolygonis the heavier paint for the single polygon the PDP address map draws. publishData— publish the fetched FeatureCollection intouseMapLayers().layerDatafor React consumers. Opt-in: every pan would otherwise push hundreds of features through context.features.publicRecord— gates the parcels overlay (overlays/parcels.ts) the wayfeatures.liveBygates the LiveBy set. The Repliers/locationssource=PublicRecordis an account entitlement: an account without it gets a 400 on the source itself, so the flag stays off until Repliers enables the dataset for that tenant’s key.
Empty-location filtering (opt-in)
MLS /locations data is dirty: a viewport often returns neighborhoods with no
listings at all, frequently as same-name duplicates under different parent
cities. Drawn as-is they give the map two “Fremont” polygons where one is empty.
An overlay opts out of that by pointing its fetchData at fetchDedupedLocations
instead of fetchLocations — one line, no other config:
// src/configs/urbn/overlays/neighborhoods.ts
fetchData: (bounds, signal) =>
fetchDedupedLocations(bounds, signal, {
type: 'neighborhood',
source,
markers
})That routes the fetch through /api/overlay-locations, which re-fetches the
same viewport server-side and keeps only locations the tenant’s
public/<tenant>/locations.json knows with a positive count:
locations.filter((location) => (countsMap.get(location.locationId) ?? 0) > 0)The generated tree is built with hideTrash, so it holds every location that had
listings at generation time and none with a zero count — it is the allowlist.
loadCountsMap parses that file once per process and retains only the counts map,
so the tree is garbage-collected and counts never reach the client.
Surviving locations keep their real Repliers locationId and are not flagged
external, so selection, filtering and popups behave exactly as with a direct
fetch — only the empties disappear.
The allowlist is only as fresh as the cache. A location that gained its first
listings after the last pnpm generate:locations <tenant> is absent from the
file and stays hidden until the next run. For a tenant with a
searchArea.boundary, locations outside that polygon are clipped out of the
cache too — and therefore out of the overlay.
Parcels mode
With features.publicRecord on, switching the parcels overlay on (overlays/parcels.ts,
publishData: true) is the mode — there is no second control. The overlay publishes its
parcels into useMapLayers().layerData, and useParcelGroups matches every listing on screen
to a parcel (groupListingsByParcel, useParcelListings/grouping.ts):
- By geometry — the listing’s pin falls inside the parcel.
- By address rescue — the pin missed (fell on the road), but the listing’s street address names a parcel within 150 m. A condo tower’s stacked records collapse onto one footprint.
What renders:
| Parcel | Hover | Click |
|---|---|---|
Holds listings — painted in its listing’s marker colour on its own GL source (useParcelListings) | Hovers the listing’s price marker, so the marker’s own hover card shows (markerHover); a marker or grid-card hover lights the parcel back (parcelOf) | Same as clicking the price marker: the listing browser on a wide screen, the listing drawer on touch |
| No listings | ParcelCard — the street address | ParcelDialog — the lot on a HomeMap + the assessor facts (ParcelProvider with a target); arrows step through the viewport’s listing-less parcels |
On the PDP, ParcelProvider finds the parcel under the listing with the same matcher, and
ListingParcelLayer / ParcelFacts draw it and its public record.
Gotchas & hints
- On touch, a tap previews and the tooltip commits. Touch has no hover, so tapping an
overlay marker opens its tooltip; the selection itself is the tooltip’s
OverlayLocationButton(“Show listings here” / “Remove this location”). The button renders only on a tap-opened tooltip of a selectable overlay, so the same card stays read-only on the PDP. - A phone or tablet search map selects through markers only.
OverlayLayersControllerpasses every overlay throughtoMarkerSelectbelowmd: aselectable: 'polygon'overlay gets name markers at its polygons’ centres (clustered like the neighborhoods), its polygons show only on a marker preview, and it keeps no polygon hover or click — which a tap on any marker above it used to trigger. Belowmda name marker may wrap to a second line within 70% of the screen. - A search polygon switches selectable overlays off.
useOverlayPolygonGuardturns off every active overlay withlocationTypesthe moment a drawn or URL-loaded polygon appears, so a marker selection can’t silently replace the polygon. Clearing the polygon does not bring them back. - Mapbox serializes feature properties as JSON strings. Properties read off a
clicked/queried GL feature come back stringified — booleans become
'true', arrays/objects become JSON text. Parse non-scalars before use (seeLiveBySchoolCard.tsx’sasBool, and parse array/object props withJSON.parse). - Polygons must stay GL. Never try to move polygon geometry onto the DOM path — only points/clusters are DOM markers.
- Overlays are gated by data + config presence. Nothing renders if
features.liveByis off (emptyoverlayLayers), if the layer isn’t inactiveLayers, or if the fetch returns no matching features. Polygon existence is checked at runtime viamap.getSource(...), never by thepolygonconfig field. - DOM markers survive
setStyle; GL layers don’t. A map-style switch wipes GL sources/layers (polygons are re-added by the re-sync), while DOM markers persist and are recoloured in place to avoid flicker. - Polygon tooltips hover via a
windowmousemove, not layer-scoped Mapbox events. Once the popup sits over the canvas it intercepts the canvas events, somap.on('mouseleave', layerId)would fire and the popup would flicker.useOverlayLayerslistens onwindowand hit-tests withmap.queryRenderedFeatures, coalesced to one test per animation frame at the latest pointer position — a high-rate mouse fires several events between frames, and each hit test walks the layer’s geometry.