feat(titulaire): afficher les acheteurs sur la carte de la fiche titulaire
Supprime point_on_map, devenue inutilisée après migration des deux pages vers get_org_location_map.
This commit is contained in:
@@ -181,79 +181,6 @@ def get_sources_tables(source_path) -> html.Div:
|
|||||||
return html.Div(children=datatable)
|
return html.Div(children=datatable)
|
||||||
|
|
||||||
|
|
||||||
def point_on_map(lat, lon, departement_code=None):
|
|
||||||
"""Fonction améliorée utilisant les codes départementaux pour la détection de région.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
lat: Coordonnée de latitude
|
|
||||||
lon: Coordonnée de longitude
|
|
||||||
departement_code: Code du département (ex: '75', '971', etc.)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
html.Div contenant la carte, ou div vide si invalide
|
|
||||||
"""
|
|
||||||
# Validation des coordonnées
|
|
||||||
try:
|
|
||||||
lat = float(lat)
|
|
||||||
lon = float(lon)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
return html.Div() # Div vide pour les coordonnées invalides
|
|
||||||
|
|
||||||
# Vérification que les coordonnées sont valides
|
|
||||||
if not (-90 <= lat <= 90) or not (-180 <= lon <= 180):
|
|
||||||
return html.Div()
|
|
||||||
|
|
||||||
# Si aucun code département n'est fourni, retourner une div vide
|
|
||||||
if not departement_code:
|
|
||||||
return html.Div()
|
|
||||||
|
|
||||||
# Détermination de la région en utilisant le code département
|
|
||||||
# Logique identique à get_geographic_maps
|
|
||||||
if departement_code in ["971", "972", "973", "974", "976"]:
|
|
||||||
region_key = departement_code # Département d'outre-mer
|
|
||||||
elif len(departement_code) == 2: # Département métropolitain
|
|
||||||
region_key = "Hexagone"
|
|
||||||
else:
|
|
||||||
return html.Div() # Format de code département invalide
|
|
||||||
|
|
||||||
# Paramètres de carte par région (réutilisés de get_geographic_maps)
|
|
||||||
regions = {
|
|
||||||
"Hexagone": {"center": [46.6, 2.2], "zoom": 5},
|
|
||||||
"971": {"center": [16.23, -61.55], "zoom": 9}, # Guadeloupe
|
|
||||||
"972": {"center": [14.64, -61.02], "zoom": 10}, # Martinique
|
|
||||||
"973": {"center": [3.93, -53.12], "zoom": 7}, # Guyane
|
|
||||||
"974": {"center": [-21.11, 55.53], "zoom": 9}, # La Réunion
|
|
||||||
"976": {"center": [-12.82, 45.16], "zoom": 10}, # Mayotte
|
|
||||||
}
|
|
||||||
|
|
||||||
settings = regions.get(region_key, regions["Hexagone"])
|
|
||||||
|
|
||||||
# Création de la carte
|
|
||||||
fig = px.scatter_map(
|
|
||||||
lat=[lat],
|
|
||||||
lon=[lon],
|
|
||||||
height=300,
|
|
||||||
# width=400,
|
|
||||||
color=[1],
|
|
||||||
zoom=settings["zoom"],
|
|
||||||
)
|
|
||||||
|
|
||||||
fig.update_traces(marker=dict(size=10))
|
|
||||||
|
|
||||||
# Configuration de la carte (interactive - zoomable)
|
|
||||||
fig.update_layout(
|
|
||||||
map_style="light", # Fond de carte clair
|
|
||||||
margin={"r": 0, "t": 0, "l": 0, "b": 0},
|
|
||||||
mapbox_center={"lat": settings["center"][0], "lon": settings["center"][1]},
|
|
||||||
mapbox_zoom=settings["zoom"],
|
|
||||||
coloraxis_showscale=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
return html.Div(
|
|
||||||
dcc.Graph(figure=fig, config={"displayModeBar": False}),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DataTable(dash_table.DataTable):
|
class DataTable(dash_table.DataTable):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
+25
-14
@@ -18,9 +18,9 @@ from src.db import aggregate_marches, count_marches, query_marches, schema
|
|||||||
from src.figures import (
|
from src.figures import (
|
||||||
DataTable,
|
DataTable,
|
||||||
get_distance_histogram,
|
get_distance_histogram,
|
||||||
|
get_org_location_map,
|
||||||
get_top_org_table,
|
get_top_org_table,
|
||||||
make_column_picker,
|
make_column_picker,
|
||||||
point_on_map,
|
|
||||||
)
|
)
|
||||||
from src.utils.data import DF_TITULAIRES, get_annuaire_data, get_departement_region
|
from src.utils.data import DF_TITULAIRES, get_annuaire_data, get_departement_region
|
||||||
from src.utils.frontend import get_button_properties
|
from src.utils.frontend import get_button_properties
|
||||||
@@ -279,7 +279,6 @@ layout = [
|
|||||||
Output(component_id="titulaire_siret", component_property="children"),
|
Output(component_id="titulaire_siret", component_property="children"),
|
||||||
Output(component_id="titulaire_nom", component_property="children"),
|
Output(component_id="titulaire_nom", component_property="children"),
|
||||||
Output(component_id="titulaire_commune", component_property="children"),
|
Output(component_id="titulaire_commune", component_property="children"),
|
||||||
Output(component_id="titulaire_map", component_property="children"),
|
|
||||||
Output(component_id="titulaire_departement", component_property="children"),
|
Output(component_id="titulaire_departement", component_property="children"),
|
||||||
Output(component_id="titulaire_region", component_property="children"),
|
Output(component_id="titulaire_region", component_property="children"),
|
||||||
Output(component_id="titulaire_lien_annuaire", component_property="href"),
|
Output(component_id="titulaire_lien_annuaire", component_property="href"),
|
||||||
@@ -302,16 +301,6 @@ def update_titulaire_infos(url):
|
|||||||
if data_etablissement:
|
if data_etablissement:
|
||||||
data_etablissement = data_etablissement[0]
|
data_etablissement = data_etablissement[0]
|
||||||
|
|
||||||
# Extraction du code département à partir du code postal
|
|
||||||
code_postal = data_etablissement.get("code_postal", "")
|
|
||||||
departement_code = code_postal[:2] if code_postal else None
|
|
||||||
|
|
||||||
# Création de la carte avec le code département pour un centrage approprié
|
|
||||||
titulaire_map = point_on_map(
|
|
||||||
data_etablissement["latitude"],
|
|
||||||
data_etablissement["longitude"],
|
|
||||||
departement_code,
|
|
||||||
)
|
|
||||||
code_departement, nom_departement, nom_region = get_departement_region(
|
code_departement, nom_departement, nom_region = get_departement_region(
|
||||||
data_etablissement["code_postal"]
|
data_etablissement["code_postal"]
|
||||||
)
|
)
|
||||||
@@ -323,7 +312,6 @@ def update_titulaire_infos(url):
|
|||||||
libelle_commune = data_etablissement["libelle_commune"]
|
libelle_commune = data_etablissement["libelle_commune"]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
titulaire_map = html.Div()
|
|
||||||
code_departement, nom_departement, nom_region = "", "", ""
|
code_departement, nom_departement, nom_region = "", "", ""
|
||||||
departement = ""
|
departement = ""
|
||||||
lien_annuaire = ""
|
lien_annuaire = ""
|
||||||
@@ -336,7 +324,6 @@ def update_titulaire_infos(url):
|
|||||||
titulaire_siret,
|
titulaire_siret,
|
||||||
raison_sociale,
|
raison_sociale,
|
||||||
libelle_commune,
|
libelle_commune,
|
||||||
titulaire_map,
|
|
||||||
departement,
|
departement,
|
||||||
nom_region,
|
nom_region,
|
||||||
lien_annuaire,
|
lien_annuaire,
|
||||||
@@ -344,6 +331,30 @@ def update_titulaire_infos(url):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@callback(
|
||||||
|
Output(component_id="titulaire_map", component_property="children"),
|
||||||
|
Input(component_id="titulaire_url", component_property="pathname"),
|
||||||
|
Input(component_id="titulaire_year", component_property="value"),
|
||||||
|
)
|
||||||
|
def update_titulaire_map(pathname, titulaire_year):
|
||||||
|
where_sql, params = _titulaire_scope(pathname, titulaire_year)
|
||||||
|
geo_columns = [
|
||||||
|
col
|
||||||
|
for col in [
|
||||||
|
"uid",
|
||||||
|
"acheteur_longitude",
|
||||||
|
"acheteur_latitude",
|
||||||
|
"acheteur_nom",
|
||||||
|
"titulaire_longitude",
|
||||||
|
"titulaire_latitude",
|
||||||
|
"titulaire_nom",
|
||||||
|
]
|
||||||
|
if col in schema.names()
|
||||||
|
]
|
||||||
|
dff = query_marches(where_sql, params, columns=geo_columns)
|
||||||
|
return get_org_location_map(dff, "titulaire", "titulaire_map_leaflet")
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
Output(component_id="titulaire_marches_remportes", component_property="children"),
|
Output(component_id="titulaire_marches_remportes", component_property="children"),
|
||||||
Output(
|
Output(
|
||||||
|
|||||||
Reference in New Issue
Block a user