Skip to main content

MapServiceClient

Struct MapServiceClient 

Source
pub struct MapServiceClient<'a> { /* private fields */ }
Expand description

Client for interacting with an ArcGIS Map Service.

Map Services provide dynamic map rendering, cached tiles, metadata, legend information, and feature identification capabilities.

§Example

use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient, ExportTarget};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);

let map_service = MapServiceClient::new(
    "https://services.arcgis.com/org/arcgis/rest/services/MapName/MapServer",
    &client,
);

// Export a map image
let result = map_service
    .export()
    .bbox("-180,-90,180,90")
    .size(800, 600)
    .execute(ExportTarget::to_path("map.png"))
    .await?;

Implementations§

Source§

impl<'a> MapServiceClient<'a>

Source

pub fn new(base_url: impl Into<String>, client: &'a ArcGISClient) -> Self

Creates a new Map Service client.

§Arguments
  • base_url - The base URL of the map service (e.g., https://services.arcgis.com/.../MapServer)
  • client - Reference to an authenticated ArcGIS client
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);

let map_service = MapServiceClient::new(
    "https://services.arcgis.com/org/arcgis/rest/services/MapName/MapServer",
    &client,
);
Source

pub fn export(&'a self) -> ExportMapBuilder<'a>

Creates a fluent builder for exporting maps.

This is the recommended way to export maps. It provides a more ergonomic API than manually constructing ExportMapParams.

§Example
use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient, ExportTarget, ImageFormat};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new(
    "https://services.arcgis.com/org/arcgis/rest/services/World/MapServer",
    &client,
);

// Use the fluent export builder
let result = service
    .export()
    .bbox("-118.0,34.0,-117.0,35.0")
    .size(800, 600)
    .format(ImageFormat::Png32)
    .transparent(true)
    .execute(ExportTarget::to_bytes())
    .await?;

if let Some(bytes) = result.bytes() {
    println!("Exported {} bytes", bytes.len());
}
Source

pub async fn export_map( &self, params: ExportMapParams, target: ExportTarget, ) -> Result<ExportResult>

Exports a map with pre-built parameters.

For most use cases, prefer using the fluent export() builder. This method is useful when you need to construct parameters programmatically or reuse the same parameters multiple times.

§Arguments
  • params - Export parameters (bbox is required)
  • target - Where to write the exported image (Path, Bytes, or Writer)
§Example
use arcgis::{
    ApiKeyAuth, ArcGISClient, MapServiceClient, ExportMapParams,
    ExportMapParamsBuilder, ExportTarget, ImageFormat,
};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let params = ExportMapParamsBuilder::default()
    .bbox("-118.0,34.0,-117.0,35.0".to_string())
    .size("800,600".to_string())
    .format(ImageFormat::Png32)
    .build()
    .expect("Valid params");

let result = service
    .export_map(params, ExportTarget::to_path("map.png"))
    .await?;
Source

pub async fn export_tile( &self, coord: TileCoordinate, target: ExportTarget, ) -> Result<ExportResult>

Exports a tile from a cached map service.

Retrieves a specific tile from a tiled/cached map service. Not all map services support tiles - check service metadata first.

§Arguments
  • coord - Tile coordinate (level, row, column)
  • target - Where to write the tile image (Path, Bytes, or Writer)
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient, TileCoordinate, ExportTarget};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

// Get tile at level 5, row 10, column 15
let coord = TileCoordinate::new(5, 10, 15);
let result = service
    .export_tile(coord, ExportTarget::to_bytes())
    .await?;
Source

pub async fn get_legend(&self) -> Result<LegendResponse>

Retrieves the legend for all layers in the map service.

The legend provides information about the symbols and labels used to represent features in each layer.

§Example
use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let legend = service.get_legend().await?;

for layer in legend.layers() {
    println!("Layer {}: {}", layer.layer_id(), layer.layer_name());
    for symbol in layer.legend() {
        println!("  - {}", symbol.label());
    }
}
Source

pub async fn get_metadata(&self) -> Result<MapServiceMetadata>

Retrieves metadata about the map service.

Provides comprehensive information about the service including layers, spatial reference, extent, tile info (if cached), and capabilities.

§Example
use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let metadata = service.get_metadata().await?;

println!("Layers: {}", metadata.layers().len());
if let Some(desc) = metadata.description() {
    println!("Description: {}", desc);
}
Source

pub async fn identify(&self, params: IdentifyParams) -> Result<IdentifyResponse>

Identifies features at a specific location on the map.

Returns information about features from visible layers at the specified geometry (typically a point, but can be other geometries).

§Arguments
  • params - Identify parameters (geometry and image extent are required)
§Example
use arcgis::{
    ApiKeyAuth, ArcGISClient, MapServiceClient, IdentifyParams,
    IdentifyParamsBuilder, LayerSelection, GeometryType,
};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let params = IdentifyParamsBuilder::default()
    .geometry("{\"x\":-118.0,\"y\":34.0}".to_string())
    .geometry_type(GeometryType::Point)
    .map_extent("-120,32,-116,36".to_string())
    .image_display("800,600,96".to_string())
    .layers(LayerSelection::Visible)
    .build()
    .expect("Valid params");

let response = service.identify(params).await?;

for result in response.results() {
    println!("Found feature in layer {}", result.layer_id());
}
Source

pub async fn find(&self, params: FindParams) -> Result<FindResponse>

Searches for features containing the specified text in a map service.

The find operation searches for text in one or more fields across multiple layers. It returns features that contain the search text along with their attributes and geometries.

§Arguments
  • params - Find parameters including search text, layers, and fields to search
§Example
use arcgis::{ArcGISClient, ApiKeyAuth, MapServiceClient, FindParams};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let params = FindParams::builder()
    .search_text("Main Street")
    .layers(vec![0, 1])
    .search_fields(vec!["NAME".to_string(), "STREET".to_string()])
    .build()
    .expect("Valid params");

let result = service.find(params).await?;
Source

pub async fn generate_kml(&self, params: GenerateKmlParams) -> Result<String>

Generates KML (Keyhole Markup Language) output for the map service.

This operation returns a KML representation of the map that can be used in Google Earth and other KML viewers.

§Arguments
  • params - Parameters for KML generation including layers and image options
§Example
use arcgis::{ArcGISClient, ApiKeyAuth, MapServiceClient, GenerateKmlParams};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let params = GenerateKmlParams::builder()
    .doc_name("MyMap")
    .layers(vec![0, 1])
    .build()
    .expect("Valid params");

let kml = service.generate_kml(params).await?;
Source

pub async fn generate_renderer( &self, layer_id: i32, params: GenerateRendererParams, ) -> Result<RendererResponse>

Generates a classification renderer for a layer.

This operation generates renderer definitions (symbols, colors, class breaks) based on the data in a layer field. Useful for creating dynamic visualizations like choropleth maps, graduated symbols, etc.

§Arguments
  • layer_id - The layer to generate renderer for
  • params - Parameters for renderer generation including classification method
§Example
use arcgis::{ArcGISClient, ApiKeyAuth, MapServiceClient, GenerateRendererParams};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

let params = GenerateRendererParams::builder()
    .classification_field("POPULATION")
    .classification_method("natural-breaks")
    .break_count(5)
    .build()
    .expect("Valid params");

let renderer = service.generate_renderer(0, params).await?;
Source

pub async fn query_domains( &self, layers: Vec<LayerId>, ) -> Result<QueryDomainsResponse>

Queries field domains and subtype information for map service layers.

This operation retrieves domain definitions (coded values, ranges) and subtype information for one or more layers in the map service. Useful for understanding valid values and field constraints.

§Arguments
  • layers - Vector of layer IDs to query domains for (empty for all layers)
§Example
use arcgis::{ArcGISClient, ApiKeyAuth, MapServiceClient, LayerId};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let service = MapServiceClient::new("https://example.com/MapServer", &client);

// Query domains for specific layers
let domains = service
    .query_domains(vec![LayerId::new(0), LayerId::new(1)])
    .await?;

// Query domains for all layers
let all_domains = service.query_domains(vec![]).await?;

Auto Trait Implementations§

§

impl<'a> Freeze for MapServiceClient<'a>

§

impl<'a> !RefUnwindSafe for MapServiceClient<'a>

§

impl<'a> Send for MapServiceClient<'a>

§

impl<'a> Sync for MapServiceClient<'a>

§

impl<'a> Unpin for MapServiceClient<'a>

§

impl<'a> !UnwindSafe for MapServiceClient<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more