source: src/django_gheat/wlheatmap/templates/js/LayerBase.js@ 9779

Last change on this file since 9779 was 9653, checked in by rick, 13 years ago

Allow prefixing on domain proto to 'hack' a way making relative URLs by making
both CDN variables blank in local_settings.py.

File size: 8.2 KB
Line 
1/**
2 * Namespace: Util.OSM
3 */
4OpenLayers.Util.OSM = {};
5
6/**
7 * Constant: MISSING_TILE_URL
8 * {String} URL of image to display for missing tiles
9 */
10OpenLayers.Util.OSM.MISSING_TILE_URL = "http://openstreetmap.org/openlayers/img/404.png";
11
12/**
13 * Property: originalOnImageLoadError
14 * {Function} Original onImageLoadError function.
15 */
16OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError;
17
18/**
19 * Function: onImageLoadError
20 */
21OpenLayers.Util.onImageLoadError = function() {
22 if (this.src.match(/^http:\/\/[abc]\.[a-z]+\.openstreetmap\.org\//)) {
23 this.src = OpenLayers.Util.OSM.MISSING_TILE_URL;
24 } if (this.src.match(/^http:\/\/[def]\.tah\.openstreetmap\.org\//) == null) {
25 OpenLayers.Util.OSM.originalOnImageLoadError;
26 }
27};
28
29function get_balanced_urls(prefix, balancers, suffix) {
30 var urls = [];
31 for (var i=0; i < balancers.length; i++) {
32 urls.push(prefix + balancers[i] + suffix);
33 };
34 return urls;
35};
36
37
38
39/**
40 * Class: OpenLayers.Layer.OSM.Mapnik
41 *
42 * Inherits from:
43 * - <OpenLayers.Layer.OSM>
44 */
45OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
46 /**
47 * Constructor: OpenLayers.Layer.OSM.Mapnik
48 *
49 * Parameters:
50 * name - {String}
51 * options - {Object} Hashtable of extra options to tag onto the layer
52 */
53 initialize: function(name, options) {
54 var url = get_balanced_urls('{{ settings.OSM_PROXY_CDN_DOMAINS_PROTOCOL }}', {{ settings.OSM_PROXY_CDN_DOMAINS|safe }}, '{{ settings.OSM_PREFIX }}/${z}/${x}/${y}.png');
55 options = OpenLayers.Util.extend({ numZoomLevels: 19 }, 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 */
69OpenLayers.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({ numZoomLevels: 18 }, options);
84 var newArguments = [name, url, options];
85 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
86 },
87
88 CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
89});
90
91/**
92 * Class: OpenLayers.Layer.OSM.CycleMap
93 *
94 * Inherits from:
95 * - <OpenLayers.Layer.OSM>
96 */
97OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, {
98 /**
99 * Constructor: OpenLayers.Layer.OSM.CycleMap
100 *
101 * Parameters:
102 * name - {String}
103 * options - {Object} Hashtable of extra options to tag onto the layer
104 */
105 initialize: function(name, options) {
106 var url = [
107 "http://a.andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png",
108 "http://b.andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png",
109 "http://c.andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png"
110 ];
111 options = OpenLayers.Util.extend({ numZoomLevels: 19 }, options);
112 var newArguments = [name, url, options];
113 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
114 },
115
116 CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap"
117});
118
119/**
120 * Class: OpenLayers.Layer.OSM.Maplint
121 *
122 * Inherits from:
123 * - <OpenLayers.Layer.OSM>
124 */
125OpenLayers.Layer.OSM.Maplint = OpenLayers.Class(OpenLayers.Layer.OSM, {
126 /**
127 * Constructor: OpenLayers.Layer.OSM.Maplint
128 *
129 * Parameters:
130 * name - {String}
131 * options - {Object} Hashtable of extra options to tag onto the layer
132 */
133 initialize: function(name, options) {
134 var url = [
135 "http://d.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
136 "http://e.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
137 "http://f.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png"
138 ];
139 options = OpenLayers.Util.extend({ numZoomLevels: 21, isBaseLayer: false, visibility: false }, options);
140 var newArguments = [name, url, options];
141 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
142 },
143
144 CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"
145});
146
147/**
148 * Gheat layer
149 */
150OpenLayers.Layer.OSM.Overlay1 = OpenLayers.Class(OpenLayers.Layer.OSM, {
151 initialize: function(name, options) {
152 var url = [
153 "/gheat/classic/${z}/${x},${y}.png"
154 ];
155 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
156 var newArguments = [name, url, options];
157 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
158 },
159 colour: "0,0,0",
160 CLASS_NAME: "OpenLayers.Layer.Overlay"
161});
162
163/**
164 * All accespoints
165 */
166OpenLayers.Layer.OSM.Overlay2 = OpenLayers.Class(OpenLayers.Layer.OSM, {
167 initialize: function(name, options) {
168 var url = get_balanced_urls('{{ settings.DJANGO_CDN_DOMAINS_PROTOCOL }}' , {{ settings.DJANGO_CDN_DOMAINS|safe }},
169 '{{ settings.DJANGO_PREFIX }}/wlheatmap/tile/${z}/${x},${y}.png?colour=90,90,90');
170 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
171 var newArguments = [name, url, options];
172 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
173 },
174 colour: "90,90,90",
175 CLASS_NAME: "OpenLayers.Layer.Overlay"
176});
177
178/**
179 * Wireless Leiden nodes
180 */
181OpenLayers.Layer.OSM.Overlay3 = OpenLayers.Class(OpenLayers.Layer.OSM, {
182 initialize: function(name, options) {
183 var url = get_balanced_urls('{{ settings.DJANGO_CDN_DOMAINS_PROTOCOL }}', {{ settings.DJANGO_CDN_DOMAINS|safe }},
184 '{{ settings.DJANGO_PREFIX }}/wlheatmap/tile/${z}/${x},${y}.png?colour=255,0,0&accespoint__organization__name__startswith=Wireless');
185 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
186 var newArguments = [name, url, options];
187 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
188 },
189 colour: "255,0,0",
190 CLASS_NAME: "OpenLayers.Layer.Overlay"
191});
192
193/**
194 * Signal strength
195 */
196OpenLayers.Layer.OSM.Overlay4 = OpenLayers.Class(OpenLayers.Layer.OSM, {
197 initialize: function(name, options) {
198 var url = get_balanced_urls('{{ settings.DJANGO_CDN_DOMAINS_PROTOCOL }}', {{ settings.DJANGO_CDN_DOMAINS|safe }},
199 '{{ settings.DJANGO_PREFIX }}/wlheatmap/tile/${z}/${x},${y}.png?colour=50,150,50&signaal__gte=0&signaal__lte=100');
200 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
201 var newArguments = [name, url, options];
202 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
203 },
204 colour: "50,150,50",
205 CLASS_NAME: "OpenLayers.Layer.Overlay"
206});
207
208// create the layer styleMap by giving the default style a context
209var context = {
210 getSize: function(feature) {
211 var resolution = map.getResolution();
212 var scale = map.getZoom();
213 var base = 1;
214 if (scale > 16) {
215 base = 5;
216 } else if (scale > 14) {
217 base = 20;
218 } else {
219 base = 50;
220 }
221 return (base / map.getResolution());
222 },
223 getColor: function(feature) {
224 return feature.attributes.color;
225
226 }
227};
228var template = {
229 pointRadius: "${getSize}", // using context.getSize(feature)
230 fillColor: "${getColor}", // using context.getColor(feature)
231 strokeWidth: 0.5
232};
233var nodesStyle = new OpenLayers.Style(template, {context: context});
234
235OpenLayers.Layer.GML.NodesOverlay = OpenLayers.Class(OpenLayers.Layer.GML, {
236 initialize: function(name, options) {
237 var url = "{% url wlheatmap.feature.nodes_json %}";
238 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
239 var newArguments = [name, url, options];
240 OpenLayers.Layer.GML.prototype.initialize.apply(this, newArguments);
241 },
242 colour: '0,255,0',
243 projection: new OpenLayers.Projection("EPSG:4326"),
244 styleMap: new OpenLayers.StyleMap(nodesStyle),
245 format: OpenLayers.Format.GeoJSON,
246 CLASS_NAME: "OpenLayers.Layer.Overlay"
247});
248
Note: See TracBrowser for help on using the repository browser.