feat(figures): mettre en avant le point de l'organisme consulté sur la carte

Marque is_home=True sur les marqueurs du home_type (acheteur ou titulaire
selon la page) dans get_org_location_map. Côté client, pointToLayer donne
à ce point un rayon légèrement plus grand (8 vs 5) et le ramène toujours
au premier plan (bringToFront), indépendamment de l'ordre des couches.
This commit is contained in:
Colin Maudry
2026-07-03 22:08:43 +02:00
parent a96f772d7a
commit f1c28acc96
3 changed files with 63 additions and 11 deletions
+11 -2
View File
@@ -1,14 +1,23 @@
window.dash_clientside = Object.assign({}, window.dash_clientside, {
leaflet: {
pointToLayer: function (feature, latlng, context) {
return L.circleMarker(latlng, {
radius: 5,
const isHome = Boolean(feature.properties.is_home);
const marker = L.circleMarker(latlng, {
radius: isHome ? 8 : 5,
fillColor: feature.properties.marker_color,
color: "white",
weight: 1,
opacity: 1,
fillOpacity: 0.8,
}).bindTooltip(feature.properties.tooltip);
// Le point de l'organisme consulté (is_home) doit toujours passer
// au-dessus de ses contreparties, quel que soit l'ordre des couches.
if (isHome) {
marker.on("add", function () {
marker.bringToFront();
});
}
return marker;
},
clusterToLayer: function (feature, latlng, index, context) {
console.log(feature);
+5 -2
View File
@@ -582,6 +582,8 @@ def get_org_location_map(
"acheteur": build_org_markers(lff, "acheteur"),
"titulaire": build_org_markers(lff, "titulaire"),
}
for marker in markers_by_type[home_type]:
marker["is_home"] = True
ns = Namespace("dash_clientside", "leaflet")
point_to_layer = ns("pointToLayer")
@@ -589,8 +591,9 @@ def get_org_location_map(
layers: list = [dl.TileLayer()]
all_points: list[tuple[float, float]] = []
# Ordre fixe (titulaire puis acheteur), comme sur /observatoire : la
# couche acheteur est toujours peinte au-dessus, quel que soit home_type.
# Ordre fixe (titulaire puis acheteur), comme sur /observatoire. Le point
# de l'organisme consulté (is_home) est de toute façon toujours ramené au
# premier plan côté client (pointToLayer, dash_clientside.js).
for org_type in ("titulaire", "acheteur"):
markers = markers_by_type[org_type]
if not markers:
+47 -7
View File
@@ -238,12 +238,8 @@ def test_build_org_markers_missing_columns_returns_empty():
assert build_org_markers(lff, "titulaire") == []
def test_get_org_location_map_bounds_cover_home_and_counterpart():
import dash_leaflet as dl
from src.figures import get_org_location_map
dff = pl.DataFrame(
def _org_map_dff():
return pl.DataFrame(
[
{
"uid": "u1",
@@ -257,7 +253,13 @@ def test_get_org_location_map_bounds_cover_home_and_counterpart():
]
)
leaflet_map = get_org_location_map(dff, "acheteur", "test-map")
def test_get_org_location_map_bounds_cover_home_and_counterpart():
import dash_leaflet as dl
from src.figures import get_org_location_map
leaflet_map = get_org_location_map(_org_map_dff(), "acheteur", "test-map")
assert isinstance(leaflet_map, dl.Map)
assert leaflet_map.bounds == [[48.11, -1.68], [48.85, 2.35]]
@@ -269,6 +271,44 @@ def test_get_org_location_map_bounds_cover_home_and_counterpart():
}
def test_get_org_location_map_marks_home_org_marker_acheteur():
import dash_leaflet as dl
from src.figures import get_org_location_map
leaflet_map = get_org_location_map(_org_map_dff(), "acheteur", "test-map")
geojson_layers = {
layer.id: layer
for layer in leaflet_map.children
if isinstance(layer, dl.GeoJSON)
}
acheteur_features = geojson_layers["test-map-acheteur"].data["features"]
titulaire_features = geojson_layers["test-map-titulaire"].data["features"]
assert all(f["properties"]["is_home"] for f in acheteur_features)
assert all(not f["properties"].get("is_home") for f in titulaire_features)
def test_get_org_location_map_marks_home_org_marker_titulaire():
import dash_leaflet as dl
from src.figures import get_org_location_map
leaflet_map = get_org_location_map(_org_map_dff(), "titulaire", "test-map")
geojson_layers = {
layer.id: layer
for layer in leaflet_map.children
if isinstance(layer, dl.GeoJSON)
}
acheteur_features = geojson_layers["test-map-acheteur"].data["features"]
titulaire_features = geojson_layers["test-map-titulaire"].data["features"]
assert all(f["properties"]["is_home"] for f in titulaire_features)
assert all(not f["properties"].get("is_home") for f in acheteur_features)
def test_get_org_location_map_defaults_to_france_view_without_coordinates():
from src.figures import get_org_location_map