Route is Now Created From Filters and Defined Start/End points - #63
Conversation
| "lat": 43.351197, | ||
| "long": -79.347344, | ||
| "lat": 43.452197, | ||
| "long": -80.147244, |
There was a problem hiding this comment.
updating buggy lat lng that was causing issues with gmaps api
| import axios from 'axios'; | ||
|
|
||
|
|
||
| // uses openstreetmap geocoding (opensource) | ||
| // https://nominatim.openstreetmap.org/ui/search.html | ||
| export const getLatLng = async (address) => { | ||
| const url = `https://nominatim.openstreetmap.org/search?format=json&limit=3&q=${address}`; | ||
| try { | ||
| const response = await axios.get(url); | ||
| if (response && response.data && response.data[0]) { | ||
| return [response.data[0].lat, response.data[0].lon]; | ||
| } | ||
| return []; | ||
| } catch(e) { | ||
| console.error('error generating lat lng', e); | ||
| return []; | ||
| } | ||
| }; | ||
|
|
||
| export default getLatLng No newline at end of file |
There was a problem hiding this comment.
this is a free geocoder i found to convert the start and end point addresses to lat lng coordinates!
| export const getMinutesString = (stringSeconds) => { | ||
| let duration = stringSeconds.replace('s',''); | ||
|
|
||
| const hours = Math.floor(duration / 3600); | ||
| duration = duration % 3600; | ||
| const minutes = Math.floor(duration / 60); | ||
|
|
||
| const hoursString = hours ? `${hours} hrs ` : ''; | ||
| const minutesString = minutes ? `${minutes} min ` : ''; | ||
| return hoursString + minutesString; | ||
| }; | ||
|
|
||
| export const getKmFromMeterString = (meters) => { | ||
| return (meters / 1000).toFixed(0); | ||
| }; No newline at end of file |
There was a problem hiding this comment.
these functions help process the seconds and meters the goog api returns for the route!
| return { | ||
| origin, | ||
| intermediates, | ||
| "destination":{ // specify ending point | ||
| "location":{ | ||
| "latLng":{ | ||
| "latitude": destination.lat, | ||
| "longitude": destination.long | ||
| } | ||
| } | ||
| }, | ||
| destination, |
There was a problem hiding this comment.
we are now taking in start and end points from user input, so updated file accordingly
| async googOptimizeRoute() { | ||
| const googResponse = await getOptimizedRoute(this.getSelectedRouteList, this.startPointAddress, this.endPointAddress); | ||
| if (googResponse && googResponse.routes && googResponse.routes[0]) { | ||
| const routeOrder = googResponse.routes[0].optimizedIntermediateWaypointIndex; // [0,3,4] | ||
| this.updateWithOptimizedRoute(routeOrder); // update current route | ||
| this.setIsRouteOptimized(true); // set flag is optimized to true | ||
|
|
||
| if (googResponse.routes[0].duration) { | ||
| this.setRouteDuration(googResponse.routes[0]?.duration); | ||
| } | ||
|
|
||
| if (googResponse.routes[0].distanceMeters) { | ||
| this.setRouteDistance(googResponse.routes[0]?.distanceMeters); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
google api call is now moved to route store to be called from any component as needed
|
|
||
| // replace intermediate waypoint array with temp | ||
| for (let j = 0; j < arrLength; j++) { | ||
| for (let j = 0; j < routeOrder.length; j++) { |
There was a problem hiding this comment.
fixed a bug here for returning optimized route
| 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); | ||
| }) |
There was a problem hiding this comment.
gets start and end point lat lng and sets the center of the map to be the start point
| 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 }) |
There was a problem hiding this comment.
here we are drawing the additional map polylines for the start and end points
| <!-- 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> | ||
|
|
There was a problem hiding this comment.
places start and end point map markers
| @@ -0,0 +1,209 @@ | |||
| <script setup> | |||
There was a problem hiding this comment.
sensorRouteBlock.vue is a new component which simply moves some of the code from the existing sensorSideBarRoutes.vue component
| filterEnabledMap: { | ||
| fillRange: false, | ||
| group: false, | ||
| assetTag: false, | ||
| binType: false, | ||
| binVolume: false, | ||
| matType: false | ||
| } |
| {{modelValue}}% | ||
| </template> | ||
| </v-range-slider> | ||
| <section v-if="!state.isCollapsed" class="filter-list__fields"> |
There was a problem hiding this comment.
made filter section collapsible

Note: 15-17 of these file changes are just me organizing components and moving image icons into a different folder!
sensorRouteListbecomeselectedRouteListapp_vue/src/utils/getLatLngFromAddressHelper.jsto get lat lngs from address for start and end pointfunction1.mov
function2.mov