Leaflet map included in an html exported from Obsidian.md only shows up after page reload / refresh

My goal:
I exported some html notes from Obsidian.md (based on this: https://github.com/KosmosisDire/obsidian-webpage-export) and am now trying to include a fictional worldmap based on the leaflet.js script (not using the leaflet Plugin for Obsidian, since this didn’t work for me in the export).

My problem:
The map works fine when I reload the page, showing the typical leaflet zoom UI as well. But when first opening the page or navigating there from another note in the hierarchy, the map and UI are gone.

I looked on stackoverflow for similar questions and already tried solutions not only for leaflet but also for other problems with scripts not executing without a refresh/reload of the page. But nothing helped.

I included the script in a simpler html and played around with a link to another page and returning to the one with the map – it worked. So I guess it’s a problem with something the other scripts in the document do (there is some ajax and pixy included which I can’t remove since it’s needed for a graphview navigation which is part of Obsidian).

I’m testing everything locally with the help of VS Code and Five Server as local webserver. There are no errors in my code (I fixed some errors caused by the generated export from Obsidian). The same problem is visible when I upload it to my webspace or try it with different browsers.

Hoping that someone here can help me, since I’m pretty sure that others who would like to have such an interactive worldmap combined with an Obsidian based page as well might stumble on this problem as well and hopefully also find the solution for this here some day.

What i tried so far:
I searched on stackoverflow for solutions.
I tried using cache, defer, preload and placing the link to the script and the script (and css) itself into different places in the html file and different folders.
I tried removing other scripts in the html file to see if it helps.

But all of this didn’t change the behaviour, only caused more errors and problems on the page (or with the leaflet UI).

So far, I haven’t found any solution that helped me. I don’t get any error message, so there is nothing I can post here unfortunately.

And yes, I am no programmer/web dev, so unfortunately I am currently not able to come up with any more elaborate solutions. I was just looking for a way to present my writing/content in a nice way.

This is my map script itself:

<script> 
// Using leaflet.js to pan and zoom a big image. 
           const map = L.map('image-map', {
             minZoom: 1,
             maxZoom: 4,
             center: [0, 0],
             zoom: 1,
             maxBoundsViscosity: 1,
             crs: L.CRS.Simple
           });
           var image= L.imageOverlay("I removed the name of my asset here, but using a webp which works", [[0,0],[240,330]]); //initial size at zoom 1 )
           image.addTo(map);
// tell leaflet that the map is exactly as big as the image
map.setMaxBounds(new L.LatLngBounds([0,0], [240,330]));  // prevent panning outside the image area.
    //Note the viscosity setting keeps the image from being dragged outside this 
</script>

New contributor

Robin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật