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

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

Nodelist progress. Shows nodes around mouse when you click on map. Next; fix boundaries per zoomlevel and nodelist display.

File size: 2.4 KB
RevLine 
[9139]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 });
[9175]20
21 map.events.register('click', map, GetMousePos);
22 function GetMousePos(pos) {
[9186]23 var pixbuffer = 100;
24 var sw = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x+pixbuffer,pos.xy.y-pixbuffer));
25 var ne = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x-pixbuffer,pos.xy.y+pixbuffer));
26 var pointsw = OpenLayers.Layer.SphericalMercator.inverseMercator(sw.lon, sw.lat);
27 var pointne = OpenLayers.Layer.SphericalMercator.inverseMercator(ne.lon, ne.lat);
28 getNodeList(pointsw, pointne);
[9175]29 }
30
[9139]31 layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
32 map.addLayer(layerMapnik);
33 layerHeatmap = new OpenLayers.Layer.OSM.Overlay1("Overlay 1", {isBaseLayer: false, visibility: true});
34 map.addLayer(layerHeatmap);
[9147]35
[9177]36 layerHeatmap2 = new OpenLayers.Layer.OSM.Overlay2("All Access points", {isBaseLayer: false, visibility: true});
[9147]37 map.addLayer(layerHeatmap2);
[9166]38
39 layerHeatmap3 = new OpenLayers.Layer.OSM.Overlay3("Wireless Leiden Only", {isBaseLayer: false, visibility: true});
40 map.addLayer(layerHeatmap3);
[9139]41
42 var lon = 4.48907;
43 var lat = 52.158431;
44 var zoom = 16;
45
46 var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
47 map.setCenter (lonLat, zoom);
48}
[9175]49
[9186]50function getNodeList(sw, ne){
[9177]51 var nodelist;
52 if (window.XMLHttpRequest){
53 // code for IE7+, Firefox, Chrome, Opera, Safari
54 nodelist=new XMLHttpRequest();
[9175]55 }
[9177]56 else{
57 // code for IE6, IE5
58 nodelist=new ActiveXObject("Microsoft.XMLHTTP");
[9175]59 }
60
[9177]61 nodelist.onreadystatechange=function(){
62 if (nodelist.readyState==4 && nodelist.status==200){
[9186]63 txt=nodelist.responseText
[9177]64 document.getElementById('nodelist').innerHTML=txt;
[9175]65 }
66 }
[9177]67
[9186]68 nodelist.open("GET","/website/nodelist/" + sw.lat + "," + sw.lon + "," + ne.lat + "," + ne.lon,true);
[9177]69 nodelist.send();
[9175]70}
Note: See TracBrowser for help on using the repository browser.