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({
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:900913"
56 var newArguments = [name, url, options];
57 OpenLayers.Layer.TMS.prototype.initialize.apply(this, newArguments);
64 * bounds - {<OpenLayers.Bounds>}
67 * {String} A string with the layer's url and parameters and also the
68 * passed-in bounds and appropriate tile size specified as
71 getURL: function (bounds) {
72 var res = this.map.getResolution();
73 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
74 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
75 var z = this.map.getZoom();
76 var limit = Math.pow(2, z);
78 if (y < 0 || y >= limit)
80 return OpenLayers.Util.OSM.MISSING_TILE_URL;
84 x = ((x % limit) + limit) % limit;
87 var path = z + "/" + x + "/" + y + ".png";
89 if (url instanceof Array)
91 url = this.selectUrl(path, url);
98 CLASS_NAME: "OpenLayers.Layer.OSM"
102 * Class: OpenLayers.Layer.OSM.Mapnik
105 * - <OpenLayers.Layer.OSM>
107 OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
109 * Constructor: OpenLayers.Layer.OSM.Mapnik
113 * options - {Object} Hashtable of extra options to tag onto the layer
115 initialize: function(name, options) {
117 "http://a.tile.openstreetmap.org/",
118 "http://b.tile.openstreetmap.org/",
119 "http://c.tile.openstreetmap.org/"
121 options = OpenLayers.Util.extend({ numZoomLevels: 19 }, options);
122 var newArguments = [name, url, options];
123 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
126 CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
130 * Class: OpenLayers.Layer.OSM.Osmarender
133 * - <OpenLayers.Layer.OSM>
135 OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
137 * Constructor: OpenLayers.Layer.OSM.Osmarender
141 * options - {Object} Hashtable of extra options to tag onto the layer
143 initialize: function(name, options) {
145 "http://a.tah.openstreetmap.org/Tiles/tile.php/",
146 "http://b.tah.openstreetmap.org/Tiles/tile.php/",
147 "http://c.tah.openstreetmap.org/Tiles/tile.php/"
149 options = OpenLayers.Util.extend({ numZoomLevels: 18 }, options);
150 var newArguments = [name, url, options];
151 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
154 CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
158 * Class: OpenLayers.Layer.OSM.Maplint
161 * - <OpenLayers.Layer.OSM>
163 OpenLayers.Layer.OSM.Maplint = OpenLayers.Class(OpenLayers.Layer.OSM, {
165 * Constructor: OpenLayers.Layer.OSM.Maplint
169 * options - {Object} Hashtable of extra options to tag onto the layer
171 initialize: function(name, options) {
173 "http://d.tah.openstreetmap.org/Tiles/maplint.php/",
174 "http://e.tah.openstreetmap.org/Tiles/maplint.php/",
175 "http://f.tah.openstreetmap.org/Tiles/maplint.php/"
177 options = OpenLayers.Util.extend({ numZoomLevels: 18, isBaseLayer: false, visibility: false }, options);
178 var newArguments = [name, url, options];
179 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
182 CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"