Skip to content

Commit a93161e

Browse files
committed
Fix Highlight selected photos
Signed-off-by: Arne Hamann <git@arne.email>
1 parent cf50108 commit a93161e

2 files changed

Lines changed: 25 additions & 45 deletions

File tree

src/components/map/PhotoSuggestionsLayer.vue

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,6 @@
55
@clusterclick="onClusterClick"
66
@clustercontextmenu="onClusterRightClick"
77
@spiderfied="onSpiderfied">
8-
<!-- <LMarker v-for="(p, i) in photoSuggestions"
9-
v-if="p"
10-
:key="i"
11-
:options="{ data: p }"
12-
:icon="getPhotoMarkerIcon(p, i)"
13-
:draggable="draggable"
14-
:lat-lng="[p.lat, p.lng]"
15-
@click="onPhotoClick($event, i)"
16-
@contextmenu="onPhotoRightClick($event, p)"
17-
@moveend="onPhotoMoved($event, i)">
18-
<LTooltip v-if="p"
19-
:class="{
20-
'tooltip-photo-suggestion-wrapper': true,
21-
'photo-suggestion-marker-selected': photoSuggestionsSelectedIndices.includes(i)
22-
}"
23-
:options="{ ...tooltipOptions, opacity: draggable ? 0 : 1 }">
24-
<img class="photo-suggestion-tooltip"
25-
:src="getPreviewUrl(p)">
26-
<p class="tooltip-photo-suggestion-date">
27-
{{ getPhotoFormattedDate(p) }}
28-
</p>
29-
<p class="tooltip-photo-suggestion-name">
30-
{{ basename(p.path) }}
31-
</p>
32-
</LTooltip>
33-
<LPopup v-if="p"
34-
class="popup-photo-suggestion-wrapper"
35-
:options="popupOptions">
36-
<NcActionButton icon="icon-toggle" @click="viewPhoto(p)">
37-
{{ t('maps', 'Display picture') }}
38-
</NcActionButton>
39-
</LPopup>
40-
</LMarker>-->
418
<LMarker
429
:lat-lng="[0, 0]"
4310
:visible="false">
@@ -54,7 +21,7 @@
5421
{{ getPhotoFormattedDate(currentSuggestion) }}
5522
</p>
5623
<p class="tooltip-photo-suggestion-name">
57-
{{ currentSuggestion ? basename(currentSuggestion.path) : ''}}
24+
{{ currentSuggestion ? basename(currentSuggestion.path) : '' }}
5825
</p>
5926
</LTooltip>
6027
<LPopup
@@ -98,7 +65,7 @@ import { LMarker, LTooltip, LPopup } from 'vue2-leaflet'
9865
import Vue2LeafletMarkerCluster from 'vue2-leaflet-markercluster'
9966
10067
import optionsController from '../../optionsController'
101-
import {binSearch} from "../../utils/common";
68+
import { binSearch } from '../../utils/common'
10269
10370
const PHOTO_MARKER_VIEW_SIZE = 40
10471
@@ -264,6 +231,14 @@ export default {
264231
)
265232
}
266233
},
234+
photoSuggestionsSelectedIndices(newIndices, oldIndices) {
235+
const oldSet = new Set(oldIndices)
236+
const newSet = new Set(newIndices)
237+
const removedIndices = oldIndices.filter((i) => { return !newSet.has(i) })
238+
const addedIndices = newIndices.filter((i) => { return !oldSet.has(i) })
239+
const changedMarkers = removedIndices.concat(addedIndices).map((i) => { return this.suggestionMarkers[i] })
240+
this.$refs.markerCluster.mapObject.refreshClusters(changedMarkers)
241+
},
267242
},
268243
269244
beforeMount() {
@@ -329,22 +304,28 @@ export default {
329304
},
330305
getClusterMarkerIcon(cluster) {
331306
const count = cluster.getChildCount()
332-
const photo = cluster.getAllChildMarkers()[0].data
307+
const markers = cluster.getAllChildMarkers()
308+
const selectedCount = markers.filter((m) => this.photoSuggestionsSelectedIndices.includes(m.i)).length
309+
const marker = markers[0]
310+
const photo = marker.data
311+
const index = marker.i
333312
if (count === 1) {
334-
return this.getPhotoMarkerIcon(photo)
313+
return this.getPhotoMarkerIcon(photo, index)
335314
}
336315
const iconUrl = this.getPreviewUrl(photo)
337316
return new L.DivIcon(L.extend({
338317
className: 'leaflet-marker-photo-suggestion cluster-suggestion-marker',
339-
html: '<div class="thumbnail" style="background-image: url(' + iconUrl + ');"></div>​<span class="label">' + count + '</span>',
318+
html: '<div class="thumbnail" style="background-image: url(' + iconUrl + ');"></div>​<span class="label">'
319+
+ (selectedCount > 0 ? '<div style="color: var(--color-warning); display: inline;">' + selectedCount + '</div>/' : '')
320+
+ count + '</span>',
340321
}, cluster, {
341322
iconSize: [PHOTO_MARKER_VIEW_SIZE, PHOTO_MARKER_VIEW_SIZE],
342323
iconAnchor: [PHOTO_MARKER_VIEW_SIZE / 2, PHOTO_MARKER_VIEW_SIZE],
343324
}))
344325
},
345-
getPhotoMarkerIcon(photo) {
326+
getPhotoMarkerIcon(photo, index) {
346327
const iconUrl = this.getPreviewUrl(photo)
347-
const selectedClass = this.photoSuggestionsSelectedIndices.includes(photo.i)
328+
const selectedClass = this.photoSuggestionsSelectedIndices.includes(index)
348329
? '-selected'
349330
: ''
350331
return L.divIcon(L.extend({

src/views/App.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,11 @@ export default {
10201020
this.showPhotoSuggestions ? this.openSidebar() : this.closeSidebar()
10211021
},
10221022
onPhotoSuggestionSelected(index) {
1023-
const indexOfIndex = this.photoSuggestionsSelectedIndices.findIndex((e) => { return index === e })
1024-
if (indexOfIndex >= 0) {
1025-
this.photoSuggestionsSelectedIndices.splice(indexOfIndex, 1)
1026-
} else {
1027-
this.photoSuggestionsSelectedIndices.push(index)
1023+
const newIndices = this.photoSuggestionsSelectedIndices.filter((e) => { return index !== e })
1024+
if (newIndices.length === this.photoSuggestionsSelectedIndices.length) {
1025+
newIndices.push(index)
10281026
}
1027+
this.photoSuggestionsSelectedIndices = newIndices
10291028
},
10301029
onPhotoSuggestionMoved(index, latLng) {
10311030
this.photoSuggestions[index].lat = latLng.lat

0 commit comments

Comments
 (0)