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 with Modal do not works #155

Open
nautilor opened this issue Mar 28, 2022 · 3 comments
Open

Marker with Modal do not works #155

nautilor opened this issue Mar 28, 2022 · 3 comments

Comments

@nautilor
Copy link

nautilor commented Mar 28, 2022

Hello,

I have created a custom component to show a marker then when pressed opens a Modal;

here's the code

<RouteModal 
	key={key} lat={lat} lng={lng} width={50}
	color={rock.color} name={name} />

the modal works fine but the marker is placed on the top left corner of the webapp (check screenshot)

by doing some checking i've seen that the lat and lng are passed correctly to the component but when rendered they somehow get lost as i don't see no transform property in the style when running the inspector.

am I missing something?

@baldulin
Copy link
Contributor

baldulin commented May 3, 2022

Hey, I think the issue is that you don't add the Marker Component as a direct child of Map. All direct Child components of Map are cloned here and will receive a left and right property. Those properties are used in the Marker Component here to create the transform css attribute.

As you don't have the option to make the Marker a direct child of Map you have to pass the "cloned" attributes manually. Simplest way I guess is the following:

const RouteModel = (props) => {
    const [modal, setModal] = useState(false);

    return (
        <>
            <Marker onClick={() => setModal(!modal)} {...props} />
            {(modal) && (
                <Modal
                    isOpen={modal}
                    onRequestClose={() => setModal(!modal)}
                    ariaHideApp={false}
                >
                    <h2>{props.name}</h2>
                    <p>{props.name}</p>
                    <button onClick={toggleModal}>Close</button>
                </Modal>
            )}
        </>
    );
}

Note though for this to work you have to pass lat, lng the "pigeon" way as an array to a prop anchor, so this is nothing but a small wrapper around the Marker component.

@mariarivm30
Copy link

I have the same problem , could you solved?

@chasoft
Copy link

chasoft commented Jul 27, 2022

You need to put <Marker /> directly inside <Map>

So, following is valid

<Map>
     <Marker ... />
</Map>

This is also valid

<Map>
     {makersList.map(marker => ( <Marker ... />  ))}
</Map>

Following is invalid

const CustomMarker = () => (
    <Marker ... />
)
.....
<Map>
     <CustomMarker ... />
</Map>

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

4 participants