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.34,-20037508.34,20037508.34,20037508.34),
52 maxResolution: 156543.0339,
54 projection: "EPSG:900913",
55 transitionEffect: "resize"
57 var newArguments = [name, url, options];
58 OpenLayers.Layer.TMS.prototype.initialize.apply(this, newArguments);
65 * bounds - {<OpenLayers.Bounds>}
68 * {String} A string with the layer's url and parameters and also the
69 * passed-in bounds and appropriate tile size specified as
72 getURL: function (bounds) {
73 var res = this.map.getResolution();
74 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
75 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
76 var z = this.map.getZoom();
77 var limit = Math.pow(2, z);
79 if (y < 0 || y >= limit)
81 return OpenLayers.Util.OSM.MISSING_TILE_URL;
85 x = ((x % limit) + limit) % limit;
88 var path = z + "/" + x + "/" + y + ".png";
90 if (url instanceof Array)
92 url = this.selectUrl(path, url);
99 CLASS_NAME: "OpenLayers.Layer.OSM"
103 * Class: OpenLayers.Layer.OSM.Mapnik
106 * - <OpenLayers.Layer.OSM>
108 OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
110 * Constructor: OpenLayers.Layer.OSM.Mapnik
114 * options - {Object} Hashtable of extra options to tag onto the layer
116 initialize: function(name, options) {
118 "http://a.tile.openstreetmap.org/",
119 "http://b.tile.openstreetmap.org/",
120 "http://c.tile.openstreetmap.org/"
122 options = OpenLayers.Util.extend({ numZoomLevels: 19 }, options);
123 var newArguments = [name, url, options];
124 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
127 CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
131 * Class: OpenLayers.Layer.OSM.Osmarender
134 * - <OpenLayers.Layer.OSM>
136 OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
138 * Constructor: OpenLayers.Layer.OSM.Osmarender
142 * options - {Object} Hashtable of extra options to tag onto the layer
144 initialize: function(name, options) {
146 "http://a.tah.openstreetmap.org/Tiles/tile/",
147 "http://b.tah.openstreetmap.org/Tiles/tile/",
148 "http://c.tah.openstreetmap.org/Tiles/tile/"
150 options = OpenLayers.Util.extend({ numZoomLevels: 18 }, options);
151 var newArguments = [name, url, options];
152 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
155 CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
159 * Class: OpenLayers.Layer.OSM.CycleMap
162 * - <OpenLayers.Layer.OSM>
164 OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, {
166 * Constructor: OpenLayers.Layer.OSM.CycleMap
170 * options - {Object} Hashtable of extra options to tag onto the layer
172 initialize: function(name, options) {
174 "http://a.andy.sandbox.cloudmade.com/tiles/cycle/",
175 "http://b.andy.sandbox.cloudmade.com/tiles/cycle/",
176 "http://c.andy.sandbox.cloudmade.com/tiles/cycle/"
178 options = OpenLayers.Util.extend({ numZoomLevels: 18 }, options);
179 var newArguments = [name, url, options];
180 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
183 CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap"
187 * Class: OpenLayers.Layer.OSM.Maplint
190 * - <OpenLayers.Layer.OSM>
192 OpenLayers.Layer.OSM.Maplint = OpenLayers.Class(OpenLayers.Layer.OSM, {
194 * Constructor: OpenLayers.Layer.OSM.Maplint
198 * options - {Object} Hashtable of extra options to tag onto the layer
200 initialize: function(name, options) {
202 "http://d.tah.openstreetmap.org/Tiles/maplint/",
203 "http://e.tah.openstreetmap.org/Tiles/maplint/",
204 "http://f.tah.openstreetmap.org/Tiles/maplint/"
206 options = OpenLayers.Util.extend({ numZoomLevels: 18, isBaseLayer: false, visibility: false }, options);
207 var newArguments = [name, url, options];
208 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
211 CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"