-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map rendered with missing parts #1108
Comments
same issue with nextjs 13 |
you're missing css import |
Thanks @sethii This works! I am also not seeing the marker icons. Any more files needed to be loaded? Thanks |
unfortunately importing leaflet/dist/leaflet.css causes the entire map to disappear for me. Not importing it leads to incomplete/scattered map tiles. Any fix for this? I'm using Vite/React+TS EditFound a solution. Add this to your styles.css and make sure it's imported in the app root (in Vite's case main.tsx) in addition to the dist/leaflet.css import #map {
height: 100vh;
}
.leaflet-container {
height: 600px;
width: 100%;
}
.leaflet-div-icon {
background: transparent;
border: none;
} |
FWIW, investigated this a bit. Basically it's never going to find the icon because you need to dig it out of the node_modules/dist. Did not look at source code, but for a workaround, you can reconstruct the default icon depending on your bundler / asset serving:
Note that iconUrl is just a Copilot generated random link. You could use your own here, or the ACTUAL file is located like so:
But you'll need some way to actually serve that since I don't think leaflet likes the raw data. Hopefully that's a start towards a better example |
Excellent work @comp615 , that works for me brother. However, I did have to add in a TypeScript ignore because TypeScript was getting upset that the file path did not exist – but it does work and fix the issue. // @ts-ignore because this image needs to be imported, but not found for some reason, but works.
import defaultIconPng from 'leaflet/dist/images/marker-icon.png'
const defaultIcon = new Icon({
iconUrl: defaultIconPng,
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41],
}); |
Fix requires both of these:
Also this issue is duplicate of #1052 |
Bug report in v4
Hi
I am trying out the React Leaflet on StackBlitz using a React TypeScript project. The map loads partially.
Expected behavior
To show the map fully
Actual behavior
Map showing partially
Steps to reproduce
StackBlitz Sample
I appreciate your support.
Bill
The text was updated successfully, but these errors were encountered: