maplair
Version:
JavaScript library for mobile-friendly interactive maps
51 lines (50 loc) • 2.07 kB
JavaScript
import { wrapNum } from "../../core/Util.js";
import { Bounds } from "../../geometry/Bounds.js";
import { LatLngBounds } from "../LatLngBounds.js";
import { LatLng } from "../LatLng.js";
//#region src/geo/crs/CRS.js
var CRS = class {
static projection = void 0;
static transformation = void 0;
static latLngToPoint(latlng, zoom) {
const projectedPoint = this.projection.project(latlng), scale = this.scale(zoom);
return this.transformation._transform(projectedPoint, scale);
}
static pointToLatLng(point, zoom) {
const scale = this.scale(zoom), untransformedPoint = this.transformation.untransform(point, scale);
return this.projection.unproject(untransformedPoint);
}
static project(latlng) {
return this.projection.project(latlng);
}
static unproject(point) {
return this.projection.unproject(point);
}
static scale(zoom) {
return 256 * 2 ** zoom;
}
static zoom(scale) {
return Math.log(scale / 256) / Math.LN2;
}
static getProjectedBounds(zoom) {
if (this.infinite) return null;
const b = this.projection.bounds, s = this.scale(zoom), min = this.transformation.transform(b.min, s), max = this.transformation.transform(b.max, s);
return new Bounds(min, max);
}
static infinite = false;
static wrapLatLng(latlng) {
latlng = new LatLng(latlng);
const lng = this.wrapLng ? wrapNum(latlng.lng, this.wrapLng, true) : latlng.lng, lat = this.wrapLat ? wrapNum(latlng.lat, this.wrapLat, true) : latlng.lat, alt = latlng.alt;
return new LatLng(lat, lng, alt);
}
static wrapLatLngBounds(bounds) {
bounds = new LatLngBounds(bounds);
const center = bounds.getCenter(), newCenter = this.wrapLatLng(center), latShift = center.lat - newCenter.lat, lngShift = center.lng - newCenter.lng;
if (latShift === 0 && lngShift === 0) return bounds;
const sw = bounds.getSouthWest(), ne = bounds.getNorthEast(), newSw = new LatLng(sw.lat - latShift, sw.lng - lngShift), newNe = new LatLng(ne.lat - latShift, ne.lng - lngShift);
return new LatLngBounds(newSw, newNe);
}
};
//#endregion
export { CRS };
//# sourceMappingURL=CRS.js.map