Adding Village Name Using Feature Group

#23
by fqa-cyber - opened
Files changed (3) hide show
  1. data/regions.json +0 -0
  2. src/map_utils.py +9 -9
  3. src/utils.py +29 -0
data/regions.json ADDED
The diff for this file is too large to render. See raw diff
 
src/map_utils.py CHANGED
@@ -1,14 +1,14 @@
1
  from branca.element import Template, MacroElement
2
 
3
  labels_unverified_requests="""
4
- <li><span style='background:#CE3C28;opacity:0.7;'></span>Rescue / إغاثة</li>
5
- <li><span style='background:#ED922E;opacity:0.7;'></span>Medical Assistance / مساعدة طبية</li>
6
- <li><span style='background:#FFCA92;opacity:0.7;'></span>Shelter / مأوى</li>
7
- <li><span style='background:#37A8DA;opacity:0.7;'></span>Food & Water / طعام وماء</li>
8
- <li><span style='background:#575757;opacity:0.7;'></span>Danger / مخاطر (تسرب الغاز، تلف في الخدمات العامة...)</li>
9
- <li><span style='background:#6EAA25;opacity:0.7;'></span>Done / تم</li>
10
- <li><span style='background:#023020;opacity:0.7;'></span>Partial / تم جزئيا</li>
11
- <li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / مخطط لها</li>
12
  """
13
  labels_verified="""
14
  <li><span style='background:#CE3C28;opacity:0.7;'></span>High Emergency / طوارئ عالية</li>
@@ -55,7 +55,7 @@ template_1 = """
55
  style='position: absolute; z-index:9999; border:2px solid grey; background-color:rgba(255, 255, 255, 0.8);
56
  border-radius:6px; padding: 10px; font-size:14px; right: 20px; bottom: 20px;'>
57
 
58
- <div class='legend-title'>Legend / مفتاح الخريطة</div>
59
  <div class='legend-scale'>
60
  <ul class='legend-labels'>
61
 
 
1
  from branca.element import Template, MacroElement
2
 
3
  labels_unverified_requests="""
4
+ <li><span style='background:#CE3C28;opacity:0.7;'></span>Rescue / Secours / إغاثة</li>
5
+ <li><span style='background:#ED922E;opacity:0.7;'></span>Medical Assistance / Assistance Médicale / مساعدة طبية</li>
6
+ <li><span style='background:#FFCA92;opacity:0.7;'></span>Shelter / Abris / مأوى</li>
7
+ <li><span style='background:#37A8DA;opacity:0.7;'></span>Food & Water / Nourriture et eau / طعام وماء</li>
8
+ <li><span style='background:#575757;opacity:0.7;'></span>Dangers / Dangers / مخاطر</li>
9
+ <li><span style='background:#6EAA25;opacity:0.7;'></span>Done / terminée / تم</li>
10
+ <li><span style='background:#023020;opacity:0.7;'></span>Partial / Partiellement terminée / تم جزئيا</li>
11
+ <li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / Prévue / مخطط لها</li>
12
  """
13
  labels_verified="""
14
  <li><span style='background:#CE3C28;opacity:0.7;'></span>High Emergency / طوارئ عالية</li>
 
55
  style='position: absolute; z-index:9999; border:2px solid grey; background-color:rgba(255, 255, 255, 0.8);
56
  border-radius:6px; padding: 10px; font-size:14px; right: 20px; bottom: 20px;'>
57
 
58
+ <div class='legend-title'>Legend / Nomenclature / مفتاح الخريطة</div>
59
  <div class='legend-scale'>
60
  <ul class='legend-labels'>
61
 
src/utils.py CHANGED
@@ -7,6 +7,7 @@ import streamlit as st
7
 
8
  EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
9
  BORDER_COLOR = "black"
 
10
 
11
  # @st.cache_resource
12
  def parse_gg_sheet(url):
@@ -15,6 +16,12 @@ def parse_gg_sheet(url):
15
  df = pd.read_csv(url, on_bad_lines="warn")
16
  return df
17
 
 
 
 
 
 
 
18
 
19
  def is_request_in_list(request, selection_list, options):
20
  if isinstance(request, float): # Check if the input is a float (like NaN)
@@ -118,6 +125,27 @@ def add_danger_distances_to_map(map_obj):
118
  ).add_to(Danger_Distances_group)
119
 
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  def init_map():
122
  m = folium.Map(
123
  location=[31.228674, -7.992047],
@@ -159,6 +187,7 @@ def init_map():
159
  # Add danger zones
160
  add_epicentre_to_map(m)
161
  add_danger_distances_to_map(m)
 
162
 
163
  # Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
164
  folium.LayerControl().add_to(m)
 
7
 
8
  EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
9
  BORDER_COLOR = "black"
10
+ DOUARS_URL = "data/regions.json"
11
 
12
  # @st.cache_resource
13
  def parse_gg_sheet(url):
 
16
  df = pd.read_csv(url, on_bad_lines="warn")
17
  return df
18
 
19
+ def parse_json_file(url):
20
+ df = pd.read_json(url)
21
+ df = pd.json_normalize(df.douars)
22
+ return df
23
+
24
+ douar_df = parse_json_file(DOUARS_URL)
25
 
26
  def is_request_in_list(request, selection_list, options):
27
  if isinstance(request, float): # Check if the input is a float (like NaN)
 
125
  ).add_to(Danger_Distances_group)
126
 
127
 
128
+ def add_village_names(douar_df, map_obj):
129
+ village_fgroup = folium.FeatureGroup(name='🔵 All the Villages / Tous les villages / جميع القرى', show=False).add_to(map_obj)
130
+
131
+ for _, row in douar_df.iterrows():
132
+ lat = row['lat']
133
+ lng = row['lng']
134
+ lat_lng = (lat, lng)
135
+ dour_name = row['name'].capitalize()
136
+ maps_url = f"https://maps.google.com/?q={lat_lng}"
137
+ display_text = f'<br><b>⛰️ Douar:</b> {dour_name}<br><a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>🧭 Google Maps</b></a>'
138
+
139
+ folium.CircleMarker(
140
+ location=[lat, lng],
141
+ radius=0.1,
142
+ tooltip = dour_name, # we might remove the tooltip to avoid crowding the map
143
+ popup=folium.Popup(display_text, max_width=200),
144
+ color= "#0046C8",
145
+ opacity = 0.7
146
+ ).add_to(village_fgroup)
147
+
148
+
149
  def init_map():
150
  m = folium.Map(
151
  location=[31.228674, -7.992047],
 
187
  # Add danger zones
188
  add_epicentre_to_map(m)
189
  add_danger_distances_to_map(m)
190
+ add_village_names(douar_df, m)
191
 
192
  # Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
193
  folium.LayerControl().add_to(m)