Skip to content

Commit

Permalink
Display file marker location when opening sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr committed Jul 5, 2024
1 parent 500cfc2 commit ad3d9a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Api_LastUpdatedBy } from '@/models/api/File';
import { ApiGen_Concepts_File } from '@/models/api/generated/ApiGen_Concepts_File';
import { ApiGen_Concepts_Project } from '@/models/api/generated/ApiGen_Concepts_Project';
import { exists } from '@/utils';
import { getLatLng } from '@/utils/mapPropertyUtils';
import { getLatLng, locationFromFileProperty } from '@/utils/mapPropertyUtils';

export interface TypedFile extends ApiGen_Concepts_File {
fileType: FileTypes;
Expand Down Expand Up @@ -120,7 +120,8 @@ export const SideBarContextProvider = (props: {
const resetFilePropertyLocations = useCallback(() => {
if (exists(fileProperties)) {
const propertyLocations = fileProperties
.map(x => getLatLng(x.property?.location))
.map(x => locationFromFileProperty(x))
.map(y => getLatLng(y))
.filter(exists);

setFilePropertyLocations && setFilePropertyLocations(propertyLocations);
Expand Down
5 changes: 2 additions & 3 deletions source/frontend/src/hooks/useDraftMarkerSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import { useMapStateMachine } from '@/components/common/mapFSM/MapStateMachineCo
import { IMapProperty } from '@/components/propertySelector/models';
import useDeepCompareEffect from '@/hooks/util/useDeepCompareEffect';
import useIsMounted from '@/hooks/util/useIsMounted';
import { latLngFromMapProperty } from '@/utils';

/**
* Get a list of file property markers from the current form values.
* As long as a parcel/building has both a lat and a lng it will be returned by this method.
* @param modifiedProperties the current form values to extract lat/lngs from.
*/
const getFilePropertyLocations = (modifiedProperties: IMapProperty[]): LatLngLiteral[] => {
return modifiedProperties.map<LatLngLiteral>((property: IMapProperty) => {
return { lat: Number(property?.latitude ?? 0), lng: Number(property?.longitude ?? 0) };
});
return modifiedProperties.map((property: IMapProperty) => latLngFromMapProperty(property));
};

/**
Expand Down
15 changes: 15 additions & 0 deletions source/frontend/src/utils/mapPropertyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,18 @@ export function pinFromFeatureSet(featureset: LocationFeatureDataset): string |
null
);
}

export function locationFromFileProperty(
fileProperty: ApiGen_Concepts_FileProperty | undefined | null,
): ApiGen_Concepts_Geometry | null {
return fileProperty?.location ?? fileProperty?.property?.location ?? null;
}

export function latLngFromMapProperty(
mapProperty: IMapProperty | undefined | null,
): LatLngLiteral | null {
return {
lat: Number(mapProperty?.fileLocation?.lat ?? mapProperty?.latitude ?? 0),
lng: Number(mapProperty?.fileLocation?.lng ?? mapProperty?.longitude ?? 0),
};
}

0 comments on commit ad3d9a4

Please sign in to comment.