From 19a6305b9d041a46d6220b5202143005897fe881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 25 Jan 2023 17:25:48 +0100 Subject: [PATCH] Add profile link to map marker popup --- webapp/pages/map.vue | 96 ++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/webapp/pages/map.vue b/webapp/pages/map.vue index 3ce51ad49..8d60fdf46 100644 --- a/webapp/pages/map.vue +++ b/webapp/pages/map.vue @@ -197,37 +197,62 @@ export default { }) this.map.on('mouseenter', 'markers', (e) => { - if (e.features[0].properties.type !== 'the-user') { - // close old popup first - if (this.markers.popup.isOpen()) { - this.markers.popup.remove() - } - - // Change the cursor style as a UI indicator. - this.map.getCanvas().style.cursor = 'pointer' - - // Copy coordinates array. - const coordinates = e.features[0].geometry.coordinates.slice() - // const description = ` - //
- //
- // ${e.features[0].properties.type === 'user' ? 'Benutzer' : 'Gruppe'}: ${e.features[0].properties.name} - //
- //
- // ` - const description = e.features[0].properties.name - - // Ensure that if the map is zoomed out such that multiple - // copies of the feature are visible, the popup appears - // over the copy being pointed to. - while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) { - coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360 - } - - // Populate the popup and set its coordinates - // based on the feature found. - this.markers.popup.setLngLat(coordinates).setHTML(description).addTo(this.map) + // if (e.features[0].properties.type !== 'the-user') {} + if (this.markers.popup.isOpen()) { + this.map.getCanvas().style.cursor = '' + this.markers.popup.remove() } + + // Change the cursor style as a UI indicator. + this.map.getCanvas().style.cursor = 'pointer' + + // Copy coordinates array. + const coordinates = e.features[0].geometry.coordinates.slice() + const markerTypeLabel = + e.features[0].properties.type === 'group' + ? 'Gruppe' + : e.features[0].properties.type === 'user' + ? 'Benutzer' + : 'Deine Position' + const markerAboutLabel = e.features[0].properties.type === 'group' ? 'Ziel' : 'Über' + const markerProfileLinkLabel = 'Profil besuchen' + const markerProfileLinkTitle = `@${e.features[0].properties.slug}` + const markerProfileLink = + (e.features[0].properties.type === 'group' ? '/group' : '/profile') + + `/${e.features[0].properties.id}/${e.features[0].properties.slug}` + let description = ` +
` + description += ` +
+ ${markerTypeLabel}: ${e.features[0].properties.name} +
` + description += + e.features[0].properties.about && e.features[0].properties.about.length > 0 + ? ` +
+ ${markerAboutLabel}: ${e.features[0].properties.about} +
` + : '' + description += ` +
+ ${markerProfileLinkLabel}: +
+ ${markerProfileLinkTitle} +
` + description += ` +
+ ` + + // Ensure that if the map is zoomed out such that multiple + // copies of the feature are visible, the popup appears + // over the copy being pointed to. + while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) { + coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360 + } + + // Populate the popup and set its coordinates + // based on the feature found. + this.markers.popup.setLngLat(coordinates).setHTML(description).addTo(this.map) }) // this.map.on('mouseleave', 'markers', () => { @@ -278,7 +303,10 @@ export default { type: 'user', iconName: 'marker-blue', iconRotate: 0.0, + id: user.id, + slug: user.slug, name: user.name, + about: user.about, }, geometry: { type: 'Point', @@ -296,7 +324,10 @@ export default { type: 'group', iconName: 'marker-green', iconRotate: 0.0, + id: group.id, + slug: group.slug, name: group.name, + about: group.about, }, geometry: { type: 'Point', @@ -313,7 +344,10 @@ export default { type: 'the-user', iconName: 'marker-orange', iconRotate: 45.0, + id: this.currentUser.id, + slug: this.currentUser.slug, name: this.currentUser.name, + about: this.currentUser.about, }, geometry: { type: 'Point', @@ -354,7 +388,7 @@ export default { this.markers.isSourceAndLayerAdded = true } - // fly to center of never done and markers added + // fly to center if never done if (!this.markers.isFlyToCenter && this.markers.isSourceAndLayerAdded) { this.mapFlyToCenter() this.markers.isFlyToCenter = true