async-geotiff 0.13.0

Async COG → XYZ tile renderer (pure Rust, no GDAL)
Documentation
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
//! `MosaicJsonSource` — read-only consumer of a pre-built cogeo-mosaic
//! MosaicJSON document (quadkey index). Building the index is out of scope.

use std::collections::{BTreeMap, HashMap};

use std::sync::Arc;

use serde::Deserialize;
use serde_json::Value;

use crate::bounds::Bbox;
use crate::error::{AgError, AgResult};
use crate::mosaic::quadkey::{lookup, QkLookup};
use crate::mosaic::source::{
    AssetDiscovery, AssetRef, DiscoveredAssets, DiscoveryOptions, MosaicSource,
};
use crate::tms::{TileCoord, TileMatrixSet};

// MosaicJson mirrors the MosaicJSON 0.0.3 schema. Some fields are not
// interpreted by the renderer yet, but they are preserved so crate users can
// expose metadata or implement their own policy on top.
/// MosaicJSON 0.0.3 document.
#[allow(dead_code)]
#[derive(Debug, Clone, Deserialize)]
pub struct MosaicJson {
    /// MosaicJSON specification version; the source accepts `0.0.3`.
    pub mosaicjson: String,
    /// Optional human-readable mosaic name.
    #[serde(default)]
    pub name: Option<String>,
    /// Optional description retained from the document.
    #[serde(default)]
    pub description: Option<String>,
    /// Producer's dataset version, defaulting to `1.0.0`.
    #[serde(default = "default_version")]
    pub version: String,
    /// Attribution text retained for consuming applications.
    #[serde(default)]
    pub attribution: Option<String>,
    /// Declared minimum display zoom and default quadkey index zoom.
    pub minzoom: u8,
    /// Declared maximum display zoom; source lookup also supports other valid tiles.
    pub maxzoom: u8,
    /// Fixed length of the quadkeys in `tiles`; defaults to `minzoom`.
    #[serde(default)]
    pub quadkey_zoom: Option<u8>,
    /// WGS84 mosaic extent `[west, south, east, north]`; defaults to the world.
    #[serde(default = "world_bounds")]
    pub bounds: [f64; 4],
    /// Suggested `[longitude, latitude, zoom]`, discarded if outside the declared bounds.
    #[serde(default)]
    pub center: Option<[f64; 3]>,
    /// WebMercator quadkeys mapped to assets in paint order, first asset on top.
    pub tiles: HashMap<String, Vec<String>>,
    /// Producer's asset type hint, retained without changing transport selection.
    #[serde(default)]
    pub asset_type: Option<String>,
    /// Literal prefix prepended to every asset location during lookup.
    #[serde(default)]
    pub asset_prefix: Option<String>,
    /// Optional sample type name; unrecognized names are discarded by the source.
    #[serde(default)]
    pub data_type: Option<String>,
    /// Producer's RGBA color metadata; rendering uses the supplied Raster Style.
    #[serde(default)]
    pub colormap: BTreeMap<String, [f64; 4]>,
    /// Retained tile matrix metadata; it does not change the WebMercator index.
    #[serde(default)]
    pub tilematrixset: Option<Value>,
    /// Producer-defined layer metadata, retained without interpretation.
    #[serde(default)]
    pub layers: BTreeMap<String, Value>,
    /// Unrecognized top-level extension fields retained for callers.
    #[serde(flatten)]
    pub extra: BTreeMap<String, Value>,
}

/// Recognized MosaicJSON sample type hints; these do not override TIFF metadata.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MosaicDataType {
    /// Signed 8-bit integer samples.
    Int8,
    /// Signed 16-bit integer samples.
    Int16,
    /// Signed 32-bit integer samples.
    Int32,
    /// Signed 64-bit integer samples.
    Int64,
    /// Unsigned 8-bit integer samples.
    UInt8,
    /// Unsigned 16-bit integer samples.
    UInt16,
    /// Unsigned 32-bit integer samples.
    UInt32,
    /// Unsigned 64-bit integer samples.
    UInt64,
    /// Half-precision floating-point samples.
    Float16,
    /// Single-precision floating-point samples.
    Float32,
    /// Double-precision floating-point samples.
    Float64,
    /// Complex samples with signed 16-bit integer components.
    CInt16,
    /// Complex samples with signed 32-bit integer components.
    CInt32,
    /// Complex samples with single-precision floating-point components.
    CFloat32,
    /// Complex samples with double-precision floating-point components.
    CFloat64,
    /// Explicit producer declaration of another sample type.
    Other,
}

impl MosaicDataType {
    /// Parse a lowercase MosaicJSON type name, returning `None` for unknown names.
    pub fn parse(s: &str) -> Option<Self> {
        match s {
            "int8" => Some(Self::Int8),
            "int16" => Some(Self::Int16),
            "int32" => Some(Self::Int32),
            "int64" => Some(Self::Int64),
            "uint8" => Some(Self::UInt8),
            "uint16" => Some(Self::UInt16),
            "uint32" => Some(Self::UInt32),
            "uint64" => Some(Self::UInt64),
            "float16" => Some(Self::Float16),
            "float32" => Some(Self::Float32),
            "float64" => Some(Self::Float64),
            "cint16" => Some(Self::CInt16),
            "cint32" => Some(Self::CInt32),
            "cfloat32" => Some(Self::CFloat32),
            "cfloat64" => Some(Self::CFloat64),
            "other" => Some(Self::Other),
            _ => None,
        }
    }
}

fn world_bounds() -> [f64; 4] {
    [-180.0, -90.0, 180.0, 90.0]
}

fn default_version() -> String {
    "1.0.0".into()
}

/// A [`MosaicSource`] backed by a cogeo-mosaic MosaicJSON quadkey index.
///
/// MosaicJSON quadkey indices are defined in the WebMercatorQuad tile matrix;
/// using this source with another TMS is not meaningful.
#[derive(Clone)]
pub struct MosaicJsonSource {
    doc: Arc<MosaicJson>,
    tile_keys: Arc<Vec<String>>,
    quadkey_zoom: u8,
    bbox: Bbox,
}

impl MosaicJsonSource {
    /// Parse a MosaicJSON document from raw JSON bytes/string.
    #[allow(clippy::should_implement_trait)]
    pub fn from_str(json: &str) -> AgResult<Self> {
        let mut doc: MosaicJson = serde_json::from_str(json)
            .map_err(|e| AgError::Mosaic(format!("parse MosaicJSON: {e}")))?;
        validate_document(&mut doc)?;
        let quadkey_zoom = doc.quadkey_zoom.unwrap_or(doc.minzoom);
        let b = doc.bounds;
        let mut tile_keys: Vec<_> = doc.tiles.keys().cloned().collect();
        tile_keys.sort_unstable();
        Ok(Self {
            tile_keys: Arc::new(tile_keys),
            quadkey_zoom,
            bbox: Bbox::new(b[0], b[1], b[2], b[3]),
            doc: Arc::new(doc),
        })
    }

    /// WGS84 bounds of the whole mosaic (mosaic-level, not per-asset).
    pub fn bounds(&self) -> Bbox {
        self.bbox
    }

    /// Parsed MosaicJSON document, including metadata and unknown extension
    /// fields preserved in [`MosaicJson::extra`].
    pub fn document(&self) -> &MosaicJson {
        &self.doc
    }
}

fn prefix_key_range(keys: &[String], prefix: &str) -> std::ops::Range<usize> {
    let start = keys.partition_point(|key| key.as_str() < prefix);
    let mut upper = prefix.to_owned();
    upper.push('4');
    let end = keys.partition_point(|key| key < &upper);
    start..end
}

fn validate_document(doc: &mut MosaicJson) -> AgResult<()> {
    if doc.mosaicjson != "0.0.3" {
        return Err(AgError::Mosaic(format!(
            "unsupported MosaicJSON version {}; expected 0.0.3",
            doc.mosaicjson
        )));
    }
    if doc.minzoom > 30 || doc.maxzoom > 30 {
        return Err(AgError::Mosaic(
            "minzoom/maxzoom must be between 0 and 30".into(),
        ));
    }
    if doc.maxzoom < doc.minzoom {
        return Err(AgError::Mosaic("maxzoom must be >= minzoom".into()));
    }
    let quadkey_zoom = doc.quadkey_zoom.unwrap_or(doc.minzoom);
    if quadkey_zoom > 30 || quadkey_zoom > doc.maxzoom {
        return Err(AgError::Mosaic(
            "quadkey_zoom must be between 0 and maxzoom".into(),
        ));
    }
    if doc.tiles.is_empty() {
        return Err(AgError::Mosaic("MosaicJSON has no tiles".into()));
    }
    for key in doc.tiles.keys() {
        if key.len() != usize::from(quadkey_zoom)
            || key.len() > 30
            || !key.bytes().all(|b| matches!(b, b'0'..=b'3'))
        {
            return Err(AgError::Mosaic(format!(
                "invalid quadkey {key:?}; expected length {quadkey_zoom}"
            )));
        }
    }
    if doc.bounds[0] > doc.bounds[2] || doc.bounds[1] > doc.bounds[3] {
        return Err(AgError::Mosaic(
            "bounds must be [left, bottom, right, top]".into(),
        ));
    }
    if let Some(center) = doc.center {
        let [lon, lat, zoom] = center;
        if lon < doc.bounds[0]
            || lon > doc.bounds[2]
            || lat < doc.bounds[1]
            || lat > doc.bounds[3]
            || zoom < f64::from(doc.minzoom)
            || zoom > f64::from(doc.maxzoom)
        {
            doc.center = None;
        }
    }
    if doc
        .data_type
        .as_deref()
        .and_then(MosaicDataType::parse)
        .is_none()
    {
        doc.data_type = None;
    }
    Ok(())
}

#[async_trait::async_trait]
impl MosaicSource for MosaicJsonSource {
    async fn statistics_assets(&self) -> AgResult<Vec<AssetRef>> {
        // A flat collection cannot represent per-quadkey coverage and paint order.
        if self.quadkey_zoom != 0 {
            return Err(AgError::query(
                "statistics",
                "MosaicJSON statistical stretch requires quadkey_zoom=0; partitioned statistics are unsupported",
            ));
        }
        self.assets_for_tile(TileCoord {
            tms: TileMatrixSet::WebMercatorQuad,
            z: 0,
            x: 0,
            y: 0,
        })
        .await
    }

    async fn assets_for_tile(&self, coord: TileCoord) -> AgResult<Vec<AssetRef>> {
        if coord.tms != TileMatrixSet::WebMercatorQuad {
            return Err(AgError::query(
                "tms",
                "MosaicJSON quadkey indexes only support WebMercatorQuad",
            ));
        }

        Ok(self
            .assets_for_tile_with_options(coord, &DiscoveryOptions::default())
            .await?
            .into_assets())
    }

    async fn statistics_assets_with_options(
        &self,
        options: &DiscoveryOptions,
    ) -> AgResult<DiscoveredAssets> {
        if self.quadkey_zoom != 0 {
            return Err(AgError::query("statistics", "MosaicJSON statistical stretch requires quadkey_zoom=0; partitioned statistics are unsupported"));
        }
        self.assets_for_tile_with_options(
            TileCoord {
                tms: TileMatrixSet::WebMercatorQuad,
                z: 0,
                x: 0,
                y: 0,
            },
            options,
        )
        .await
    }

    async fn assets_for_tile_with_options(
        &self,
        coord: TileCoord,
        options: &DiscoveryOptions,
    ) -> AgResult<DiscoveredAssets> {
        if coord.tms != TileMatrixSet::WebMercatorQuad {
            return Err(AgError::query(
                "tms",
                "MosaicJSON quadkey indexes only support WebMercatorQuad",
            ));
        }
        crate::tms::Tms::cached(coord.tms)?.validate_tile(coord.z, coord.x, coord.y)?;
        let source = self.clone();
        let options = options.clone();
        let permit = options.cpu_limiter.acquire().await?;
        let request = crate::request::RequestContext::current();
        tokio::task::spawn_blocking(move || {
            let _permit = permit;
            crate::request::RequestContext::run_blocking(request.clone(), || {
                let mut out = AssetDiscovery::new(options.clone());
                let mut add = |urls: &[String]| -> AgResult<()> {
                    for url in urls {
                        if let Some(request) = &request {
                            request.check()?;
                        }
                        let prefix = source.doc.asset_prefix.as_deref().unwrap_or("");
                        let len = prefix
                            .len()
                            .checked_add(url.len())
                            .filter(|n| *n <= options.max_asset_bytes)
                            .ok_or_else(|| {
                                AgError::ResourceLimit(
                                    "asset URL exceeds discovery byte limit".into(),
                                )
                            })?;
                        if prefix.is_empty() {
                            out.push(url, url, source.bbox)?;
                        } else {
                            let _temporary = options.work_budget.try_reserve(len as u64)?;
                            let href = format!("{prefix}{url}");
                            out.push(&href, &href, source.bbox)?;
                        }
                    }
                    Ok(())
                };
                match lookup(coord.z, coord.x, coord.y, source.quadkey_zoom) {
                    QkLookup::Exact(key) => {
                        if let Some(urls) = source.doc.tiles.get(&key) {
                            add(urls)?;
                        }
                    }
                    QkLookup::Prefix(prefix) => {
                        for key in &source.tile_keys[prefix_key_range(&source.tile_keys, &prefix)] {
                            if let Some(request) = &request {
                                request.check()?;
                            }
                            if let Some(urls) = source.doc.tiles.get(key) {
                                add(urls)?;
                            }
                        }
                    }
                }
                Ok(out.finish())
            })
        })
        .await
        .map_err(|e| AgError::Mosaic(format!("discovery join: {e}")))?
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    const DOC: &str = r#"{
      "mosaicjson": "0.0.3",
      "name": "fixture",
      "version": "1.2.3",
      "attribution": "test",
      "minzoom": 7,
      "maxzoom": 12,
      "quadkey_zoom": 7,
      "bounds": [0.0, 0.0, 10.0, 10.0],
      "center": [5.0, 5.0, 8],
      "asset_type": "COG",
      "asset_prefix": "https://x/",
      "data_type": "uint16",
      "colormap": {"0": [0, 0, 0, 0]},
      "tilematrixset": {"id": "WebMercatorQuad"},
      "layers": {"rgb": {"bidx": ["b1", "b2", "b3"]}},
      "vendor:extension": {"ok": true},
      "tiles": {
        "1230123": ["a.tif", "b.tif"],
        "1230120": ["c.tif"]
      }
    }"#;

    fn coord_for_quadkey(quadkey: &str) -> TileCoord {
        let (mut x, mut y) = (0u32, 0u32);
        for ch in quadkey.chars() {
            x <<= 1;
            y <<= 1;
            match ch {
                '0' => {}
                '1' => x |= 1,
                '2' => y |= 1,
                '3' => {
                    x |= 1;
                    y |= 1;
                }
                _ => unreachable!(),
            }
        }
        TileCoord {
            tms: TileMatrixSet::WebMercatorQuad,
            z: quadkey.len() as u8,
            x,
            y,
        }
    }

    #[test]
    fn prefix_key_range_limits_candidates() {
        let keys = ["0000000", "1230120", "1230123", "2000000"]
            .map(str::to_owned)
            .to_vec();

        let matching = prefix_key_range(&keys, "123012");
        assert_eq!(&keys[matching], &["1230120", "1230123"]);

        let all = prefix_key_range(&keys, "");
        assert_eq!(all, 0..keys.len());
    }

    #[tokio::test]
    async fn invalid_coordinates_fail_before_quadkey_lookup() {
        let source = MosaicJsonSource::from_str(DOC).unwrap();
        for (z, x, y) in [(1, 2, 0), (1, 0, 2), (33, 17, 19), (u8::MAX, 0, 0)] {
            let coord = TileCoord {
                tms: TileMatrixSet::WebMercatorQuad,
                z,
                x,
                y,
            };
            assert!(matches!(source.assets_for_tile(coord).await,
                Err(AgError::TileOutOfBounds { z: ez, x: ex, y: ey }) if (ez, ex, ey) == (z, x, y)));
            assert!(
                matches!(source.assets_for_tile_with_options(coord, &DiscoveryOptions::default()).await,
                Err(AgError::TileOutOfBounds { z: ez, x: ex, y: ey }) if (ez, ex, ey) == (z, x, y))
            );
        }
    }

    #[tokio::test]
    async fn lower_zoom_unions_matching_prefix_assets() {
        let source = MosaicJsonSource::from_str(DOC).unwrap();
        let got = source
            .assets_for_tile(coord_for_quadkey("123012"))
            .await
            .unwrap();
        let urls: Vec<_> = got.iter().map(|asset| asset.url.as_str()).collect();

        assert_eq!(
            urls,
            vec!["https://x/c.tif", "https://x/a.tif", "https://x/b.tif"]
        );
    }

    #[tokio::test]
    async fn zoom_zero_empty_prefix_returns_all_assets() {
        let source = MosaicJsonSource::from_str(DOC).unwrap();
        let got = source.assets_for_tile(coord_for_quadkey("")).await.unwrap();
        let urls: Vec<_> = got.iter().map(|asset| asset.url.as_str()).collect();

        assert_eq!(
            urls,
            vec!["https://x/c.tif", "https://x/a.tif", "https://x/b.tif"]
        );
    }

    #[tokio::test]
    async fn exact_zoom_returns_listed_assets() {
        let s = MosaicJsonSource::from_str(DOC).unwrap();
        let got = s
            .assets_for_tile(coord_for_quadkey("1230123"))
            .await
            .unwrap();
        let urls: Vec<_> = got.iter().map(|a| a.url.as_str()).collect();
        assert_eq!(urls, vec!["https://x/a.tif", "https://x/b.tif"]);
    }

    #[test]
    fn preserves_mosaicjson_003_metadata_and_unknown_fields() {
        let s = MosaicJsonSource::from_str(DOC).unwrap();
        let doc = s.document();
        assert_eq!(doc.name.as_deref(), Some("fixture"));
        assert_eq!(doc.version, "1.2.3");
        assert_eq!(doc.attribution.as_deref(), Some("test"));
        assert_eq!(doc.center, Some([5.0, 5.0, 8.0]));
        assert_eq!(doc.asset_type.as_deref(), Some("COG"));
        assert_eq!(doc.asset_prefix.as_deref(), Some("https://x/"));
        assert_eq!(doc.data_type.as_deref(), Some("uint16"));
        assert_eq!(doc.colormap["0"], [0.0, 0.0, 0.0, 0.0]);
        assert_eq!(doc.tilematrixset.as_ref().unwrap()["id"], "WebMercatorQuad");
        assert!(doc.layers.contains_key("rgb"));
        assert!(doc.extra.contains_key("vendor:extension"));
    }

    #[tokio::test]
    async fn bounded_discovery_counts_unique_urls_and_keeps_leases() {
        let source = MosaicJsonSource::from_str(r#"{"mosaicjson":"0.0.3","minzoom":0,"maxzoom":1,"quadkey_zoom":0,"tiles":{"": ["a", "a", "b"]}}"#).unwrap();
        let budget = crate::resource::WorkBudget::new(4096);
        let options = DiscoveryOptions {
            max_assets: 2,
            work_budget: budget.clone(),
            ..DiscoveryOptions::default()
        };
        let assets = source
            .statistics_assets_with_options(&options)
            .await
            .unwrap();
        assert_eq!(
            assets
                .assets()
                .iter()
                .map(|a| a.url.as_str())
                .collect::<Vec<_>>(),
            ["a", "b"]
        );
        assert!(budget.used_bytes() > 0);
        drop(assets);
        assert_eq!(budget.used_bytes(), 0);
        let capped = DiscoveryOptions {
            max_assets: 1,
            ..options.clone()
        };
        assert!(source
            .assets_for_tile_with_options(coord_for_quadkey(""), &capped)
            .await
            .is_err());
        assert!(source
            .statistics_assets_with_options(&capped)
            .await
            .is_err());
        assert_eq!(budget.used_bytes(), 0);
        let tiny = DiscoveryOptions {
            max_asset_bytes: 1,
            ..options
        };
        assert!(matches!(
            source.statistics_assets_with_options(&tiny).await,
            Err(AgError::ResourceLimit(_))
        ));
        assert_eq!(budget.used_bytes(), 0);
    }

    #[test]
    fn empty_tiles_is_error() {
        let bad = r#"{"mosaicjson":"0.0.3","minzoom":1,"maxzoom":2,"bounds":[-180,-90,180,90],"tiles":{}}"#;
        assert!(MosaicJsonSource::from_str(bad).is_err());
    }

    #[tokio::test]
    async fn rejects_non_webmercator_tile_matrix_set() {
        let s = MosaicJsonSource::from_str(DOC).unwrap();
        let err = s
            .assets_for_tile(TileCoord {
                tms: TileMatrixSet::WorldCrs84Quad,
                z: 7,
                x: 0,
                y: 0,
            })
            .await
            .unwrap_err();
        assert!(matches!(err, AgError::Query { name, .. } if name == "tms"));
    }

    #[test]
    fn invalid_optional_data_type_is_ignored() {
        let doc = r#"{
          "mosaicjson": "0.0.3",
          "minzoom": 1,
          "maxzoom": 2,
          "quadkey_zoom": 1,
          "bounds": [-180, -90, 180, 90],
          "data_type": "bogus",
          "tiles": {"0": ["a.tif"]}
        }"#;
        let s = MosaicJsonSource::from_str(doc).unwrap();
        assert!(s.document().data_type.is_none());
    }

    #[test]
    fn invalid_quadkey_zoom_or_key_is_error() {
        let bad_zoom = r#"{
          "mosaicjson": "0.0.3",
          "minzoom": 1,
          "maxzoom": 2,
          "quadkey_zoom": 3,
          "bounds": [-180, -90, 180, 90],
          "tiles": {"000": ["a.tif"]}
        }"#;
        assert!(MosaicJsonSource::from_str(bad_zoom).is_err());

        let bad_key = r#"{
          "mosaicjson": "0.0.3",
          "minzoom": 1,
          "maxzoom": 2,
          "quadkey_zoom": 1,
          "bounds": [-180, -90, 180, 90],
          "tiles": {"04": ["a.tif"]}
        }"#;
        assert!(MosaicJsonSource::from_str(bad_key).is_err());
    }
}