Skip to content

Commit

Permalink
feat: CE-876-Add-option-to-use-UTM-for-geo-coordinates (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitri-korin-bcps authored Oct 29, 2024
1 parent 156aad7 commit 4bf412a
Show file tree
Hide file tree
Showing 18 changed files with 695 additions and 316 deletions.
4 changes: 2 additions & 2 deletions frontend/cypress/e2e/allegation-details-create.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ describe("Complaint Create Page spec - Create View", () => {
cy.get('dd[id="comp-details-violation-observed"]').contains(createCallDetails.violationObservedString);
cy.get('dd[id="comp-details-location"]').contains(createCallDetails.location);
cy.get('dd[id="comp-details-location-description"]').should("have.text", createCallDetails.locationDescription);
cy.get('span[id="call-details-x-coordinate"]').contains(createCallDetails.xCoord);
cy.get('span[id="call-details-y-coordinate"]').contains(createCallDetails.yCoord);
cy.get('span[id="geo-details-x-coordinate"]').contains(createCallDetails.xCoord);
cy.get('span[id="geo-details-y-coordinate"]').contains(createCallDetails.yCoord);
cy.get('dd[id="comp-details-community"]').contains(createCallDetails.community);
cy.get('dd[id="comp-details-office"]').contains(createCallDetails.office);
cy.get('dd[id="comp-details-zone"]').contains(createCallDetails.zone);
Expand Down
8 changes: 4 additions & 4 deletions frontend/cypress/e2e/allegation-details-edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,16 @@ describe("Complaint Edit Page spec - Edit Allegation View", () => {
cy.get("#attractants-pair-id input").should("not.exist");

// X Coordinate
cy.get('[for="comp-details-edit-x-coordinate-input"]').should(($label) => {
cy.get('[for="input-x-coordinate"]').should(($label) => {
expect($label).to.contain.text("Longitude");
});
cy.get("#comp-details-edit-x-coordinate-input-div").should("exist");
cy.get("#input-x-coordinate").should("exist");

// Y Coordinate
cy.get('[for="comp-details-edit-y-coordinate-input"]').should(($label) => {
cy.get('[for="input-y-coordinate"]').should(($label) => {
expect($label).to.contain.text("Latitude");
});
cy.get("#comp-details-edit-y-coordinate-input-div").should("exist");
cy.get("#input-y-coordinate").should("exist");

// Area/Community
cy.get("#area-community-pair-id label").should(($label) => {
Expand Down
12 changes: 6 additions & 6 deletions frontend/cypress/e2e/hwcr-details-create-enter-coordinates.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ describe("Complaint Create Page spec - Enter Coordinates - Create View", () => {

cy.selectItemById("reported-select-id", createCallerInformation.reported);

cy.get("#comp-details-edit-x-coordinate-input").click({ force: true });
cy.get("#comp-details-edit-x-coordinate-input").clear().type(createCallDetails.xCoord);
cy.get("#input-x-coordinate").click({ force: true });
cy.get("#input-x-coordinate").clear().type(createCallDetails.xCoord);

cy.get("#comp-details-edit-y-coordinate-input").click({ force: true });
cy.get("#comp-details-edit-y-coordinate-input").clear().type(createCallDetails.yCoord);
cy.get("#input-y-coordinate").click({ force: true });
cy.get("#input-y-coordinate").clear().type(createCallDetails.yCoord);

cy.get("#complaint-location-description-textarea-id").click({
force: true,
Expand Down Expand Up @@ -114,8 +114,8 @@ describe("Complaint Create Page spec - Enter Coordinates - Create View", () => {
});

cy.get('dd[id="comp-details-location-description"]').should("have.text", createCallDetails.locationDescription);
cy.get('span[id="call-details-x-coordinate"]').contains(createCallDetails.xCoord);
cy.get('span[id="call-details-y-coordinate"]').contains(createCallDetails.yCoord);
cy.get('span[id="geo-details-x-coordinate"]').contains(createCallDetails.xCoord);
cy.get('span[id="geo-details-y-coordinate"]').contains(createCallDetails.yCoord);
cy.get('dd[id="comp-details-community"]').contains(createCallDetails.community);
cy.get('dd[id="comp-details-office"]').contains(createCallDetails.office);
cy.get('dd[id="comp-details-zone"]').contains(createCallDetails.zone);
Expand Down
4 changes: 2 additions & 2 deletions frontend/cypress/e2e/hwcr-details-create.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ describe("Complaint Create Page spec - Create View", () => {

cy.get('dd[id="comp-details-location"]').contains(createCallDetails.location);
cy.get('dd[id="comp-details-location-description"]').should("have.text", createCallDetails.locationDescription);
cy.get('span[id="call-details-x-coordinate"]').contains(createCallDetails.xCoord);
cy.get('span[id="call-details-y-coordinate"]').contains(createCallDetails.yCoord);
cy.get('span[id="geo-details-x-coordinate"]').contains(createCallDetails.xCoord);
cy.get('span[id="geo-details-y-coordinate"]').contains(createCallDetails.yCoord);
cy.get('dd[id="comp-details-community"]').contains(createCallDetails.community);
cy.get('dd[id="comp-details-office"]').contains(createCallDetails.office);
cy.get('dd[id="comp-details-zone"]').contains(createCallDetails.zone);
Expand Down
8 changes: 4 additions & 4 deletions frontend/cypress/e2e/hwcr-details-edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,16 @@ describe("Complaint Edit Page spec - Edit View", () => {
cy.get("#attractants-pair-id input").should("exist");

// X Coordinate
cy.get('[for="comp-details-edit-x-coordinate-input"]').should(($label) => {
cy.get('[for="input-x-coordinate"]').should(($label) => {
expect($label).to.contain.text("Longitude");
});
cy.get("#comp-details-edit-x-coordinate-input-div").should("exist");
cy.get("#input-x-coordinate").should("exist");

// Y Coordinate
cy.get('[for="comp-details-edit-y-coordinate-input"]').should(($label) => {
cy.get('[for="input-y-coordinate"]').should(($label) => {
expect($label).to.contain.text("Latitude");
});
cy.get("#comp-details-edit-y-coordinate-input-div").should("exist");
cy.get("#input-y-coordinate").should("exist");

// Area/Community
cy.get("#area-community-pair-id label").should(($label) => {
Expand Down
6 changes: 3 additions & 3 deletions frontend/cypress/e2e/hwcr-outcome-equipment.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe("HWCR Outcome Equipment", () => {
let inputs = [
"#equipment-type-div",
"#equipment-address-div",
"#equipment-coordinate-div",
"#equipment-coordinate-div",
"#equipment-coordinates",
"#equipment-coordinates",
"#equipment-officer-set-div",
];
cy.hasErrorMessage(inputs, "Errors creating equipment");
Expand All @@ -63,7 +63,7 @@ describe("HWCR Outcome Equipment", () => {
equipmentType: "Bear snare",
};
cy.get("#equipment-copy-address-button").click();
cy.get("#equipment-copy-coordinates-button").click();
cy.get("#copy-coordinates-button").click();

cy.fillInHWCSection(sectionParams).then(() => {
cy.validateHWCSection(sectionParams);
Expand Down
6 changes: 6 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"uncontrollable": "^8.0.2",
"urlpattern-polyfill": "^9.0.0",
"util": "^0.12.5",
"utm-latlng": "^1.0.8",
"uuid": "^9.0.1",
"warning": "^4.0.3",
"web-vitals": "^3.0.0"
Expand Down
40 changes: 40 additions & 0 deletions frontend/src/app/common/methods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { GirType } from "../types/app/code-tables/gir-type";
import { WildlifeComplaint as WildlifeComplaintDto } from "../types/app/complaints/wildlife-complaint";
import { AllegationComplaint as AllegationComplaintDto } from "../types/app/complaints/allegation-complaint";
import { GeneralIncidentComplaint as GeneralIncidentComplaintDto } from "../types/app/complaints/general-complaint";
let utmObj = require("utm-latlng");

type Coordinate = number[] | string[] | undefined;

Expand Down Expand Up @@ -232,6 +233,15 @@ export const bcBoundaries = {
maxLongitude: -114.0337,
};

export const bcUtmBoundaries = {
minEasting: 280220.6,
maxEasting: 720184.9,
minNorthing: 5346051.7,
maxNorthing: 6655120.8,
};

export const bcUtmZoneNumbers = ["7", "8", "9", "10", "11"];

// given coordinates, return true if within BC or false if not within BC
export const isWithinBC = (coordinates: Coordinate): boolean => {
if (!coordinates) {
Expand Down Expand Up @@ -424,3 +434,33 @@ export const getThumbnailDataURL = async (file: File): Promise<string> => {
export function isPositiveNum(number: string) {
return !isNaN(Number(number)) && Number(number) >= 0;
}

export const formatLatLongCoordinate = (input: string | undefined): string | undefined => {
const regex = /-?(?:\d+(\.\d+)?|.\d+)/;
if (input && regex.exec(input)) {
const tokens = input.split(".");
if (tokens.length > 1) {
const decimals = tokens[1].length;
if (decimals <= 7) {
return input;
} else {
return tokens[0] + "." + tokens[1].substring(0, 7);
}
}
}
return input;
};

export const latLngToUtm = (lat: string, lng: string): { easting: string; northing: string; zone: string } => {
const regex = /-?(?:\d+(\.\d+)?|.\d+)/;
if (regex.exec(lat) && regex.exec(lng) && ![lat, lng].includes("0")) {
let utm = new utmObj();
const utmCoordinates = utm.convertLatLngToUtm(lat, lng, 3);
return {
easting: utmCoordinates.Easting.toFixed(0),
northing: utmCoordinates.Northing.toFixed(0),
zone: utmCoordinates.ZoneNumber ?? "",
};
}
return { easting: "", northing: "", zone: "" };
};
Loading

0 comments on commit 4bf412a

Please sign in to comment.