Files
librenms-librenms/resources/views/widgets/worldmap.blade.php
Tony Murray f0966f4d23 Widget hot refresh & worldmap cleanup (#16053)
* Iterate in javascript and separate processing

* Widget refresh/destroy events

* Remove old dom and unbind events

* fix whitespace

* Fix up bootgrid tables, they inserted a div before the first div breaking event propagation
switch to regular js function to scope variables instead of jquery

* Handle settings the same way as the normal widget

* Use standard init_map and add layer control

* May need L.Control.Locate now

* Set maxZoom for marker cluster

* Try setMaxZoom

* worldmap size 100 and resize on refresh/widget resize

* Add resize event (and throttle it a bit)

* Further worldmap cleanup

* Move most javascript to common js, will cause js errors until page is reloaded, but better in the long run
2024-05-22 21:23:39 -05:00

37 lines
1.7 KiB
PHP

<div id="worldmap_widget-{{ $id }}" class="worldmap_widget" data-reload="false"></div>
<script type="application/javascript">
(function () {
const map_id = 'worldmap_widget-{{ $id }}';
const status = {{ Js::from($status) }};
const device_group = {{ (int) $device_group }};
const map_config = {{ Js::from($map_config) }};
const group_radius = {{ (int) $group_radius }};
loadjs('js/leaflet.js', function () {
loadjs('js/leaflet.markercluster.js', function () {
loadjs('js/leaflet.awesome-markers.min.js', function () {
loadjs('js/L.Control.Locate.min.js', function () {
init_map(map_id, map_config).scrollWheelZoom.disable();
populate_map_markers(map_id, group_radius, status, device_group);
// register listeners
$('#' + map_id).on('click', function (event) {
get_map(map_id).scrollWheelZoom.enable();
}).on('mouseleave', function (event) {
get_map(map_id).scrollWheelZoom.disable();
}).on('resize', function (event) {
get_map(map_id).invalidateSize();
}).on('refresh', function (event) {
get_map(map_id).invalidateSize();
populate_map_markers(map_id, group_radius, status, device_group);
}).on('destroy', function (event) {
destroy_map(map_id);
});
});
});
});
});
})();
</script>