Skip to content

Commit

Permalink
improve constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mapsam committed Oct 2, 2024
1 parent f58d1ca commit 6f85523
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const R2D = 180 / Math.PI;
export const A = 6378137.0;
export const MAXEXTENT = 20037508.342789244;
export const SPHERICAL_MERCATOR_SRS = '900913'; // https://epsg.io/900913
export const WGS84 = 'WGS84';
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { D2R, R2D, A, MAXEXTENT, SPHERICAL_MERCATOR_SRS } from './constants';
import {
D2R,
R2D,
A,
MAXEXTENT,
SPHERICAL_MERCATOR_SRS,
WGS84,
} from './constants';

interface Options {
size?: number;
Expand All @@ -20,7 +27,7 @@ type South = number;
type East = number;
type North = number;
type BBox = [West, South, East, North];
type SRS = string;
type SRS = typeof SPHERICAL_MERCATOR_SRS | typeof WGS84;

const cache: Record<any, any> = {};
function isFloat(n: number): boolean {
Expand Down Expand Up @@ -170,7 +177,7 @@ export class SphericalMercator {
public xyz(bbox: BBox, zoom: Zoom, tmsStyle?: boolean, srs?: SRS): XYZ {
// If web mercator provided reproject to WGS84.
const box =
srs === SPHERICAL_MERCATOR_SRS ? this.convert(bbox, 'WGS84') : bbox;
srs === SPHERICAL_MERCATOR_SRS ? this.convert(bbox, WGS84) : bbox;

const ll: LonLat = [box[0], box[1]]; // lower left
const ur: LonLat = [box[2], box[3]]; // upper right
Expand Down

0 comments on commit 6f85523

Please sign in to comment.