|
4 | 4 | import { getLegendItems } from "./legend-utils"; |
5 | 5 | import SearchBoxTab from "../search-box/search-box-tab.vue"; |
6 | 6 | import { computed, ref } from "vue"; |
7 | | - import { useDomEventListener } from "../../utils/utils"; |
8 | 7 | import { useResizeObserver } from "../../utils/vue"; |
9 | | - import { injectContextRequired, requireClientContext, requireMapContext } from "../facil-map-context-provider/facil-map-context-provider.vue"; |
| 8 | + import { injectContextRequired, requireClientContext } from "../facil-map-context-provider/facil-map-context-provider.vue"; |
10 | 9 | import { useI18n } from "../../utils/i18n"; |
11 | 10 |
|
12 | 11 | const context = injectContextRequired(); |
13 | 12 | const client = requireClientContext(context); |
14 | | - const mapContext = requireMapContext(context); |
15 | 13 | const i18n = useI18n(); |
16 | 14 |
|
| 15 | + const placeholderRef = ref<HTMLElement>(); |
17 | 16 | const absoluteContainerRef = ref<HTMLElement>(); |
18 | 17 |
|
19 | 18 | const scale = ref(1); |
20 | 19 |
|
21 | | - useDomEventListener(window, "resize", updateMaxScale); |
22 | 20 | useResizeObserver(absoluteContainerRef, updateMaxScale); |
| 21 | + useResizeObserver(placeholderRef, updateMaxScale); |
23 | 22 | updateMaxScale(); |
24 | 23 |
|
25 | 24 | function updateMaxScale(): void { |
26 | | - if (absoluteContainerRef.value) { |
27 | | - const mapContainer = mapContext.value.components.map.getContainer(); |
28 | | - const maxHeight = mapContainer.offsetHeight - 94; |
29 | | - const maxWidth = mapContainer.offsetWidth - 20; |
| 25 | + if (absoluteContainerRef.value && placeholderRef.value) { |
| 26 | + const maxHeight = placeholderRef.value.offsetHeight; |
| 27 | + const maxWidth = placeholderRef.value.offsetWidth; |
30 | 28 |
|
31 | 29 | const currentHeight = absoluteContainerRef.value.offsetHeight; |
32 | 30 | const currentWidth = absoluteContainerRef.value.offsetWidth; |
|
53 | 51 | <template> |
54 | 52 | <div class="fm-legend" v-if="legendItems.length > 0 || legend1 || legend2"> |
55 | 53 | <template v-if="!context.isNarrow"> |
| 54 | + <div class="fm-legend-placeholder" ref="placeholderRef"></div> |
56 | 55 | <div |
57 | 56 | class="fm-legend-absolute card" |
58 | 57 | :style="{ '--fm-scale-factor': scale }" |
|
72 | 71 | </template> |
73 | 72 |
|
74 | 73 | <style lang="scss"> |
| 74 | + .fm-legend-placeholder { |
| 75 | + position: absolute; |
| 76 | + pointer-events: none; |
| 77 | + left: calc(10px + var(--facilmap-control-margin-left)); |
| 78 | + right: calc(10px + var(--facilmap-control-margin-right)); |
| 79 | + top: calc(69px + var(--facilmap-control-margin-top)); |
| 80 | + bottom: calc(25px + var(--facilmap-control-margin-bottom)); |
| 81 | + } |
| 82 | +
|
75 | 83 | .fm-legend-absolute.fm-legend-absolute { |
76 | 84 | position: absolute; |
77 | | - right: 10px; |
78 | | - bottom: 25px; |
| 85 | + right: calc(10px + var(--facilmap-control-margin-right)); |
| 86 | + bottom: calc(25px + var(--facilmap-control-margin-bottom)); |
79 | 87 | max-width: 20rem; |
80 | 88 | z-index: 800; |
81 | 89 | transform-origin: bottom right; |
|
0 commit comments