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

LatLng.distanceTo not working for custom CRS #2946

Closed
jpuerto opened this issue Oct 14, 2014 · 3 comments
Closed

LatLng.distanceTo not working for custom CRS #2946

jpuerto opened this issue Oct 14, 2014 · 3 comments

Comments

@jpuerto
Copy link

jpuerto commented Oct 14, 2014

Hi all,

I'm working on a project where we defined a custom CRS, I've added the AnimatedMarker plugin and then I've realized that the distance values are completely wrong in the scale. A closer look to the plugin reveals that it's using the LatLng.distanceTo() method that in current development code is like this:

distanceTo: function (other) {
return L.CRS.Earth.distance(this, L.latLng(other));
}

I think that the LatLng object should use the defined CRS instead of hard code the most common implementation. Does anyone knows a workaround for this? ATM I have configured a fixed value to obtain an acceptable movement rate but I need to be able to define this rate programmatically so the ideal should be to use the configured map CRS implementation.

TIA and salu2.

@mourner mourner changed the title LatLng.distanceTo not working for custom CRS LatLng.distanceTo not working for custom CRS Oct 14, 2014
@perliedman
Copy link
Member

Since LatLngs have no connection to map instances, they can't know what "the defined CRS" is, so that makes it a bit hard to do this dynamically.

You can of course overwrite LatLng's prototype's distanceTo with whatever you like.

@mourner
Copy link
Member

mourner commented Oct 15, 2014

Yes, LatLng.distanceTo is meant as a shortcut for convenience. For non-trivial CRS uses, you should always use map.distance(latlng1, latlng2), since latlng doesn't know what CRS you use, as @perliedman mentioned.

@mourner mourner closed this as completed Oct 15, 2014
@jpuerto
Copy link
Author

jpuerto commented Oct 15, 2014

Thanks for your replies.

I asked here because I saw the problem that @perliedman described, the LatLng object is decoupled from the map so there's no way to know the CRS at this point. As I understand, the problem then is the plugin that should use map.distance(latlng1, latlng2) method instead. I will open an issue for the plugin.

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