map_functions.inc 45.6 KB
Newer Older
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1
2
3
4
5
6
7
8
<?php

/**
 * @name        map_functions.inc
 * @category    MESH MAP
 * @subcategory Display Map routines
 * @package     Active Node List
 * @author      Eric Satterlee, KG6WXC with K6GSE
9
10
 * @copyright   Copyright (c) 2018 as Open Source
 * @license     GPLv3 or later
Eric - kg6wxc's avatar
Eric - kg6wxc committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * @version     $Id$
 * @abstract    Eric has written a tool called get-map-info which retrieves HAM Mesh network devices,
 *                     their configuration and Linkage information. These details are populated in several SQL tables.
 *
 *
 *             These are the working functions for the meshMap display.
 *             There are three major sections of functions in this file:
 *             MESHMAP Map       - These are used to build the Markers and Links
 *             DATABASE access   - Used for all read-only access to the Database
 *             HTML Page Setup   - Used to build the infrastructure needed for the map display
 *
 *
 ********************************************************************************************************************/

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/******
* This file is part of the Mesh Mapping System.
* The Mesh Mapping System is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Mesh Mapping System is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.  
*
* You should have received a copy of the GNU General Public License   
* along with The Mesh Mapping System.  If not, see <http://www.gnu.org/licenses/>.
******/
Eric - kg6wxc's avatar
Eric - kg6wxc committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

/*
* MESHMAP Map Functions
*
*********************************************************************************************************************/
/**
 * @param $NodeList
 * @param $TopoList
 */
function build_NodesAndLinks($NodeList, $TopoList, $MarkerList = null)
{
    global $STABLE_MESH_VERSION;
    global $useNodes;
    global $useLinks;
    global $useMarkers;
    //icon names: default (green), update firmware (red) and for the different bands

57
    $markerList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
58
59
60
61
62
63
64
65
66
67
68
69

    //then get info from the node info database
    //use it to:
    //1: create markers for the map
    //2: do lots of stuff, like, use the topology data to make the link lines,
    //try to detect the tunnels vs everything else,
    //check what band the device is on,
    //find distance and bearing info of linked nodes. :) yes really!
    //try and tell the dtd links apart from the ones that are not dtd links but appear to be,
    //*real* DTD links will be very close together, if not the same,
    //the others, (like what Ventura Mesh uses) will be far apart and therefore probably not a "real" dtd link.

70
    $display_NodeList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
71
72
73
74
75
76
77
78
79
80
81
    if (is_array($NodeList) && !empty($NodeList))
    {
        foreach ($NodeList as $node_info)
        {
            $node_FirmwareStatus = checkVersion($node_info['firmware_version'], $STABLE_MESH_VERSION);

            if ($node_info['lat'] && $node_info['lon']) // Are there nodes with locations?
            {
                /*
                * find the Linked nodes to list
                *********************/
82
                $node_LinkedList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
83
84
85
86
87
                $node_LinkedList = load_LinkedTO($node_info, $TopoList);

                /*
                * Find the Services for the node
                ********************************/
88
			//	$node_ServiceList = load_ServiceList($node_info['olsrinfo_json']);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
89
90
			//	$node_ServiceList = '';
                $node_ServiceList = load_ServiceList($node_info['services']);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
91
92
93
94
95
96
97
98
99
100
101
102
103

                /*
                * Build the Nodes Marker
                */
                $display_NodeList .= build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_FirmwareStatus);
            }
        }
        if (!empty($display_NodeList))
        {
            $display_NodeList = rtrim($display_NodeList); // Rtrim off an ending newline
        }
    }

104
    $display_MarkerList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    if (isset($useMarkers) && $useMarkers)
    {
        foreach ($MarkerList as $Marker)
        {
            if ($Marker['lat'] && $Marker['lon']) //Are there Markers with location?
            {
                $display_MarkerList .= buildStationMarker($Marker); // Build Marker
            }
        }
        if (!empty($display_MarkerList))
        {
            $display_MarkerList = rtrim($display_MarkerList); // Rtrim off an ending newline
        }
    }

    /*
    * Create and Display the Link Lines
    ****************************************/
123
    $display_LinkList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    if (isset($useLinks) && $useLinks)
    {
        $display_LinkList = load_LinkList($NodeList, $TopoList);
        if (!empty($display_LinkList))
        {
            $display_LinkList = rtrim($display_LinkList); // Rtrim off an ending newline
        }
    }
    $display_MarkersAndLinks = $display_NodeList . $display_MarkerList . $display_LinkList;
    if (!empty($display_MarkersAndLinks))
    {
        $display_MarkersAndLinks = rtrim($display_MarkersAndLinks, ','); // Trim off the very last comma
    }
    $display_MarkersAndLinks .= ";\n\n";

    return $display_MarkersAndLinks;
}

/**
 * loadServiceList
 * This function parses the json data obtained from the node.
 * It looks for all of the plugins/services installed on the node.
 * The Service_line format is:
 *         Link or host value | [TCP | UDP ] | Advertised  service
 *
 * This routine will return the last ( end ) field of the service line, which is the Advertised service
 *
 * @param $json_array
 *
 * @return string List of Services to Display
 */
Eric - kg6wxc's avatar
Eric - kg6wxc committed
155
function load_ServiceList($serviceList)
Eric - kg6wxc's avatar
Eric - kg6wxc committed
156
{
Eric - kg6wxc's avatar
Eric - kg6wxc committed
157
    $localServiceArray =  wxc_listServices($serviceList);
158
    $serviceList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
159

Eric - kg6wxc's avatar
Eric - kg6wxc committed
160
    if (is_array($localServiceArray))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
161
    {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
162
    	foreach ($localServiceArray as $key => $value)
Eric - kg6wxc's avatar
Eric - kg6wxc committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
        {
            //WXC 6-30-2017: removed links for services that have no link
            if ($value == NULL) {
                $serviceList .= '<br>'. $key;
            }else {
                //WXC 6-30-2017: Moved <br> from after link to before the link,
                //made the pop up look better.
                $serviceList .= "<br><a href='" . $value . "' target='service'>" . $key . "</a>";
            }
        }
    }
    return $serviceList;
}

/**
 * loadLinkList
 * This function iterates through the topology array to build a leaflet package polyline
 * There are four types of links defined, each is represented by a different color.
 * RF Link - Standard Mesh Node link
 * DTD Link - Mesh nodes connected by direct link ( typically via a switch )
 * Tunnel Link -
 * Infinite Link - Links reported by and marked as unusable by olsr
 *
 * @param $NodeList
 * @param $TopoList
 *
 * @return mixed
 */
function load_LinkList($NodeList, $TopoList)
{
    global $MESH_SETTINGS;
194
    $linkList = "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
195
196
197
198
199
200
201
202
203
204
205
    if (isset($TopoList))
    {
        foreach ($TopoList as $value)
        {
            if ($value['nodelat'] && $value['linklon'])
                //if there's no location info ignore the entry
            {
                $node_lat = $value['nodelat'];
                $node_lon = $value['nodelon'];
                $link_lat = $value['linklat'];
                $link_lon = $value['linklon'];
206
                $display_color = 'red';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
207
208
209
                $display_weight = 2;
                $display_opacity = 1;
                $display_offset = 2;
210
                $map_LayerAssigned = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
                $tunnel = 0;
                $dtd = 0;
                $moreThanTen = 0;
                $infinite = 0;
                $nodeHasTunnel = 0;
                $linkHasTunnel = 0;
                $nodeName = $value['node'];
                $linkName = $value['linkto'];
                if ($value['cost'] == 1.0 && !($tunnel)) //find the tunnels
                {
                    foreach ($NodeList as $searching_for_tunnels)
                    {
                        if ($searching_for_tunnels['node'] == $nodeName)
                        {
                            if ($searching_for_tunnels['active_tunnel_count'] >= 1)
                            {
                                $nodeHasTunnel = 1;
                            }
                        }
                        if ($searching_for_tunnels['node'] == $linkName)
                        {
                            if ($searching_for_tunnels['active_tunnel_count'] >= 1)
                            {
                                $linkHasTunnel = 1;
                            }
                        }
                        if (($linkHasTunnel) && ($nodeHasTunnel))
                        {
                            $tunnel = 1;
                            $nodeHasTunnel = 0;
                            $linkHasTunnel = 0;
                            $display_color = $MESH_SETTINGS['Link_Tunnel'];
                            $dtd = 1;
                            $display_opacity = 0.5;
245
                            $map_LayerAssigned = 'tunnelLinks';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
                        }
                    }
                }
                if ($value['cost'] == 0.1 && $value['distance'] <= 0.7)
                    //find DTD links (always a cost of 0.1)
                {
                    $display_color = $MESH_SETTINGS['DTD_Link_Minus'];
                    $dtd = 1;
                    $display_opacity = 0.2;
                    $map_LayerAssigned = 'dtdLinks';
                }
                //this is for the "other" DTD links
                //using other wireless tech to create links that are seen as "DTD" by the AREDN software
                if ($value['cost'] == 0.1 && $value['distance'] > 0.7)
                {
                    $display_color = $MESH_SETTINGS['DTD_Link_Plus'];
                    $dtd = 1;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
263
264
                    $display_opacity = 0.3;
                    $display_weight = 0.3;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
                    $map_LayerAssigned = 'dtdLinks';
                }
                //find the "infinite cost" links (they show as "INFINITE" in the olsr files the other script changes that to 99.99)
                if ($value['cost'] == 99.99)
                {
                    $display_color = $MESH_SETTINGS['Link_Infinite'];
                    $infinite = 1;
                    $display_opacity = 0.2;
                    $map_LayerAssigned = 'infiniteLinks';
                }
                //links with a cost of less than 1.0 but NOT tunnels or DTD links
                //tunnels are always 1.0 and DTD is always 0.1
                if (($value['cost'] <= 1.000) && ($value['cost'] != 0.1) && !($tunnel))
                {
                    //these will always be a solid green
                    $display_color = $MESH_SETTINGS['Link_GOOD'];
                    $display_opacity = 0.5;
                    $map_LayerAssigned = 'rfLinks';
                }
                //links of greater than 10.000 ETX, but not "INFINITE" (these links are always red)
                if ($value['cost'] > 10.000 && $value['cost'] != 99.99)
                {
                    $display_color = $MESH_SETTINGS['Link_BAD'];
                    $moreThanTen = 1;
                    $display_opacity = 0.3;
                    $map_LayerAssigned = 'rfLinks';
                }
                //now for the more normal links
                //less than ETX 5.0 links
                if ($value['cost'] < 5 && !($dtd) && !($tunnel))
                {
                    $display_color = sprintf("#%02XFF00", ($value['cost'] - 1) * (255 / (5 - 1)));
                    $map_LayerAssigned = 'rfLinks';
                }
                //more than ETX 5.0 links
                if ($value['cost'] > 5 && !($moreThanTen) && !($infinite))
                {
                    $display_color = sprintf("#FF%02X00", ($value['cost'] - 1) * (255 / (5 - 1)) -
                        255);
                    $display_opacity = 0.5;
                    $map_LayerAssigned = 'rfLinks';
                }
                if ($map_LayerAssigned)
                {
309
310
311
312
313
314
                    $linkList .= 'L.polyline([[' . $node_lat . ',' . $node_lon . '],[' . $link_lat .
                        ',' . $link_lon . ']], {color: "' . $display_color . '", opacity: ' . $display_opacity .
                        ', weight: ' . $display_weight . ', offset: ' . $display_offset . '})
						.bindPopup("<strong>' .  $nodeName . '</strong> to <strong>' . $linkName . '</strong><br><strong>Cost</strong>: ' .
                        $value['cost'] . '")
						.addTo(' . $map_LayerAssigned . '),' . "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

                }
            }
        }
    }

    return $linkList;
}

/**
 * loadLinkedTO
 * This routine create a HTML formatted text list of link details.
 * The information gathered here is display as part of the node popup detail.
 *
 * @param $node_info
 * @param $TopoList
 *
 * @return string
 */
function load_LinkedTO($node_info, $TopoList)
{
336
    $linkedToList = '';
337
338
339
340
341
    $linkInfoForStationPopups = array($node_info['node'] => array());
    
    //don't init what is going to be an array as a string!!
    //$linkInfoForStationPopups = array($node_info['node'] => "");
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
342
    $node = $node_info['node'];
343
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
344
345
346
347
348
349
350
351
352
353
354
355
356
    //and build a big 3D array of it all
    //like  this:
    //array
    //	"NodeName"
    //		"1stLinkedNodesName"
    //			"CostFrom"
    //			"CostTo"
    //			"distance"
    //			"bearing"
    //		"2ndLinkedNodesName"
    //			"CostFrom"
    //			"CostTo"
    //etc..etc..
357
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
358
359
360
361
362
363
364
    if (isset($TopoList))
    {
        foreach ($TopoList as $value)
        {
            //if there's no location info (at each end of the link) ignore the entry
            if ($value['nodelat'] && $value['linklon'])
            {
365
366
                
                //this is the section that is exploding in php7.2.3
Eric - kg6wxc's avatar
Eric - kg6wxc committed
367
                if ($value['linkto'] == $node)
368
                {              
Eric - kg6wxc's avatar
Eric - kg6wxc committed
369
                    //this will be the cost FROM each linked station back TO the node we are currently looking at in the while loop
370
                    //had to create the array correctly! fixed 3-28-2018 - wxc
371
                    if (isset($linkInfoForStationPopups[$node_info['node']][$value['node']]) && is_array($linkInfoForStationPopups[$node_info['node']][$value['node']])) {
372
                        $linkInfoForStationPopups[$node_info['node']][$value['node']]['costFrom'] = $value['cost'];
373
374
375
                    }else {
                        $linkInfoForStationPopups[$node_info['node']][$value['node']] = array('costFrom' => $value['cost']);
                    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
376
377
378
                }
                if ($value['node'] == $node)
                {
379
                    //$linkedNodesKeyNameArray = array("costTo", "distance", "bearing");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
380
                    //this will be the cost TO each linked station FROM the node we are currently looking at in the while loop
381
382
                    //distance and bearing added too for goo measure! :)
                    //$linkInfoForStationPopups[$node_info['node']][$value['linkto']] = array_fill_keys($linkedNodesKeyNameArray, "");
383
                    $linkInfoForStationPopups[$node_info['node']][$value['linkto']]['costTo'] = $value['cost'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
384
                    //add in the distance to that linked node
385
                    $linkInfoForStationPopups[$node_info['node']][$value['linkto']]['distance'] = $value['distance'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
386
                    //add in the bearing to that linked node
387
                    $linkInfoForStationPopups[$node_info['node']][$value['linkto']]['bearing'] = $value['bearing'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
388
389
390
391
                }
            }
        }
    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    //now take all that info back out and put into a properly formatted string variable that we'll use later
    //this part of the function reformatted by kg6wxc.
    foreach ($linkInfoForStationPopups as $nodeNameLinkArray => $linktoArray) {
        if (!empty($linktoArray)) {
            foreach ($linktoArray as $linkedNodeName => $costArray) {
            	if (!empty($costArray)) {
            		if (!empty($costArray['costTo']) && !empty($costArray['costFrom'])) {
		                //if ((isset($costArray['costTo']) == 0.1) && (isset($costArray['costFrom']) == 0.1)) {
            			if ($costArray['costTo'] == "0.1" && $costArray['costFrom'] == "0.1") {
		                    $display_cost = ' <Link_DTD>(DTD)</Link_DTD> ';
		                }else {
		                    $display_cost = ' (' . $costArray['costTo'] . '/' . $costArray['costFrom'] . ') ';
		                }
		                $linkedToList .= $linkedNodeName . $display_cost . $costArray['distance'] . ' mi ' . $costArray['bearing'] . '&deg;<br>';
            		}
            	}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
            }
        }
    }

    return $linkedToList;
}


/**
 * buildMarker
 * This routine builds Mesh Markers.
 * These mesh markers are added to various map layer depending upon the type of node
 * The currently defined Mesh Markers are categorized by frequency
 *          2Ghz, 3Ghz, 5Ghz, 900Mhz, Linux systems
 *
 * Mesh Markers are stored in the node_info table, which is updated by the get-map-info.php routine
 *
 * @param $node_info
 * @param $node_ServiceList
 * @param $node_LinkedList
 * @param $node_FirmwareStatus
 *
 * @return string AssignedLayer
 */
function build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_FirmwareStatus)
{
434
    $markerList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
435
436
437
438
439
440
441
    $nodeUrl = "<NodeTitle><a href='http://" . $node_info['node'] . ".local.mesh:8080'>" . $node_info['node'] .
        "</a></NodeTitle>";

    //Now we look at the 'channel' value, for each node, from the node_info database.
    //Then compare it to what we know about each bands channels
    //if we find a match, we assume we're in that band...

442
    if ($node_info['firmware_version'] == 'Linux' || $node_info['firmware_version'] == 'linux')
Eric - kg6wxc's avatar
Eric - kg6wxc committed
443
    { // Linux Devices ( Special for SNOOPY )
444
445
        $icon = 'linuxCircle';
        $band = '<Device_Linux>Linux</Device_Linux>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
446
447
448
449
        $AssignedLayer = 'otherStations';
    }
    else
    {
450
        switch ((wxc_checkBand($node_info['channel'], $node_info['board_id'])))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
451
        {
452
453
454
            case '2GHz': // 2.4GHz devices
                $icon = 'twoRadioCircle';
                $band = '<Device_24GHz>2.4GHz</Device_24GHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
455
456
                $AssignedLayer = 'twoGHzStations';
                break;
457
458
459
            case '3GHz': // 3GHz devices
                $icon = 'threeRadioCircle';
                $band = '<Device_3GHz>3.4GHz</Device_3GHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
460
461
                $AssignedLayer = 'threeGHzStations';
                break;
462
463
464
            case '5GHz': // 5GHz devices
                $icon = 'fiveRadioCircle';
                $band = '<Device_5GHz>5.8GHz</Device_5GHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
465
466
                $AssignedLayer = 'fiveGHzStations';
                break;
467
468
469
            case '900MHz': // Note: Channel values borked for 900Mhz
                $icon = 'nineRadioCircle';
                $band = '<Device_900MHz>900MHz</Device_900MHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
470
471
472
                $AssignedLayer = 'nineHundredMHzStations';
                break;
            default: // unknown
473
474
                $icon = 'unknownRadioCircle';
                $band = '<unknown>?</unknown>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
475
476
477
478
479
480
481
482
483
484
485
                $AssignedLayer = 'otherStations';
        }
    }


    /*
    * check for Out of Date Firmware
    */
    switch ($node_FirmwareStatus)
    {
        case 1:
486
            $firmware = '<OutOfDate>Firmware: ' . $node_info['firmware_version'] . '</OutOfDate>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
487
488
            break;
        case 2:
489
490
            $firmware = '<Experimental>Firmware: ' . $node_info['firmware_version'] .
                '</Experimental>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
491
492
493
494
495
496
497
498
499
500
501
            break;
        default:
            $firmware = $node_info['firmware_version'];
    }


    /*
    * Now build the marker
    */
    if ($node_ServiceList)
    {
502
        $node_ServiceList = '<hr><Strong>Services:</Strong>' . $node_ServiceList;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
503
504
505
506
    }
    if ($node_LinkedList)
    {
        $node_LinkedList =
507
            '<hr><Strong>Linked to:<br>Node Name (cost to/from) distance bearing</Strong><br>' . $node_LinkedList;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
508
509
510
511
512
    }
    $markerList .= "L.marker([" . $node_info['lat'] . "," . $node_info['lon'] . "], {title: '" . $node_info['node'] .
        "', icon: " . $icon . "}).bindPopup(\" " . $nodeUrl . " (" . $band . ")<br>" . $node_info['lat'] .
        ", " . $node_info['lon'] . "<br>SSID: " . $node_info['ssid'] . "<br>Channel: " . $node_info['channel'] .
        ", Bandwidth: " . $node_info['chanbw'] . "<br>" . $node_info['model'] . "<br>" . $firmware .
Eric - kg6wxc's avatar
Eric - kg6wxc committed
513
514
515
516
517
518
519
520
        "<br>Last Polled: " . $node_info['last_seen'] . '<br>' . "Uptime: " . $node_info['uptime'] . '<br>';
    //dot
    if ($node_info['loadavg'] !== "NotAvailable") {
    	$loadavgs = unserialize($node_info['loadavg']);
    	//var_dump($loadavgs);
    	$markerList .= 'LoadAvg: 1 min ' . $loadavgs[0] . ', 5 min ' . $loadavgs[1] . ', 15 min ' . $loadavgs[2] . "<br>";
    }
    $markerList .= $node_ServiceList . $node_LinkedList . "\").addTo(" . $AssignedLayer . ") ,\n"; // Close out this node
Eric - kg6wxc's avatar
Eric - kg6wxc committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
    /*
    * If Upgrade Suggested add Node to that layer
    */
    if ($node_FirmwareStatus > 0)
    {
        $markerList .= "L.marker([" . $node_info['lat'] . "," . $node_info['lon'] . "], {title: '" .
            $node_info['node'] . "', icon: " . (($node_FirmwareStatus == 1) ? "redCircle" :
                "orangeCircle") . "}).bindPopup(\" " . $nodeUrl . " (" . $band . ")<br>" . $node_info['model'] .
            "<br>" . $firmware . "<br>" . (($node_FirmwareStatus == 1) ?
                "Software upgrade is highly recommended" : "Experimental") . " \").addTo(upgradeStations) ,\n";
    }

    return $markerList;
}

/**
 * buildStationMarker
 * This routine builds Station Markers. Station Markers are auxiliary (non-mesh) details to be displayed on the map.
 * These markers are added to the "Other Stations" layer.
 * The currently defined Station Markers are:
 *          Operator, Police Station, Fire Station, EOC, Hospital, Other
 *
 * Station Markers are stored in the station_info table. Station Markers are manually created.
 *
 * @param $station_info
 *
 * @return string AssignedLayer
 */
function buildStationMarker($Marker)
{

    //Now we look at the 'channel' value, for each node, from the node_info database.
    //Then compare it to what we know about each bands channels
    //if we find a match, we assume we're in that band...

    switch ($Marker['type'])
    {
        case "operator":
            // Operator Home Station
            $icon = "operatorIcon";
            $AssignedLayer = 'operatorsElements';
            break;
        case "police":
            $icon = "policeIcon";
            $AssignedLayer = 'policeElements';
            break;
        case "eoc":
            $icon = "eocIcon";
            $AssignedLayer = 'racesElements';
            break;
        case "firedepartment":
            $icon = "fireIcon";
            $AssignedLayer = 'fireElements';
            break;
        case "hospital":
            $icon = "hospitalIcon";
            $AssignedLayer = 'hospitalElements';
            break;
        default:
            // unknown
            $icon = "Red_Marker";
            $AssignedLayer = 'otherElements';
    }

    /*
    * Now build the marker
    */
    $markerList = "L.marker([" . $Marker['lat'] . "," . $Marker['lon'] . "], {title: '" . $Marker['name'] .
        "', icon: " . $icon . "}).bindPopup(\" " . $Marker['name'] . "<br>" . $Marker['description'] .
        "<br>" . $Marker['lat'] . ", " . $Marker['lon'] . "<br>TYPE: " . $Marker['type'] . "\")
        .addTo(" . $AssignedLayer . ") ,\n";

    return $markerList;
}


/*
* DATABASE access routines
**********************************************************************************************************************/
/**
 * load the Node data into an array.
 *
 * Where Clause and Orderby are optional
 * @param null $whereClause
 * @param null $orderBy
 *
 * @return array
 */
function load_Nodes($whereClause = null, $orderBy = null)
{
    /*
    * Node Table Query
    */
    global $USER_SETTINGS;
    global $useNodes;
    $NodeList = array();
    if (isset($USER_SETTINGS['sql_db_tbl_node']))
    {
        // Setup the Query ( replace WHERE and ORDER By as needed )
        $query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_node'] . " " .
            ($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
            ($orderBy ? $orderBy : " ORDER BY node");
        // Retrieve the data
        $node_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
        or die('Could not Select Items from Node Table: ' . mysqli_error());
        // Load the data into an array for ease of handling
        while ($node_info = mysqli_fetch_array($node_info_db, MYSQLI_ASSOC))
        {
            $NodeList[] = $node_info;
        }
        $useNodes = true;
    }
    else
    {
        $useNodes = false;
    }
    return $NodeList;
}


/**
 * load the Marker data into an array.
 *
 * Where Clause and Orderby are optional
 * @param null $whereClause
 * @param null $orderBy
 *
 * @return array
 */
function load_Markers($whereClause = null, $orderBy = null)
{
    /*
    * marker Table Query
    */
    global $USER_SETTINGS;
    global $useMarkers;
    $MarkerList = array();
    if (isset($USER_SETTINGS['sql_db_tbl_marker']))
    {
        // Setup the Query ( replace WHERE and ORDER By as needed )
        $query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_marker'] . " " .
            ($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
            ($orderBy ? $orderBy : " ORDER BY name");
        // Retrieve the data
        $marker_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
        or die('Could not Select Items from marker Table: ' . mysqli_error());
        // Load the data into an array for ease of handling
        while ($marker_info = mysqli_fetch_array($marker_info_db, MYSQLI_ASSOC))
        {
            $MarkerList[] = $marker_info;
        }
        $useMarkers = true;
    }
    else
    {
        $useMarkers = false;
    }
    return $MarkerList;
}


/**
 * load the Topology (or Link) Data into an array.
 *
 * Where Clause and Orderby are optional
 * @param null $whereClause
 * @param null $orderBy
 *
 * @return array
 */
function load_Topology($whereClause = null, $orderBy = null)
{
    /*
    * Topology Table Query
    */
    global $USER_SETTINGS;
    global $useLinks;
    $TopoList = array();
    if (isset($USER_SETTINGS['sql_db_tbl_topo']))
    {
        // Setup the Query ( replace WHERE and ORDER By as needed )
        $query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_topo'] . " " .
            ($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
            ($orderBy ? $orderBy : " ORDER BY distance, cost");
        // Retrieve the data
        $topology_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
        or die('Could not Select Items from Topology Table: ' . mysqli_error());
708
        $num = mysqli_num_rows($topology_info_db);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
709
        // Load the data into an array for ease of handling
710
711
        for ($i = 0; $i <= $num; ++$i)
        //while ($topology_info = mysqli_fetch_array($topology_info_db, MYSQLI_ASSOC))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
712
        {
713
714
            $TopoList[] = mysqli_fetch_array($topology_info_db, MYSQLI_ASSOC);
            //$TopoList[] = $topology_info;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
        }
        $useLinks = true;
    }
    else
    {
        $useLinks = false;
    }
    return $TopoList;
}

/*
* HTML Page Setup routines
**********************************************************************************************************************/
/**
 * add_MapLayers
 *
 * This routine adds the MapLayers needed
 * the (navigator.online) controls the display for online or offline browsers
733
 * No it doesn't, it doesn't tell you crap really... being on a LAN makes navigator.online true!!! DO NOT USE IT.
Eric - kg6wxc's avatar
Eric - kg6wxc committed
734
735
736
737
738
739
740
741
742
743
 * It has no bearing whatsoever if internet access is available or not
 *
 *
 * @return string - This string will need to be outputed to the browser
 */
function add_MapLayers()
{
if($GLOBALS['mesh']) {
	$offline_map_tiles = $GLOBALS['USER_SETTINGS']['offlineMapTileDir'];
	$Content = <<< EOD
744
            var offlineMapTiles = "$offline_map_tiles";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
745
746
747
748
749
750
751
            var defaultMap = new L.tileLayer(offlineMapTiles);

            var baseLayers = {"Offline Map": defaultMap};

        \n\n
EOD;
}else {
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
    $Content = "\n";
    $baseLayersString = "var baseLayers = {";
    $map_num = 0;
    foreach ($GLOBALS['USER_SETTINGS']['inetTileServer'] as $map_name => $map_url) {
        if(@strpos($map_name, "-Default")) {
            $map_name = preg_replace('/-Default/', '', $map_name);
            $Content .= "var defaultMap = new L.tileLayer('" . $map_url . "');\n";
            $baseLayersString .= "\"" . $map_name . "\": defaultMap,";
        }else {
            $map_num++;
            $Content .= "var map" . $map_num . " = new L.tileLayer('" . $map_url . "');\n";
            $baseLayersString .= "\"" . $map_name . "\": map" . $map_num . ",";
        }
    }
    $baseLayersString .= "};\n";
    $Content .= $baseLayersString;
/*
Eric - kg6wxc's avatar
Eric - kg6wxc committed
769
770
771
772
773
774
775
776
777
778
779
780
781
    $Content = <<< EOD
            var OSMMapURL = '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
            var terrainMapURL = '//stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg';
            var topoMapURL = '//{s}.tile.opentopomap.org/{z}/{x}/{y}.png';
            
            var OSMmap = new L.tileLayer(OSMMapURL);
            var defaultMap = new L.tileLayer(terrainMapURL);
            var topologyMap = new L.tileLayer(topoMapURL);
            
            var baseLayers = {"Topographic": topologyMap, "Street": OSMmap, "Terrain": defaultMap};

		\n\n
EOD;
782
*/
Eric - kg6wxc's avatar
Eric - kg6wxc committed
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
}
    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function add_MapImages($numNodes, $numLinks, $numMarkers)
{
    global $MESH_SETTINGS;
    $Content = "
    // Node and Link Icons
        var greenRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Default'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        // Out of Date node software
        var redCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_OOD'] . "',
            iconSize: [22, 22], iconAnchor: [11, 11], popupAnchor: [0, -9]
        });
        // Experiment node software
        var orangeCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Experimental'] . "',
            iconSize: [22, 22], iconAnchor: [11, 11], popupAnchor: [0, -9]
        });
        // 900 Mhz
        var nineRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_900MHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //2.4GHz
        var twoRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_24GHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //3GHz
        var threeRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_3GHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //5GHz
        var fiveRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_5GHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //Unknown
        var unknownRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Unknown'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        
        //a special one
        var linuxCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Linux'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });\n";

    if ($numMarkers > 0)
    {
        $Content .= "
        // Marker Icons
        var policeIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Police'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var fireIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Fire'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var operatorIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Operator'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var hospitalIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Hospital'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var eocIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_EOC'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var Red_Marker = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Future'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });\n\n";
    }
    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function create_MapLayers($numNodes, $numLinks, $numMarkers)
{
    //overlay groups to help superposition order
    $Content = "
    // Node Groups
    var nineHundredMHzStations = new L.LayerGroup();
    var twoGHzStations = new L.LayerGroup();
    var threeGHzStations = new L.LayerGroup();
    var fiveGHzStations = new L.LayerGroup();
    var otherStations = new L.LayerGroup();
    var upgradeStations = new L.LayerGroup();\n
";

    if ($numLinks > 0)
    {
        $Content .= "
        // Link Groups
        var rfLinks = new L . LayerGroup();
        var tunnelLinks = new L . LayerGroup();
        var dtdLinks = new L . LayerGroup();
        var infiniteLinks = new L . LayerGroup();
        var stations = new L . LayerGroup();
        var linkLines = new L . LayerGroup();
        var legendLayer = new L . layerGroup();\n
";
    }
    if ($numMarkers > 0)
    {
        $Content .= "
        // Marker Groups
        var otherElements = new L . LayerGroup();
        var policeElements = new L . LayerGroup();
        var fireElements = new L . LayerGroup();
        var hospitalElements = new L . LayerGroup();
        var racesElements = new L . LayerGroup();
        var operatorsElements = new L . LayerGroup();
        var otherElements = new L . LayerGroup();
        \n\n
";
    }

    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function create_MapOverlays($numNodes, $numLinks, $numMarkers)
{
    global $MESH_SETTINGS;
    $Content = "// Node Overlays
    var groupedOverlays = {
        \"Stations\": {
                \"<img src='" . $MESH_SETTINGS['Device_24GHz'] . "' height='20'>2.4GHz\": twoGHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_3GHz'] . "' height='20'>3.4GHz\": threeGHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_5GHz'] . "' height='20'>5.8GHz\": fiveGHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_900MHz'] . "' height='20'>900MHz\": nineHundredMHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_Linux'] . "' height='20'>Additional Mesh\": otherStations,
                \"<img src='" . $MESH_SETTINGS['Device_OOD'] . "' height='20'>Check Versions\": upgradeStations
        }";

    if ($numLinks > 0)
    {
        $Content .= "
                ,\n
        // Link Overlays
    \"Links\": {
    \"<Link_RF_Only>RF Only</Link_RF_Only>\": rfLinks,
            \"<Link_DTD>DTD</Link_DTD>\": dtdLinks,
            \"<Link_Tunnel>Tunnels</Link_Tunnel>\": tunnelLinks,
            \"<Link_Infinite>Infinite</Link_Infinite>\": infiniteLinks
        }\n";
    }

    if ($numMarkers > 0)
    {
        $Content .= "
        ,\n
        // Marker Layers
        \"Additional\": {
            \"<img src='" . $MESH_SETTINGS['Marker_Police'] . "' height='20'>Police\": policeElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Fire'] . "' height='20'>Fire Dept\": fireElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Hospital'] . "' height='20'>Hospital\": hospitalElements,
            \"<img src='" . $MESH_SETTINGS['Marker_EOC'] . "' height='20'>EOC\": racesElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Operator'] . "' height='20'>Operators\": operatorsElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Future'] . "' height='20'>Future Mesh\": otherElements
        }\n";
    }
    $Content .= "};\n\n";

    return $Content;
}


/**
 * @return string
 */
function create_MapLegend()
{
    //legend overlay
    $Content = <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
992
993
994
995
996
997
	var legendHidden = L.control({position: 'topright'});
	legendHidden.onAdd = function(map) {
		var div = L.DomUtil.create('div', 'info legendHidden', L.DomUtil.get('map'));
		div.innerHTML += '<button id="legendLinkButtonHidden" onclick="hideLegend()">Map Legend</button>';
		return div;
	};
Eric - kg6wxc's avatar
Eric - kg6wxc committed
998
999
1000
1001
    var legend = L.control({position: 'topright'});
    legend.onAdd = function (map) {
        var div = L.DomUtil.create('div', 'info legend', L.DomUtil.get('map'));
        div.innerHTML +=
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
        '<div id="legend">' +
                '<div id="legendGradientRectangle">1.000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Link Cost&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10.000</div>' +
                '<div id="legendDTDLink">DTD</div>' +
                '<div id="legendOtherWireless">RF DTD</div>' +
                '<div id="legendTunnelLink">Tunnel</div>' +
                '<div id="legendInfinite">Infinite</div>' +
				'<div id="legendUnknownOther">' +
						'<img class="legendBandIcon" src="images/mapMarkers/greyRadioCircle-icon.png">Unknown' +
				'</div>' +
                '<div id="legend900MHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/magentaRadioCircle-icon.png">900MHz' +
                '</div>' +
                '<div id="legend2GHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/purpleRadioCircle-icon.png">2GHz' +
                '</div>' +
                '<div id="legend3GHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/blueRadioCircle-icon.png">3GHz' +
                '</div>' +
                '<div id="legend5GHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/goldRadioCircle-icon.png">5GHz' +
                '</div>' +
				'<div id="legendHide"><button id="legendLinkButton" onclick="hideLegend()">Hide</button></div>' +
        '</div>';
//            '<img src="images/mapLegend/LinkCostLegend.jpg" alt="legend" width="175" height="25"><br>' +
//            '<img src="images/mapLegend/DTDLinkLegend.jpg" alt="legend" width="75" height="60" align="right">';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
        return div;
    };\n\n
EOD;

    return $Content;
}


/**
 * @return string
 */
function create_MapImage()
{
    global $USER_SETTINGS;
    //init the map with size, zoom level, center co-ords, etc...
    //http://leafletjs.com/reference-1.0.3.html#control-zoom
    $Content = "
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
	if (typeof rfLinks === 'undefined' || rfLinks === null) {
		var map = L.map('mapid', {
			//attributionControl: false,
	        center: [" . $USER_SETTINGS['map_center_coordinates'] . "],
	        zoom: [" . $USER_SETTINGS['map_initial_zoom_level'] . "],            
	        minZoom: 0,
			maxZoom: 18,
			//zoomSnap: 0,
			zoomSnap: 1,
			//zoomDelta: 0.25,
			zoomDelta: 1,
	        //layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations, rfLinks, tunnelLinks, dtdLinks, infiniteLinks],
	        layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations],
			//layers: [defaultMap],
			fullscreenControl: true
    	});\n\n
	}else {
	    var map = L.map('mapid', {
			//attributionControl: false,
	        center: [" . $USER_SETTINGS['map_center_coordinates'] . "],
	        zoom: [" . $USER_SETTINGS['map_initial_zoom_level'] . "],            
	        minZoom: 0,
			maxZoom: 18,
			//zoomSnap: 0,
			zoomSnap: 1,
			//zoomDelta: 0.25,
			zoomDelta: 1,
	        layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations, rfLinks, tunnelLinks, dtdLinks, infiniteLinks],
	        //layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations],
			//layers: [defaultMap],
			fullscreenControl: true
	    });\n\n
	}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
";

    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function show_MapMarkerDetails($numNodes, $numLinks, $numMarkers, $numNodesTotal, $numLinksTotal)
{
    // Get the last time we updated the link info
    $filetime = wxc_scriptGetLastDateTime("LINKINFO", "topology");
    if ($filetime)
    {
        $filetime = date_format($filetime, 'F d Y H:i:s');
    }

    //$Content = "MeshMapDetails = '<strong>" . $numNodes . " Nodes shown, with " . $numLinks .
    //    " links " . " &nbsp;&nbsp;&nbsp;Data Last Acquired @ " . $filetime . "</strong>';\n";
    
    $Content = "MeshMapDetails = '<strong><a style=\"color: inherit;text-decoration: none;\" href=\"\" title=\"" .
    	$numNodesTotal . " Total nodes in the database." . '\n' . "Nodes without Location info cannot be shown.\">" .
    	$numNodes . "</a> Nodes shown, with <a style=\"color: inherit;text-decoration: none;\" href=\"\" title=\"" .
    	$numLinksTotal . " Total links in the database." . '\n' . "Nodes without Location info cannot have links shown.\">" . 
1106
    	$numLinks . "</a> links " . "&nbsp;|&nbsp;Data Last Acquired @ " . $filetime . "</strong>';\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1107

1108
1109
1110
1111
1112
1113
    $Content .= "WXCAttribution = '<a href=mailto:kg6wxc@gmail.com title=\'" .
        "MeshMap version 2.5" . '\n\n' .
    	"Map originally created by:" . '\n' .
    	"KG6WXC in Oct 2016" .'\n' .
		"With later contributions from:" . '\n' .
		"N2MH and K6GSE\'>KG6WXC</a>&nbsp;|&nbsp;';\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135

    $Content .= "MapAttribution = '<a href=http://leafletjs.com title=\'" .
        "Map data &copy; by OpenStreetMap (http://openstreetmap.org) with contributions from:" . '\n' .
        "CC-BY-SA (http://creativecommons.org/licenses/by-sa/2.0/" . '\n' .
        "Map tiles (http://maps.stamen.com) by Stamen Design (http://stamen.com), under CC BY 3.0" .
        '\n' . "Map style (http://viewfinderpanoramas.org)" . '\n' . "Icons (www.flaticon.com)" . '\n' .
        "OpenTopoMap (https://opentopomap.org)\'>Leaflet</a>&nbsp;';\n";

    $Content .= "attributionCtrl = map.attributionControl;\n";
    $Content .= "attributionCtrl.setPrefix(WXCAttribution + MapAttribution);\n";
    $Content .= "attributionCtrl.addAttribution(MeshMapDetails);\n";

    return $Content;
}


/**
 * @return string
 */
function instantiate_Map()
{
    $Content = <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
// Create additional Control placeholders
function addControlPlaceholders(map) {
    var corners = map._controlCorners,
        l = 'leaflet-',
        container = map._controlContainer;

    function createCorner(vSide, hSide) {
        var className = l + vSide + ' ' + l + hSide;

        corners[vSide + hSide] = L.DomUtil.create('div', className, container);
    }

    createCorner('verticalcenter', 'left');
    createCorner('verticalcenter', 'right');
}
addControlPlaceholders(map);
map.zoomControl.setPosition('verticalcenterleft');
map.fullscreenControl.setPosition('verticalcenterleft');

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1155
1156
1157
1158
EOD;

    if (!isset($GLOBALS['hide_admin']) == "1") {
    $Content .= <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
//admin icon (the gears)
L.Control.Admin = L.Control.extend({
	options: {
		position: 'verticalcenterleft'
	},
	onAdd: function(map) {
		var adminControl = L.DomUtil.create('div', 'leaflet-control-custom leaflet-bar');
		adminControl.style.backgroundColor = 'white';
		//adminControl.content = "\F013";
		//adminControl.font-family = "FontAwesome";
		//adminControl.style.background = "fa-cog";
		adminControl.style.width = '30px';
		adminControl.style.height = '30px';
		adminControl.title = 'Admin';
		var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', adminControl);
		var gear = L.DomUtil.create('span', 'fa fa-cogs', link);
		gear.style.fontSize = '15px';
		adminControl.onclick = function() {
			//alert('you clicked it');
			window.location = "admin/admin.php";
		}
		return adminControl;
	}
});
L.control.admin = function(opts) {
	return new L.Control.Admin(opts);
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1186
1187
1188
1189
1190
1191
1192
/*
*admin control button
*/
L.control.admin().addTo(map);
EOD;
    }
    $Content .= <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
//the ruler
var rulerOptions = {position: 'verticalcenterleft',
	lengthUnit: {
		factor: 0.621371,
		display: 'Miles',
		decimal: 3}
	};
    L.control.ruler(rulerOptions).addTo(map);
    document.getElementById('ruler').title = 'Ruler\\n(ESC 1x to stop, 2x to remove)';

//the watermark logo
L.Control.Watermark = L.Control.extend({
	onAdd: function(map) {
		var img = L.DomUtil.create('img');
		img.src = 'images/MESHMAP_LOGO.svg';
		img.style.width = '75px';
		//img.className += 'watermark';
		img.style.background = 'rgba(0,0,0,0.5)';
		img.style.border = '1px solid black';
		img.style.borderRadius = '5px';
		img.style.opacity = '0.3';
		img.style.filter = 'alpha(opacity=30)';

		return img;
	},
	OnRemove: function(map) {
		//nothing
	}
});
L.control.watermark = function(opts) {
	return new L.Control.Watermark(opts);
}
L.control.watermark({position: 'bottomright'}).addTo(map);

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1227
1228
1229
1230
1231
1232
    var hash = new L.Hash(map);

    /*
     * MeshMap Legend
     */
    legend.addTo(map);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1233
	legendHidden.addTo(map);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1234
1235
1236
    /*
     * Layer Control
     */
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1237
    var layerControls = L.control.groupedLayers(baseLayers, groupedOverlays, {position: 'verticalcenterleft'}).addTo(map);
1238
1239
	L.DomEvent.disableClickPropagation(layerControls._container);
	L.DomEvent.disableScrollPropagation(layerControls._container);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1240
1241
1242
1243
    /*
     * Scale Control
     */
    L.control.scale().addTo(map);\n
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
/*
*The "help" button
*/
var contents = "";

EOD;

    
//    $help_msg = file_get_contents('../webpage/help_msg.html');
//    $Content .= "L.Control.slideMenu(\"" . $help_msg . "\").addTo(map);\n";

    $help_msg_file = fopen("help_msg.html", "r");
    if ($help_msg_file) {
        while (($line = fgets($help_msg_file)) != false) {
            $Content .= "contents += \"" . trim(preg_replace('/\s\s+/', ' ', $line)) . "\";\n";
        }
        fclose($help_msg_file);
    }else {
        $Content .= "alert('Could not open help_msg.html');\n";
    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1264
    $Content .= "\nL.control.slideMenu(contents, {width: '400px', position: 'verticalcenterleft'}).addTo(map);\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1265
1266
	/* Attribution */
	//attributionCtrl({position: 'bottomleft'}).addTo(map);\n
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1267
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1268
1269
1270
1271
1272
1273
    return $Content;
}
?>