Returned feature coordinates different then original feature? #609
-
Hi there, loving maplibre for the past 6 months in a project. You are doing great work. I ran into something and I want to confirm its expected behaviour. I have a map with points and when I click on those points I have a popup appear to display the clicked feature's details include coordinate. However, if I make a point at say [-75.0, 45.0] depending on the zoom level I get an approximation of that coordinate in the feature's geometry property, with it being more accurate as I zoom in. Is this expected? I really want to get the original coordinates the feature was created with. EDIT: example: https://codepen.io/Terribill/pen/KKvZNjx |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I am glad you enjoy using MapLibre. From what I have seen in the unit test, numerical equality checks are usually restricted to only a few digits. So I guess what you show here is the expected behavior. |
Beta Was this translation helpful? Give feedback.
-
I also think that the output in your popup is correct. If I read the documentation and the code for The In your case, however, I think that the easiest thing to do is to use:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the replies. Unfortunately I need 6 decimal places so I found a workaround of putting the source coordinates in the feature properties for future use in popups and that works well. |
Beta Was this translation helpful? Give feedback.
I also think that the output in your popup is correct. If I read the documentation and the code for
map.on('mouseenter', 'places',..)
correctly, then the coordinate of the mouse position on theplaces
layer
is displayed as accurately as possible.The
source
, I mean the value fore.features[0].geometry.coordinates
of theGeoJson
is not the target of the event. I think that is what you expect. But you would have to do this differently.In your case, however, I think that the easiest thing to do is to use:
popup.setLngLat(coordinates).setHTML(description + coordinates[0].toFixed(2) + "," + coordinates[1].toFixed(2)).addTo(map);