-
Notifications
You must be signed in to change notification settings - Fork 1
Route is Now Created From Filters and Defined Start/End points #63
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
Changes from all commits
9c13c0c
c0c935c
afa6a46
9a370aa
77b412e
fc2ae0f
a24768c
1c6af1f
716b8e2
4e491a7
2dc06b2
af730ee
7663edf
9128888
21b5e9e
1390317
b0c651a
81414b4
2af062e
b1e065e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,68 @@ | ||
| <script setup> | ||
| import { reactive, ref, onMounted, watch } from 'vue' | ||
| import { reactive, onMounted, watch, onBeforeMount, onDeactivated } from 'vue' | ||
| import SensorMapMarker from '@/components/sensorMapMarker.vue'; | ||
| import 'leaflet/dist/leaflet.css' | ||
| import { LMap, LTileLayer, LMarker, LControlZoom, LPolyline } from '@vue-leaflet/vue-leaflet' | ||
| import { LMap, LTileLayer, LMarker, LControlZoom, LPolyline, LIcon } from '@vue-leaflet/vue-leaflet' | ||
| import { useDevice, DEVICE_SIZE } from '@/utils/screenSizeHelper'; | ||
| import { getLatLng } from '@/utils/getLatLngFromAddressHelper'; | ||
| import { useSensorStore } from '@/stores/sensors_store'; | ||
| import { useRouteStore } from '@/stores/route_store'; | ||
| import { storeToRefs } from 'pinia'; | ||
|
|
||
| const center = ref([43.7, -79.42]); // TODO: update to possibly be user's current location | ||
| const zoom = ref(10); | ||
| // stores | ||
| const sensorStore = useSensorStore(); | ||
| const { sensors } = storeToRefs(sensorStore); | ||
| const routeStore = useRouteStore(); | ||
| const { | ||
| getSelectedRouteLatLong, | ||
| getIsRouteOptimized } = storeToRefs(routeStore); | ||
|
|
||
| const state = reactive({ | ||
| location: 'bottomright', | ||
| device: useDevice() | ||
| device: useDevice(), | ||
| isRouteOptimized: false, | ||
| polyLineLatLngs: [], | ||
| startPointLatLng: [], | ||
| endPointLatLng: [], | ||
| zoom: 10, | ||
| center: [43.7, -79.42] | ||
| }); | ||
| const polyLineLatLngs = ref([]); | ||
|
|
||
| const routeStore = useRouteStore(); | ||
| const { getSensorRouteLatLong } = storeToRefs(routeStore); | ||
| const startImgUrl = 'src/assets/images/feather-disc.svg'; | ||
| const endImgUrl = 'src/assets/images/feather-map-pin.svg'; | ||
|
|
||
| watch(getSensorRouteLatLong, () => { | ||
| polyLineLatLngs.value = routeStore.getSensorRouteLatLong; | ||
| }, { deep: true }) | ||
| onBeforeMount(async () => { | ||
| // processing start/end/center lat lng points | ||
| state.startPointLatLng = await getLatLng(routeStore.getStartPointAddress); | ||
| state.endPointLatLng = await getLatLng(routeStore.getEndPointAddress); | ||
| state.center = state.startPointLatLng; | ||
|
|
||
| routeStore.setHasMappedStartEnd(true); | ||
| }) | ||
|
|
||
| onMounted(() => { | ||
| positionZoom(); | ||
| window.addEventListener("resize", positionZoom); | ||
| }); | ||
|
|
||
| onDeactivated(() => { | ||
| routeStore.setHasMappedStartEnd(false); | ||
| }) | ||
|
|
||
| watch(getSelectedRouteLatLong, () => { | ||
| state.polyLineLatLngs = routeStore.getSelectedRouteLatLong; | ||
|
|
||
| // additional lines for start and end points | ||
| if (state.startPointLatLng.length && state.endPointLatLng.length) { | ||
| state.polyLineLatLngs.unshift(state.startPointLatLng); // append as first element | ||
| state.polyLineLatLngs.push(state.endPointLatLng); // append as last element | ||
| } | ||
| }, { deep: true }) | ||
|
Comment on lines
+52
to
+60
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here we are drawing the additional map polylines for the start and end points |
||
|
|
||
| watch(getIsRouteOptimized, () => { | ||
| state.isRouteOptimized = routeStore.getIsRouteOptimized; | ||
| }) | ||
|
|
||
| function positionZoom() { | ||
| state.device = useDevice(); | ||
| if (state.device.size === DEVICE_SIZE.s || state.device.size === DEVICE_SIZE.xs) { | ||
|
|
@@ -42,17 +75,30 @@ | |
|
|
||
| <template> | ||
| <div v-if="sensors" class="sensor-map-container"> | ||
| <l-map ref="map" v-model:zoom="zoom" :use-global-leaflet="false" :center="center" :options="{zoomControl: false}"> | ||
| <l-map ref="map" v-model:zoom="state.zoom" :use-global-leaflet="false" :center="state.center" :options="{zoomControl: false}"> | ||
| <l-control-zoom :position="state.location"/> | ||
| <!-- alternative maps (for aesthetic): --> | ||
| <!-- favourite: https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png --> | ||
| <!-- another one: https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png --> | ||
| <!-- alternative maps URLS (for aesthetic): --> | ||
| <!-- https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png --> | ||
| <!-- https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png --> | ||
| <l-tile-layer | ||
| url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
| layer-type="base" | ||
| name="OpenStreetMap" | ||
| ></l-tile-layer> | ||
| <l-polyline :lat-lngs="polyLineLatLngs"></l-polyline> | ||
| <l-polyline v-if="state.isRouteOptimized" :lat-lngs="state.polyLineLatLngs"></l-polyline> | ||
|
|
||
| <!-- starting point marker --> | ||
| <l-marker v-if="state.startPointLatLng.length" | ||
| :lat-lng="state.startPointLatLng"> | ||
| <l-icon class="color-green" :icon-size="[25, 25]" :icon-anchor="[15, 14]" :icon-url="startImgUrl" /> | ||
| </l-marker> | ||
|
|
||
| <!-- ending point marker --> | ||
| <l-marker v-if="state.endPointLatLng.length" | ||
| :lat-lng="state.endPointLatLng"> | ||
| <l-icon :icon-size="[25, 25]" :icon-anchor="[12, 14]" :icon-url="endImgUrl" /> | ||
| </l-marker> | ||
|
|
||
|
Comment on lines
+90
to
+101
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. places start and end point map markers |
||
|
|
||
| <l-marker | ||
| v-for="sensor in sensors" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gets start and end point lat lng and sets the center of the map to be the start point