Skip to content
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

Marker doesn't stay pinned when zoomed on NextJS 13.5.2 #12

Open
Lodimup opened this issue Sep 21, 2023 · 2 comments
Open

Marker doesn't stay pinned when zoomed on NextJS 13.5.2 #12

Lodimup opened this issue Sep 21, 2023 · 2 comments

Comments

@Lodimup
Copy link

Lodimup commented Sep 21, 2023

Great lib the only problem I have so far is When zoomed the marker moves from its correct position. Thanks!

export const MarkerCard = (props: MarkerCardProps) => {
...
return (
    <Marker
      position={props.location}
      size={[224, 112]}
      riseOnHover
      placement="bottom"
    >
...
      <MapContainer
        className="h-screen w-full bg-gray-100"
        // @ts-ignore
        center={coord}
        zoom={16}
        scrollWheelZoom={false}>
        <TileLayer
          attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
        <HandleLocation />
        <MarkerLayer>
          {DUMMY.map((props, index) => (<MarkerCard key={props.id} {...props}/>))}
        </MarkerLayer>
      </MapContainer>

it seems that this problem is NextJS specific. PaulLeCam/react-leaflet#808 (comment) does not resolve the issue.

@Lodimup Lodimup changed the title When zoomed market moves from its correct position Marker doesn't stay pinned when zoomed on NextJS 13.5.2 Sep 21, 2023
@Shadowfita
Copy link

Same issue!

@stevenmulgrew
Copy link

stevenmulgrew commented Dec 11, 2024

I've just bumped into the same issue, trying to display numerous React components wrapped in markers using v1.1.4
What has worked for me is setting the position to "absolute" on the div rendered by the marker.
The component offers a ref to the underlying div so you can set the style accordingly.
Hope this helps someone.

const ProjectMarker = ({ project }: ProjectMarkerProps) => {
    
    const ref = React.createRef<HTMLDivElement | null>();

    React.useEffect(() => {
        setTimeout(() => {
            if (ref.current) ref.current.style.position = "absolute";
        }, 0);
    }, [ref]);

    return (
        <Marker
            position={{
                lat: project.latitude,
                lng: project.longitude,
            }}
            innerRef={ref}
        >
            <MyCustomComponent />
        </Marker>
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants