diff --git a/.gitignore b/.gitignore index 1596c165..5f7e80a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.html +*.zip *.geojson *.geojson.zip *.arrow diff --git a/build.mjs b/build.mjs index f2f8ec2c..095b2737 100755 --- a/build.mjs +++ b/build.mjs @@ -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", + }, }); diff --git a/lonboard/_map.py b/lonboard/_map.py index bb5acc98..660e8620 100644 --- a/lonboard/_map.py +++ b/lonboard/_map.py @@ -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 @@ -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]