Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/pages/CaseFlag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<base-input
v-model="currentFlag.requested_action"
:placeholder="$t('flag.google_map_url')"
@input="spliceUrl"
/>
<p class="mt-5 mb-3">
{{ $t('flag.click_if_location_unknown') }}
Expand Down Expand Up @@ -406,6 +407,10 @@ export default {
this.incidents = orderBy(response.data.results, ['id'], ['desc']);
},
methods: {
spliceUrl(url) {
// eslint-disable-next-line prefer-destructuring
this.currentFlag.requested_action = url.split('data')[0];
},
async flagWorksite() {
if (
this.currentFlag.reason_t === 'flag.worksite_wrong_incident' &&
Expand Down
14 changes: 14 additions & 0 deletions src/utils/__tests__/map.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getGoogleMapsLocation } from '../map';

describe('Google Maps Parse', () => {
const coords = {
lat: 38.8976763,
long: -77.0387185,
};

const url =
'https://www.google.com/maps/place/white+house/@38.8976763,-77.0387185,17z/data=!3m1!4b1!4m5!3m4!1s0x89b7b7bcdecbb1df:0x715969d86d0b76bf!8m2!3d38.8976763!4d-77.0365298';
test('Gets Correct Latitude and Longitude', () => {
expect(getGoogleMapsLocation(url) === coords);
});
});
8 changes: 4 additions & 4 deletions src/utils/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export const mapAttribution =
'&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="http://cartodb.com/attributions">CartoDB</a>';

export const getGoogleMapsLocation = (url) => {
const regex = new RegExp('@(.*),(.*),');
const match = url.match(regex);
const latitude = Number(match[1]);
const longitude = Number(match[2]);
const regex = '@(-?\\d+\\.\\d+),(-?\\d+\\.\\d+),(\\d+\\.?\\d?)+z';
const match = url.matchAll(regex);
const latitude = match[0];
const longitude = match[1];

return {
longitude,
Expand Down