Merge branch 'snap-to-grid' of https://repos.hackathon.bz.it/2025-summer/team-3 into snap-to-grid

This commit is contained in:
Dennis Orlando 2025-08-02 09:13:51 +02:00
commit 51c0117b9d

View file

@ -940,6 +940,12 @@ editor = {
editor._geometries_layer.addTo(editor.map); editor._geometries_layer.addTo(editor.map);
editor._highlight_layer.addTo(editor.map); editor._highlight_layer.addTo(editor.map);
editor._loading_geometry = false; editor._loading_geometry = false;
// Initialize clone floor functionality now that geometries are loaded
if (editor.cloneFloor && editor.cloneFloor.init) {
editor.cloneFloor.init();
}
if (editor._bounds_layer === null && editor._geometries_layer.getLayers().length) editor._bounds_layer = editor._geometries_layer; if (editor._bounds_layer === null && editor._geometries_layer.getLayers().length) editor._bounds_layer = editor._geometries_layer;
if (editor._next_zoom && editor._bounds_layer !== null) { if (editor._next_zoom && editor._bounds_layer !== null) {
editor.map.flyToBounds((editor._bounds_layer.getBounds !== undefined) ? editor._bounds_layer.getBounds() : [editor._bounds_layer.getLatLng(), editor._bounds_layer.getLatLng()], { editor.map.flyToBounds((editor._bounds_layer.getBounds !== undefined) ? editor._bounds_layer.getBounds() : [editor._bounds_layer.getLatLng(), editor._bounds_layer.getLatLng()], {
@ -2548,8 +2554,14 @@ editor.cloneFloor = {
isSelectionMode: false, isSelectionMode: false,
init: function() { init: function() {
// This will be called after geometries are loaded
// Check if clone floor elements exist in the template // Check if clone floor elements exist in the template
if ($('#clone-floor-btn').length > 0) { if ($('#clone-floor-btn').length > 0) {
// Unbind any existing handlers first
$('#clone-floor-btn').off('click');
$('#execute-clone-btn').off('click');
$('#cancel-clone-btn').off('click');
// Bind click event to the button that's already in the template // Bind click event to the button that's already in the template
$('#clone-floor-btn').click(editor.cloneFloor.toggleSelectionMode); $('#clone-floor-btn').click(editor.cloneFloor.toggleSelectionMode);
@ -2581,17 +2593,24 @@ editor.cloneFloor = {
$('#clone-floor-selector').show(); $('#clone-floor-selector').show();
editor.cloneFloor.updateSelectedCount(); editor.cloneFloor.updateSelectedCount();
// Add click handlers to geometry items // Add click handlers directly to geometry layers
if (editor._geometries_layer) { if (editor._geometries_layer) {
let layerCount = 0; let layerCount = 0;
editor._geometries_layer.eachLayer(function(layer) { editor._geometries_layer.eachLayer(function(layer) {
if (layer.feature && layer.feature.properties) { if (layer.feature && layer.feature.properties) {
// Add click handler for selection
layer.on('click', editor.cloneFloor.onItemClick); layer.on('click', editor.cloneFloor.onItemClick);
layer.setStyle({cursor: 'pointer'});
// Make layer visually selectable
const currentStyle = layer.options || {};
layer.setStyle(Object.assign({}, currentStyle, {
cursor: 'pointer',
opacity: Math.max(currentStyle.opacity || 0, 0.5)
}));
layerCount++; layerCount++;
} }
}); });
console.log('Clone floor: Added click handlers to', layerCount, 'layers'); console.log('Clone floor: Made', layerCount, 'geometries selectable');
} else { } else {
console.log('Clone floor: No geometries layer found'); console.log('Clone floor: No geometries layer found');
} }
@ -2607,28 +2626,33 @@ editor.cloneFloor = {
$('#clone-floor-btn').html('<i class="glyphicon glyphicon-copy"></i> Clone to Floor').removeClass('btn-warning').addClass('btn-info'); $('#clone-floor-btn').html('<i class="glyphicon glyphicon-copy"></i> Clone to Floor').removeClass('btn-warning').addClass('btn-info');
$('#clone-floor-selector').hide(); $('#clone-floor-selector').hide();
// Remove click handlers and reset styles // Remove click handlers and reset styles for all geometry layers
if (editor._geometries_layer) { if (editor._geometries_layer) {
editor._geometries_layer.eachLayer(function(layer) { editor._geometries_layer.eachLayer(function(layer) {
if (layer.feature && layer.feature.properties) { if (layer.feature && layer.feature.properties) {
// Remove click handler
layer.off('click', editor.cloneFloor.onItemClick); layer.off('click', editor.cloneFloor.onItemClick);
layer.setStyle({cursor: 'default'});
// Reset to original style
layer.setStyle(editor._get_geometry_style(layer.feature));
} }
}); });
} }
// Re-enable map editing // Re-enable map editing
editor.map.doubleClickZoom.enable(); editor.map.doubleClickZoom.enable();
// Reset visual selection
editor.cloneFloor.updateVisualSelection();
}, },
onItemClick: function(e) { onItemClick: function(e) {
if (!editor.cloneFloor.isSelectionMode) return; if (!editor.cloneFloor.isSelectionMode) return;
// Prevent default behavior and stop propagation
if (e.originalEvent) {
e.originalEvent.stopPropagation(); e.originalEvent.stopPropagation();
e.originalEvent.preventDefault(); e.originalEvent.preventDefault();
}
L.DomEvent.stopPropagation(e);
L.DomEvent.preventDefault(e);
const layer = e.target; const layer = e.target;
const feature = layer.feature; const feature = layer.feature;
@ -2637,13 +2661,14 @@ editor.cloneFloor = {
if (!feature || !feature.properties) { if (!feature || !feature.properties) {
console.log('Clone floor: No feature or properties found'); console.log('Clone floor: No feature or properties found');
return; return false;
} }
const itemId = feature.properties.id; const itemId = feature.properties.id;
const itemType = feature.properties.type; const itemType = feature.properties.type;
console.log('Clone floor: Item ID:', itemId, 'Type:', itemType); console.log('Clone floor: Item ID:', itemId, 'Type:', itemType);
console.log('Clone floor: Full feature properties:', JSON.stringify(feature.properties, null, 2));
// Check if item is already selected // Check if item is already selected
const existingIndex = editor.cloneFloor.selectedItems.findIndex( const existingIndex = editor.cloneFloor.selectedItems.findIndex(
@ -2665,6 +2690,8 @@ editor.cloneFloor = {
editor.cloneFloor.updateSelectedCount(); editor.cloneFloor.updateSelectedCount();
editor.cloneFloor.updateVisualSelection(); editor.cloneFloor.updateVisualSelection();
return false; // Prevent further event propagation
}, },
updateSelectedCount: function() { updateSelectedCount: function() {
@ -2693,8 +2720,10 @@ editor.cloneFloor = {
layer.setStyle({ layer.setStyle({
stroke: true, stroke: true,
color: '#ff0000', color: '#ff0000',
weight: 3, weight: 4,
fillOpacity: 0.7 opacity: 1,
fillOpacity: 0.7,
fillColor: '#ff0000'
}); });
} }
} }
@ -2735,8 +2764,11 @@ editor.cloneFloor = {
keep_sync: keepSync keep_sync: keepSync
}; };
// Make API call // Debug: Log detailed request data
console.log('Clone floor: Making API call with data:', requestData); console.log('Clone floor: Making API call with data:', requestData);
console.log('Clone floor: Selected items details:', JSON.stringify(editor.cloneFloor.selectedItems, null, 2));
console.log('Clone floor: Source level ID:', currentLevelId);
console.log('Clone floor: Target level ID:', parseInt(targetLevelId));
// Use the raw fetch API with better error handling // Use the raw fetch API with better error handling
c3nav_api.authenticated().then(function() { c3nav_api.authenticated().then(function() {
@ -2766,9 +2798,11 @@ editor.cloneFloor = {
}) })
.then(function(data) { .then(function(data) {
console.log('Clone floor: API response data:', data); console.log('Clone floor: API response data:', data);
console.log('Clone floor: API response type:', typeof data);
console.log('Clone floor: API response keys:', Object.keys(data));
if (data.success) { if (data.success) {
alert(`Successfully cloned ${data.cloned_items.length} items: ${data.message}`); alert(`Successfully cloned ${data.cloned_items?.length || 0} items: ${data.message}`);
editor.cloneFloor.cancelSelection(); editor.cloneFloor.cancelSelection();
} else { } else {
alert(`Clone failed: ${data.message}`); alert(`Clone failed: ${data.message}`);
@ -2786,8 +2820,4 @@ editor.cloneFloor = {
if ($('#sidebar').length) { if ($('#sidebar').length) {
editor.init(); editor.init();
// Initialize clone floor functionality after editor is ready
setTimeout(function() {
editor.cloneFloor.init();
}, 1000);
} }