mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
allow users to set coordinate display type (#141)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
type Coordinate,
|
||||
CoordinateDisplayOrder,
|
||||
CoordinateDisplayFormat,
|
||||
CoordinateDirectionFormat,
|
||||
CoordinateDisplayType,
|
||||
getNormalizedCoordinate
|
||||
} from '@/core/coordinate.ts';
|
||||
|
||||
export function formatCoordinate(value: Coordinate, coordinateDisplayType: number): string {
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
value = getNormalizedCoordinate(value);
|
||||
|
||||
const displayType = CoordinateDisplayType.valueOf(coordinateDisplayType) || CoordinateDisplayType.Default;
|
||||
const formattedLatitude = formatCoordinateValue(value.latitude, 'N', 'S', displayType.displayFormat, displayType.directionFormat);
|
||||
const formattedLongitude = formatCoordinateValue(value.longitude, 'E', 'W', displayType.displayFormat, displayType.directionFormat);
|
||||
|
||||
if (displayType.displayOrder === CoordinateDisplayOrder.LatitudeLongitude) {
|
||||
return `${formattedLatitude}, ${formattedLongitude}`;
|
||||
} else if (displayType.displayOrder === CoordinateDisplayOrder.LongitudeLatitude) {
|
||||
return `${formattedLongitude}, ${formattedLatitude}`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function formatCoordinateValue(value: number, positiveDirectionName: string, negativeDirectionName: string, displayFormat: CoordinateDisplayFormat, directionFormat: CoordinateDirectionFormat): string {
|
||||
let prefix = '';
|
||||
let suffix = '';
|
||||
|
||||
if (directionFormat === CoordinateDirectionFormat.Signed) {
|
||||
prefix = value >= 0 ? '' : '-';
|
||||
} else if (directionFormat === CoordinateDirectionFormat.Directional) {
|
||||
suffix = value >= 0 ? positiveDirectionName : negativeDirectionName;
|
||||
}
|
||||
|
||||
value = Math.abs(value);
|
||||
|
||||
if (displayFormat === CoordinateDisplayFormat.DecimalDegrees) {
|
||||
return `${prefix}${value.toFixed(6)}${suffix}`;
|
||||
} else if (displayFormat === CoordinateDisplayFormat.DecimalMinutes) {
|
||||
const degrees = Math.floor(value);
|
||||
const minutes = (value - degrees) * 60;
|
||||
return `${prefix}${degrees}°${minutes.toFixed(5)}'${suffix}`;
|
||||
} else if (displayFormat === CoordinateDisplayFormat.DegreesMinutesSeconds) {
|
||||
const degrees = Math.floor(value);
|
||||
const minutes = Math.floor((value - degrees) * 60);
|
||||
const seconds = (value - degrees - minutes / 60) * 3600;
|
||||
return `${prefix}${degrees}°${minutes}'${seconds.toFixed(4)}"${suffix}`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-nocheck
|
||||
import type { MapPosition } from '@/core/map.ts';
|
||||
import type { Coordinate } from '@/core/coordinate.ts';
|
||||
import type { MapProvider, MapInstance, MapInstanceInitOptions } from './base.ts';
|
||||
|
||||
import { asyncLoadAssets } from '@/lib/misc.ts';
|
||||
@@ -105,7 +105,7 @@ export class AmapMapInstance implements MapInstance {
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
public setMapCenterTo(center: MapPosition, zoomLevel: number): void {
|
||||
public setMapCenterTo(center: Coordinate, zoomLevel: number): void {
|
||||
if (!AmapMapProvider.AMap || !this.amapInstance) {
|
||||
return;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export class AmapMapInstance implements MapInstance {
|
||||
});
|
||||
}
|
||||
|
||||
public setMapCenterMarker(position: MapPosition): void {
|
||||
public setMapCenterMarker(position: Coordinate): void {
|
||||
if (!AmapMapProvider.AMap || !this.amapInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-nocheck
|
||||
import type { MapPosition } from '@/core/map.ts';
|
||||
import type { Coordinate } from '@/core/coordinate.ts';
|
||||
import type { MapProvider, MapInstance, MapInstanceInitOptions } from './base.ts';
|
||||
|
||||
import { asyncLoadAssets } from '@/lib/misc.ts';
|
||||
@@ -96,7 +96,7 @@ export class BaiduMapInstance implements MapInstance {
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
public setMapCenterTo(center: MapPosition, zoomLevel: number): void {
|
||||
public setMapCenterTo(center: Coordinate, zoomLevel: number): void {
|
||||
if (!BaiduMapProvider.BMap || !this.baiduMapInstance) {
|
||||
return;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ export class BaiduMapInstance implements MapInstance {
|
||||
}
|
||||
}
|
||||
|
||||
public setMapCenterMarker(position: MapPosition): void {
|
||||
public setMapCenterMarker(position: Coordinate): void {
|
||||
if (!BaiduMapProvider.BMap || !this.baiduMapInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
import type { MapPosition } from '@/core/map.ts';
|
||||
import type { Coordinate } from '@/core/coordinate.ts';
|
||||
|
||||
export interface MapProvider {
|
||||
getWebsite(): string;
|
||||
@@ -13,18 +13,18 @@ export interface MapInstance {
|
||||
readonly defaultZoomLevel: number;
|
||||
readonly minZoomLevel: number;
|
||||
initMapInstance(mapContainer: HTMLElement, options: MapInstanceInitOptions): void;
|
||||
setMapCenterTo(center: MapPosition, zoomLevel: number): void;
|
||||
setMapCenterMarker(position: MapPosition): void;
|
||||
setMapCenterTo(center: Coordinate, zoomLevel: number): void;
|
||||
setMapCenterMarker(position: Coordinate): void;
|
||||
removeMapCenterMarker(): void;
|
||||
}
|
||||
|
||||
export interface MapInstanceInitOptions {
|
||||
readonly language?: string;
|
||||
readonly initCenter: MapPosition;
|
||||
readonly initCenter: Coordinate;
|
||||
readonly zoomLevel: number;
|
||||
readonly text: {
|
||||
readonly zoomIn: string;
|
||||
readonly zoomOut: string;
|
||||
};
|
||||
readonly onClick?: (position: MapPosition) => void;
|
||||
readonly onClick?: (position: Coordinate) => void;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-nocheck
|
||||
import type { MapPosition } from '@/core/map.ts';
|
||||
import type { Coordinate } from '@/core/coordinate.ts';
|
||||
import type { MapProvider, MapInstance, MapInstanceInitOptions } from './base.ts';
|
||||
|
||||
import { asyncLoadAssets } from '@/lib/misc.ts';
|
||||
@@ -94,7 +94,7 @@ export class GoogleMapInstance implements MapInstance {
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
public setMapCenterTo(center: MapPosition, zoomLevel: number): void {
|
||||
public setMapCenterTo(center: Coordinate, zoomLevel: number): void {
|
||||
if (!GoogleMapProvider.GoogleMap || !this.googleMapInstance) {
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ export class GoogleMapInstance implements MapInstance {
|
||||
this.googleMapInstance.setZoom(zoomLevel);
|
||||
}
|
||||
|
||||
public setMapCenterMarker(position: MapPosition): void {
|
||||
public setMapCenterMarker(position: Coordinate): void {
|
||||
if (!GoogleMapProvider.GoogleMap || !this.googleMapInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-nocheck
|
||||
import type { MapPosition } from '@/core/map.ts';
|
||||
import type { Coordinate } from '@/core/coordinate.ts';
|
||||
|
||||
import { type LeafletTileSource, type LeafletTileSourceExtraParam, LEAFLET_TILE_SOURCES } from '@/consts/map.ts';
|
||||
|
||||
@@ -97,8 +97,7 @@ export class LeafletMapInstance implements MapInstance {
|
||||
center: [ options.initCenter.latitude, options.initCenter.longitude ],
|
||||
zoom: options.zoomLevel,
|
||||
attributionControl: false,
|
||||
zoomControl: false,
|
||||
worldCopyJump: true
|
||||
zoomControl: false
|
||||
});
|
||||
|
||||
let tileUrlFormat, tileUrlSubDomains, annotationUrlFormat, annotationUrlSubDomains: string | undefined;
|
||||
@@ -180,7 +179,7 @@ export class LeafletMapInstance implements MapInstance {
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
public setMapCenterTo(center: MapPosition, zoomLevel: number): void {
|
||||
public setMapCenterTo(center: Coordinate, zoomLevel: number): void {
|
||||
if (!this.leafletInstance) {
|
||||
return;
|
||||
}
|
||||
@@ -188,7 +187,7 @@ export class LeafletMapInstance implements MapInstance {
|
||||
this.leafletInstance.setView([ center.latitude, center.longitude ], zoomLevel);
|
||||
}
|
||||
|
||||
public setMapCenterMarker(position: MapPosition): void {
|
||||
public setMapCenterMarker(position: Coordinate): void {
|
||||
if (!LeafletMapProvider.Leaflet || !this.leafletInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user