-
Notifications
You must be signed in to change notification settings - Fork 2
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
Setup Leaflet and React Leaflet #11
Conversation
@MacAndersonUche can you reference the GH issue here? You obviously didn't read the whole ticket? Did chatgpt do this for you? |
Added Map.tsx to pages folder as a component. I'm having trouble with Typescript errors because they aren't recognizing the react-leaflet component attributes. Tried installing @types/react-leaflet as per the docs but alas didn't fix the red squiggles. The map will need to be centered still and markers will need to be ironed out. Let me know if there is anything glaringly breaking. From Setup Leaflet and React Leaflet #8:
|
pages/index.tsx
Outdated
const MapWithNoSSR = dynamic(() => import('./Map'), { | ||
ssr: false, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip the dynamic import for now and keep it simple. Just import and render the component. Is this working for you? It wasn't for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that it is not working for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: I read instructions on react-leaflet and nextjs ssr. Got it. This looks correct with the dynamic import like this for now. If we use SSR that'll be useful.
For So importing Nextjs file structure is just a little different than React. Sorry I forgot to tell you. |
@ranegray I took a look at this and I apologize it is working for me. It's just I couldn't see the map. Can you adjust the style to make the map fit the entire viewport? |
webpack: (config) => { | ||
config.plugins.push( | ||
new CopyPlugin({ | ||
patterns: [ | ||
{ | ||
from: 'node_modules/leaflet/dist/images', | ||
to: path.resolve(__dirname, 'public', 'leaflet', 'images') | ||
}, | ||
], | ||
}), | ||
) | ||
return config | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranegray @MacAndersonUche why do we need this? Looks like it's copying over the layers, and marker images to over public dir.
We can customize the markers and stuff in the future 👍
Found the answer here: https://jan-mueller.at/blog/react-leaflet/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left this config in. Not sure if you wanted me to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes looks like we need it for now 👍
pages/Map.jsx
Outdated
return null; | ||
} | ||
|
||
export default function Map() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use const
instead of function
just preference 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to const in newest commit. export default at bottom of file.
Newest commit. Added full viewport map, added lib/component file structure. Changed naming convention of function to arrow sytanx with default export at bottom of Maps.jsx. Removed any imports or functions that weren't being used. Clean slate ready for whatever. |
lib/Components/Map.jsx
Outdated
@@ -17,7 +11,7 @@ export default function Map() { | |||
<MapContainer | |||
center={center} | |||
zoom={12} | |||
style={{ height: "50%", width: "100%" }} | |||
style={{ height: "100vh", width: "100vw" }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranegray for width
you don't need to specify the viewport units as the cause problems👍 100% is good. I pushed up the change for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranegray well done 🚀
References Issue: #8