Ticket #1950 (closed bug: fixed)

Opened 19 months ago

Last modified 17 months ago

Make a Layer.OSM class

Reported by: crschmidt Owned by:
Priority: minor Milestone: 2.8 Release
Component: Layer Version: 2.7
Keywords: Cc:
State: Complete

Description

Right now, OSM is possible to use, but annoying to set up if you're not intimiately familiar with the way OpenLayers works. We've documented this relatively well, but enough people are using this now that it makes sense to pull into core.

Proposal:

  • Create an OpenLayers.Layer.XYZ class -- this will be a class which inherits from grid. It is a simple class, essentially providing just a getURL function. This getURL function will support URLs like " http://tile.openstreetmap.org/${z}/${x}/${y}.png"
  • Create either a subclass or an option that sets the spherical mercator options by default.
        options = OpenLayers.Util.extend({
            maxExtent: new OpenLayers.Bounds(-156543.03390625*128,-20037508.34,156543.03390625*128,20037508.34),
            maxResolution: 156543.03390625,
            numZoomLevels: 19,
            units: "m",
            projection: "EPSG:900913"
        }, options);
        var newArguments = [name, url, options];
        OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments);

Create an OSM layer subclass, which sets:

  • A default OSM tile URL
  • OSM attribution string.
OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.XYZ.SphericalMercator, {
     attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
     url: "http://tile.openstreetmap.org/${z}/${x}/${y}.png",
     CLASS_NAME: "OpenLayers.Layer.OSM"
}); 

Attachments

XYZ.js Download (3.4 KB) - added by crschmidt 19 months ago.
xyz.patch Download (15.2 KB) - added by crschmidt 17 months ago.
xyz.2.patch Download (15.1 KB) - added by crschmidt 17 months ago.

Change History

Changed 19 months ago by crschmidt

  Changed 19 months ago by crschmidt

Potential strawman

  Changed 19 months ago by fredj

and why not make Layer.TileCache and Layer.TMS inherit from Layer.XYZ ?

  Changed 19 months ago by crschmidt

1. Layer.TileCache isn't just x/y/z: it's x1/x2/3/y1/y2/y3, which would be annoying to configure. 2. I'd like this in 2.8, so I'm targeting minimal change.

WRT TMS: TMS actually goes 'backwards' -- x is the bottom.. Also in theory, I think it's not possible to rearrange the x/y/z. One of the reasons to do this is that many different tile services have different arrangements of tile pairs. for example:

 http://wesmilepretty.com/gmap2/zoom1maps/0_0_1.jpg

Has: zoom${z}/${x}_${y}_${z}, while OSM has /${z}/${x}/${y}.

In theory, TMS is also 'versioned', so hiding that aspect from the user is nice as well; in practice, of course, no one uses versioning.

Perhaps 2.8 could add the XYZ layer, and a later revision could ponder changing other layers like this... Since the TMS laye rwould require extra options to 'flip' the y.

  Changed 18 months ago by crschmidt

  • state set to Needs More Work

  Changed 18 months ago by crschmidt

(In [9023]) Add the Layer.XYZ code, and extend it; improve the spherical mecator example to use the layer.xyz. (See #1950)

  Changed 18 months ago by euzuro

I know very little about the XYZ and OSM worlds, but I really like this patch in principle. One of the things we hear over and over and over again is people wanting to use OpenLayers for this or that, but they don't have the data.

In my mind, this makes it *that* much easier to give those users a simple, stock answer (that is better than blue marble on MetaCarta servers).

My only question/comment/concerns at this point are:

1) Instead of making the new namespace 'OpenLayers.Layer.XYZ.SphericalMercator', I would go the route that you suggested above, which is making it a property on the class and dealing with it accordingly in the 'OpenLayers.Layer.XYZ' constructor.

2) I'm wondering if there is maybe a way to take them even one step *further* by helping them out with the 'url' parameter? I know that cr5 and I discussed this before, but it just seems to me like requiring people to hunt down that url is (sadly) too much work. If I could just say

    var osmLayer = new OpenLayers.Layer.OSM('OSM');

...and it would just *know* what to do... that would be such a killer feature. It would defintiely notch it up a bit further towards the big three commercial layers.

If I remember correctly, the problem with this is that there are *many* OSM url's, and we can't safely rely on any of them. Could we maybe define some of the more stable ones as constants somewhere? defaults?

/me is grasping at straws

follow-up: ↓ 9   Changed 18 months ago by crschmidt

Erik:

 http://trac.openlayers.org/browser/sandbox/crschmidt/pre-2.8/lib/OpenLayers/Layer/XYZ.js?rev=9023

Does both of those two things, defaulting to the canonical OSM url, with docs included on how to switch to another primary one, which will let people move forward and work with any of the others if they chose to.

It's my plan to make the work in pre-2.8 (r9023) be the 'final' revision, once I get time (next week) to upload a patch.

  Changed 18 months ago by crschmidt

  • owner changed from euzuro to crschmidt
  • status changed from new to assigned

in reply to: ↑ 7   Changed 18 months ago by euzuro

Rock!!!

Replying to crschmidt:

Erik:  http://trac.openlayers.org/browser/sandbox/crschmidt/pre-2.8/lib/OpenLayers/Layer/XYZ.js?rev=9023 Does both of those two things, defaulting to the canonical OSM url, with docs included on how to switch to another primary one, which will let people move forward and work with any of the others if they chose to. It's my plan to make the work in pre-2.8 (r9023) be the 'final' revision, once I get time (next week) to upload a patch.

Changed 17 months ago by crschmidt

  Changed 17 months ago by crschmidt

  • owner crschmidt deleted
  • status changed from assigned to new
  • state changed from Needs More Work to Review

  Changed 17 months ago by crschmidt

Layer, modifications to example, tests. Review welcome.

  Changed 17 months ago by fredj

Please add multiple URL for OpenLayers.Layer.OSM. Something like:

OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.XYZ, {
    name: "OpenStreetMap",
    attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
    sphericalMercator: true,
    url: ['http://a.tile.openstreetmap.org/${z}/${x}/${y}.png',
          'http://b.tile.openstreetmap.org/${z}/${x}/${y}.png',
          'http://c.tile.openstreetmap.org/${z}/${x}/${y}.png'],
    CLASS_NAME: "OpenLayers.Layer.OSM"
});

  Changed 17 months ago by crschmidt

This would be in violation of  http://wiki.openstreetmap.org/index.php/Tile_usage_policy , which recommends a maximum of two download threads. If someone wishes to change this, they are welcome to, but by default, the Layer will be configured not to overburden OSM's tile servers.

  Changed 17 months ago by fredj

Wasn't aware of this usage policy, this document says that the maximum of two download threads does not apply to web browsers. But you're right: the OSM servers should not be overburden by default.

Some remarks about xyz.patch:

  • tests/Layer/XYZ.html:
    • line 5: the isMozilla seems not used in tests.
    • line 114, 142: remove options arguments
    • line 115: no need to create a new option

Thanks for this new feature !

  Changed 17 months ago by elemoine

Line 31 of the patch, it should be Constructor: OpenLayers.Layer.XYZ instead of Constructor: OpenLayers.Layer.OSM.

Changed 17 months ago by crschmidt

  Changed 17 months ago by crschmidt

elemoine, fredj: Do either of those count as reviews? :) new patch takes both comments into account.

  Changed 17 months ago by fredj

  • state changed from Review to Commit

thanks for the changes, please commit.

  Changed 17 months ago by crschmidt

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [9240]) adding XYZ layer (and OSM laayer) to OpenLayers. r=fredj, (Closes #1950)

Note: See TracTickets for help on using tickets.