Skip to content

Commit

Permalink
Parameterize the map popup
Browse files Browse the repository at this point in the history
  • Loading branch information
chiatt committed Jan 17, 2025
1 parent c00873d commit 883c841
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions afrc/src/afrc/Search/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ onMounted(async () => {
:overlays="overlays"
:sources="sources"
:include-drawer="false"
:popup-enabled="false"
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const props = defineProps<{
basemaps: Basemap[];
sources: MapSource[];
includeDrawer: boolean;
popupEnabled: boolean;
}>();
const map: Ref<Map | null> = ref(null);
Expand Down Expand Up @@ -116,6 +117,7 @@ function updateSelectedDrawnFeature(feature: Feature) {
:overlays="overlays"
:sources="sources"
:is-drawing-enabled="true"
:is-popup-enabled="popupEnabled"
@map-initialized="
(mapInstance) => {
map = mapInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface Props {
isDrawingEnabled?: boolean;
drawnFeatures?: Feature[];
drawnFeaturesBuffer?: Buffer;
isPopupEnabled?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -76,6 +77,7 @@ const props = withDefaults(defineProps<Props>(), {
isDrawingEnabled: false,
drawnFeatures: () => [],
drawnFeaturesBuffer: undefined,
isPopupEnabled: false,
});
const {
Expand All @@ -86,6 +88,7 @@ const {
isDrawingEnabled,
drawnFeatures,
drawnFeaturesBuffer,
isPopupEnabled,
} = props;
let resultsSelected = inject("resultsSelected") as Ref<string[]>;
Expand All @@ -105,7 +108,7 @@ const resourceOverlaysClickHandlers: {
[key: string]: (e: MapMouseEvent) => void;
} = {};
// const popupInstance: Ref<Popup | null> = ref(null);
const popupInstance: Ref<Popup | null> = ref(null);
const clickedFeatures: Ref<Feature[]> = ref([]);
const clickedCoordinates: Ref<[number, number]> = ref([0, 0]);
const popupContainerRerenderKey = ref(0);
Expand Down Expand Up @@ -144,15 +147,17 @@ watch(
},
);
// watch(clickedFeatures, () => {
// if (popupInstance.value) {
// popupInstance.value.remove();
// }
// popupInstance.value = new maplibregl.Popup()
// .setLngLat(clickedCoordinates.value)
// .setDOMContent(popupContainer.value!.$el)
// .addTo(map.value!);
// });
if (isPopupEnabled) {
watch(clickedFeatures, () => {
if (popupInstance.value) {
popupInstance.value.remove();
}
popupInstance.value = new maplibregl.Popup()
.setLngLat(clickedCoordinates.value)
.setDOMContent(popupContainer.value!.$el)
.addTo(map.value!);
});
}
onMounted(() => {
createMap();
Expand Down

0 comments on commit 883c841

Please sign in to comment.