source: trunk/Modules/Map/Map.php@ 378

Last change on this file since 378 was 378, checked in by chronos, 13 years ago
  • Přidáno: Model pro NetworkSegment.
  • Upraveno: Přepracován model systém pro načítání modelů modulů.
File size: 4.8 KB
Line 
1<?php
2
3class NetworkMap extends Page
4{
5 var $FullTitle = 'Mapa sítě';
6 var $ShortTitle = 'Mapa sítě';
7 var $Load = 'initialize()';
8 var $Unload = 'GUnload()';
9
10 function Show()
11 {
12 global $Config;
13
14 $Output = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key='.$Config['Web']['GoogleMapsApiKey'].'"
15 type="text/javascript">
16 </script>';
17 $Output .= '<script type="text/javascript">
18
19 var map;
20 var tinyIcon;
21
22 function initialize()
23 {
24 if (GBrowserIsCompatible())
25 {
26 map = new GMap2(document.getElementById("map_canvas"));
27 map.setMapType(G_SATELLITE_MAP);
28 map.setCenter(new GLatLng(49.260422, 18.081179), 15);
29 map.setUIToDefault();
30 map.addControl(new GOverviewMapControl(new GSize(128, 96)));
31
32
33// Create our "tiny" marker icon
34var tinyIcon = new GIcon();
35tinyIcon.image = "point.gif";
36tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
37tinyIcon.iconSize = new GSize(10, 10);
38tinyIcon.shadowSize = new GSize(10, 10);
39tinyIcon.iconAnchor = new GPoint(5, 5);
40tinyIcon.infoWindowAnchor = new GPoint(5, 1);';
41
42 $Output .= '
43 }
44 }
45
46function toggleLabel(id)
47{
48 var ele = document.getElementById(id);
49 ele.checked = !ele.checked;
50 ele.onclick( );
51}
52
53 function UpdateNetworkLinks()
54 {
55 if ((document.getElementById("NetworkLinks")).checked == true)
56 {
57 NetworkLinks = [';
58 $DbResult = $this->Database->query('SELECT * FROM NetworkLink WHERE Interface1 <> 0 AND Interface2 <> 0');
59 while($Link = $DbResult->fetch_assoc())
60 {
61 $DbResult2 = $this->Database->query('SELECT * FROM NetworkDevice WHERE NetworkDevice.Id = (SELECT Device FROM NetworkInterface WHERE NetworkInterface.Id = '.$Link['Interface1'].')');
62 $DbResult3 = $this->Database->query('SELECT * FROM NetworkDevice WHERE NetworkDevice.Id = (SELECT Device FROM NetworkInterface WHERE NetworkInterface.Id = '.$Link['Interface2'].')');
63 if(($DbResult2->num_rows > 0) and ($DbResult3->num_rows > 0))
64 {
65 $Device1 = $DbResult2->fetch_assoc();
66 $Device2 = $DbResult3->fetch_assoc();
67 if(($Device1['Used'] == 1) and ($Device2['Used'] == 1))
68 $Output .= 'new GPolyline([new GLatLng('.$Device1['PositionLatitude'].', '.$Device1['PositionLongitude'].'),new GLatLng('.$Device2['PositionLatitude'].', '.$Device2['PositionLongitude'].')], "#4F4FBF", 3, 0.8), ';
69 }
70 }
71 $Output .= '];
72 for (var i in NetworkLinks)
73 {
74 map.addOverlay(NetworkLinks[i]);
75 }
76
77 } else { //checkbox turned off
78 for (var i in NetworkLinks)
79 {
80 map.removeOverlay(NetworkLinks[i]);
81 NetworkLinks[i] = null;
82 }
83 }
84}
85
86function toggleLabel(id)
87{
88 var ele = document.getElementById(id);
89 ele.checked = !ele.checked;
90 ele.onclick( );
91}
92
93 function UpdateNetworkDevices()
94 {
95 if ((document.getElementById("NetworkDevices")).checked == true)
96 {
97 NetworkDevices = [';
98
99 $DbResult = $this->Database->query('SELECT * FROM NetworkDevice WHERE Used=1');
100 while($Device = $DbResult->fetch_assoc())
101 {
102 $Output .= 'new GMarker(new GLatLng('.$Device['PositionLatitude'].', '.$Device['PositionLongitude'].'), {title: "'.$Device['Name'].'", icon:tinyIcon }), ';
103 }
104 $Output .= '];
105 for (var i in NetworkDevices)
106 {
107 map.addOverlay(NetworkDevices[i]);
108 }
109
110 } else { //checkbox turned off
111 for (var i in NetworkDevices)
112 {
113 map.removeOverlay(NetworkDevices[i]);
114 NetworkDevices[i] = null;
115 }
116 }
117}
118
119 </script>';
120 $Output .= '<table style="margin-left: auto; margin-right: auto; width: 100%; height: 80%;">
121 <tr>
122 <td style="width: 80%; height: 100%;">
123 <div id="map_canvas" style="width: 100%; height: 100%;"></div></td>
124 <td style="width: 20%">
125 <form>
126 <input type="checkbox" id="NetworkLinks" onClick="UpdateNetworkLinks();" >
127 <a href="" onClick="toggleLabel(\'NetworkLinks\');return false;">Ukázat spoje</a>
128 </input><br />
129 <input type="checkbox" id="NetworkDevices" onClick="UpdateNetworkDevices();" >
130 <a href="" onClick="toggleLabel(\'NetworkDevices\');return false;">Ukázat zařízení</a>
131 </input>
132 </form></td>
133 </tr>
134 </table>';
135 return($Output);
136 }
137}
138
139class ModuleMap extends Module
140{
141 function __construct($Database, $System)
142 {
143 parent::__construct($Database, $System);
144 $this->Name = 'Map';
145 $this->Version = '1.0';
146 $this->Creator = 'Chronos';
147 $this->License = 'GNU/GPL';
148 $this->Description = 'Show objects on Google maps';
149 $this->Dependencies = array('Network');
150 $this->SupportedModels = array();
151 }
152
153 function Init()
154 {
155 $this->System->Pages['map'] = 'NetworkMap';
156 }
157}
158
159?>
Note: See TracBrowser for help on using the repository browser.