-
Notifications
You must be signed in to change notification settings - Fork 19
PB-2337: compact overflowing map attributions #1586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
5462617
5224bb0
3cf56db
3f6f478
3d9d04a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <script setup> | ||
| import { computed } from 'vue' | ||
| import { computed, ref } from 'vue' | ||
| import { useI18n } from 'vue-i18n' | ||
| import { useStore } from 'vuex' | ||
|
|
||
|
|
@@ -8,6 +8,7 @@ import ThirdPartyDisclaimer from '@/utils/components/ThirdPartyDisclaimer.vue' | |
|
|
||
| const store = useStore() | ||
| const { t } = useI18n() | ||
| const isExpanded = ref(false) | ||
|
|
||
| const visibleLayers = computed(() => store.getters.visibleLayers) | ||
| const currentBackgroundLayer = computed(() => store.getters.currentBackgroundLayer) | ||
|
|
@@ -19,15 +20,16 @@ const layers = computed(() => { | |
| layersWithAttributions.push(currentBackgroundLayer.value) | ||
| } | ||
| layersWithAttributions.push( | ||
| ...visibleLayers.value.filter((layer) => layer.attributions.length > 0) | ||
| ...visibleLayers.value.filter((layer) => (layer.attributions ?? []).length > 0) | ||
| ) | ||
| return layersWithAttributions | ||
| }) | ||
|
|
||
| const sources = computed(() => { | ||
| return layers.value | ||
| .map((layer) => { | ||
| return layer.attributions.map((attribution) => { | ||
| .flatMap((layer) => { | ||
| const isLocalFile = store.getters.isLocalFile(layer) | ||
| return (layer.attributions ?? []).map((attribution) => { | ||
| return { | ||
| id: attribution.name.replace(/[._]/g, '-'), | ||
| name: attribution.name, | ||
|
|
@@ -37,26 +39,62 @@ const sources = computed(() => { | |
| layer.isExternal, | ||
| layer.baseUrl | ||
| ), | ||
| isLocalFile: store.getters.isLocalFile(layer), | ||
| isLocalFile, | ||
| isTruncated: isLocalFile, | ||
| } | ||
| }) | ||
| }) | ||
| .flat() | ||
| .filter((attribution, index, array) => { | ||
| const firstIndex = array.findIndex((item) => item.name === attribution.name) | ||
| return index === firstIndex | ||
| }) | ||
| }) | ||
|
|
||
| const VISIBLE_SOURCE_COUNT = 4 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine in this mapviewer context! Idea for SWISSGEO: Rather than a hardcoded number of attributions, we might consider the relative width of the attributions list. So e.g. 6 short attributions are ok, while 4 longer ones would already be compacted. Also, we can make this responsive and treat differently depending on the kind of the device / available screen width
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have places within the mapviewer where we automatically truncate and add a small tooltip which contains the full string (for example: title features). We could use a similar approach to have a character limit, be a bit smart about it to avoid cutting an attribution in the middle, and have it be our trigger to see if we need to truncate the attribution list or not.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say we keep it as in this PR for the mapviewer. |
||
| const primarySources = computed(() => sources.value.filter((source) => !source.isLocalFile)) | ||
| const localSources = computed(() => sources.value.filter((source) => source.isLocalFile)) | ||
| const visibleLocalSourceCount = computed(() => | ||
| Math.max(VISIBLE_SOURCE_COUNT - primarySources.value.length, 0) | ||
| ) | ||
| const inlineSources = computed(() => [ | ||
| ...primarySources.value, | ||
| ...localSources.value.slice(0, visibleLocalSourceCount.value), | ||
| ]) | ||
| const expandedSources = computed(() => localSources.value.slice(visibleLocalSourceCount.value)) | ||
| const hiddenSourceCount = computed(() => expandedSources.value.length) | ||
| const isCompact = computed(() => hiddenSourceCount.value > 0) | ||
| const toggleButtonText = computed(() => (isExpanded.value ? '-' : `+${hiddenSourceCount.value}`)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, when expanded, we should display an |
||
|
|
||
| const expandButtonLabel = computed(() => { | ||
| if (isExpanded.value) { | ||
| return t('attribution_overflow_hide_sources') | ||
| } | ||
| return t( | ||
| hiddenSourceCount.value === 1 | ||
| ? 'attribution_overflow_show_source' | ||
| : 'attribution_overflow_show_sources', | ||
| { count: hiddenSourceCount.value } | ||
| ) | ||
| }) | ||
|
|
||
| function closeExpanded() { | ||
| isExpanded.value = false | ||
| } | ||
|
|
||
| function toggleExpanded() { | ||
| isExpanded.value = !isExpanded.value | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <div | ||
| class="map-footer-attribution" | ||
| v-click-outside="closeExpanded" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess it might make sense to also close on pressing ESC or the like, not only on clicking outside, if that is possible without too large an effort |
||
| class="map-footer-attribution d-inline-flex align-items-center flex-wrap" | ||
| data-cy="layers-copyrights" | ||
| > | ||
| <span v-if="sources.length > 0">{{ t('copyright_data') }}</span> | ||
| <div | ||
| v-for="(source, index) in sources" | ||
| v-for="(source, index) in inlineSources" | ||
| :key="source.name" | ||
| class="d-inline-flex" | ||
| > | ||
|
|
@@ -67,22 +105,70 @@ const sources = computed(() => { | |
| :is-local-file="source.isLocalFile" | ||
| > | ||
| <MapFooterAttributionItem | ||
| :source-id="source.id" | ||
| :source-id="`${source.id}-${index}`" | ||
| :source-name="source.name" | ||
| :source-url="source.url" | ||
| :has-data-disclaimer="true" | ||
| :is-last="index === sources.length - 1" | ||
| :is-last="!isCompact && index === inlineSources.length - 1" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need the |
||
| :is-truncated="source.isTruncated" | ||
| /> | ||
| </ThirdPartyDisclaimer> | ||
| <MapFooterAttributionItem | ||
| v-else | ||
| :source-id="source.id" | ||
| :source-id="`${source.id}-${index}`" | ||
| :source-name="source.name" | ||
| :source-url="source.url" | ||
| :has-data-disclaimer="false" | ||
| :is-last="index === sources.length - 1" | ||
| :is-last="!isCompact && index === inlineSources.length - 1" | ||
| :is-truncated="source.isTruncated" | ||
| /> | ||
| </div> | ||
| <button | ||
| v-if="isCompact" | ||
| type="button" | ||
| class="map-footer-attribution-toggle btn btn-light btn-sm ms-1 border px-1 py-0" | ||
| data-cy="attribution-expand-toggle" | ||
| :title="expandButtonLabel" | ||
| @click="toggleExpanded" | ||
| > | ||
| {{ toggleButtonText }} | ||
| </button> | ||
| <div | ||
| v-if="isCompact && isExpanded" | ||
| class="map-footer-attribution-expanded-list position-absolute d-flex flex-column end-0 gap-1 overflow-y-auto rounded border bg-white p-2 text-start text-wrap shadow-sm" | ||
| data-cy="attribution-expanded-list" | ||
| > | ||
| <div | ||
| v-for="(source, index) in expandedSources" | ||
| :key="source.name" | ||
| class="d-flex lh-base" | ||
| > | ||
| <ThirdPartyDisclaimer | ||
| v-if="source.hasDataDisclaimer" | ||
| :source-name="source.name" | ||
| :complete-disclaimer-on-click="!source.url" | ||
| :is-local-file="source.isLocalFile" | ||
| > | ||
| <MapFooterAttributionItem | ||
| :source-id="`${source.id}-expanded-${index}`" | ||
| :source-name="source.name" | ||
| :source-url="source.url" | ||
| :has-data-disclaimer="true" | ||
| :is-last="true" | ||
| :is-truncated="source.isTruncated" | ||
| /> | ||
| </ThirdPartyDisclaimer> | ||
| <MapFooterAttributionItem | ||
| v-else | ||
| :source-id="`${source.id}-expanded-${index}`" | ||
| :source-name="source.name" | ||
| :source-url="source.url" | ||
| :has-data-disclaimer="false" | ||
| :is-last="true" | ||
| :is-truncated="source.isTruncated" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
|
|
@@ -96,5 +182,18 @@ const sources = computed(() => { | |
| text-align: center; | ||
| position: relative; | ||
| pointer-events: all; | ||
| max-width: calc(100vw - 0.5rem); | ||
| } | ||
|
|
||
| .map-footer-attribution-toggle { | ||
| font-size: inherit; | ||
| line-height: 1.2; | ||
| } | ||
|
|
||
| .map-footer-attribution-expanded-list { | ||
| bottom: calc(100% + 0.25rem); | ||
| z-index: $zindex-desktop-footer-infobox; | ||
| max-width: min(24rem, calc(100vw - 1rem)); | ||
| max-height: 30vh; | ||
| } | ||
| </style> | ||
Uh oh!
There was an error while loading. Please reload this page.