We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have a nextjs Project which is running server side. I try to implement a leaflet map into my component.
I have a page.js which is running SSR: I implemented my MapCaller in it, which looks like this:
"use client"; import dynamic from "next/dynamic"; const LazyMap = dynamic(() => import("@/app/_components/Map/Map"), { ssr: false, loading: () => <p>Loading...</p>, }); const MapCaller = () => { return ( <div> <LazyMap /> </div> ); } export default MapCaller;
My Map Component looks like this:
"use client"; import React, { useState } from "react"; import { MapContainer, TileLayer, GeoJSON, Marker, Popup } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import "leaflet-defaulticon-compatibility"; import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css"; import L from "leaflet"; // GeoJSON sample data const countriesData = { type: "FeatureCollection", features: [ { type: "Feature", properties: { NAME: "Georgia", CONTINENT: "Asia" }, geometry: { type: "Polygon", coordinates: [ [ [44.97248, 41.248129], [43.582746, 41.092143], [42.619549, 41.583173], [44.97248, 41.248129], ], ], }, }, ], }; const pointsData = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [17.309889, 12.082583], }, properties: { title: "Random Point", }, }, ], }; const Map = ({initialData}) => { const [hoveredCountry, setHoveredCountry] = useState(null); const countryStyle = { fillColor: "green", color: "black", weight: 1, fillOpacity: 0.5, }; const onEachCountry = (feature, layer) => { layer.on({ mouseover: (e) => { setHoveredCountry(feature.properties); layer.setStyle({ fillColor: "blue", color: "blue" }); }, mouseout: () => { setHoveredCountry(null); layer.setStyle({ fillColor: "green", color: "black" }); }, }); }; return ( <div style={{ position: "relative" }}> <MapContainer center={[51.505, -0.09]} zoom={2} scrollWheelZoom={false} style={{ height: "500px" }} > <TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" attribution="© OpenStreetMap contributors" /> <GeoJSON data={countriesData} style={countryStyle} onEachFeature={onEachCountry} /> {pointsData.features.map((point, index) => ( <Marker key={index} position={[ point.geometry.coordinates[1], // Latitude point.geometry.coordinates[0], // Longitude ]} > <Popup>{point.properties.title}</Popup> </Marker> ))} </MapContainer> {hoveredCountry && ( <div style={{ position: "absolute", top: 10, left: 10, background: "white", padding: 10, zIndex: 1000, }} > <strong>{hoveredCountry.NAME}</strong> <p>Continent: {hoveredCountry.CONTINENT}</p> </div> )} </div> ); }; export default Map;
But now i am getting this error:
I hope somebody can help me with my problem
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug report in v5
Expected behavior
I have a nextjs Project which is running server side.
I try to implement a leaflet map into my component.
Actual behavior
I have a page.js which is running SSR: I implemented my MapCaller in it, which looks like this:
My Map Component looks like this:
But now i am getting this error:
I hope somebody can help me with my problem
The text was updated successfully, but these errors were encountered: