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
Support basic objects as map centers #1412
Comments
Hmm, what's the use case? Just a bit more descriptive way to pass coordinates in the API? |
It simplifies the surface of the API by only requiring you to use one API call. That, or when you're calling map.setView from data, it's nice to be able to interact with it with as little transformation of the data as possible (my dream api for leaflet et all is just geojson literals everywhere) |
You can currently do |
Yeah - so like |
This does make the code easier to read, and doesn't leave one to guess "Which is first - lat or lng?" Just my 2¢... |
Initially I adopted If I add this signature, should I use |
IMHO: Both, unless someone else has some reason we shouldn't do this. As far as I know all of Leaflet's documentation uses |
I'm used to |
Like I said, my opinion was humble, and has changed, thanks to @tmcw ;) Now I'd say both for sure since there seams to be this larger standard for the term. |
(to make life more complicated, the public API of d3 deals exclusively in two element arrays which are, you guessed it, in |
@tmcw, that does complicate things... and I I think that in the interest of Leaflet they have to draw the line somewhere. The beauty of adding an object context like this is it doesn't matter which comes first. |
Like this? |
Google LatLng objects have .lat() and .lng(). Would it make sense to support those too, or is that a step too far? |
It's not possible with current JavaScript to have a property that acts both as a number and as a function. |
Sure, but this would be accepting an object that could have either a number or a function, not both. I'm not talking about adding .lat() and .lng() to the Leaflet LatLng, just accepting a Google LatLng in the constructor. Something like
|
I see, thanks! But are there actually any real world use cases for this? |
I don't know how common it is, but I had it come up recently. I had a position from a Google Street View panorama and wanted to use it to set a Leaflet map center. Of course it's not that hard to use |
I think it's pretty normal to use |
Fair enough. I just thought Google LatLng objects might be more common than the objects that have .lat and .lng or .lon. But if I'm part of a tiny minority, it's definitely not worth adding. |
Is currently not supported but be quite easily if
L.LatLng
accepted this kind of basic object as a parameter. I can pull together a pr for this if it seems fine.The text was updated successfully, but these errors were encountered: