Browse Source

Fix tool button initialization timing issue

- Defer tool button initialization until DOM is ready
- Add null checks to prevent errors if elements don't exist
- Use setTimeout to ensure DOM elements are available
- This fixes all track tool buttons not responding to clicks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
master
HikeMap User 1 month ago
parent
commit
efc4bd1720
  1. 34
      index.html

34
index.html

@ -3909,8 +3909,12 @@
}); });
} }
// Tool buttons
const toolButtons = {
// Tool buttons - initialize later after DOM is ready
let toolButtons = {};
// Initialize tool buttons after DOM elements exist
function initializeToolButtons() {
toolButtons = {
select: document.getElementById('selectTool'), select: document.getElementById('selectTool'),
split: document.getElementById('splitTool'), split: document.getElementById('splitTool'),
draw: document.getElementById('drawTool'), draw: document.getElementById('drawTool'),
@ -3919,11 +3923,23 @@
geocache: document.getElementById('geocacheTool') geocache: document.getElementById('geocacheTool')
}; };
// Tool button event listeners
Object.keys(toolButtons).forEach(tool => {
if (toolButtons[tool]) {
toolButtons[tool].addEventListener('click', () => setTool(tool));
} else {
console.warn(`Tool button not found: ${tool}`);
}
});
}
// Set active tool // Set active tool
function setTool(tool) { function setTool(tool) {
currentTool = tool; currentTool = tool;
Object.keys(toolButtons).forEach(t => { Object.keys(toolButtons).forEach(t => {
if (toolButtons[t]) {
toolButtons[t].classList.toggle('active', t === tool); toolButtons[t].classList.toggle('active', t === tool);
}
}); });
// Cancel any drawing in progress // Cancel any drawing in progress
@ -3932,8 +3948,10 @@
} }
// Show/hide tool-specific controls // Show/hide tool-specific controls
document.getElementById('reshapeControls').style.display = tool === 'reshape' ? 'block' : 'none';
document.getElementById('smoothControls').style.display = tool === 'smooth' ? 'block' : 'none';
const reshapeControls = document.getElementById('reshapeControls');
const smoothControls = document.getElementById('smoothControls');
if (reshapeControls) reshapeControls.style.display = tool === 'reshape' ? 'block' : 'none';
if (smoothControls) smoothControls.style.display = tool === 'smooth' ? 'block' : 'none';
// Update cursor // Update cursor
const container = map.getContainer(); const container = map.getContainer();
@ -3953,10 +3971,10 @@
} }
} }
// Tool button event listeners
Object.keys(toolButtons).forEach(tool => {
toolButtons[tool].addEventListener('click', () => setTool(tool));
});
// Initialize tool buttons when DOM is ready
setTimeout(() => {
initializeToolButtons();
}, 100);
// Track class // Track class
class Track { class Track {

Loading…
Cancel
Save