4 OpenLayers.Util.OSM = {};
7 * Constant: MISSING_TILE_URL
8 * {String} URL of image to display for missing tiles
10 OpenLayers.Util.OSM.MISSING_TILE_URL = "http://openstreetmap.org/openlayers/img/404.png";
13 * Property: originalOnImageLoadError
14 * {Function} Original onImageLoadError function.
16 OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError;
19 * Function: onImageLoadError
21 OpenLayers.Util.onImageLoadError = function() {
22 if (this.src.match(/^http:\/\/[abc]\.[a-z]+\.openstreetmap\.org/)) {
23 this.src = OpenLayers.Util.OSM.MISSING_TILE_URL;
25 OpenLayers.Util.OSM.originalOnImageLoadError;
30 * @requires OpenLayers/Layer/TMS.js
32 * Class: OpenLayers.Layer.OSM
35 * - <OpenLayers.Layer.TMS>
37 OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.TMS, {
39 * Constructor: OpenLayers.Layer.OSM
44 * options - {Object} Hashtable of extra options to tag onto the layer
46 initialize: function(name, url, options) {
47 options = OpenLayers.Util.extend(options, { attribution: "Powered by <a href='http://openstreetmap.org/'>OpenStreetMap</a>" });
48 OpenLayers.Layer.TMS.prototype.initialize.apply(this, arguments);
55 * bounds - {<OpenLayers.Bounds>}
58 * {String} A string with the layer's url and parameters and also the
59 * passed-in bounds and appropriate tile size specified as
62 getURL: function (bounds) {
63 var res = this.map.getResolution();
64 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
65 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
66 var z = this.map.getZoom();
67 var limit = Math.pow(2, z);
69 if (y < 0 || y >= limit)
71 return OpenLayers.Util.OSM.MISSING_TILE_URL;
75 x = ((x % limit) + limit) % limit;
78 var path = z + "/" + x + "/" + y + ".png";
80 if (url instanceof Array)
82 url = this.selectUrl(path, url);
89 CLASS_NAME: "OpenLayers.Layer.OSM"
93 * Class: OpenLayers.Layer.OSM.Mapnik
96 * - <OpenLayers.Layer.OSM>
98 OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
100 * Constructor: OpenLayers.Layer.OSM.Mapnik
104 * options - {Object} Hashtable of extra options to tag onto the layer
106 initialize: function(name, options) {
108 "http://a.tile.openstreetmap.org/",
109 "http://b.tile.openstreetmap.org/",
110 "http://c.tile.openstreetmap.org/"
112 var newArguments = [name, url, options];
113 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
116 CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
120 * Class: OpenLayers.Layer.OSM.Osmarender
123 * - <OpenLayers.Layer.OSM>
125 OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
127 * Constructor: OpenLayers.Layer.OSM.Osmarender
131 * options - {Object} Hashtable of extra options to tag onto the layer
133 initialize: function(name, options) {
135 "http://a.tah.openstreetmap.org/Tiles/tile.php/",
136 "http://b.tah.openstreetmap.org/Tiles/tile.php/",
137 "http://c.tah.openstreetmap.org/Tiles/tile.php/"
139 var newArguments = [name, url, options];
140 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
143 CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"