From 83d4bf5f4334a16ae4f025f21408d299e3575105 Mon Sep 17 00:00:00 2001 From: jgenero Date: Wed, 4 Oct 2023 16:53:59 +0200 Subject: [PATCH] add folium marker cluster to route /geolocalisation --- app/routes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/routes.py b/app/routes.py index a1ebd4f..cb3db0f 100644 --- a/app/routes.py +++ b/app/routes.py @@ -24,6 +24,7 @@ from collections import defaultdict from flask import Blueprint, render_template, request, url_for, redirect import folium +from folium.plugins import MarkerCluster from pymongo import ASCENDING @@ -191,6 +192,8 @@ def geolocalisation(): actes=plaintext_response(search, actecol, prince_bigram)) m = folium.Map(location=[46.603354, 1.888334], zoom_start=6) + marker_cluster = MarkerCluster().add_to(m) + markers = defaultdict(list) for result in actecol.find(): @@ -208,7 +211,7 @@ def geolocalisation(): latitude = value[0][1] longitude = value[0][2] urls = [(url[0], url[3]) for url in value] - #print("urls", urls) + # print("urls", urls) popup = [f"{name}
"] for location, see in urls: popup.append(f"{see}
") @@ -216,9 +219,10 @@ def geolocalisation(): if latitude is not None: folium.Marker( location=[latitude, longitude], - popup= popup, + popup=popup, icon=folium.Icon(color='lightgray', icon="circle", prefix='fa') - ).add_to(m) + ).add_to(marker_cluster) + # to remove marker_cluster : .add_to(m) geolocalisation = m._repr_html_() return render_template("map.html", geolocalisation=geolocalisation)