map_functions.inc 49.6 KB
Newer Older
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1001
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
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
 * @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
1061
1062
1063
1064
1065
1066
	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
1067
1068
1069
1070
    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
1071
1072
1073
1074
1075
1076
1077
        '<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">' +
1078
						'<img class="legendBandIcon" src="images/mapMarkers/greyRadioCircle-icon.png">Other' +
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
				'</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
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
        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
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
	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
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
";

    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)
    {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1165
    	date_timezone_set($filetime, $GLOBALS['localTimeZone']);
1166
        $filetime = date_format($filetime, 'F d Y H:i:s T');
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1167
1168
1169
1170
1171
1172
1173
1174
1175
    }

    //$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.\">" . 
1176
    	$numLinks . "</a> links " . "&nbsp;|&nbsp;Data Last Acquired @ " . $filetime . "</strong>';\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1177

1178
1179
1180
1181
1182
    $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' .
1183
		"N2MH and K6GSE" . '\n' .
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1184
1185
		"Official Testing Guinea Pig:" . '\n' .
		"N7QJK\'>KG6WXC</a>&nbsp;|&nbsp;';\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207

    $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
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
// 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
1227
1228
1229
EOD;

    $Content .= <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
//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
1264
1265
1266
1267
1268
1269
    var hash = new L.Hash(map);

    /*
     * MeshMap Legend
     */
    legend.addTo(map);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1270
	legendHidden.addTo(map);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1271
1272
1273
    /*
     * Layer Control
     */
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1274
    var layerControls = L.control.groupedLayers(baseLayers, groupedOverlays, {position: 'verticalcenterleft'}).addTo(map);
1275
1276
	L.DomEvent.disableClickPropagation(layerControls._container);
	L.DomEvent.disableScrollPropagation(layerControls._container);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1277
1278
1279
1280
    /*
     * Scale Control
     */
    L.control.scale().addTo(map);\n
1281
1282
1283
1284
1285
1286
1287
/*
*The "help" button
*/
var contents = "";

EOD;

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
    if (!isset($GLOBALS['hide_admin']) == "1") {
    	$Content .= <<< EOD
	//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);
	}
	/*
	*admin control button
	*/
	L.control.admin().addTo(map);
EOD;
    }
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
    
//    $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
1336
    $Content .= "\nL.control.slideMenu(contents, {width: '400px', position: 'verticalcenterleft'}).addTo(map);\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1337
1338
	/* Attribution */
	//attributionCtrl({position: 'bottomleft'}).addTo(map);\n
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1339
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1340
1341
1342
1343
1344
1345
    return $Content;
}
?>