From 9a8552c1eaa538b7a9aff3ae6e9e419b4a3cb1b5 Mon Sep 17 00:00:00 2001 From: Ole Schlueter Date: Fri, 4 Feb 2022 17:32:56 +0100 Subject: [PATCH] Add basic click on room handling --- app/javascript/packs/leafletMap.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/javascript/packs/leafletMap.js b/app/javascript/packs/leafletMap.js index 8592d12b..8a710d8e 100644 --- a/app/javascript/packs/leafletMap.js +++ b/app/javascript/packs/leafletMap.js @@ -219,6 +219,18 @@ async function getView() { }); } +function showRoomInfo(e) { + const roomName = e.target.options.name; + // center and zoom in on element + map.flyTo(e.latlng, 21); + // TODO: because there is no relation between a the a room's visualization and database entry we search for the room and do not show the detail page immediately + // to fix this the lealet feature needs either the id or the name needs to be a key/id for rooms + ajaxCall(null, "/search_results", "query=" + roomName) + // put the search term in the input field and open the overlay + $("#search").val(roomName) + $("#_overlay").addClass('open'); +} + function setupGeoJsonFeature(feature, layer) { const level = parseInt(feature.properties.level_name); @@ -243,6 +255,11 @@ function setupGeoJsonFeature(feature, layer) { } floors[level].rooms.addLayer(layer); + // we give the layer a name so we know which room it is + layer.options["name"] = feature.properties.name + layer.on({ + click: showRoomInfo, + }); // find a position, create an invisible marker and bind a tooltip to it // we do not bind the tooltip to the room because you can only change the position of a tooltip by defining an offset