Skip to content
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

Hide interaction drawer #4

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions afrc/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,14 @@ def add_map_layers(apps, schema_editor):
"==", "$type", "Point"
]],
"paint": {
"circle-radius": 6,
"circle-radius": [
"case",
["boolean", ["feature-state", "selected"], False],
6,
4
],
"circle-opacity": 1,
"circle-color": "#00f"
"circle-color": "#00f",
}
}, {
"id": "referencecollections-point",
Expand All @@ -1469,7 +1474,12 @@ def add_map_layers(apps, schema_editor):
"type": "line",
"paint": {
"line-color": "#00f",
"line-width": 3
"line-width": [
"case",
["boolean", ["feature-state", "selected"], False],
3,
1
]
},
"layout": {
"line-cap": "round",
Expand All @@ -1483,7 +1493,12 @@ def add_map_layers(apps, schema_editor):
"type": "line",
"paint": {
"line-color": "#00f",
"line-width": 3
"line-width": [
"case",
["boolean", ["feature-state", "selected"], False],
3,
1
],
},
"filter": [
"==",
Expand All @@ -1503,7 +1518,7 @@ def add_map_layers(apps, schema_editor):
"paint": {
"fill-color": "#00f",
"fill-opacity": 0.1,
"fill-outline-color": "#0ff"
"fill-outline-color": "#00f"
},
"filter": [
"==",
Expand Down
7 changes: 6 additions & 1 deletion afrc/src/afrc/Search/SearchPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import { onMounted, ref, watch, provide } from "vue";
import type { Ref } from "vue";
import { useGettext } from "vue3-gettext";

Expand Down Expand Up @@ -30,10 +30,13 @@ const showMap = ref(false);
const basemaps: Ref<Basemap[]> = ref([]);
const overlays: Ref<MapLayer[]> = ref([]);
const sources: Ref<MapSource[]> = ref([]);
const resultsSelected: Ref<string[]> = ref([]);
const dataLoaded = ref(false);
const toast = useToast();
const { $gettext } = useGettext();

provide("resultsSelected", resultsSelected);

watch(queryString, () => {
doQuery();
});
Expand Down Expand Up @@ -97,6 +100,7 @@ const doQuery = function () {
console.log(data);
searchResults.value = data.results.hits.hits;
resultsCount.value = data.total_results;
resultsSelected.value = [];
});

// self.updateRequest = $.ajax({
Expand Down Expand Up @@ -226,6 +230,7 @@ onMounted(async () =>{
:basemaps="basemaps"
:overlays="overlays"
:sources="sources"
:include-drawer="false"
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const props = defineProps<{
overlays: MapLayer[];
basemaps: Basemap[];
sources: MapSource[];
includeDrawer: boolean;
}>();

const map: Ref<Map | null> = ref(null);
Expand Down Expand Up @@ -71,6 +72,7 @@ provide("overlays", props.overlays);
provide("basemaps", props.basemaps);
provide("selectedDrawnFeature", selectedDrawnFeature);


watch(
() => props.basemaps,
(updatedBasemaps) => {
Expand Down Expand Up @@ -131,7 +133,7 @@ function updateSelectedDrawnFeature(feature: Feature) {
@drawn-feature-selected="updateSelectedDrawnFeature"
/>
<InteractionsDrawer
v-if="map"
v-if="map && includeDrawer"
:map="map"
:settings="settings"
:items="mapInteractionItems"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref, useTemplateRef, watch } from "vue";
import { onMounted, ref, useTemplateRef, watch, inject } from "vue";

import MapboxDraw from "@mapbox/mapbox-gl-draw";
import maplibregl from "maplibre-gl";
Expand Down Expand Up @@ -88,6 +88,8 @@ const {
drawnFeaturesBuffer,
} = props;

let resultsSelected = inject("resultsSelected") as Ref<string[]>;

const emits = defineEmits([
"mapInitialized",
"drawnFeatureSelected",
Expand Down Expand Up @@ -124,6 +126,15 @@ watch(
{ deep: true },
);

watch(
() => resultsSelected,
(selected) => {
if (selected) {
updateFeatureSelection(selected as Ref<string[]>);
}
}, {deep: true}
);

watch(
() => drawnFeaturesBuffer,
() => {
Expand Down Expand Up @@ -185,6 +196,28 @@ async function fitBoundsOfFeatures(features: FeatureCollection) {
});
}

function updateFeatureSelection(selected: Ref<string[]>) {
const layers: Array<string> = [];
overlays.forEach((overlay) => {
layers.push(...overlay.layerdefinitions.map(
(layerDefinition) => layerDefinition.id,
));
});
const features = map.value!.queryRenderedFeatures({layers:layers});
features.forEach(feature => {
const featureSelected = selected.value.includes(feature.properties?.resourceinstanceid);
map.value!.setFeatureState(
{
source: "referencecollections",
sourceLayer: "referencecollections",
id: feature.id,
},
{ selected: featureSelected }
);
});
}


function addBufferLayer() {
map.value!.addSource(BUFFER_LAYER_ID, {
type: "geojson",
Expand Down Expand Up @@ -337,9 +370,7 @@ function addOverlayToMap(overlay: MapLayer) {
}
});

if (
overlay.maplayerid === "8914d88e-ac00-4140-a7d8-81893099b0ad" // Cultural Resource - Primary
) {
if (overlay.maplayerid && resultsSelected) {
resourceOverlaysClickHandlers[overlay.maplayerid] = function (
e: MapMouseEvent,
) {
Expand All @@ -352,6 +383,11 @@ function addOverlayToMap(overlay: MapLayer) {
popupContainerRerenderKey.value += 1;
clickedCoordinates.value = [e.lngLat.lng, e.lngLat.lat];
clickedFeatures.value = features;
resultsSelected.value = [];
const uniqueResourceIds = new Set(features.map((feature) => feature.properties?.resourceinstanceid as string));
resultsSelected.value = Array.from(uniqueResourceIds);
} else {
resultsSelected.value = [];
}
};

Expand Down
26 changes: 25 additions & 1 deletion afrc/src/afrc/Search/components/SearchResultItem.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
<script setup lang="ts">
import Button from "primevue/button";
import { inject } from "vue";
import type { Ref } from "vue";

const resultsSelected = inject("resultsSelected") as Ref<string[]>;

const props = defineProps({
searchResult: {
type: Object,
required: true,
},
});

function selectResult(resourceid: string) {
resultsSelected.value = [resourceid];
}

function clearResult() {
resultsSelected.value = [];
}

</script>

<template>
<section class="result">
<section
class="result"
:class="{
hovered: resultsSelected.includes(searchResult._source.resourceinstanceid)
}"
@mouseenter="selectResult(searchResult._source.resourceinstanceid)"
@mouseleave="clearResult"
>
<div class="image-placeholder">
<img src="https://picsum.photos/160" />
</div>
Expand Down Expand Up @@ -44,6 +64,10 @@ const props = defineProps({
display: flex;
flex-direction: row;
}
.result.hovered {
background-color: rgb(239 245 252);
border: 1px solid rgb(139 145 252);
}
.result .result-content {
height: 10rem;
overflow: hidden;
Expand Down
Loading