modules/freifunk: fix some quirks in the map
[project/luci.git] / modules / freifunk / luasrc / view / freifunk-map / map.htm
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3         <head>
4                 <title>Map</title>
5         </head>
6
7         <body style="margin:0">
8                 <script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>
9                 <script type="text/javascript">
10                         var alias = new Array;
11                         var points = new Array;
12                         var unkpos = new Array;
13                         var lineid = 0;
14                         onload=new Function("if(null!=window.ffmapinit)ffmapinit();");
15
16                         function Mid(mainip,aliasip)
17                         {
18                                 alias[aliasip]=mainip;
19                         }
20
21                         function Node(mainip,lat,lon,ishna,hnaip,name)
22                         {
23                                 points[mainip] = new VELatLong(lat, lon);
24                                 map.AddPushpin(new VEPushpin(mainip, points[mainip],
25                                 '<%=luci.config.main.resourcebase%>/freifunk-map/'+(ishna?'hna':'node')+'.gif', 'Node:'+name,
26                                 '<br><img src="<%=luci.config.main.resourcebase%>/freifunk-map/'+(ishna?'hna':'node')+'.gif">'+
27                                 '<br>IP:'+mainip+'<br>DefGW:'+hnaip));
28                         }
29
30                         function Self(mainip,lat,lon,ishna,hnaip,name)
31                         {
32                                 //map.SetDashboardSize(VEDashboardSize.Small);
33                                 map.LoadMap(new VELatLong(lat, lon), 15, VEMapStyle.Hybrid);
34                                 map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
35                                 map.ShowMiniMap(14, 474);
36                                 Node(mainip,lat,lon,ishna,hnaip,name);
37                         }
38
39                         function Link(fromip,toip,lq,nlq,etx)
40                         {
41                                 if (0==lineid && null!=window.ffmapstatic) ffmapstatic();
42                                 if (null != alias[toip]) toip = alias[toip];
43                                 if (null != alias[fromip]) fromip = alias[fromip];
44                                 if (null != points[fromip] && null != points[toip])
45                                 {
46                                         var w = 1;
47                                         if (etx < 4) w++;
48                                         if (etx < 2) w++;
49                                         map.AddPolyline(new VEPolyline('id'+lineid, [points[fromip], points[toip]],
50                                         new VEColor(102,Math.floor(lq*255.0),Math.floor(nlq*255.0),1.0), w));
51                                 }
52                                 else
53                                 {
54                                         if (null == points[toip]) unkpos[toip] = '';
55                                         if (null == points[fromip]) unkpos[fromip] = '';
56                                 }
57                                 lineid++;
58                         }
59
60                         function PLink(fromip,toip,lq,nlq,etx,lata,lona,ishnaa,latb,lonb,ishnab)
61                         {
62                                 Link(fromip,toip,lq,nlq,etx);
63                         }
64
65                         function ffmapinit()
66                         {
67                                 if(null!=window.map)map.Dispose();
68
69                                 var INFINITE = 99.99;
70
71                                 map = new VEMap('ffmap');
72                                 <%
73                                         local fd
74                                         local uci = require "luci.model.uci".cursor()
75
76                                         uci:foreach("olsrd", "LoadPlugin", function(s)
77                                                 if s.library == "olsrd_nameservice.so.0.3" and s.latlon_file then
78                                                         fd = io.open(s.latlon_file)
79                                                 end
80                                         end)
81
82                                         if fd then
83                                                 local data = fd:read("*a")
84                                                 fd:close()
85
86                                                 if data then
87                                                         local line
88                                                         for line in data:gmatch("[^\n]+") do
89                                                                 if line:match(";$") then
90                                                                         write(line .. "\n")
91                                                                 else
92                                                                         break
93                                                                 end
94                                                         end
95                                                 end
96                                         end
97                                 %>
98                         }
99
100                         function ffgoto(ip)
101                         {
102                                 map.SetCenter(points[ip]);
103                         }
104                 </script>
105                 <div id="ffmap" style="position:relative; width:100%; height:640px;"></div>
106         </body>
107 </html>