Skip to content

Commit a67b9f5

Browse files
committed
hover thumbnails
1 parent fecbd2f commit a67b9f5

File tree

7 files changed

+72
-11
lines changed

7 files changed

+72
-11
lines changed

memorymap_toolkit/settings/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
'': {
178178
'site_small': {'size': (300, 175), 'crop': 'smart', 'upscale': True},
179179
'banner': {'size': (600, 350), 'crop': 'smart', 'upscale': True},
180+
'hover_thumb': {'size': (100, 100), 'crop': 'smart', 'upscale': True},
180181
},
181182
}
182183

@@ -216,12 +217,13 @@
216217
'CACHE_TIMEOUT': (0, 'If you have a large number of interactive features and heavy site traffic, you can optionally cache them to reduce load on the database, at the expense of having changes to your map visible on the website immediately. This setting determines the number of minutes the tiles are cached for.'),
217218
'MAPBOX_VERSION': ('v1.11.0', 'The version of the MapboxGL library you want to use to display your map. Versions above v1.11.0 hosted by Mapbox require a Mapbox key.'),
218219
'LAYERS_MENU_TITLE': ('Themes', 'The name of the switchable layers menu.'),
219-
'SHOW_AUDIO_PLAYER_TITLES': (True, 'Whether or not audio player titles are visible. Useful if your audio has the same title as the map feature that it\'s attached to.')
220+
'SHOW_AUDIO_PLAYER_TITLES': (True, 'Whether or not audio player titles are visible. Useful if your audio has the same title as the map feature that it\'s attached to.'),
221+
'HOVER_THUMBNAILS': (True, 'Whether image thumbnails are shown on hovering over a map feature'),
220222
}
221223

222224
CONSTANCE_CONFIG_FIELDSETS = {
223-
'Site Settings': ('SITE_TITLE', 'LOGO_IMAGE', 'WELCOME_MESSAGE', 'CUSTOM_CSS', 'LAYERS_MENU_TITLE', 'SHOW_AUDIO_PLAYER_TITLES', 'SITE_METADATA', 'CACHE_TIMEOUT'),
224-
'Map Settings': ('MAP_CENTER_LATITUDE', 'MAP_CENTER_LONGITUDE', 'BOUNDS_SW_LONGITUDE', 'BOUNDS_SW_LATITUDE', 'BOUNDS_NE_LATITUDE', 'BOUNDS_NE_LONGITUDE', 'ZOOM', 'MIN_ZOOM', 'MAX_ZOOM', 'SCALE', 'PITCH', 'BEARING', 'MAPBOX_VERSION'),
225+
'Site Settings': ('SITE_TITLE', 'LOGO_IMAGE', 'WELCOME_MESSAGE', 'CUSTOM_CSS', 'LAYERS_MENU_TITLE', 'SHOW_AUDIO_PLAYER_TITLES', 'SITE_METADATA', 'CACHE_TIMEOUT', 'HOVER_THUMBNAILS'),
226+
'Map Settings': ('MAP_CENTER_LATITUDE', 'MAP_CENTER_LONGITUDE', 'BOUNDS_SW_LATITUDE', 'BOUNDS_SW_LONGITUDE', 'BOUNDS_NE_LATITUDE', 'BOUNDS_NE_LONGITUDE', 'ZOOM', 'MIN_ZOOM', 'MAX_ZOOM', 'SCALE', 'PITCH', 'BEARING', 'MAPBOX_VERSION'),
225227
'Map Style': ('BASE_MAP_STYLE_URL', 'MAPTILER_KEY', 'MAPBOX_KEY', 'SWITCHABLE_LAYERS', 'FEATURE_LABEL_FONT', 'BASE_MAP_STYLE_FILE')
226228
}
227229

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 3.1.13 on 2023-01-09 15:35
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mmt_map', '0030_auto_20221215_1536'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='line',
15+
name='thumbnail_url',
16+
field=models.CharField(blank=True, max_length=300),
17+
),
18+
migrations.AddField(
19+
model_name='point',
20+
name='thumbnail_url',
21+
field=models.CharField(blank=True, max_length=300),
22+
),
23+
migrations.AddField(
24+
model_name='polygon',
25+
name='thumbnail_url',
26+
field=models.CharField(blank=True, max_length=300),
27+
),
28+
]

mmt_map/models.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class AbstractFeature(models.Model):
5757
banner_image = models.ImageField(upload_to=feature_directory_path, null=True, blank=True, verbose_name='Banner Image')
5858
banner_image_copyright = models.CharField(max_length=240, blank=True)
5959
popup_image = models.ImageField(upload_to=feature_directory_path, null=True, blank=True)
60+
thumbnail_url = models.CharField(max_length=300, blank=True)
6061
popup_audio_title = models.CharField(max_length=128, blank=True)
6162
popup_audio_slug = models.SlugField(max_length=128, blank=True)
6263
popup_audio_file = FilerFileField(null=True, blank=True, related_name='%(app_label)s_%(class)s_popup_audio_file', on_delete=models.SET_NULL)
@@ -88,13 +89,13 @@ def get_banner_image_url(self):
8889
else:
8990
return ''
9091

91-
def __str__(self):
92-
return self.name
93-
9492
def get_absolute_url(self):
9593
feature_type = self.get_type()
9694
return '/?feature_type=' + feature_type + '&id=' + str(self.id)
9795

96+
def __str__(self):
97+
return self.name
98+
9899
class Meta:
99100
abstract = True
100101

@@ -106,7 +107,12 @@ class Point(AbstractFeature):
106107
def save(self, *args, **kwargs):
107108
# Model has to be saved first to access the tags
108109
super(Point, self).save(*args, **kwargs)
109-
#self.tag_str = ', '.join(self.tags.names())
110+
self.tag_str = ', '.join(self.tags.names())
111+
# The hover thumbnail url needs to be saved in the DB because it needs to be accessed from the MVTs, not the API
112+
if self.popup_image:
113+
thumbnail_url = get_thumbnailer(self.popup_image)['hover_thumb'].url
114+
self.thumbnail_url = thumbnail_url
115+
super(Point, self).save(*args, **kwargs)
110116

111117

112118

@@ -117,6 +123,10 @@ class Polygon(AbstractFeature):
117123
def save(self, *args, **kwargs):
118124
super(Polygon, self).save(*args, **kwargs)
119125
self.tag_str = ', '.join(self.tags.names())
126+
# The hover thumbnail url needs to be saved in the DB because it needs to be accessed from the MVTs, not the API
127+
if self.popup_image:
128+
thumbnail_url = get_thumbnailer(self.popup_image)['hover_thumb'].url
129+
self.thumbnail_url = thumbnail_url
120130
super(Polygon, self).save(*args, **kwargs)
121131

122132

@@ -127,6 +137,10 @@ class Line(AbstractFeature):
127137
def save(self, *args, **kwargs):
128138
super(Line, self).save(*args, **kwargs)
129139
self.tag_str = ', '.join(self.tags.names())
140+
# The hover thumbnail url needs to be saved in the DB because it needs to be accessed from the MVTs, not the API
141+
if self.popup_image:
142+
thumbnail_url = get_thumbnailer(self.popup_image)['hover_thumb'].url
143+
self.thumbnail_url = thumbnail_url
130144
super(Line, self).save(*args, **kwargs)
131145

132146

mmt_map/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def vector_tile(request, z, x, y, tile_format):
8080
),
8181
"mvtgeom" AS (
8282
SELECT ST_AsMVTGeom(ST_Transform("t"."geom", 3857), "bounds"."b2d") AS "geom",
83-
"id", "name", "weight", "theme_id", "tag_str"
83+
"id", "name", "weight", "theme_id", "tag_str", "thumbnail_url"
8484
FROM {table} "t", "bounds"
8585
WHERE ST_Intersects("t"."geom", ST_Transform("bounds"."geom", 4326)) AND "published" = TRUE
8686
)

project_static/css/styles.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ article img {
448448
width: 22rem;
449449
}
450450

451+
.hover_popup .mapboxgl-popup-content {
452+
width: 4rem;
453+
margin: 0;
454+
padding: 0;
455+
}
456+
451457
.popup_player #play_button_container {
452458
border-radius: 2.5rem;
453459
height: 2.5rem;
@@ -464,6 +470,9 @@ article img {
464470
.detail_popup .mapboxgl-popup-content {
465471
width: 22rem;
466472
}
473+
.hover_popup .mapboxgl-popup-content {
474+
width: 6rem;
475+
}
467476
}
468477

469478
/* Extra large devices (large desktops, 1200px and up) */

project_static/js/interactionHandler.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ MmtMap.hoverInteractions = {
88

99
smallPopup: new mapboxgl.Popup({
1010
closeButton: false,
11-
closeOnClick: false
11+
closeOnClick: false,
12+
className: 'hover_popup'
1213
}),
1314

1415
togglePopup: function(sourceLayer) {
@@ -27,7 +28,13 @@ MmtMap.hoverInteractions = {
2728
// Popup
2829
map.getCanvas().style.cursor = 'pointer';
2930
let name = feature.properties.name;
30-
MmtMap.hoverInteractions.smallPopup.setLngLat(coords).setHTML('<p class="text-center">' + name + '</p>').addTo(map);
31+
let thumbnail = feature.properties.thumbnail_url;
32+
33+
if (MmtMap.settings.hoverThumbs) {
34+
MmtMap.hoverInteractions.smallPopup.setLngLat(coords).setHTML('<div class="popup_header"><img alt="location thumbnail" src="' + thumbnail + '" class="m-0 p-0" /img><p class="m-0 p-0 text-center">' + name + '</p></div>').addTo(map);
35+
} else {
36+
MmtMap.hoverInteractions.smallPopup.setLngLat(coords).setHTML('<p class="m-0 p-0 text-center">' + name + '</p>').addTo(map);
37+
}
3138
}
3239
}
3340

templates/mmt_map/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
pitch: {{ config.PITCH }},
3232
bearing: {{ config.BEARING }},
3333
scale: '{{ config.SCALE }}',
34-
font: '{{ config.FEATURE_LABEL_FONT}}'
34+
font: '{{ config.FEATURE_LABEL_FONT}}',
35+
hoverThumbs: {% if config.HOVER_THUMBNAILS %}true{% else %}false{% endif %}
3536
},
3637

3738
themes: [

0 commit comments

Comments
 (0)