Skip to content

Commit

Permalink
Save widget to standalone HTML file (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Nov 3, 2023
1 parent 9a1fb0d commit 5ab35d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.html
*.zip
*.geojson
*.geojson.zip
*.arrow
Expand Down
10 changes: 5 additions & 5 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// build.js
import esbuild from "esbuild";
// import { wasmLoader } from "esbuild-plugin-wasm";

esbuild.build({
entryPoints: [
"./src/index.tsx",
],
entryPoints: ["./src/index.tsx"],
bundle: true,
minify: true,
target: ["es2020"],
outdir: "lonboard/static/",
// plugins: [wasmLoader()],
format: "esm",
// Ref https://github.com/manzt/anywidget/issues/369#issuecomment-1792376003
define: {
"define.amd": "false",
},
});
10 changes: 10 additions & 0 deletions lonboard/_map.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from pathlib import Path
from typing import Union

import anywidget
import ipywidgets
import traitlets
from ipywidgets.embed import embed_minimal_html

from lonboard._layer import BaseLayer
from lonboard._viewport import compute_view
Expand Down Expand Up @@ -92,6 +94,14 @@ class Map(anywidget.AnyWidget):
- Default: `True`
"""

def to_html(self, filename: Union[str, Path]) -> None:
"""Save the current map as a standalone HTML file.
Args:
filename: where to save the generated HTML file.
"""
embed_minimal_html(filename, views=[self], drop_defaults=False)

@traitlets.default("_initial_view_state")
def _default_initial_view_state(self):
tables = [layer.table for layer in self.layers]
Expand Down

0 comments on commit 5ab35d5

Please sign in to comment.