1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Map Service.
//!
//! This module provides support for ArcGIS Map Services, which offer dynamic map
//! rendering, cached tile access, metadata retrieval, legend information, and
//! feature identification capabilities.
//!
//! # Operations
//!
//! - **Export Map** - Dynamically render and export map images with custom parameters
//! - **Export Tile** - Retrieve cached tiles from tiled/cached services
//! - **Get Legend** - Retrieve legend information for all layers
//! - **Get Metadata** - Retrieve service metadata (layers, extent, capabilities)
//! - **Identify** - Identify features at a specific location
//!
//! # Quick Start
//!
//! ```no_run
//! use arcgis::{ApiKeyAuth, ArcGISClient, MapServiceClient, ExportTarget, ImageFormat};
//!
//! # async fn example() -> arcgis::Result<()> {
//! 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/World/MapServer",
//! &client,
//! );
//!
//! // Export a map with fluent builder
//! let result = map_service
//! .export()
//! .bbox("-118.0,34.0,-117.0,35.0")
//! .size(800, 600)
//! .format(ImageFormat::Png32)
//! .transparent(true)
//! .execute(ExportTarget::to_path("map.png"))
//! .await?;
//!
//! // Get service metadata
//! let metadata = map_service.get_metadata().await?;
//! println!("Service has {} layers", metadata.layers().len());
//!
//! // Get legend
//! let legend = map_service.get_legend().await?;
//! for layer in legend.layers() {
//! println!("Layer {}: {}", layer.layer_id(), layer.layer_name());
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Export Targets
//!
//! Maps and tiles can be exported to three different targets:
//!
//! - **Path** - Stream directly to a file (most efficient for large images)
//! - **Bytes** - Collect into memory as `Vec<u8>` (convenient for small images)
//! - **Writer** - Stream to any `AsyncWrite` implementation
//!
//! ```no_run
//! # use arcgis::{MapServiceClient, ExportTarget};
//! # async fn example(service: &MapServiceClient<'_>) -> arcgis::Result<()> {
//! // To file
//! let result = service
//! .export()
//! .bbox("-118,34,-117,35")
//! .execute(ExportTarget::to_path("output.png"))
//! .await?;
//!
//! // To bytes
//! let result = service
//! .export()
//! .bbox("-118,34,-117,35")
//! .execute(ExportTarget::to_bytes())
//! .await?;
//!
//! if let Some(bytes) = result.bytes() {
//! // Process image bytes...
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Image Formats
//!
//! Supported image formats (via [`ImageFormat`]):
//!
//! - PNG variants: `Png`, `Png8`, `Png24`, `Png32` (supports transparency)
//! - `Jpg` - Compact, lossy compression
//! - `Gif` - Supports transparency
//! - Vector formats: `Pdf`, `Svg`, `Svgz`
//! - Others: `Bmp`, `Emf`, `Ps`
//!
//! # Layer Visibility
//!
//! Control which layers appear in exported maps using [`LayerOperation`]:
//!
//! ```no_run
//! # use arcgis::{MapServiceClient, ExportTarget, LayerOperation};
//! # async fn example(service: &MapServiceClient<'_>) -> arcgis::Result<()> {
//! // Show only specific layers
//! service
//! .export()
//! .bbox("-118,34,-117,35")
//! .layer_visibility(LayerOperation::Show, &[0, 1, 2])
//! .execute(ExportTarget::to_bytes())
//! .await?;
//!
//! // Hide specific layers
//! service
//! .export()
//! .bbox("-118,34,-117,35")
//! .layer_visibility(LayerOperation::Hide, &[3, 4])
//! .execute(ExportTarget::to_bytes())
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! # Cached Tiles
//!
//! For cached/tiled services, retrieve individual tiles:
//!
//! ```no_run
//! # use arcgis::{MapServiceClient, TileCoordinate, ExportTarget};
//! # async fn example(service: &MapServiceClient<'_>) -> arcgis::Result<()> {
//! let coord = TileCoordinate::new(5, 10, 15); // level, row, col
//! let result = service
//! .export_tile(coord, ExportTarget::to_bytes())
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! # Feature Identification
//!
//! Identify features at a location on the map:
//!
//! ```no_run
//! # use arcgis::{MapServiceClient, IdentifyParamsBuilder, LayerSelection, GeometryType};
//! # async fn example(service: &MapServiceClient<'_>) -> arcgis::Result<()> {
//! 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());
//! }
//! # Ok(())
//! # }
//! ```
pub use MapServiceClient;
pub use ;
pub use ExportMapBuilder;
pub use ;