Skip to content

Commit

Permalink
Carte - Popup : Afficher la photo principale main_photo
Browse files Browse the repository at this point in the history
FIX : Affiche la vignette de la photo définie comme principale pour chaque site (champ ``main_photo``).
Actuellement, il semble que ce soit la dernière ajoutée sur le site qui s'affiche (en tout cas la dernière appelée dans variable array qui liste les photos du site).
  • Loading branch information
Xavier ARBEZ committed Nov 4, 2020
1 parent 943418a commit 8403f17
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions backend/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,34 @@ def sites():
'township': townships
}

photo_ids = []
sites_without_photo = []
for site in sites:
photo_id = site.get('main_photo')
if photo_id:
photo_ids.append(site.get('main_photo'))
else:
sites_without_photo.append(str(site.get('id_site')))

query_photos = models.TPhoto.query.filter(
models.TPhoto.id_photo.in_(photo_ids)
)
dump_photos = photo_schema.dump(query_photos).data

if len(sites_without_photo):
sql_missing_photos_str = "select distinct on (id_site) * from geopaysages.t_photo where id_site IN (" + ",".join(sites_without_photo) + ") order by id_site, filter_date desc"
sql_missing_photos = text(sql_missing_photos_str)
missing_photos_result = db.engine.execute(sql_missing_photos).fetchall()
missing_photos = [dict(row) for row in missing_photos_result]
for missing_photo in missing_photos:
missing_photo['t_site'] = missing_photo.get('id_site')
dump_photos.append(missing_photo)

for site in sites:
id_site = site.get('id_site')
photo = next(photo for photo in dump_photos if (photo.get('t_site') == id_site))
site['photo'] = utils.getThumbnail(photo).get('output_url')

def getItem(name, id):
return next(item for item in dbs.get(name) if item.get('id') == id)

Expand Down
2 changes: 1 addition & 1 deletion backend/static/js/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ geopsg.initSites = (options) => {
if (site.ref_site) {
markerText += '<br/>' + '(réf : ' + site.ref_site + ')'
}
marker.bindPopup('<div class="img" style="background-image: url(' + site.photos[site.photos.length - 1].url + ');"></div><div class="title">' + markerText + '</div>', {
marker.bindPopup('<div class="img" style="background-image: url(' + site.photo + ');"></div><div class="title">' + markerText + '</div>', {
closeButton: false
})
marker.on('mouseover', (e) => {
Expand Down

0 comments on commit 8403f17

Please sign in to comment.