-
Notifications
You must be signed in to change notification settings - Fork 52
Closed
Description
I am exploring the maplibre library with anywidget. The following code works perfectly with Colab. Jupyter Lab can display the map, but the map size is always fixed no matter what div.style.width
and div.style.height
values. VS Code throws errors. Any advice?
import anywidget
import traitlets
class MapWidget(anywidget.AnyWidget):
_esm = """
function loadScript(src) {
return new Promise((resolve, reject) => {
let script = Object.assign(document.createElement("script"), {
type: "text/javascript",
async: true,
src: src,
});
script.addEventListener("load", resolve);
script.addEventListener("error", reject);
document.body.appendChild(script);
});
};
await loadScript("https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js");
export function render(view) {
const div = document.createElement("div");
div.style.width = "100%";
div.style.height = "500px";
var map = new maplibregl.Map({
container: div,
style: 'https://demotiles.maplibre.org/style.json', // stylesheet location
center: [0, 20], // starting position [lng, lat]
zoom: 2 // starting zoom
});
view.el.appendChild(div);
}
"""
# make sure to include styles
_css = "https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css"
token = traitlets.Unicode().tag(sync=True)
m = MapWidget()
m
Metadata
Metadata
Assignees
Labels
No labels