Skip to content

Commit

Permalink
style: improve map popup layout
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst committed Feb 6, 2024
1 parent 2fe9839 commit aa1e681
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
23 changes: 17 additions & 6 deletions components/data-map-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function onLayerClick(features: Array<MapGeoJSONFeature & Pick<EntityFeature, "p
}
});
const point = turf.center(createFeatureCollection(entities))
const point = turf.center(createFeatureCollection(entities));
const coordinates = point.geometry.coordinates;
popover.value = { coordinates, entities };
Expand Down Expand Up @@ -117,11 +117,22 @@ function createDateSpan(date: { earliest?: string; latest?: string }) {
:width="width"
@layer-click="onLayerClick"
>
<GeoMapPopup v-if="popover != null" :coordinates="popover.coordinates" @close="popover = null">
<article v-for="entity of popover.entities">
<strong class="text-semibold">{{ entity.properties.title }}</strong>
<NavLink class="underline" :href="{ path: `/entities/${entity.properties._id}` }">
{{ t('DataMapView.go-to-details-page') }}
<GeoMapPopup
v-if="popover != null"
:coordinates="popover.coordinates"
@close="popover = null"
>
<article
v-for="entity of popover.entities"
:key="entity.properties._id"
class="grid gap-0.5 font-body text-xs"
>
<strong class="block font-medium">{{ entity.properties.title }}</strong>
<NavLink
class="underline hover:no-underline"
:href="{ path: `/entities/${entity.properties._id}` }"
>
{{ t("DataMapView.go-to-details-page") }}
</NavLink>
</article>
</GeoMapPopup>
Expand Down
29 changes: 18 additions & 11 deletions components/geo-map-popup.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,50 @@ import { assert } from "@acdh-oeaw/lib";
import { Popup } from "maplibre-gl";
const props = defineProps<{
coordinates: [number, number]
coordinates: [number, number];
}>();
const emit = defineEmits<{
(event: 'close'): void
}>()
(event: "close"): void;
}>();
const { map } = useGeoMap();
const elementRef = ref<HTMLElement | null>(null);
interface Context {
popup: Popup | null
popup: Popup | null;
}
const context: Context = {
popup: null
popup: null,
};
onMounted(async () => {
await nextTick()
await nextTick();
assert(elementRef.value != null);
assert(map != null);
const popup = new Popup({ closeButton: false })
const popup = new Popup({ closeButton: false, maxWidth: "256px" })
.setLngLat(props.coordinates)
.setDOMContent(elementRef.value)
.addTo(map);
popup.once("close", () => emit("close"))
popup.once("close", () => {
emit("close");
});
context.popup = popup;
});
watch(() => props.coordinates, (coordinates) => {
context.popup?.setLngLat(coordinates)
})
watch(
() => {
return props.coordinates;
},
(coordinates) => {
context.popup?.setLngLat(coordinates);
},
);
onScopeDispose(() => {
context.popup?.remove();
Expand Down

0 comments on commit aa1e681

Please sign in to comment.