Crate cjseq2

Crate cjseq2 

Source
Expand description

§CityJSONSeq

Create, process, modify, and convert CityJSONSeq files.

§Cross-platform Support

This crate supports both native platforms and WebAssembly (WASM):

  • Native platforms: Uses reqwest for HTTP requests.
  • WASM targets: Uses gloo-net for HTTP requests.

When compiling for WASM, note that some functionality works differently:

  • The synchronous fetch_from_url method returns a placeholder in WASM environments.
  • Use the fetch_from_url_async method when working with WASM targets.

§Example

use cjseq2::{CityJSON, CityJSONFeature, Extension, ExtensionFile};
use std::collections::HashMap;

// To process a CityJSON file:
let json_str = std::fs::read_to_string("path/to/file.json").unwrap();
let city_json = CityJSON::from_str(&json_str).unwrap();

// To fetch extension data (native platforms):
#[cfg(not(target_arch = "wasm32"))]
{
    // Make sure to create a long-lived reference to the extension
    let extensions = &city_json.extensions.unwrap();
    let extension = extensions.get("my_extension").unwrap();
    let extension_file = extension.fetch_extension_file("MyExt".to_string()).unwrap();
}

// To fetch extension data (WASM):
#[cfg(target_arch = "wasm32")]
async {
    if let Some(extensions) = &city_json.extensions {
        if let Some(extension) = extensions.get("my_extension") {
            let extension_file = ExtensionFile::fetch_from_url_async(
                "MyExt".to_string(),
                extension.url.clone(),
                extension.version.clone()
            ).await.unwrap();
        }
    }
}

Re-exports§

pub use error::*;

Modules§

conv
error

Structs§

Address
Appearance
CityJSON
CityJSONFeature
CityObject
Extension
ExtensionFile
Geometry
GeometryTemplates
MaterialObject
MaterialReference
Metadata
PointOfContact
ReferenceSystem
A reference system following the OGC Name Type Specification.
Semantics
SemanticsSurface
TextureObject
TextureReference
Transform

Enums§

GeometryType
NestedArray
Our nested structure, generic over T.
SortingStrategy
TextFormat
TextType
WrapMode

Traits§

JsonIndex
Validate

Type Aliases§

Boundaries
For convenience, define Boundaries as NestedArray<u32> (no null allowed).
GeographicalExtent
MaterialValues
SemanticsValues
For Semantics, define SemanticsValues as NestedArray<Option<u32>> (null allowed).
TextureValues