Latlng
This commit is contained in:
7
web/packages/base/types/index.ts
Normal file
7
web/packages/base/types/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* A location, represented as a (latitude, longitude) pair.
|
||||
*/
|
||||
export interface Location {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { decryptMetadataJSON, encryptMetadataJSON } from "@/base/crypto";
|
||||
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
|
||||
import { apiURL } from "@/base/origins";
|
||||
import type { Location } from "@/base/types";
|
||||
import {
|
||||
type EnteFile,
|
||||
type FilePublicMagicMetadata,
|
||||
} from "@/new/photos/types/file";
|
||||
import { mergeMetadata1 } from "@/new/photos/utils/file";
|
||||
import { ensure } from "@/utils/ensure";
|
||||
import { nullToUndefined } from "@/utils/transform";
|
||||
import { z } from "zod";
|
||||
import { FileType } from "./file-type";
|
||||
|
||||
@@ -559,7 +561,7 @@ export interface ParsedMetadata {
|
||||
*/
|
||||
creationDate?: ParsedMetadataDate;
|
||||
/** The GPS coordinates where the photo was taken. */
|
||||
location?: { latitude: number; longitude: number };
|
||||
location?: Location;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -760,3 +762,22 @@ export const toUIDate = (dateLike: ParsedMetadataDate | string | number) => {
|
||||
return new Date(dateLike / 1000);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the GPS coordinates (if any) present in the given {@link EnteFile}.
|
||||
*/
|
||||
export const fileLocation = (enteFile: EnteFile): Location | undefined => {
|
||||
// TODO: EnteFile types. Need to verify that metadata itself, and
|
||||
// metadata.lat/lng can not be null (I think they likely can, if so need to
|
||||
// update the types). Need to supress the linter meanwhile.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (!enteFile.metadata) return undefined;
|
||||
|
||||
const latitude = nullToUndefined(enteFile.metadata.latitude);
|
||||
const longitude = nullToUndefined(enteFile.metadata.longitude);
|
||||
|
||||
if (latitude === undefined || longitude === undefined) return undefined;
|
||||
|
||||
return { latitude, longitude };
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ export interface SearchPerson {
|
||||
|
||||
// TODO-cgroup: Audit below
|
||||
|
||||
export interface Location {
|
||||
export interface LocationOld {
|
||||
latitude: number | null;
|
||||
longitude: number | null;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ export interface LocationTagData {
|
||||
radius: number;
|
||||
aSquare: number;
|
||||
bSquare: number;
|
||||
centerPoint: Location;
|
||||
centerPoint: LocationOld;
|
||||
}
|
||||
|
||||
export interface City {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { expose } from "comlink";
|
||||
import type {
|
||||
City,
|
||||
DateSearchResult,
|
||||
Location,
|
||||
LocationOld,
|
||||
LocationTagData,
|
||||
SearchDateComponents,
|
||||
SearchQuery,
|
||||
@@ -166,10 +166,13 @@ const isMatch = (file: EnteFile, query: SearchQuery) => {
|
||||
getUICreationDate(file, getPublicMagicMetadataSync(file)),
|
||||
);
|
||||
}
|
||||
|
||||
const [latitude, longitude] = [file.metadata.latitude, file.metadata.longitude];
|
||||
if (latitude !== undefined && longitude !== undefined )
|
||||
if (query?.location) {
|
||||
return isInsideLocationTag(
|
||||
{
|
||||
latitude: file.metadata.latitude ?? null,
|
||||
latitude: ?? null,
|
||||
longitude: file.metadata.longitude ?? null,
|
||||
},
|
||||
query.location,
|
||||
@@ -221,11 +224,11 @@ const defaultCityRadius = 10;
|
||||
const kmsPerDegree = 111.16;
|
||||
|
||||
const isInsideLocationTag = (
|
||||
location: Location,
|
||||
location: LocationOld,
|
||||
locationTag: LocationTagData,
|
||||
) => isWithinRadius(location, locationTag.centerPoint, locationTag.radius);
|
||||
|
||||
const isInsideCity = (location: Location, city: City) =>
|
||||
const isInsideCity = (location: LocationOld, city: City) =>
|
||||
isWithinRadius(
|
||||
{ latitude: city.lat, longitude: city.lng },
|
||||
location,
|
||||
@@ -233,8 +236,8 @@ const isInsideCity = (location: Location, city: City) =>
|
||||
);
|
||||
|
||||
const isWithinRadius = (
|
||||
centerPoint: Location,
|
||||
location: Location,
|
||||
centerPoint: LocationOld,
|
||||
location: LocationOld,
|
||||
radius: number,
|
||||
) => {
|
||||
const a =
|
||||
|
||||
Reference in New Issue
Block a user