forked from maplibre/maplibre-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
use std::marker::PhantomData; | ||
use cxx::{CxxVector, UniquePtr}; | ||
|
||
use crate::ffi; | ||
use crate::ffi::MapRenderer_setSize; | ||
|
||
/// Configuration options for a tile server. | ||
pub struct MapRenderer(UniquePtr<ffi::MapRenderer>); | ||
#[derive(Debug, Clone, Default)] | ||
pub struct ImageRendererOptions { | ||
pixel_ratio: f32, | ||
} | ||
|
||
impl MapRenderer { | ||
/// Create a new default configuration | ||
impl ImageRendererOptions { | ||
pub fn new() -> Self { | ||
Self(ffi::MapRenderer_new()) | ||
Self::default() | ||
} | ||
|
||
pub fn build_static_renderer(self) -> ImageRenderer<Static> { | ||
ImageRenderer::new(self.pixel_ratio) | ||
} | ||
|
||
pub fn set_size(&mut self, width: u32, height: u32) -> &mut Self { | ||
ffi::MapRenderer_setSize(self.0.pin_mut(), width, height); | ||
self | ||
pub fn build_tile_renderer(self) -> ImageRenderer<Static> { | ||
ImageRenderer::new(self.pixel_ratio) | ||
} | ||
} | ||
|
||
/// Internal state type to render a static map image. | ||
pub struct Static; | ||
/// Internal state type to render a map tile. | ||
pub struct Tile; | ||
|
||
/// Configuration options for a tile server. | ||
pub struct ImageRenderer<State>(UniquePtr<ffi::MapRenderer>, PhantomData<State>); | ||
|
||
impl<State> ImageRenderer<State> { | ||
/// Private constructor. | ||
fn new(_pixel_ratio: f32/*, mode: Mode*/) -> Self { | ||
let map = ffi::MapRenderer_new(); | ||
// map.set_pixel_ratio(self.pixel_ratio); | ||
// map.set_mode(self.mode); | ||
Self(map, PhantomData) | ||
} | ||
} | ||
|
||
pub fn render(&mut self) -> UniquePtr<CxxVector<u8>> { | ||
ffi::MapRenderer_render(self.0.pin_mut()) | ||
impl ImageRenderer<Static> { | ||
pub fn render_static(&mut self, width: u32, height: u32) -> Image { | ||
MapRenderer_setSize(self.0.pin_mut(), width, height); | ||
Image(ffi::MapRenderer_render(self.0.pin_mut()) ) | ||
} | ||
} | ||
|
||
impl Default for MapRenderer { | ||
fn default() -> Self { | ||
Self::new() | ||
impl ImageRenderer<Tile> { | ||
pub fn render_tile(&mut self, zoom: f64, x: u64, y: u64) -> Image { | ||
MapRenderer_setSize(self.0.pin_mut(), 512, 512); | ||
// TODO: set tile location | ||
Image(ffi::MapRenderer_render(self.0.pin_mut()) ) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests {} | ||
pub struct Image(UniquePtr<CxxVector<u8>>); | ||
|
||
impl Image { | ||
pub fn as_slice(&self) -> &[u8] { | ||
self.0.as_ref().unwrap().as_slice() | ||
} | ||
} |