use super::ResponseFormat;
use crate::{
ExportMapParams, ExportResult, ExportTarget, ImageFormat, LayerOperation, MapServiceClient,
Result, TimeRelation,
};
use tracing::instrument;
pub struct ExportMapBuilder<'a> {
client: &'a MapServiceClient<'a>,
params: ExportMapParams,
}
impl<'a> ExportMapBuilder<'a> {
#[instrument(skip(client))]
pub(crate) fn new(client: &'a MapServiceClient<'a>) -> Self {
tracing::debug!("Creating ExportMapBuilder");
Self {
client,
params: ExportMapParams::default(),
}
}
pub fn bbox(mut self, bbox: impl Into<String>) -> Self {
self.params.set_bbox(bbox.into());
self
}
pub fn bbox_sr(mut self, wkid: i32) -> Self {
self.params.set_bbox_sr(Some(wkid));
self
}
pub fn layers(mut self, layers: impl Into<String>) -> Self {
self.params.set_layers(Some(layers.into()));
self
}
pub fn layer_visibility(mut self, operation: LayerOperation, layer_ids: &[i32]) -> Self {
let ids = layer_ids
.iter()
.map(|id| id.to_string())
.collect::<Vec<_>>()
.join(",");
self.params
.set_layers(Some(format!("{}:{}", operation.as_str(), ids)));
self
}
pub fn layer_defs(mut self, defs: impl Into<String>) -> Self {
self.params.set_layer_defs(Some(defs.into()));
self
}
pub fn size(mut self, width: u32, height: u32) -> Self {
self.params.set_size(Some(format!("{},{}", width, height)));
self
}
pub fn dpi(mut self, dpi: i32) -> Self {
self.params.set_dpi(Some(dpi));
self
}
pub fn image_sr(mut self, wkid: i32) -> Self {
self.params.set_image_sr(Some(wkid));
self
}
pub fn format(mut self, format: ImageFormat) -> Self {
self.params.set_format(Some(format));
self
}
pub fn transparent(mut self, transparent: bool) -> Self {
self.params.set_transparent(Some(transparent));
self
}
pub fn time(mut self, time: impl Into<String>) -> Self {
self.params.set_time(Some(time.into()));
self
}
pub fn time_relation(mut self, relation: TimeRelation) -> Self {
self.params.set_time_relation(Some(relation));
self
}
pub fn layer_time_options(mut self, options: impl Into<String>) -> Self {
self.params.set_layer_time_options(Some(options.into()));
self
}
pub fn dynamic_layers(mut self, layers: impl Into<String>) -> Self {
self.params.set_dynamic_layers(Some(layers.into()));
self
}
pub fn gdb_version(mut self, version: impl Into<String>) -> Self {
self.params.set_gdb_version(Some(version.into()));
self
}
pub fn map_scale(mut self, scale: f64) -> Self {
self.params.set_map_scale(Some(scale));
self
}
pub fn rotation(mut self, degrees: f64) -> Self {
self.params.set_rotation(Some(degrees));
self
}
pub fn datum_transformations(mut self, transformations: impl Into<String>) -> Self {
self.params
.set_datum_transformations(Some(transformations.into()));
self
}
pub fn map_range_values(mut self, values: impl Into<String>) -> Self {
self.params.set_map_range_values(Some(values.into()));
self
}
pub fn layer_parameter_values(mut self, values: impl Into<String>) -> Self {
self.params.set_layer_parameter_values(Some(values.into()));
self
}
pub fn pretty_json(mut self, pretty: bool) -> Self {
let format = if pretty {
ResponseFormat::PJson
} else {
ResponseFormat::Json
};
self.params.set_format_response(format);
self
}
pub fn response_format(mut self, format: ResponseFormat) -> Self {
self.params.set_format_response(format);
self
}
#[instrument(skip(self, target), fields(bbox = %self.params.bbox(), size = ?self.params.size()))]
pub async fn execute(self, target: ExportTarget) -> Result<ExportResult> {
tracing::debug!("Executing export");
self.client.export_map(self.params, target).await
}
}