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 Click to Return Lat Lng #5397

Closed
Craytor opened this issue Oct 4, 2017 · 7 comments
Closed

Marker Click to Return Lat Lng #5397

Craytor opened this issue Oct 4, 2017 · 7 comments

Comments

@Craytor
Copy link

Craytor commented Oct 4, 2017

mapbox-gl-js version: 0.40.0

I am having a strange issue with MapBox GL. I've searched through the issues and couldn't find my exact issue.

I have markers that I have created and added to my map as a type of "circles" and I'm using the data options so I have base and stops. When I click on a maker, I expect to be able to find the lat and lng of the point in the geometry, but that is not the case. When I click on a marker from way out, I get the response that I clicked the marker (logging it to the console), but also it clicks onto a polygon (this is fine), so I can see the originating point of where I clicked. When I zoom in on a marker it is way off from a point, and therefore if I click the point again the geometry in the feature shows a different point.

Here is what I'm trying to do: click on a marker, get the marker's point (as I set in the geojson) and then find all polygons that exist at that layer.

When you think you click on the icon (the listener that listens to icon clicks says you clicked):
screen shot 2017-10-03 at 8 36 38 pm

After you zoom in this is how far off the click was:
screen shot 2017-10-03 at 8 37 00 pm

And finally, if you click the marker again this is what it shows:
screen shot 2017-10-03 at 8 37 15 pm

Any suggestions would be much appreciated!

@jfirebaugh
Copy link
Contributor

Thanks for using Mapbox, and sorry to hear you're running into an issue. In order for us to diagnose this issue, we'll need to be able to reproduce it ourselves. Could you please create a minimal self-contained JSFiddle that demonstrates the issue?

@Craytor
Copy link
Author

Craytor commented Oct 4, 2017

@jfirebaugh Alright, should have added that earlier. It isn't as great, but I think it has what is needed, and was able to see the issue using this as well.

http://jsfiddle.net/Craytor/01b97w0L/75/

Please let me know if I should add anything to the fiddle.

It logs the click to the console.

@jfirebaugh
Copy link
Contributor

Thanks. So what's the issue you're reporting, in terms of "expected result" versus "actual result"?

@Craytor
Copy link
Author

Craytor commented Oct 4, 2017

I'm expecting that when I click on a marker that I can get the lat and lng of the marker so that I can find out what polygons exist at that point.

Instead, what is happening is that it seems to be getting the point where you click the map, which is not necessarily the actual point of the marker (that was defined in the geojson).

I was hoping that e.features[0].geometry.coordinates was the point of the marker, but it appears it is where you click the map based on my trial and errors.

@jfirebaugh
Copy link
Contributor

Inside the click handler for the myPoint, e.features[0].geometry.coordinates is the location of the marker. Is what you're noticing that if you place a popup at that location when the map is zoomed out, and then zoom in, that it's no longer precisely positioned on the point? If so, see #4733 and mapbox/mapbox-gl-native#8992 (comment).

@Craytor
Copy link
Author

Craytor commented Oct 4, 2017

Okay, so I am confused by e.features[0].geometry.coordinates being the location of the marker because in my geojson the coordinate is [-123.199274, 39.153673]. Though, when you click on the marker it is saying -123.19931030273438, 39.15349256868936 and not -123.199274, 39.153673.

@jfirebaugh
Copy link
Contributor

GeoJSON data is converted to a tiled format (like vector tiles) internally, and coordinates at a given zoom level may not round trip exactly. What you're seeing is the same as #4733; closing as a duplicate.

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

No branches or pull requests

2 participants