pub struct WasmCogViewer { /* private fields */ }Expand description
WASM-compatible COG (Cloud Optimized GeoTIFF) viewer
This is the basic COG viewer for browser-based geospatial data visualization. It provides simple access to COG metadata and tile reading functionality.
§Features
- Efficient tile-based access to large GeoTIFF files
- Support for multi-band imagery
- Overview/pyramid level access for different zoom levels
- CORS-compatible HTTP range request support
- Automatic TIFF header parsing
- GeoTIFF metadata extraction (CRS, geotransform, etc.)
§Performance
The viewer uses HTTP range requests to fetch only the required portions
of the file, making it efficient for large files. However, for production
use cases with caching and advanced features, consider using
AdvancedCogViewer instead.
§Example
const viewer = new WasmCogViewer();
await viewer.open('<https://example.com/image.tif>');
console.log(`Size: ${viewer.width()}x${viewer.height()}`);
const tile = await viewer.read_tile_as_image_data(0, 0, 0);Implementations§
Source§impl WasmCogViewer
impl WasmCogViewer
Sourcepub async fn open(&mut self, url: &str) -> Result<(), JsValue>
pub async fn open(&mut self, url: &str) -> Result<(), JsValue>
Opens a COG file from a URL
This method performs the following operations:
- Sends a HEAD request to determine file size and range support
- Fetches the TIFF header to validate format
- Parses IFD (Image File Directory) to extract metadata
- Extracts GeoTIFF tags for coordinate system information
- Counts overview levels for multi-resolution support
§Arguments
url- The URL of the COG file to open. Must support HTTP range requests for optimal performance. CORS must be properly configured.
§Returns
Returns Ok(()) on success, or a JavaScript error on failure.
§Errors
This method can fail for several reasons:
- Network errors (no connection, timeout, etc.)
- HTTP errors (404, 403, 500, etc.)
- CORS errors (missing headers)
- Invalid TIFF format
- Unsupported TIFF variant
§Example
const viewer = new WasmCogViewer();
try {
await viewer.open('<https://example.com/landsat.tif>');
console.log('Successfully opened COG');
} catch (error) {
console.error('Failed to open:', error);
}Sourcepub fn tile_width(&self) -> u32
pub fn tile_width(&self) -> u32
Returns the tile width
Sourcepub fn tile_height(&self) -> u32
pub fn tile_height(&self) -> u32
Returns the tile height
Sourcepub fn band_count(&self) -> u32
pub fn band_count(&self) -> u32
Returns the number of bands
Sourcepub fn overview_count(&self) -> usize
pub fn overview_count(&self) -> usize
Returns the number of overview levels
Sourcepub fn metadata_json(&self) -> String
pub fn metadata_json(&self) -> String
Returns metadata as JSON
Sourcepub fn pixel_scale_x(&self) -> Option<f64>
pub fn pixel_scale_x(&self) -> Option<f64>
Returns pixel scale X (degrees/pixel in lon direction)
Sourcepub fn pixel_scale_y(&self) -> Option<f64>
pub fn pixel_scale_y(&self) -> Option<f64>
Returns pixel scale Y (degrees/pixel in lat direction, negative)
Sourcepub fn tiepoint_geo_x(&self) -> Option<f64>
pub fn tiepoint_geo_x(&self) -> Option<f64>
Returns tiepoint geo X (top-left longitude)
Sourcepub fn tiepoint_geo_y(&self) -> Option<f64>
pub fn tiepoint_geo_y(&self) -> Option<f64>
Returns tiepoint geo Y (top-left latitude)
Trait Implementations§
Source§impl Default for WasmCogViewer
impl Default for WasmCogViewer
Source§impl From<WasmCogViewer> for JsValue
impl From<WasmCogViewer> for JsValue
Source§fn from(value: WasmCogViewer) -> Self
fn from(value: WasmCogViewer) -> Self
Source§impl FromWasmAbi for WasmCogViewer
impl FromWasmAbi for WasmCogViewer
Source§impl IntoWasmAbi for WasmCogViewer
impl IntoWasmAbi for WasmCogViewer
Source§impl LongRefFromWasmAbi for WasmCogViewer
impl LongRefFromWasmAbi for WasmCogViewer
Source§impl OptionFromWasmAbi for WasmCogViewer
impl OptionFromWasmAbi for WasmCogViewer
Source§impl OptionIntoWasmAbi for WasmCogViewer
impl OptionIntoWasmAbi for WasmCogViewer
Source§impl RefFromWasmAbi for WasmCogViewer
impl RefFromWasmAbi for WasmCogViewer
Source§type Anchor = RcRef<WasmCogViewer>
type Anchor = RcRef<WasmCogViewer>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for WasmCogViewer
impl RefMutFromWasmAbi for WasmCogViewer
Source§impl TryFromJsValue for WasmCogViewer
impl TryFromJsValue for WasmCogViewer
Source§impl VectorFromWasmAbi for WasmCogViewer
impl VectorFromWasmAbi for WasmCogViewer
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[WasmCogViewer]>
Source§impl VectorIntoWasmAbi for WasmCogViewer
impl VectorIntoWasmAbi for WasmCogViewer
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[WasmCogViewer]>) -> Self::Abi
Source§impl WasmDescribeVector for WasmCogViewer
impl WasmDescribeVector for WasmCogViewer
impl SupportsConstructor for WasmCogViewer
impl SupportsInstanceProperty for WasmCogViewer
impl SupportsStaticProperty for WasmCogViewer
Auto Trait Implementations§
impl Freeze for WasmCogViewer
impl RefUnwindSafe for WasmCogViewer
impl Send for WasmCogViewer
impl Sync for WasmCogViewer
impl Unpin for WasmCogViewer
impl UnsafeUnpin for WasmCogViewer
impl UnwindSafe for WasmCogViewer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.