diff --git a/components/cal/map.vue b/components/cal/map.vue index 15ad0f0..b366f90 100644 --- a/components/cal/map.vue +++ b/components/cal/map.vue @@ -43,8 +43,8 @@ import { type Stop, stopToStopCsv } from '~/src/stop' import { type Route, routeToRouteCsv } from '~/src/route' import type { Bbox, Feature, PopupFeature, MarkerFeature } from '~/src/geom' import { colors, routeTypes } from '~/src/constants' -import type { CensusGeography } from '~/src/census' -import type { ScenarioFilterResult } from '~/src/scenario/scenario' +import type { ScenarioConfig, ScenarioFilterResult } from '~/src/scenario/scenario' +import type { UIConfig } from '~/pages/tne.vue' const emit = defineEmits<{ setBbox: [value: Bbox] @@ -54,15 +54,37 @@ const emit = defineEmits<{ }>() const props = defineProps<{ - bbox: Bbox - dataDisplayMode: string - colorKey: string - displayEditBboxMode?: boolean - hideUnmarked: boolean - censusGeographiesSelected: CensusGeography[] + // bbox: Bbox + // dataDisplayMode: string + // colorKey: string + // displayEditBboxMode?: boolean + // hideUnmarked: boolean + // censusGeographiesSelected: CensusGeography[] scenarioFilterResult?: ScenarioFilterResult }>() +const scenarioConfig = defineModel('scenarioConfig') +const uiConfig = defineModel('uiConfig') + +const bbox = computed(() => { + return scenarioConfig.value?.bbox || { valid: false, ne: { lon: 0, lat: 0 }, sw: { lon: 0, lat: 0 } } +}) +const displayEditBboxMode = computed(() => { + return uiConfig.value?.displayEditBboxMode || false +}) +const dataDisplayMode = computed(() => { + return uiConfig.value?.dataDisplayMode || 'default' +}) +const colorKey = computed(() => { + return uiConfig.value?.colorKey || 'default' +}) +const hideUnmarked = computed(() => { + return uiConfig.value?.hideUnmarked || false +}) +const censusGeographiesSelected = computed(() => { + return [] +}) + const showShareMenu = ref(false) const toggleShareMenu = useToggle(showShareMenu) @@ -71,15 +93,15 @@ const toggleShareMenu = useToggle(showShareMenu) // Compute initial center point; do not update const centerPoint = { - lon: (props.bbox.sw.lon + props.bbox.ne.lon) / 2, - lat: (props.bbox.sw.lat + props.bbox.ne.lat) / 2 + lon: (bbox.value.sw.lon + bbox.value.ne.lon) / 2, + lat: (bbox.value.sw.lat + bbox.value.ne.lat) / 2 } // Polygon for drawing bbox area const bboxArea = computed(() => { const f: Feature[] = [] - if (props.bbox.valid && props.displayEditBboxMode) { - const p = props.bbox + if (bbox.value.valid && displayEditBboxMode.value) { + const p = bbox.value const coords = [[ [p.sw.lon, p.sw.lat], [p.sw.lon, p.ne.lat], @@ -104,7 +126,7 @@ const bboxArea = computed(() => { const bboxMarkers = computed(() => { const ret: MarkerFeature[] = [] - if (!props.displayEditBboxMode) { + if (!displayEditBboxMode.value) { return ret } @@ -116,14 +138,14 @@ const bboxMarkers = computed(() => { swElement.appendChild(swIconElement) ret.push({ - point: props.bbox.sw, + point: bbox.value.sw, color: '#ff0000', draggable: true, element: swElement, onDragEnd: (c: any) => { emit('setBbox', { valid: true, - ne: props.bbox.ne, + ne: bbox.value.ne, sw: { lon: c.target.getLngLat().lng, lat: c.target.getLngLat().lat, @@ -140,14 +162,14 @@ const bboxMarkers = computed(() => { neElement.appendChild(neIconElement) ret.push({ - point: props.bbox.ne, + point: bbox.value.ne, color: '#00ff00', draggable: true, element: neElement, onDragEnd: (c: any) => { emit('setBbox', { valid: true, - sw: props.bbox.sw, + sw: bbox.value.sw, ne: { lon: c.target.getLngLat().lng, lat: c.target.getLngLat().lat, diff --git a/components/cal/query.vue b/components/cal/query.vue index 09b1629..cbe25d7 100644 --- a/components/cal/query.vue +++ b/components/cal/query.vue @@ -8,7 +8,7 @@ Specify your desired date range and geographic bounds. Then click Run Query. -
+
- + - + {{ selectSingleDay ? 'Set an end date' : 'Remove end date' }} @@ -36,7 +36,7 @@ - + @@ -48,7 +48,7 @@
@@ -67,32 +67,32 @@
-
+
-
+
import { useToggle } from '@vueuse/core' import { useLazyQuery } from '@vue/apollo-composable' -import type { Bbox, Point } from '~/src/geom' +import type { UIConfig } from '~/pages/tne.vue' import { cannedBboxes, geomSources } from '~/src/constants' import { type CensusDataset, type CensusGeography, geographySearchQuery } from '~/src/census' +import type { ScenarioConfig } from '~/src/scenario/scenario' const emit = defineEmits([ 'setBbox', @@ -135,34 +136,24 @@ const emit = defineEmits([ ]) const loadExampleData = async () => { - emit('loadExampleData', cannedBbox.value) + emit('loadExampleData', uiConfig.value?.cannedBbox) } -const props = defineProps<{ - censusGeographyLayerOptions: { label: string, value: string }[] - mapExtentCenter: Point | null -}>() +const scenarioConfig = defineModel('scenarioConfig') +const uiConfig = defineModel('uiConfig') -const bbox = defineModel('bbox', { default: null }) -const geographyIds = defineModel('geographyIds') -const censusGeographiesSelected = defineModel('censusGeographiesSelected', { default: [] }) -const cannedBbox = defineModel('cannedBbox', { default: null }) +// Local state const debugMenu = useDebugMenu() -const endDate = defineModel('endDate') -const geomLayer = defineModel('geomLayer') const geomSearch = ref('') -const geomSource = defineModel('geomSource') -const scheduleEnabled = defineModel('scheduleEnabled') const selectSingleDay = ref(true) -const startDate = defineModel('startDate') const toggleSelectSingleDay = useToggle(selectSingleDay) const geomSearchVars = computed(() => { return { - layer: geomLayer.value, + layer: uiConfig.value?.geomLayer, search: geomSearch.value, limit: 10, - focus: props.mapExtentCenter, + focus: uiConfig.value?.mapExtentCenter, } }) @@ -181,8 +172,8 @@ const { ) watch(geomSearchVars, () => { - if ((geomSearch.value || '').length >= 2 && geomLayer.value) { - if (geomSearch.value && geomLayer.value) { + if ((geomSearch.value || '').length >= 2 && uiConfig.value?.geomLayer) { + if (geomSearch.value && uiConfig.value.geomLayer) { geomLoad(geographySearchQuery) } else { geomRefetch() @@ -193,7 +184,7 @@ watch(geomSearchVars, () => { const selectedGeographyTagOptions = computed((): { value: number, label: string }[] => { // Combine both the selected geographies and the search results const geogs: CensusGeography[] = [] - for (const geo of censusGeographiesSelected.value || []) { + for (const geo of uiConfig.value?.censusGeographiesSelected || []) { geogs.push({ ...geo, }) @@ -232,7 +223,7 @@ const selectedGeographyTagOptions = computed((): { value: number, label: string ///////////////////////////////////////// const validQueryParams = computed(() => { - return startDate.value && bbox?.value?.valid + return scenarioConfig?.value?.startDate && scenarioConfig?.value?.bbox }) diff --git a/pages/tne.vue b/pages/tne.vue index 443e52c..3b5761d 100644 --- a/pages/tne.vue +++ b/pages/tne.vue @@ -56,64 +56,33 @@
- + /> -->
- + /> -->
@@ -127,16 +96,10 @@
@@ -158,19 +121,37 @@ + +