@@ -24,7 +24,12 @@ import {
2424 DEFAULT_ZOOM ,
2525} from "../utils/constants" ;
2626import { readInitialView , writeView } from "../utils/url" ;
27- import { buildFilter , densityCountExpr , matchesFilters } from "../utils/filters" ;
27+ import {
28+ buildFilter ,
29+ densityCountExpr ,
30+ isDensityCountApproximate ,
31+ matchesFilters ,
32+ } from "../utils/filters" ;
2833import { transformFeature } from "../utils/format" ;
2934import { bboxAreaKm2 , getFullBbox , type BBox } from "../utils/geo" ;
3035import { ItemBoundsCache , fetchItemBounds , getTmsUrl , thumbUrl } from "../utils/tiles" ;
@@ -42,10 +47,7 @@ interface Props {
4247 selectedFeature : ImageFeature | null ;
4348 onSelect : ( f : ImageFeature | null ) => void ;
4449 onFeaturesUpdate : ( fs : ImageFeature [ ] ) => void ;
45- // Collections present in the tile SOURCE, independent of the active layer
46- // filter. Reported separately from onFeaturesUpdate because the rendered
47- // features are already filtered, so they cannot tell the UI which other
48- // sources exist to switch to.
50+ // Collection IDs available independently of the active filter.
4951 onCollectionsUpdate ?: ( ids : string [ ] ) => void ;
5052 searchBbox : BBox | null ;
5153 onSearchArea : ( bbox : BBox , center : [ number , number ] , exactBounds : BBox ) => void ;
@@ -136,7 +138,7 @@ export default function OamMap({
136138 useEffect ( ( ) => {
137139 onFeaturesUpdateRef . current = onFeaturesUpdate ;
138140 onCollectionsUpdateRef . current = onCollectionsUpdate ;
139- } , [ onFeaturesUpdate ] ) ;
141+ } , [ onFeaturesUpdate , onCollectionsUpdate ] ) ;
140142 useEffect ( ( ) => {
141143 filtersRef . current = filters ;
142144 } , [ filters ] ) ;
@@ -163,9 +165,6 @@ export default function OamMap({
163165 // triggers the Sidebar's built-in "Zoom in to see images" prompt.
164166 const emitVisibleFeatures = ( ) => {
165167 if ( ! map . current || ! onFeaturesUpdateRef . current ) return ;
166- // Before the zoom gate: which sources exist is a different question from
167- // which images are listable, and the answer must survive zooming out.
168- emitSeenCollections ( ) ;
169168 if ( map . current . getZoom ( ) < FOOTPRINT_MIN_ZOOM ) {
170169 onFeaturesUpdateRef . current ( [ ] ) ;
171170 return ;
@@ -193,17 +192,10 @@ export default function OamMap({
193192 } catch ( e ) {
194193 console . error ( "Error querying rendered features:" , e ) ;
195194 }
196-
197195 } ;
198196
199- // Which sources the catalogue holds, independent of zoom and of the active
200- // filter. Read from two places because neither covers the whole zoom range:
201- // footprints carry `collection` but only exist at FOOTPRINT_MIN_ZOOM and
202- // above, and below that the density cells carry the same answer in their
203- // per-source bucket keys. Without the second half the Source chip
204- // disappears when you zoom out, which reads as the filter being broken.
205- // querySourceFeatures ignores the layer filter, so both still see every
206- // source in the loaded tiles while a source filter is active.
197+ // Read collections from footprints at high zoom and density buckets at low zoom.
198+ // querySourceFeatures is unaffected by layer filters.
207199 const emitSeenCollections = ( ) => {
208200 if ( ! map . current || ! onCollectionsUpdateRef . current ) return ;
209201 const ids = new Set < string > ( ) ;
@@ -276,10 +268,14 @@ export default function OamMap({
276268 ] as FilterSpecification ) ;
277269 }
278270 if ( map . current . getLayer ( "density-count" ) ) {
279- map . current . setLayoutProperty ( "density-count" , "text-field" , [
280- "to-string" ,
281- countExpr ,
282- ] as unknown as maplibregl . DataDrivenPropertyValueSpecification < string > ) ;
271+ const countText = isDensityCountApproximate ( f )
272+ ? [ "concat" , "up to " , [ "to-string" , countExpr ] ]
273+ : [ "to-string" , countExpr ] ;
274+ map . current . setLayoutProperty (
275+ "density-count" ,
276+ "text-field" ,
277+ countText as unknown as maplibregl . DataDrivenPropertyValueSpecification < string > ,
278+ ) ;
283279 map . current . setFilter ( "density-count" , [
284280 "all" ,
285281 [ "==" , [ "geometry-type" ] , "Point" ] ,
@@ -642,6 +638,7 @@ export default function OamMap({
642638 } ) ;
643639
644640 map . current ! . on ( "idle" , ( ) => {
641+ emitSeenCollections ( ) ;
645642 emitVisibleFeatures ( ) ;
646643 setMapZoom ( map . current ! . getZoom ( ) ) ;
647644 setIdleTick ( ( t ) => t + 1 ) ;
0 commit comments