mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Settings page for Worldmap widget
This commit is contained in:
@@ -23,7 +23,53 @@
|
||||
*/
|
||||
|
||||
if ($config['map']['engine'] == 'leaflet') {
|
||||
|
||||
if ((defined('show_settings') || empty($widget_settings)) && $config['front_page'] == "pages/front/tiles.php") {
|
||||
$temp_output = '
|
||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4">
|
||||
<label for="init_lat" class="control-label">Initial Latitude: </label>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<input class="form-control" name="init_lat" id="input_lat_'.$unique_id.'" value="'.$widget_settings['init_lat'].'" placeholder="ie. 51.4800 for Greenwich">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4">
|
||||
<label for="init_lng" class="control-label">Initial Longitude: </label>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<input class="form-control" name="init_lng" id="input_lng_'.$unique_id.'" value="'.$widget_settings['init_lng'].'" placeholder="ie. 0 for Greenwich">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4">
|
||||
<label for="init_zoom" class="control-label">Initial Zoom: </label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<select class="form-control" name="init_zoom" id="select_zoom'.$unique_id.'">
|
||||
';
|
||||
for ($i=0; $i<19; $i++) {
|
||||
if ($i == $widget_settings['init_zoom']) {
|
||||
$temp_output .= '<option selected value="'.$i.'">'.$i.'</option>';
|
||||
}
|
||||
else {
|
||||
$temp_output .= '<option value="'.$i.'">'.$i.'</option>';
|
||||
}
|
||||
}
|
||||
$temp_output .= '
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-2">
|
||||
<button type="submit" class="btn btn-default">Set</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
';
|
||||
}
|
||||
else {
|
||||
$temp_output = '
|
||||
<script src="js/leaflet.js"></script>
|
||||
<script src="js/leaflet.markercluster-src.js"></script>
|
||||
@@ -31,11 +77,18 @@ $temp_output = '
|
||||
<div id="leaflet-map"></div>
|
||||
<script>
|
||||
';
|
||||
|
||||
$map_init = "[" . $config['leaflet']['default_lat'] . ", " . $config['leaflet']['default_lng'] . "], " . sprintf("%01.0f", $config['leaflet']['default_zoom']);
|
||||
|
||||
if (!empty($widget_settings)) {
|
||||
$init_lat = $widget_settings['init_lat'];
|
||||
$init_lng = $widget_settings['init_lng'];
|
||||
$init_zoom = $widget_settings['init_zoom'];
|
||||
}
|
||||
elseif (isset($config['leaflet'])) {
|
||||
$init_lat = $config['leaflet']['default_lat'];
|
||||
$init_lng = $config['leaflet']['default_lng'];
|
||||
$init_zoom = $config['leaflet']['default_zoom'];
|
||||
}
|
||||
$map_init = "[" . $init_lat . ", " . $init_lng . "], " . sprintf("%01.0f", $init_zoom);
|
||||
$temp_output .= 'var map = L.map(\'leaflet-map\').setView('.$map_init.');
|
||||
|
||||
L.tileLayer(\'//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\', {
|
||||
attribution: \'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors\'
|
||||
}).addTo(map);
|
||||
@@ -50,7 +103,6 @@ var greenMarker = L.AwesomeMarkers.icon({
|
||||
markerColor: \'green\', prefix: \'fa\', iconColor: \'white\'
|
||||
});
|
||||
';
|
||||
|
||||
// Checking user permissions
|
||||
if (is_admin() || is_read()) {
|
||||
// Admin or global read-only - show all devices
|
||||
@@ -74,13 +126,11 @@ foreach (dbFetchRows($sql, array($_SESSION['user_id'])) as $map_devices) {
|
||||
if ($map_devices['status'] == 0) {
|
||||
$icon = 'redMarker';
|
||||
}
|
||||
|
||||
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getImageSrc($map_devices)."\" width=\"32\" height=\"32\" alt=\"\">".$map_devices['hostname']."</a>';
|
||||
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: title, icon: $icon});
|
||||
marker.bindPopup(title);
|
||||
markers.addLayer(marker);\n";
|
||||
}
|
||||
|
||||
$temp_output .= 'map.addLayer(markers);
|
||||
map.scrollWheelZoom.disable();
|
||||
$(document).ready(function(){
|
||||
@@ -92,8 +142,9 @@ $(document).ready(function(){
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
$temp_output = 'Mapael engine not supported here';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user