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

Popup on marker doesn't show correctly. #299

Open
3 tasks done
FavioT opened this issue May 17, 2021 · 4 comments
Open
3 tasks done

Popup on marker doesn't show correctly. #299

FavioT opened this issue May 17, 2021 · 4 comments

Comments

@FavioT
Copy link

FavioT commented May 17, 2021

Before submitting an issue, please verify the following:

If this is a request for help, please use Stack Overflow and use the ngx-leaflet tag, or review the Getting Help section of the README. We watch the ngx-leaflet tag on Stack Overflow and will respond there. We will no longer be responding to help and 'how-to' requests on GitHub.

If this is a bug, issue, enhancement request, etc. verify the following before submitting your issue:

  • Review the README to see if your issue is covered, and pay particular attention to the Getting Help section.
  • Tell us what version of Leaflet, Angular, and ngx-leaflet you're using
  • Include code that reproduces your issue

I'm using :

[email protected]
@angular/[email protected]
@asymmetrik/[email protected]

Hello everyone,

I'm having trouble displaying correctly a marker popup on the map.
the popup is shown covering the marker icon, when the correct thing would be for it to be shown above it, as it happens with the original leaflet library.

I tried it on my Angular project and also i have even trying on the source code of the demo of this repository and exactly the same thing happens.

image

image

This is the portion of code that i am testing.

image

Am I doing something wrong?

@reblace
Copy link
Contributor

reblace commented May 17, 2021

Try changing:

const newMarker = marker(...).bindPopup(...);
this.markers.push(newMarker);

to

const newMarker = marker(...);
newMarker.bindPopup(...);
this.markers.push(newMarker);

I would assume what's happening is you're adding the popup to the markers array instead of adding the marker since bindPopup(...) probably returns the popup and not the marker.

@FavioT
Copy link
Author

FavioT commented May 18, 2021

Thanks @reblace for your quickly response, i have changed that portion of code, but it's still happens the same, i am testing this issue directly on the demo of this repo.

here is the code.

addMarker() {
		const newMarker = marker(
			[ 46.879966 + 0.1 * (Math.random() - 0.5), -121.726909 + 0.1 * (Math.random() - 0.5) ],
			{
				icon: icon({
					iconSize: [ 25, 41 ],
					iconAnchor: [ 13, 41 ],
					iconUrl: '2b3e1faf89f94a4835397e7a43b4f77d.png',
					iconRetinaUrl: '680f69f3c2e6b90c1812a813edf67fd7.png',
					shadowUrl: 'a0c6cc1401c107b501efee6477816891.png'
				})
			}
		);

		newMarker.bindPopup("<p>This is my marker!<p>");

		this.markers.push(newMarker);
	}

@loremaps
Copy link

Hi @FavioT

Can you please try to add this to the icon:

icon: icon({
   ...
   popupAnchor: [1, -34]
})

I think this is because you use a custom icon. Please check the tutorial here: https://leafletjs.com/examples/custom-icons/

@FavioT
Copy link
Author

FavioT commented May 26, 2021

It works! @loremaps, thank you!

I've been struggling with this for days.

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