-
Notifications
You must be signed in to change notification settings - Fork 761
Allow map and layer coordinates to be provided as latitude and longitude. #248
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
base: master
Are you sure you want to change the base?
Conversation
|
I like this idea, but a couple of comments. At the moment, Map.center is not an api property, so if the recommendation is to set it in initialize() (which does simplify things) I think this should be changed (the same applies to zoom). Also, I think examples should be changed to reflect this. It also implies that setCenter() no longer requires a LonLat either, so I think the api docs for that should be changed too. I seem to remember in the discussions about v3 talk of having a new OpenLayers.Location class, like LonLat but with projection, and have setCenter() use that. Have you gone off that idea in favour of using simple objects? |
|
@probins Couple of things:
|
|
I think that we could add a Location object, and use it in Center() operations without breaking backwards compatibility? It would just mean we'd have to duplicate all the code paths in some way, right? (I'm not saying it's right, only that it's technically feasible.) |
|
One additional restriction is that center and zoom options are only applied if options.layers is present - which makes sense but should be documented. As for Location, yes, I was thinking that you could create a new Location class and set center to either a LonLat or a Location. However, I'm not sure it's a good idea. LonLat (and presumably Location) do have some logic in them (add(), equals() ...) but in this case all you need is the coordinates, and it simplifies people's code if they are able to supply a simple coords obj or array rather than having to instantiate an object |
|
@probins For the missing documentation, can you please issue a pull request against my branch? Thanks. |
|
thinking a bit more on this, I think the examples in Map constructor could do with updating too:
|
|
and change docs similarly for Layer.MaxExtent |
|
@probins These suggestions sound reasonable. It would be great if you could issue a pull request. Thanks! |
|
@ahocevar Yes, I can, but ... there's more. There are really 2 different parts to what you are proposing:
Also, for consistency, ISTM Map.minExtent should also have this capability. |
|
@probins: #1 is only partially true. You can only provide lat/lon object literals in the context of a map or layer when the target projection is known. The array of coordinates in the target projection works everywhere. You are right about #2. And you are also right about Map.minExtent. A pull request of yours would still be much appreciated! |
|
@probins yes, but I didn't mean to expose this to the API, because it is confusing (without the proj argument, you won't get what you expect, and with the proj argument, your |
|
hm, well, personally, I don't find that any more confusing than |
|
@ahocevar do you think that's 2.12 material? It's currently marked as so. (I haven't looked at the patch yet.) |
|
whether or not this patch goes into 2.12, I think what I wrote documenting the ability to enter coordinates as an array should go in. |
|
This patch relates to the APIs so I think it needs discussions. My first impression is that this patch does improve the API a bit, but it is not really satisfactory. I even fear that it makes the OpenLayers API even more being confusing. I don't want to sound harsh here, but that's my first feeling about this patch. Couldn't we introduce Just a random idea. Feel free to throw tomatoes at me :) |
|
No worries @elemoine - you don't sound harsh at all, and it's good to have this discussion! Let's others share their opinions as well. |
|
Leaving this open for further discussion, but removing it from the 2.12 milestone. I'm not so convinced any more that this pull request should be merged as-is. |
|
@elemoine What do you gain by creating these extra classes? Seems over-complicated for something that ought to be simple. Surely all I as a developer want to do is specify coords and which projection they are in. I don't need classes for this in my code, so why do I have to instantiate them? Similarly, I shouldn't have to transform every coord I give; OL should be clever enough to do it itself.
|
|
Things I think we should do:
Even if we don't add Location right away, let's leave room for it. My note of caution above was because I don't think we should go too far accepting arbitrarily structured object literals without thinking about what other improvements we might want to add later (e.g. |
|
@tschaub This is more or less similar to what I've proposed with One thing: if the map is not 4326 you'll always need to set a projection in your |
|
@probins I don't think custom types like |
|
"if the map is not 4326 you'll always need to set a projection in your Location and Envelope objects" I wouldn't describe LonLat or Bounds as evil; they encapsulate logic that can be useful (bounds intersects/contains/etc). My point is that you don't need any of that logic when specifying a center or extent. I'd be happy with having convenience args as well as providing a Location/Bounds instance, so developers can provide either. |
|
I think we agree. What I'm saying is if the map is not 4326 and if Location is 4326 by default then the app developper will need to set "projection" to the map projection in Location/Envelope objects he passes to the map ("center" option for example). |
|
if developer wants to submit coords in map projection, yes. Which is a change from current situation where coords have to be in map projection and converted by developer if not. |
|
The Location and Envelope types could expose a static function/property that allows changing the default projection. |
As a follow-up to bce3ace, this change adds more convenience to coordinate handling. Instead of configuring a map like this:
uses can now use latitudes and longitudes to set extents and center:
And instead of configuring a layer like this:
it is now possible to work with latitude and longitude as well: