source: src/django_gheat/website/static/heatmap.js@ 9179

Last change on this file since 9179 was 9177, checked in by dennisw, 14 years ago

Progress on showing nodes around mouse when hovering over map.
Right now, it returns some placeholder json object on click.

Next steps: replace placeholder with real data, print readable lines instead of [object Object], and get mouse boundaries.

File size: 2.2 KB
Line 
1function init(){
2
3 var projection_wgs = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
4
5 map = new OpenLayers.Map('heatmap', {
6 controls: [
7 new OpenLayers.Control.Navigation(),
8 new OpenLayers.Control.PanZoomBar(),
9 new OpenLayers.Control.ScaleLine(),
10 new OpenLayers.Control.LayerSwitcher(),
11 new OpenLayers.Control.MousePosition({ 'displayProjection' : projection_wgs }),
12 ],
13 maxExtent: new OpenLayers.Bounds(-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892),
14 numZoomLevels:16,
15 maxResolution:156543.0339,
16 units:'m',
17 projection: "EPSG:900913",
18 displayProjection: new OpenLayers.Projection("EPSG:4326")
19 });
20
21 map.events.register('click', map, GetMousePos);
22 function GetMousePos(pos) {
23 var pixel = new OpenLayers.Pixel(pos.xy.x,pos.xy.y);
24 var lonlat = map.getLonLatFromPixel(pixel);
25 var mousepos = OpenLayers.Layer.SphericalMercator.inverseMercator(lonlat.lon, lonlat.lat);
26 loadNodeList(mousepos);
27 }
28
29 layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
30 map.addLayer(layerMapnik);
31 layerHeatmap = new OpenLayers.Layer.OSM.Overlay1("Overlay 1", {isBaseLayer: false, visibility: true});
32 map.addLayer(layerHeatmap);
33
34 layerHeatmap2 = new OpenLayers.Layer.OSM.Overlay2("All Access points", {isBaseLayer: false, visibility: true});
35 map.addLayer(layerHeatmap2);
36
37 layerHeatmap3 = new OpenLayers.Layer.OSM.Overlay3("Wireless Leiden Only", {isBaseLayer: false, visibility: true});
38 map.addLayer(layerHeatmap3);
39
40 var lon = 4.48907;
41 var lat = 52.158431;
42 var zoom = 16;
43
44 var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
45 map.setCenter (lonLat, zoom);
46}
47
48function loadNodeList(mousepos){
49 var nodelist;
50 if (window.XMLHttpRequest){
51 // code for IE7+, Firefox, Chrome, Opera, Safari
52 nodelist=new XMLHttpRequest();
53 }
54 else{
55 // code for IE6, IE5
56 nodelist=new ActiveXObject("Microsoft.XMLHTTP");
57 }
58
59 nodelist.onreadystatechange=function(){
60 if (nodelist.readyState==4 && nodelist.status==200){
61 txt=eval("("+nodelist.responseText+")")
62 document.getElementById('nodelist').innerHTML=txt;
63 }
64 }
65
66 nodelist.open("GET","/website/nodelist/" + mousepos.lat + "," + mousepos.lon,true);
67 nodelist.send();
68}
Note: See TracBrowser for help on using the repository browser.