Skip to content

Commit a7ecd52

Browse files
authored
Allow popup on overlay (#5076)
* add popup on overlay * add default behaviour of popups * correct LABEL_PER_MODEL * correct LAYER_PER_MODEL default values * add documentation * make quality * fix paths' popup in forms * add entry in changelog * change LABEL_PER_MODEL setting name * fix ignored custom settings * modify mapentity dependance * Use 8.15.0 version of mapentity * Add get_expected_popup_content method in test to fix test_api_popup_content failure
1 parent 1636de4 commit a7ecd52

File tree

29 files changed

+301
-23
lines changed

29 files changed

+301
-23
lines changed

docs/advanced-configuration/interface.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ By default, job cost details are not included in intervention exports. You can e
9898
9999
When enabled, a new column will be added to intervention exports, displaying the total cost for each job.
100100

101+
.. _custom-columns-available:
102+
101103
Custom columns available
102104
~~~~~~~~~~~~~~~~~~~~~~~~~
103105

docs/advanced-configuration/map-settings.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,26 @@ Since IGN map backgrounds are very dense and colourful, a dark opacity is applie
326326
327327
MAPENTITY_CONFIG['MAP_BACKGROUND_FOGGED'] = False
328328
329+
Popup configuration
330+
-------------------
331+
332+
Geotrek displays a popup when clicking on an object on the map.
333+
By default, this popup shows the object's name, its type, and a button linking to its detail page.
334+
335+
You can customize the fields displayed in the popup for each model by defining the ``POPUP_CONTENT`` setting in ``/var/conf/custom.py``:
336+
337+
.. code-block:: python
338+
339+
POPUP_CONTENT = {
340+
"signage": ["code", "type", "conditions"],
341+
}
342+
343+
Each key corresponds to a model name written in lowercase (for example, ``"signage"``),
344+
and each value is a list of field names to display in the popup.
345+
346+
The available fields are the same as those that can be configured for column display and exports.
347+
For more information, see :ref:`Custom columns available <custom-columns-available>`.
348+
329349
Map screenshots
330350
----------------
331351

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ CHANGELOG
1414

1515
- Reorganize the "Import data" chapter
1616

17+
**Improvements**
18+
19+
* Add configurable popups on map overlay (refs #4626).
20+
1721

1822
2.120.2 (2025-10-28)
1923
----------------------------

geotrek/core/static/core/geotrek.forms.snap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ MapEntity.GeometryField.GeometryFieldPathMixin = {
4141
*/
4242
buildPathsLayer: function (objectsLayer) {
4343
var url_path = window.SETTINGS.urls.path_layer
44-
var pathsLayer = MapEntity.pathsLayer({style: {clickable: true}, no_draft: objectsLayer.modelname != 'path'});
44+
var pathsLayer = MapEntity.pathsLayer({style: {clickable: true}, no_draft: objectsLayer.modelname != 'path', displayPopup: false});
4545
if (objectsLayer.modelname != 'path')
4646
url_path += '?_no_draft=true';
4747
pathsLayer.load(url_path, true);

geotrek/core/static/core/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $(window).on('entity:map', function (e, data) {
2424

2525
var pathsLayer = MapEntity.pathsLayer({
2626
indexing: false,
27-
style: { clickable: false },
27+
style: { clickable: true },
2828
modelname: 'path',
2929
no_draft: data.modelname != 'path',
3030
});

geotrek/core/static/core/trail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $(window).on('entity:map', function (e, data) {
44
var url = window.SETTINGS.urls[layername];
55
var loaded_trail = false;
66
var map = data.map;
7-
var style = L.Util.extend({ clickable: false },
7+
var style = L.Util.extend({ clickable: true },
88
window.SETTINGS.map.styles[modelname] || {});
99
// Show trail layer in application maps
1010
var layer = new L.ObjectsLayer(null, {

geotrek/core/tests/test_views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ def get_good_data(self):
174174
"geom": '{"geom": "LINESTRING (99.0 89.0, 100.0 88.0)", "snap": [null, null]}',
175175
}
176176

177+
def get_expected_popup_content(self):
178+
return (
179+
f'<div class="d-flex flex-column justify-content-center">\n'
180+
f' <p class="text-center m-0 p-1"><strong>{str(self.obj)}</strong></p>\n \n'
181+
f' <button id="detail-btn" class="btn btn-sm btn-info mt-2" onclick="window.location.href=\'/path/{self.obj.pk}/\'">Detail sheet</button>\n'
182+
f"</div>"
183+
)
184+
177185
def _post_add_form(self):
178186
# Avoid overlap, delete all !
179187
for p in Path.objects.all():
@@ -2287,6 +2295,14 @@ def get_bad_data(self):
22872295
"certifications-MAX_NUM_FORMS": "0",
22882296
}, _("This field is required.")
22892297

2298+
def get_expected_popup_content(self):
2299+
return (
2300+
f'<div class="d-flex flex-column justify-content-center">\n'
2301+
f' <p class="text-center m-0 p-1"><strong>{str(self.obj)}</strong></p>\n \n'
2302+
f' <button id="detail-btn" class="btn btn-sm btn-info mt-2" onclick="window.location.href=\'/trail/{self.obj.pk}/\'">Detail sheet</button>\n'
2303+
f"</div>"
2304+
)
2305+
22902306
def test_detail_page(self):
22912307
trail = TrailFactory()
22922308
response = self.client.get(trail.get_detail_url())

geotrek/diving/static/diving/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $(window).on('entity:map', function (e, data) {
44
var url = window.SETTINGS.urls[layername];
55
var loaded_dive = false;
66
var map = data.map;
7-
var style = L.Util.extend({ clickable: false },
7+
var style = L.Util.extend({ clickable: true },
88
window.SETTINGS.map.styles[modelname] || {});
99
// Show dive layer in application maps
1010
var layer = new L.ObjectsLayer(null, {

geotrek/diving/tests/test_views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ def get_good_data(self):
5454
"geom": '{"type": "Point", "coordinates":[0, 0]}',
5555
}
5656

57+
def get_expected_popup_content(self):
58+
return (
59+
f'<div class="d-flex flex-column justify-content-center">\n'
60+
f' <p class="text-center m-0 p-1"><strong>{str(self.obj)}</strong></p>\n \n'
61+
f' <p class="m-0 p-1">\n'
62+
f" {str(self.obj.practice)}<br>\n"
63+
f" </p>\n \n"
64+
f' <button id="detail-btn" class="btn btn-sm btn-info mt-2" onclick="window.location.href=\'/dive/{self.obj.pk}/\'">Detail sheet</button>\n'
65+
f"</div>"
66+
)
67+
5768

5869
class DiveViewsLiveTests(CommonLiveTest):
5970
model = Dive

geotrek/feedback/static/feedback/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ $(window).on('entity:map', function (e, data) {
66
var modelname = 'report';
77
var layername = `${modelname}_layer`;
88
var url = window.SETTINGS.urls[layername];
9-
var loaded_infrastructure = false;
9+
var loaded_report = false;
1010
var map = data.map;
1111

1212
// Show report layer in application maps
13-
var style = L.Util.extend({ clickable: false },
13+
var style = L.Util.extend({ clickable: true },
1414
window.SETTINGS.map.styles[modelname] || {});
1515
var layer = new L.ObjectsLayer(null, {
1616
modelname: modelname,
@@ -23,10 +23,10 @@ $(window).on('entity:map', function (e, data) {
2323

2424
map.on('layeradd', function (e) {
2525
var options = e.layer.options || { 'modelname': 'None' };
26-
if (!loaded_infrastructure) {
26+
if (!loaded_report) {
2727
if (options.modelname == modelname && options.modelname != data.modelname) {
2828
e.layer.load(url);
29-
loaded_infrastructure = true;
29+
loaded_report = true;
3030
}
3131
}
3232
});

0 commit comments

Comments
 (0)