Skip to content

map constructor with object as property #15

Open
@ttdonovan

Description

@ttdonovan

This may not specifically be an issue with leaflet-rs and more of a wasm_bindgen question but looking for suggestions how to approach this. Thanks in advanced.

Example of the JS constructor that I am wanting.

const map = L.map("map", {
  crs: L.CRS.Simple,
  minZoom: -3,
  maxBoundsViscosity: 1.0,
});

What to do in Rust or how to add L.CRS to the bindings?

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct MapOptions {
    // crs: ???, // this is JS object... L.CRS.Simple
    min_zoom: i32,
    max_bounds_viscosity: f64,
}

...

let options = JsValue::from_serde(&MapOptions {
    // crs: "L.CRS.Simple".to_string(), // how to make this a serializable JS Object...
    min_zoom: -3,
    max_bounds_viscosity: 1.0,
}).expect("Unable to serialize map options");

let map = Map::new("map", &options);

My goal is to add a game map and here is my feeble attempt...

master...ttdonovan:image-overlay

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions