pub struct GlobalMercator { /* private fields */ }Implementations§
Source§impl GlobalMercator
impl GlobalMercator
Sourcepub fn new(tile_size: u64) -> Self
pub fn new(tile_size: u64) -> Self
Create a new instance of the coordinate transformer
Example:
let transformer = webmerc::GlobalMercator::new(256);
assert_eq!(transformer.tile_size(), 256);Sourcepub fn tile_size(&self) -> u64
pub fn tile_size(&self) -> u64
Get the tile_size used to instantiate the transformer
Example:
let transformer = webmerc::GlobalMercator::new(256);
assert_eq!(transformer.tile_size(), 256);Sourcepub fn lat_lon_to_meters(&self, lon: f64, lat: f64) -> (f64, f64)
pub fn lat_lon_to_meters(&self, lon: f64, lat: f64) -> (f64, f64)
Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857
Example:
let transformer = webmerc::GlobalMercator::new(256);
let (x, y) = transformer.lat_lon_to_meters(10.0, 10.0);
assert_relative_eq!(x, 1113194.91, epsilon = 1e-2);
assert_relative_eq!(y, 1118889.97, epsilon = 1e-2);Sourcepub fn meters_2_lat_lon(&self, mx: f64, my: f64) -> (f64, f64)
pub fn meters_2_lat_lon(&self, mx: f64, my: f64) -> (f64, f64)
Converts XY point from Spherical Mercator EPSG:3857 to lat/lon in WGS84 Datum
let transformer = webmerc::GlobalMercator::new(256);
let (lon, lat) = transformer.meters_2_lat_lon(-20037508.0, -20037508.0);
assert_relative_eq!(lon, -179.999997, epsilon = 1e-6);
assert_relative_eq!(lat, -85.051129, epsilon = 1e-6);Sourcepub fn pixels_to_meters(&self, px: u64, py: u64, zoom: u64) -> (f64, f64)
pub fn pixels_to_meters(&self, px: u64, py: u64, zoom: u64) -> (f64, f64)
Converts pixel coordinates in given Zoom level of pyramid to EPSG:3857
Sourcepub fn meters_to_pixels(&self, mx: f64, my: f64, zoom: u64) -> (u64, u64)
pub fn meters_to_pixels(&self, mx: f64, my: f64, zoom: u64) -> (u64, u64)
Converts EPSG:3857 to pyramid pixel coordinates in given Zoom level
Sourcepub fn pixels_to_tile(&self, px: u64, py: u64) -> (u64, u64)
pub fn pixels_to_tile(&self, px: u64, py: u64) -> (u64, u64)
Returns a Tile covering region in given pixel coordinates
Sourcepub fn pixels_to_raster(&self, px: u64, py: u64, zoom: u64) -> (u64, u64)
pub fn pixels_to_raster(&self, px: u64, py: u64, zoom: u64) -> (u64, u64)
Move the origin of pixel coordinates to top-left corner
Sourcepub fn meters_to_tile(&self, mx: f64, my: f64, zoom: u64) -> (u64, u64)
pub fn meters_to_tile(&self, mx: f64, my: f64, zoom: u64) -> (u64, u64)
Returns tile for given mercator coordinates
Sourcepub fn tile_bounds(&self, tx: u64, ty: u64, zoom: u64) -> (f64, f64, f64, f64)
pub fn tile_bounds(&self, tx: u64, ty: u64, zoom: u64) -> (f64, f64, f64, f64)
Returns bounds of the given tile in EPSG:3857 coordinates
Sourcepub fn tile_lat_lon_bounds(
&self,
tx: u64,
ty: u64,
zoom: u64,
) -> (f64, f64, f64, f64)
pub fn tile_lat_lon_bounds( &self, tx: u64, ty: u64, zoom: u64, ) -> (f64, f64, f64, f64)
Returns bounds of the given tile in latitude/longitude using WGS84 datum
Sourcepub fn resolution(&self, zoom: u64) -> f64
pub fn resolution(&self, zoom: u64) -> f64
Resolution (meters/pixel) for given zoom level (measured at Equator)
Sourcepub fn zoom_for_pixel_size(&self, pixel_size: f64) -> u64
pub fn zoom_for_pixel_size(&self, pixel_size: f64) -> u64
Maximal scaledown zoom of the pyramid closest to the pixelSize.