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;
24 } else if (this.src.match(/^http:\/\/[def]\.tah\.openstreetmap\.org\//)) {
25 // do nothing - this layer is transparent
27 OpenLayers.Util.OSM.originalOnImageLoadError;
32 * @requires OpenLayers/Layer/TMS.js
34 * Class: OpenLayers.Layer.OSM
37 * - <OpenLayers.Layer.TMS>
39 OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.TMS, {
41 * Constructor: OpenLayers.Layer.OSM
46 * options - {Object} Hashtable of extra options to tag onto the layer
48 initialize: function(name, url, options) {
49 options = OpenLayers.Util.extend(options, {
50 attribution: "Data by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
51 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
52 maxResolution: 156543,
54 projection: "EPSG:41001"
56 OpenLayers.Layer.TMS.prototype.initialize.apply(this, arguments);
63 * bounds - {<OpenLayers.Bounds>}
66 * {String} A string with the layer's url and parameters and also the
67 * passed-in bounds and appropriate tile size specified as
70 getURL: function (bounds) {
71 var res = this.map.getResolution();
72 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
73 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
74 var z = this.map.getZoom();
75 var limit = Math.pow(2, z);
77 if (y < 0 || y >= limit)
79 return OpenLayers.Util.OSM.MISSING_TILE_URL;
83 x = ((x % limit) + limit) % limit;
86 var path = z + "/" + x + "/" + y + ".png";
88 if (url instanceof Array)
90 url = this.selectUrl(path, url);
97 CLASS_NAME: "OpenLayers.Layer.OSM"
101 * Class: OpenLayers.Layer.OSM.Mapnik
104 * - <OpenLayers.Layer.OSM>
106 OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
108 * Constructor: OpenLayers.Layer.OSM.Mapnik
112 * options - {Object} Hashtable of extra options to tag onto the layer
114 initialize: function(name, options) {
116 "http://a.tile.openstreetmap.org/",
117 "http://b.tile.openstreetmap.org/",
118 "http://c.tile.openstreetmap.org/"
120 options = OpenLayers.Util.extend(options, { numZoomLevels: 19 });
121 var newArguments = [name, url, options];
122 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
125 CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
129 * Class: OpenLayers.Layer.OSM.Osmarender
132 * - <OpenLayers.Layer.OSM>
134 OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
136 * Constructor: OpenLayers.Layer.OSM.Osmarender
140 * options - {Object} Hashtable of extra options to tag onto the layer
142 initialize: function(name, options) {
144 "http://a.tah.openstreetmap.org/Tiles/tile.php/",
145 "http://b.tah.openstreetmap.org/Tiles/tile.php/",
146 "http://c.tah.openstreetmap.org/Tiles/tile.php/"
148 options = OpenLayers.Util.extend(options, { numZoomLevels: 18 });
149 var newArguments = [name, url, options];
150 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
153 CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
157 * Class: OpenLayers.Layer.OSM.Maplint
160 * - <OpenLayers.Layer.OSM>
162 OpenLayers.Layer.OSM.Maplint = OpenLayers.Class(OpenLayers.Layer.OSM, {
164 * Constructor: OpenLayers.Layer.OSM.Maplint
168 * options - {Object} Hashtable of extra options to tag onto the layer
170 initialize: function(name, options) {
172 "http://d.tah.openstreetmap.org/Tiles/maplint.php/",
173 "http://e.tah.openstreetmap.org/Tiles/maplint.php/",
174 "http://f.tah.openstreetmap.org/Tiles/maplint.php/"
176 options = OpenLayers.Util.extend(options, { numZoomLevels: 18, isBaseLayer: false });
177 var newArguments = [name, url, options];
178 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
181 CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"