source: src/django_gheat/wlheatmap/static/heatmap.js@ 9816

Last change on this file since 9816 was 9813, checked in by rick, 13 years ago

Permalink custom layers, nice!

File size: 6.1 KB
Line 
1/**
2 * Var 'map' is set global, used in 'heatmap_extensions.js'.
3 */
4var map;
5
6function init_heatmap(){
7 var lat = getURLParameter('lat');
8 var lon = getURLParameter('lon');
9 var zoom = getURLParameter('zoom');
10
11 if(lat=='null' || lon=='null' || zoom=='null'){
12 var lat = 52.15514;
13 var lon = 4.48959;
14 var zoom = 13;
15 }
16 var projection_wgs = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
17
18 map = new OpenLayers.Map('heatmap', {
19 theme: null,
20 controls: [
21 new OpenLayers.Control.Navigation(),
22 new OpenLayers.Control.Permalink({
23 anchor : false,
24 createParams: function(center, zoom, layers) {
25 center = center || this.map.getCenter();
26
27 var params = OpenLayers.Util.getParameters(this.base);
28
29 // If there's still no center, map is not initialized yet.
30 // Break out of this function, and simply return the params from the
31 // base link.
32 if (center) {
33
34 //zoom
35 params.zoom = zoom || this.map.getZoom();
36
37 //lon,lat
38 var lat = center.lat;
39 var lon = center.lon;
40
41 if (this.displayProjection) {
42 var mapPosition = OpenLayers.Projection.transform(
43 { x: lon, y: lat },
44 this.map.getProjectionObject(),
45 this.displayProjection );
46 lon = mapPosition.x;
47 lat = mapPosition.y;
48 }
49 params.lat = Math.round(lat*100000)/100000;
50 params.lon = Math.round(lon*100000)/100000;
51
52 //layers
53 layers = layers || this.map.layers;
54 params.layers = '';
55 for (var i=0, len=layers.length; i<len; i++) {
56 var layer = layers[i];
57
58 if (layer.isBaseLayer) {
59 params.layers += (layer == this.map.baseLayer) ? "B" : "0";
60 } else {
61 params.layers += (layer.getVisibility()) ? "T" : "F";
62 }
63 }
64 // Update permalink URL to reflect new location and filters
65 layerid = 0;
66 // First two and last one should be ignored
67 for (var i=4, len=layers.length; i < len; i++) {
68 var layer = layers[i];
69 if ($.isArray(layer.url)) {
70 var url = layer.url[0];
71 } else {
72 var url = layer.url;
73 }
74 var filter = url.split('?')[1];
75 layerid += 1;
76 params['layername' + layerid] = layer.name;
77 params['layercolour' + layerid] = layer.colour;
78 params['layerfilter' + layerid] = filter;
79 }
80 params['layercount'] = layerid;
81 }
82 return params;
83 },
84 draw: function() {
85 OpenLayers.Control.prototype.draw.apply(this, arguments);
86
87 if (!this.element && !this.anchor) {
88 this.element = document.createElement("a");
89 this.element.innerHTML = OpenLayers.i18n("Permalink");
90 this.element.href="";
91 this.div.appendChild(this.element);
92 }
93 this.map.events.on({
94 'moveend': this.updateLink,
95 'changelayer': this.updateLink,
96 'addlayer': this.updateLink,
97 'removelayer': this.updateLink,
98 'changebaselayer': this.updateLink,
99 scope: this
100 });
101
102 // Make it so there is at least a link even though the map may not have
103 // moved yet.
104 this.updateLink();
105
106 return this.div;
107 },
108 }),
109 new OpenLayers.Control.PanZoomBar(),
110 new OpenLayers.Control.ZoomBox(),
111 new OpenLayers.Control.OverviewMap({
112 maximized : false,
113 mapOptions: { theme: null }
114 }),
115 new OpenLayers.Control.MousePosition({ 'displayProjection' : projection_wgs })
116 /**
117 * Decided to disable these controls.
118 * The layerswitcher has been replaced with a custom one. If you want the original back,
119 * make sure to disable the custom one to prevent collision.
120 */
121
122 //new OpenLayers.Control.PanZoomBav(),
123 //new OpenLayers.Control.ScaleLine(),
124 //new OpenLayers.Control.LayerSwitcher(),
125 ],
126 maxExtent: new OpenLayers.Bounds(-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892),
127 numZoomLevels:16,
128 maxResolution:156543.0339,
129 units:'m',
130 projection: "EPSG:900913",
131 displayProjection: new OpenLayers.Projection("EPSG:4326")
132 });
133
134 map.events.register('click', map, GetMousePos);
135 function GetMousePos(pos) {
136 var pix = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x,pos.xy.y));
137 var mousepos = OpenLayers.Layer.SphericalMercator.inverseMercator(pix.lon, pix.lat);
138 var zoomlevel = map.getZoom();
139 getNodeList(zoom, mousepos);
140 }
141
142 layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
143 map.addLayer(layerMapnik);
144
145 var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
146 map.setCenter (lonLat, zoom);
147
148
149 /**
150 * Layers are created and put in switcher
151 */
152 function add_item(category, layer) {
153 map.addLayer(layer);
154 var checked = '';
155 if (layer.getVisibility()) { checked = "checked='checked'"; };
156 $("#" + category).append("<span id=\"" + layer.name + "\">" +
157 " <div id='layer_switcher_colour' style='background-color:rgb(" + layer.colour + ")' />" +
158 "<input type='checkbox' id='togglelayer' " + checked + " /><font>" + layer.name + " </font><br /></span>"
159 );
160 }
161
162 var signallayer = new OpenLayers.Layer.OSM.Overlay4("signallayer", {isBaseLayer: false, visibility: false});
163 var wlsignalLayer = new OpenLayers.Layer.OSM.Overlay3("Wireless Leiden Coverage", {isBaseLayer: false, visibility: true});
164 var nodesLayer = new OpenLayers.Layer.GML.NodesOverlay("Node Locations", {isBaseLayer: false, visibility: false});
165
166 add_item('default', signallayer);
167 add_item('default', wlsignalLayer);
168 add_item('features', nodesLayer);
169}
Note: See TracBrowser for help on using the repository browser.