mbtmap_rabbita

    Maps in rabbita apps: the mbt-map element as a view, its events as messages

    map
    gis
    webgis
    rabbita
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    9 hours ago
    Downloads
    7

    #t-ujiie-g/mbtmap_rabbita

    Maps in rabbita apps (js target): the <mbt-map> element of the mbt-map npm package as a view, its events as messages, and the typed API of t-ujiie-g/mbtmap from update.

    moon add t-ujiie-g/mbtmap_rabbita npm install mbt-map # or an import map for "mbt-map" and "mbt-map/element"

    priv enum Msg {
    Moved(@mbtmap_rabbita.Camera)
    Clicked(@mbtmap_rabbita.Click)
    GoTo(@mbtmap.LngLat)
    }

    fn app() -> @rabbita.Val[@html.Html] {
    let (model, emit) = @rabbita.create_state_with_init(
    // Give the map its style and camera once the view is on the page.
    init=_ => (None, @mbtmap_rabbita.setup("map", style(), center=@mbtmap.lnglat(139.7671, 35.6812), zoom=14.0)),
    update=(model, msg, _) => match msg {
    Moved(camera) => (Some(camera), @rabbita.none)
    Clicked(_) => (model, @rabbita.none)
    GoTo(place) =>
    (model, @mbtmap_rabbita.with_map("map", map => {
    map.fly_to(center=place, zoom=15.0)
    @rabbita.none
    }))
    },
    // The element's events as messages.
    subscriptions=(_, emit) => @mbtmap_rabbita.events(
    "map",
    on_moveend=emit.map(c => Moved(c)),
    on_click=emit.map(c => Clicked(c)),
    ),
    )
    model.map(camera => @html.div([
    @html.button(on_click=emit(GoTo(@mbtmap.lnglat(138.7274, 35.3606))), "Mt Fuji"),
    @mbtmap_rabbita.view("map", css="display:block;height:400px"),
    @html.p(match camera {
    Some(c) => "zoom \{c.zoom}"
    None => ""
    }),
    ]))
    }

    • view(id, css?, class?): the <mbt-map> element.
    • setup(id, style, center?, zoom?, bearing?, pitch?): a command that gives the map its style (@style.Style) and camera after the view renders; run it again to change the style.
    • events(id, on_load?, on_idle?, on_move?, on_moveend?, on_click?, on_error?): a subscription.
    • with_map(id, f): runs f on the typed @mbtmap.Map and then the command it returns; query_features(id, point, layers?, emit) sends the features at a point as a message.

    The repository's examples/rabbita/ is a complete app. Licensed under the Apache License 2.0.

    Camera

    pub(all) struct Camera {
    center :
    LngLat

    zoom : Double
    bearing : Double
    pitch : Double
    } derive(Eq,
    Debug
    )

    The map's camera as an event leaves it.

    Camera::equal

    fn Camera::equal(Camera, Camera) -> Bool

    Camera::not_equal

    fn Camera::not_equal(x : Camera, y : Camera) -> Bool

    Camera::to_repr

    Click

    A click on the map: the screen point, the place under it and the camera then.

    Click::equal

    fn Click::equal(Click, Click) -> Bool

    Click::not_equal

    fn Click::not_equal(x : Click, y : Click) -> Bool

    Click::to_repr

    events

    The events of <mbt-map> id as messages: on_load (first view drawn), on_idle (settled, also right after load), on_move (each frame the camera moves), on_moveend, on_click and on_error (the error's message). Return it from subscriptions.

    query_features

    The features drawn at point of the map of <mbt-map> id (in layers only, if given), topmost first, as a message.

    setup

    fn setup(id : String, style :
    Style
    , center? :
    LngLat
    , zoom? : Double, bearing? : Double, pitch? : Double) ->
    Cmd

    Gives the map of <mbt-map> id its style and camera once the view is on the page; the map is made then. Run it again to change the style (tiles of sources that stay alike are kept).

    view

    fn view(id : String, css? : String, class? : String) ->
    Html

    A <mbt-map> element with id, which setup, with_map and events find the map by. css is its inline style (give it a height); the map fills it.

    with_map

    Runs f on the map of <mbt-map> id (once it has loaded, if it has not yet) and then the command f returns: the typed API of t-ujiie-g/mbtmap from update.