Clusters : option valueMinCount — la valeur sous la bulle n'apparaît que pour les bulles significatives (cartes denses)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2 changed files +23 −3
modified
src/core/KaMap.ts
+12 −2
@@ -81,7 +81,13 @@ export interface KaMapOptions { | ||
| 81 | 81 | /** Clustering tuning. Lou-Ka style per-building geocoding wants |
| 82 | 82 | * maxZoom 15 so stacked units stay grouped as long as possible. |
| 83 | 83 | * `valueClamp` bounds each item's contribution to the bubble mean. */ |
| 84 | − cluster?: { maxZoom?: number; radius?: number; valueClamp?: [number, number] }; | |
| 84 | + cluster?: { | |
| 85 | + maxZoom?: number; | |
| 86 | + radius?: number; | |
| 87 | + valueClamp?: [number, number]; | |
| 88 | + /** N minimal d'items pour afficher la valeur sous une bulle. */ | |
| 89 | + valueMinCount?: number; | |
| 90 | + }; | |
| 85 | 91 | } |
| 86 | 92 | |
| 87 | 93 | const EMPTY_FC: GeoJSON.FeatureCollection = { |
@@ -133,6 +139,7 @@ export class KaMap { | ||
| 133 | 139 | maxZoom: number; |
| 134 | 140 | radius: number; |
| 135 | 141 | valueClamp?: [number, number]; |
| 142 | + valueMinCount?: number; | |
| 136 | 143 | }; |
| 137 | 144 | |
| 138 | 145 | /** Mouvement en cours déclenché par le code (fitBounds, easeTo interne) : |
@@ -166,6 +173,7 @@ export class KaMap { | ||
| 166 | 173 | maxZoom: Math.round(options.cluster?.maxZoom ?? 14), |
| 167 | 174 | radius: options.cluster?.radius ?? 46, |
| 168 | 175 | valueClamp: options.cluster?.valueClamp, |
| 176 | + valueMinCount: options.cluster?.valueMinCount, | |
| 169 | 177 | }; |
| 170 | 178 | |
| 171 | 179 | this.map = new mapboxgl.Map({ |
@@ -296,7 +304,9 @@ export class KaMap { | ||
| 296 | 304 | // hachés par propertiesToGeoJSON) |
| 297 | 305 | }); |
| 298 | 306 | } |
| 299 | − for (const layer of buildPropertyLayers(this.theme, this.sourceId)) { | |
| 307 | + for (const layer of buildPropertyLayers(this.theme, this.sourceId, { | |
| 308 | + valueMinCount: this.clusterOptions.valueMinCount, | |
| 309 | + })) { | |
| 300 | 310 | if (!map.getLayer(layer.id)) map.addLayer(layer); |
| 301 | 311 | } |
| 302 | 312 | this.installDrawLayers(); |
modified
src/layers/propertyLayer.ts
+11 −1
@@ -222,6 +222,11 @@ function familyColorExpressions(theme: KaMapTheme): FamilyColors { | ||
| 222 | 222 | export function buildPropertyLayers( |
| 223 | 223 | theme: KaMapTheme, |
| 224 | 224 | sourceId: string = PROPERTY_SOURCE_ID, |
| 225 | + opts?: { | |
| 226 | + /** N minimal d'items pour afficher la valeur sous la bulle — cartes | |
| 227 | + * denses (Immo-Ka) : éviter un ≈prix sous chaque micro-bulle. */ | |
| 228 | + valueMinCount?: number; | |
| 229 | + }, | |
| 225 | 230 | ): (SymbolLayerSpecification | CircleLayerSpecification)[] { |
| 226 | 231 | const colors = familyColorExpressions(theme); |
| 227 | 232 | const dimmed: ExpressionSpecification = ["boolean", ["feature-state", "dimmed"], false]; |
@@ -307,7 +312,12 @@ export function buildPropertyLayers( | ||
| 307 | 312 | slot: "top", |
| 308 | 313 | type: "symbol", |
| 309 | 314 | source: sourceId, |
| 310 | − filter: ["all", ["has", "point_count"], [">", ["to-number", ["get", "valueCount"]], 0]], | |
| 315 | + filter: [ | |
| 316 | + "all", | |
| 317 | + ["has", "point_count"], | |
| 318 | + [">", ["to-number", ["get", "valueCount"]], 0], | |
| 319 | + [">=", ["to-number", ["get", "point_count"]], opts?.valueMinCount ?? 0], | |
| 320 | + ], | |
| 311 | 321 | minzoom: 9, |
| 312 | 322 | layout: { |
| 313 | 323 | "text-field": [ |
| 314 | 324 | |