Changed map functionality in device overview (#13225)

Changed map in overview page for devices so that it is possible to move and drop the marker to update position, and possible to pan/move map without marker being stuck in center, marker stays in its fixed position.
This commit is contained in:
kimhaak 2021-09-11 16:09:57 +02:00 committed by GitHub
parent 258505ed44
commit e409a22e7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,16 +147,21 @@ if ($device['location_id']) {
<script>
var device_marker, device_location, device_map;
$("#toggle-map").on("shown.bs.collapse", function () {
if (device_marker == null) {
if (device_marker == null) {
device_location = new L.LatLng(' . (float) $location->lat . ', ' . (float) $location->lng . ');
config = {"tile_url": "' . Config::get('leaflet.tile_url', '{s}.tile.openstreetmap.org') . '"};
device_map = init_map("location-map", "' . $maps_engine . '", "' . $maps_api . '", config);
device_marker = init_map_marker(device_map, device_location);
device_marker = L.marker(device_location).addTo(device_map);
device_map.setView(device_location);
device_map.setZoom(18);
device_marker.dragging.enable();
';
if (Auth::user()->isAdmin()) {
echo ' device_map.on("dragend", function () {
echo ' device_marker.on("dragend", function () {
var new_location = device_marker.getLatLng();
if (confirm("Update location to " + new_location + "? This will update this location for all devices!")) {
update_location(' . $location->id . ', new_location, function(success) {