GithubHelp home page GithubHelp logo

Comments (8)

usefulthink avatar usefulthink commented on June 15, 2024 2

We're in a bit of a transition-period right now – the version currently in beta will introduce the web-components (<gmp-map> and <gmp-advanced-marker>), and with that we'll probably also get support for DOM events on the AdvancedMarkerElement itself.

But I wouldn't want to make the beta-channel a requirement for using AdvancedMarker, if we can solve this in another way.

Until the web-components are in GA (weekly and quarterly channels), the best thing to do is probably to add the event-listeners to the advancedMarker.element instead. We probably don't even need a different handling of this for when web-components are released, but that remains to be seen.

from react-google-maps.

usefulthink avatar usefulthink commented on June 15, 2024 1

Unfortunately, that doesn't work if your content is just a Pin component. I should be able to look into this tomorrow.

from react-google-maps.

usefulthink avatar usefulthink commented on June 15, 2024 1

Yeah, I'm thinking the same. For the map it was necessary because the map-events mostly don't contain any useful data about the event, but here we have perfectly functional DOM-events already :)

from react-google-maps.

rvanderfeer avatar rvanderfeer commented on June 15, 2024

I ran into this too. You can work around this by adding the props to your AdvancedMarker content, for example;

<AdvancedMarker
	ref={markerRef}
	position={markerPosition}
	onClick={() => setInfowindowOpen(true)}
	{...other}
>
	<div
		onMouseOver={() => setInfowindowOpen(true)}
		onMouseOut={() => setInfowindowOpen(false)}
		style={{
			width: 20,
			height: 20,
			position: 'absolute',
			top: 0,
			left: 0,
			background: '#F00',
			border: `2px solid #FFF`,
			borderRadius: '50%',
			transform: 'translate(-50%, -50%)'
		}}
	/>
	{infowindowOpen && (
		<InfoWindow
			anchor={marker}
			maxWidth={200}
			onCloseClick={() => setInfowindowOpen(false)}
		>
			infowindow content
		</InfoWindow>
	)}
</AdvancedMarker>

from react-google-maps.

BParvatkar avatar BParvatkar commented on June 15, 2024

Were you able to look into it @usefulthink. I was looking into the API reference for AdvanceMarker here. Seems that the addEventListener method is part of beta version as of now. The APIProvider component does allow us to pass version as prop. Was wondering if this will work:

  • Pass version as beta in APIProvider prop
  • The AdvancedMarker component extends for all EventListener.
  • The user passes any listener as prop, let say onMouseEnter
  • If APIProvider is initialized in beta mode then we allow this events, else give error saying that its still in beta and needs to initialize APIProvider in beta version.

The benefit of this approach is that we don't have to manually add each listener to the components like AdvancedMarker or Pin

from react-google-maps.

BParvatkar avatar BParvatkar commented on June 15, 2024

Is there any example of adding listeners to the advancedMarker.element or does it need to be built?

from react-google-maps.

usefulthink avatar usefulthink commented on June 15, 2024

No, it's on my ToDo-list, but I haven't gotten to it yet. I'm still pondering if we should use wrapped events for the markers like we do for the map itself, or if we should just use the native events.

from react-google-maps.

BParvatkar avatar BParvatkar commented on June 15, 2024

Earlier it made sense to add each declaration because the type of events was MapMouseEvent and not the native events emitted by the element. But as per the docs, they will be emitting native events so I think it will be better to go the native way.

from react-google-maps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.