Skip to content

Commit

Permalink
hide bounding box depending on model
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Nov 21, 2023
1 parent 345ecb0 commit a20ccdc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/frontend/src/components/ModelSelectDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const modelsStore = useModelsStore();
const models = modelsStore.models
function selectModel(model, toggle) {
modelsStore.selectedModel = model
// modelsStore.selectedModel = model
modelsStore.updateModel(model)
toggle()
}
Expand Down
1 change: 0 additions & 1 deletion app/frontend/src/components/SubmitButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function submit() {
const model = modelsStore.selectedModel
const hucsArray = Map.selected_hucs
submitHucs(hucsArray, model.shortName)
modelsStore.selectedModel
}
async function submitHucs(selected_hucs, model) {
selected_hucs = selected_hucs.map(a => a.hucid);
Expand Down
54 changes: 47 additions & 7 deletions app/frontend/src/components/TheLeafletMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,42 @@ import L from 'leaflet'
import "leaflet-easybutton/src/easy-button";
import { onMounted } from 'vue'
import { useMapStore } from '@/stores/map'
import { useModelsStore } from '@/stores/models'
const mapStore = useMapStore()
const modelsStore = useModelsStore();
const modelAction = modelsStore.$onAction(
({
name, // name of the action
store, // store instance, same as `someStore`
args, // array of parameters passed to the action
after, // hook after the action returns or resolves
onError, // hook if the action throws or rejects
}) => {
// this will trigger if the action succeeds and after it has fully run.
// it waits for any returned promised
after((result) => {
console.log(store.selectedModel.input)
if( store.selectedModel.input != "bbox" ){
removeBbox()
}else{
updateMapBBox()
}
})
// this will trigger if the action throws or returns a promise that rejects
onError((error) => {
console.warn(
`Failed "${name}" after ${Date.now() - startTime}ms.\nError: ${error}.`
)
})
}
)
// manually remove the listener
// modelAction()
const Map = mapStore.mapObject
onMounted(() => {
Expand Down Expand Up @@ -902,12 +936,7 @@ function updateMapBBox() {
Map.bbox = [xmin, ymin, xmax, ymax];
// remove the bbox layer if it exists
if ('BBOX' in Map.huclayers) {
// remove the polygon overlay
Map.huclayers['BBOX'].clearLayers();
delete Map.huclayers['BBOX'];
}
removeBbox()
// redraw the bbox layer with new coordinates
let coords = [[[xmin, ymin],
Expand All @@ -932,11 +961,22 @@ function updateMapBBox() {
// save the layer
Map.huclayers['BBOX'] = json_polygon;
json_polygon.addTo(Map.map);
if (modelsStore.selectedModel.input == "bbox"){
json_polygon.addTo(Map.map);
}
return bbox.is_valid
}
function removeBbox(){
// remove the bbox layer if it exists
if ('BBOX' in Map.huclayers) {
// remove the polygon overlay
Map.huclayers['BBOX'].clearLayers();
delete Map.huclayers['BBOX'];
}
}
/**
* Toggles HUC boundaries on the map, on/off.
Expand Down
6 changes: 5 additions & 1 deletion app/frontend/src/stores/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ export const useModelsStore = defineStore('models', () => {
])
const selectedModel = ref({})

return { models, selectedModel }
function updateModel(model) {
this.selectedModel = model
}

return { models, selectedModel, updateModel }
})

0 comments on commit a20ccdc

Please sign in to comment.