BlazorLeaflet
BlazorLeaflet copied to clipboard
BlazorLeaflet not working with WebAssembly and .net core 3.1
Hello,
when I download the repository and run the sample, all works fine. However, when I try integrating a map in my own application, I get this error:
Microsoft.JSInterop.JSException: Could not find 'leafletBlazor' in 'window.window'.
I referenced the BlazorLeaflet.dll file I built myself from my project and added a script reference in index.html. Do I have to do anything beyond that to get it to work?
Thanks! Greets, Menno
A follow-up: I get the same error when using the lib in a server project.
It does however work (server-side only, not with WebAssembly), when I include the BlazorLeaflet project in my own solution, and reference the project from my web app.
Same issue here. The only way I manage to run this package is by downloading project and then referencing to my app
Similiar issue in client-side Blazor Webassembly (.net 5.0): "Error: Could not find 'window.leafletBlazor.create' ('leafletBlazor' was undefined)."
Am I missing something? Should I create a new issue for that?
I was having similar issues; resolved them by referencing leaflet.js in index.html/_Host.cshtml. The README doesn't specify to do this, but I believe you have to?
From sample project:
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
My experience was that with an older browser I got the window.window error, but with newer browsers it seems to work. I actually believe (as far as I can remember) it was a challenge for older browsers with the spread operator ...
that is used in the leafletBlazorInterops.js file.
I was getting the same error message as shown above. The fix for me was to add the following line after your leaflet script tag.
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>
<script src="_content/BlazorLeaflet/leafletBlazorInterops.js"></script>
I am using Leaflet 1.9.3 and the 0.4.0 alpha release of the BlazorLeaflet library from NuGet. I found this by reviewing the example section and saw this was the only difference between my code and the example code.
Do you have any info about this problem? For me the only possibility to solve this was to add the BlazorLeaflet project to my solution, other combinations had failed.