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

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

Some tricks to start making permalinks for custom filters to be able to share more interesing views right from a single link. As building those filters can sometimes be a burden...

File size: 4.6 KB
RevLine 
[9302]1/**
2 * Var 'map' is set global, used in 'heatmap_extensions.js'.
3 */
[9203]4var map;
[9302]5
[9570]6function init_heatmap(){
[9269]7 var lat = getURLParameter('lat');
8 var lon = getURLParameter('lon');
9 var zoom = getURLParameter('zoom');
10
11 if(lat=='null' || lon=='null' || zoom=='null'){
[9316]12 var lat = 52.15514;
13 var lon = 4.48959;
14 var zoom = 13;
[9269]15 }
[9264]16 var projection_wgs = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
[9139]17
[9264]18 map = new OpenLayers.Map('heatmap', {
[9583]19 theme: null,
[9264]20 controls: [
21 new OpenLayers.Control.Navigation(),
[9782]22 new OpenLayers.Control.Permalink({
23 anchor : true,
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 }
65 //XXX: Hack custom filters in here
66 params.customParam = "foo";
67 return params;
68 }
69 }),
[9546]70 new OpenLayers.Control.PanZoomBar(),
[9587]71 new OpenLayers.Control.ZoomBox(),
[9583]72 new OpenLayers.Control.OverviewMap({
[9587]73 maximized : false,
[9648]74 mapOptions: { theme: null }
[9583]75 }),
[9649]76 new OpenLayers.Control.MousePosition({ 'displayProjection' : projection_wgs })
[9302]77 /**
78 * Decided to disable these controls.
79 * The layerswitcher has been replaced with a custom one. If you want the original back,
80 * make sure to disable the custom one to prevent collision.
81 */
82
[9576]83 //new OpenLayers.Control.PanZoomBav(),
[9264]84 //new OpenLayers.Control.ScaleLine(),
[9276]85 //new OpenLayers.Control.LayerSwitcher(),
[9264]86 ],
87 maxExtent: new OpenLayers.Bounds(-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892),
88 numZoomLevels:16,
89 maxResolution:156543.0339,
90 units:'m',
91 projection: "EPSG:900913",
92 displayProjection: new OpenLayers.Projection("EPSG:4326")
93 });
[9175]94
[9264]95 map.events.register('click', map, GetMousePos);
96 function GetMousePos(pos) {
97 var pix = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x,pos.xy.y));
98 var mousepos = OpenLayers.Layer.SphericalMercator.inverseMercator(pix.lon, pix.lat);
99 var zoomlevel = map.getZoom();
100 getNodeList(zoom, mousepos);
101 }
[9175]102
[9264]103 layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
104 map.addLayer(layerMapnik);
[9147]105
[9264]106 var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
107 map.setCenter (lonLat, zoom);
[9274]108
109
[9302]110 /**
[9599]111 * Layers are created and put in switcher
[9302]112 */
[9599]113 function add_item(category, layer) {
114 map.addLayer(layer);
115 var checked = '';
116 if (layer.getVisibility()) { checked = "checked='checked'"; };
117 $("#" + category).append("<span id=\"" + layer.name + "\">" +
118 " <div id='layer_switcher_colour' style='background-color:rgb(" + layer.colour + ")' />" +
119 "<input type='checkbox' id='togglelayer' " + checked + " /><font>" + layer.name + " </font><br /></span>"
120 );
121 }
[9302]122
[9599]123 var signallayer = new OpenLayers.Layer.OSM.Overlay4("signallayer", {isBaseLayer: false, visibility: false});
124 var wlsignalLayer = new OpenLayers.Layer.OSM.Overlay3("Wireless Leiden Coverage", {isBaseLayer: false, visibility: true});
125 var nodesLayer = new OpenLayers.Layer.GML.NodesOverlay("Node Locations", {isBaseLayer: false, visibility: false});
[9274]126
[9599]127 add_item('default', signallayer);
128 add_item('default', wlsignalLayer);
129 add_item('features', nodesLayer);
[9139]130}
Note: See TracBrowser for help on using the repository browser.