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:
@@ -1,14 +1,23 @@
|
|||||||
window.dash_clientside = Object.assign({}, window.dash_clientside, {
|
window.dash_clientside = Object.assign({}, window.dash_clientside, {
|
||||||
leaflet: {
|
leaflet: {
|
||||||
pointToLayer: function (feature, latlng, context) {
|
pointToLayer: function (feature, latlng, context) {
|
||||||
return L.circleMarker(latlng, {
|
const isHome = Boolean(feature.properties.is_home);
|
||||||
radius: 5,
|
const marker = L.circleMarker(latlng, {
|
||||||
|
radius: isHome ? 8 : 5,
|
||||||
fillColor: feature.properties.marker_color,
|
fillColor: feature.properties.marker_color,
|
||||||
color: "white",
|
color: "white",
|
||||||
weight: 1,
|
weight: 1,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
fillOpacity: 0.8,
|
fillOpacity: 0.8,
|
||||||
}).bindTooltip(feature.properties.tooltip);
|
}).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) {
|
clusterToLayer: function (feature, latlng, index, context) {
|
||||||
console.log(feature);
|
console.log(feature);
|
||||||
|
|||||||
+5
-2
@@ -582,6 +582,8 @@ def get_org_location_map(
|
|||||||
"acheteur": build_org_markers(lff, "acheteur"),
|
"acheteur": build_org_markers(lff, "acheteur"),
|
||||||
"titulaire": build_org_markers(lff, "titulaire"),
|
"titulaire": build_org_markers(lff, "titulaire"),
|
||||||
}
|
}
|
||||||
|
for marker in markers_by_type[home_type]:
|
||||||
|
marker["is_home"] = True
|
||||||
|
|
||||||
ns = Namespace("dash_clientside", "leaflet")
|
ns = Namespace("dash_clientside", "leaflet")
|
||||||
point_to_layer = ns("pointToLayer")
|
point_to_layer = ns("pointToLayer")
|
||||||
@@ -589,8 +591,9 @@ def get_org_location_map(
|
|||||||
|
|
||||||
layers: list = [dl.TileLayer()]
|
layers: list = [dl.TileLayer()]
|
||||||
all_points: list[tuple[float, float]] = []
|
all_points: list[tuple[float, float]] = []
|
||||||
# Ordre fixe (titulaire puis acheteur), comme sur /observatoire : la
|
# Ordre fixe (titulaire puis acheteur), comme sur /observatoire. Le point
|
||||||
# couche acheteur est toujours peinte au-dessus, quel que soit home_type.
|
# 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"):
|
for org_type in ("titulaire", "acheteur"):
|
||||||
markers = markers_by_type[org_type]
|
markers = markers_by_type[org_type]
|
||||||
if not markers:
|
if not markers:
|
||||||
|
|||||||
+47
-7
@@ -238,12 +238,8 @@ def test_build_org_markers_missing_columns_returns_empty():
|
|||||||
assert build_org_markers(lff, "titulaire") == []
|
assert build_org_markers(lff, "titulaire") == []
|
||||||
|
|
||||||
|
|
||||||
def test_get_org_location_map_bounds_cover_home_and_counterpart():
|
def _org_map_dff():
|
||||||
import dash_leaflet as dl
|
return pl.DataFrame(
|
||||||
|
|
||||||
from src.figures import get_org_location_map
|
|
||||||
|
|
||||||
dff = pl.DataFrame(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"uid": "u1",
|
"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 isinstance(leaflet_map, dl.Map)
|
||||||
assert leaflet_map.bounds == [[48.11, -1.68], [48.85, 2.35]]
|
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():
|
def test_get_org_location_map_defaults_to_france_view_without_coordinates():
|
||||||
from src.figures import get_org_location_map
|
from src.figures import get_org_location_map
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user