summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-freifunk/luasrc/view/freifunk-map/map.htm
blob: f69401d6e35669b532a88a1ecda1d3a38161533d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Map</title>
	</head>

	<body style="margin:0">
		<script src="//dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1&s=1" type="text/javascript"></script>
		<script type="text/javascript">
			var alias = new Array;
			var points = new Array;
			var unkpos = new Array;
			var lineid = 0;
			onload=new Function("if(null!=window.ffmapinit)ffmapinit();");

			function Mid(mainip,aliasip)
			{
				alias[aliasip]=mainip;
			}

			function Node(mainip,lat,lon,ishna,hnaip,name)
			{
				points[mainip] = new VELatLong(lat, lon);
				map.AddPushpin(new VEPushpin(mainip, points[mainip],
				'<%=luci.config.main.resourcebase%>/freifunk-map/'+(ishna?'hna':'node')+'.gif', 'Node:'+name,
				'<br><img src="<%=luci.config.main.resourcebase%>/freifunk-map/'+(ishna?'hna':'node')+'.gif">'+
				'<br>IP:'+mainip+'<br>DefGW:'+hnaip));
			}

			function Self(mainip,lat,lon,ishna,hnaip,name)
			{
				//map.SetDashboardSize(VEDashboardSize.Small);
				map.LoadMap(new VELatLong(lat, lon), 15, VEMapStyle.Hybrid);
				map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
				map.ShowMiniMap(14, 474);
				Node(mainip,lat,lon,ishna,hnaip,name);
			}

			function Link(fromip,toip,lq,nlq,etx)
			{
				if (0==lineid && null!=window.ffmapstatic) ffmapstatic();
				if (null != alias[toip]) toip = alias[toip];
				if (null != alias[fromip]) fromip = alias[fromip];
				if (null != points[fromip] && null != points[toip])
				{
					var color;
					var red = 240;
					var green = 0;
					var blue = 0;
					var w = 1

					if (etx < 100) {red=252;green=102;blue=0;w=2};
					if (etx < 10) {red=255;green=203;blue=5;w=3};
					if (etx < 4) {red=240;green=255;blue=0;w=4};
					if (etx < 2) {red=0;green=204;blue=0;w=5};
					if (etx < 1) {red=80;green=0;blue=0;w=1};

					map.AddPolyline(new VEPolyline('id'+lineid, [points[fromip], points[toip]],
					new VEColor(red, green, blue, 0.5), w));


				}
				else
				{
					if (null == points[toip]) unkpos[toip] = '';
					if (null == points[fromip]) unkpos[fromip] = '';
				}
				lineid++;
			}

			function PLink(fromip,toip,lq,nlq,etx,lata,lona,ishnaa,latb,lonb,ishnab)
			{
				Link(fromip,toip,lq,nlq,etx);
			}

			function ffmapinit()
			{
				if(null!=window.map)map.Dispose();

				var INFINITE = 99.99;

				map = new VEMap('ffmap');
				<%
					local fd
					local uci = require "luci.model.uci".cursor()

					uci:foreach("olsrd", "LoadPlugin", function(s)
						if s.library == "olsrd_nameservice" and s.latlon_file then
							fd = io.open(s.latlon_file)
						end
					end)

					if fd then
						local data = fd:read("*a")
						fd:close()

						if data then
							local line
							for line in data:gmatch("[^\n]+") do
								if line:match(";$") then
									write(line .. "\n")
								else
									break
								end
							end
						end
					end
				%>
			}

			function ffgoto(ip)
			{
				map.SetCenter(points[ip]);
			}
		</script>
		<div id="ffmap" style="position:relative; width:100%; height:640px;"></div>
	</body>
</html>