68620dacb3ecbe520ee829e2ce15ce1886b1e6bd
[rails.git] / vendor / assets / openlayers / OpenStreetMap.js
1 /**
2  * Namespace: Util.OSM
3  */
4 OpenLayers.Util.OSM = {};
5
6 /**
7  * Constant: MISSING_TILE_URL
8  * {String} URL of image to display for missing tiles
9  */
10 OpenLayers.Util.OSM.MISSING_TILE_URL = "http://www.openstreetmap.org/openlayers/img/404.png";
11
12 /**
13  * Property: originalOnImageLoadError
14  * {Function} Original onImageLoadError function.
15  */
16 OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError;
17
18 /**
19  * Function: onImageLoadError
20  */
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
26     } else {
27         OpenLayers.Util.OSM.originalOnImageLoadError;
28     }
29 };
30
31 /**
32  * Class: OpenLayers.Layer.OSM.Mapnik
33  *
34  * Inherits from:
35  *  - <OpenLayers.Layer.OSM>
36  */
37 OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
38     /**
39      * Constructor: OpenLayers.Layer.OSM.Mapnik
40      *
41      * Parameters:
42      * name - {String}
43      * options - {Object} Hashtable of extra options to tag onto the layer
44      */
45     initialize: function(name, options) {
46         var url = [
47             "http://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
48             "http://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
49             "http://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
50         ];
51         options = OpenLayers.Util.extend({
52             numZoomLevels: 19,
53             buffer: 0,
54             transitionEffect: "resize"
55         }, options);
56         var newArguments = [name, url, options];
57         OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
58     },
59
60     CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
61 });
62
63 /**
64  * Class: OpenLayers.Layer.OSM.Osmarender
65  *
66  * Inherits from:
67  *  - <OpenLayers.Layer.OSM>
68  */
69 OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
70     /**
71      * Constructor: OpenLayers.Layer.OSM.Osmarender
72      *
73      * Parameters:
74      * name - {String}
75      * options - {Object} Hashtable of extra options to tag onto the layer
76      */
77     initialize: function(name, options) {
78         var url = [
79             "http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
80             "http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
81             "http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
82         ];
83         options = OpenLayers.Util.extend({
84             numZoomLevels: 18,
85             buffer: 0,
86             transitionEffect: "resize"
87         }, options);
88         var newArguments = [name, url, options];
89         OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
90     },
91
92     CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
93 });
94
95 /**
96  * Class: OpenLayers.Layer.OSM.CycleMap
97  *
98  * Inherits from:
99  *  - <OpenLayers.Layer.OSM>
100  */
101 OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, {
102     /**
103      * Constructor: OpenLayers.Layer.OSM.CycleMap
104      *
105      * Parameters:
106      * name - {String}
107      * options - {Object} Hashtable of extra options to tag onto the layer
108      */
109     initialize: function(name, options) {
110         var url = [
111             "http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
112             "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
113             "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"
114         ];
115         options = OpenLayers.Util.extend({
116             numZoomLevels: 19,
117             buffer: 0,
118             transitionEffect: "resize"
119         }, options);
120         var newArguments = [name, url, options];
121         OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
122     },
123
124     CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap"
125 });
126
127 /**
128  * Class: OpenLayers.Layer.OSM.TransportMap
129  *
130  * Inherits from:
131  *  - <OpenLayers.Layer.OSM>
132  */
133 OpenLayers.Layer.OSM.TransportMap = OpenLayers.Class(OpenLayers.Layer.OSM, {
134     /**
135      * Constructor: OpenLayers.Layer.OSM.TransportMap
136      *
137      * Parameters:
138      * name - {String}
139      * options - {Object} Hashtable of extra options to tag onto the layer
140      */
141     initialize: function(name, options) {
142         var url = [
143             "http://a.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png",
144             "http://b.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png",
145             "http://c.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png"
146         ];
147         options = OpenLayers.Util.extend({
148             numZoomLevels: 19,
149             buffer: 0,
150             transitionEffect: "resize"
151         }, options);
152         var newArguments = [name, url, options];
153         OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
154     },
155
156     CLASS_NAME: "OpenLayers.Layer.OSM.TransportMap"
157 });