Skip to content

Commit

Permalink
Add simple Leptos example
Browse files Browse the repository at this point in the history
  • Loading branch information
shimatar0 authored and yukinarit committed Apr 20, 2023
1 parent ff45825 commit daac7ed
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ members = [
"examples/simple",
"examples/sycamore-simple",
"examples/add-image",
"examples/leptos-simple",
]
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ members = [
"simple",
"sycamore-simple",
"add-image",
"leptos-simple",
]
4 changes: 4 additions & 0 deletions examples/leptos-simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
/dist
/app
/node_modules
8 changes: 8 additions & 0 deletions examples/leptos-simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "leptos-simple"
version = "0.1.0"
edition = "2021"

[dependencies]
mapboxgl = { path = "../../" }
leptos = { version = "0.2.5", features = ["stable"]}
9 changes: 9 additions & 0 deletions examples/leptos-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Leptos with Mapbox simple Example

In order to run this example you need to specify an [Mapbox access token](https://account.mapbox.com/access-tokens)

```
MAPBOX_TOKEN={ACCESS_TOKEN} trunk serve
```

Open http://127.0.0.1:8080 in your browser
10 changes: 10 additions & 0 deletions examples/leptos-simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>leptos simple</title>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css' rel='stylesheet' />
<script src="https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js"></script>
</head>
<body style="margin: 0; padding: 0"></body>
</html>
18 changes: 18 additions & 0 deletions examples/leptos-simple/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use leptos::*;
use mapboxgl::{LngLat, MapFactory, MapOptions};

fn main() {
let token = std::env!("MAPBOX_TOKEN");
mount_to_body(|cx| view! { cx, <Map/> });
let _map = MapFactory::new(
MapOptions::new(token.into(), "map".into())
.center(LngLat::new(139.7647863, 35.6812373))
.zoom(15.0),
)
.unwrap();
}

#[component]
fn Map(cx: Scope) -> impl IntoView {
view! {cx, <div id="map" style="width: 100%; height: 100vh"/>}
}

0 comments on commit daac7ed

Please sign in to comment.