Skip to content

Commit 5c4738d

Browse files
committed
Add settings and search buttons
1 parent a09f7ed commit 5c4738d

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

webapp/script.js

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,101 @@ L.control.scale({
1515
imperial: false
1616
}).addTo(map);
1717

18+
// Add background menu control
19+
L.Control.BackgroundMenu = L.Control.extend({
20+
options: {
21+
position: 'topright'
22+
},
23+
24+
onAdd: function(map) {
25+
const container = L.DomUtil.create('div', 'leaflet-control-settings');
26+
container.style.position = 'relative';
27+
28+
const settingsBtn = L.DomUtil.create('button', 'leaflet-control-search-btn', container);
29+
settingsBtn.innerHTML = '⚙️';
30+
settingsBtn.title = 'Background Options';
31+
settingsBtn.onclick = () => {
32+
const settingsMenu = container.querySelector('.settings');
33+
if (settingsMenu.style.display === 'block') {
34+
settingsMenu.style.display = 'none';
35+
} else {
36+
settingsMenu.style.display = 'block';
37+
// Position settings menu to the left of the button
38+
settingsMenu.style.position = 'absolute';
39+
settingsMenu.style.top = `${settingsBtn.offsetTop}px`;
40+
settingsMenu.style.right = `${container.offsetWidth - settingsBtn.offsetLeft + settingsBtn.offsetWidth}px`;
41+
settingsMenu.style.width = '100px';
42+
settingsMenu.style.zIndex = '1000';
43+
}
44+
};
45+
46+
const settingsMenu = L.DomUtil.create('div', 'settings', container);
47+
settingsMenu.style.display = 'none'; // hidden initially
48+
49+
// Create buttons in menu
50+
const normalBtn = L.DomUtil.create('button', '', settingsMenu);
51+
normalBtn.innerHTML = 'Normal';
52+
normalBtn.onclick = () => {
53+
tileLayer.getContainer().style.filter = '';
54+
settingsMenu.style.display = 'none';
55+
};
56+
57+
const grayBtn = L.DomUtil.create('button', '', settingsMenu);
58+
grayBtn.innerHTML = 'Grayscale';
59+
grayBtn.onclick = () => {
60+
tileLayer.getContainer().style.filter = 'grayscale(100%)';
61+
settingsMenu.style.display = 'none';
62+
};
63+
64+
const invertedBtn = L.DomUtil.create('button', '', settingsMenu);
65+
invertedBtn.innerHTML = 'Inverted';
66+
invertedBtn.onclick = () => {
67+
tileLayer.getContainer().style.filter = 'grayscale(100%) invert(100%)';
68+
settingsMenu.style.display = 'none';
69+
};
70+
71+
return container;
72+
}
73+
});
74+
75+
// Add search menu control
76+
L.Control.SearchMenu = L.Control.extend({
77+
options: {
78+
position: 'topright'
79+
},
80+
81+
onAdd: function(map) {
82+
const container = L.DomUtil.create('div', 'leaflet-control-search');
83+
container.style.position = 'relative';
84+
85+
const searchBtn = L.DomUtil.create('button', 'leaflet-control-search-btn', container);
86+
searchBtn.innerHTML = '🔍';
87+
searchBtn.title = 'Toggle Search Menu';
88+
searchBtn.onclick = () => {
89+
const searchContainer = document.querySelector('.search-container');
90+
if (searchContainer.style.display === 'block') {
91+
searchContainer.style.display = 'none';
92+
} else {
93+
searchContainer.style.display = 'block';
94+
// Position search menu to the left of the button
95+
searchContainer.style.position = 'absolute';
96+
searchContainer.style.top = `${searchBtn.offsetTop}px`;
97+
searchContainer.style.right = `${container.offsetWidth - searchBtn.offsetLeft + searchBtn.offsetWidth}px`;
98+
searchContainer.style.width = '200px';
99+
searchContainer.style.zIndex = '1000';
100+
}
101+
};
102+
103+
return container;
104+
}
105+
});
106+
107+
// Add background menu control to map
108+
map.addControl(new L.Control.BackgroundMenu());
109+
110+
// Add search menu control to map
111+
map.addControl(new L.Control.SearchMenu());
112+
18113
// Add screenshot control
19114
L.Control.Screenshot = L.Control.extend({
20115
options: {
@@ -710,7 +805,6 @@ loadDataBtn.addEventListener('click', async function() {
710805
// Hide data selector and show slider and search
711806
document.querySelector('.data-selector').style.display = 'none';
712807
document.querySelector('.slider-container').style.display = 'block';
713-
document.querySelector('.search-container').style.display = 'block';
714808
}).catch(error => {
715809
console.error("Error loading CSV files:", error);
716810
alert('Error loading data files. Please check the console for details.');

webapp/styles.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ body, html {
6363
color: #666;
6464
font-size: 14px;
6565
}
66+
67+
.leaflet-control-search-btn {
68+
width: 32px;
69+
height: 32px;
70+
display: flex;
71+
align-items: center;
72+
justify-content: center;
73+
color: black;
74+
background: white;
75+
border: 2px solid rgba(0,0,0,0.2);
76+
border-radius: 4px;
77+
box-shadow: 0 1px 5px rgba(0,0,0,0.4);
78+
font-size: 18px;
79+
margin-bottom: 5px;
80+
cursor: pointer;
81+
}
6682

6783
/* Search container */
6884
.search-container {
@@ -134,4 +150,37 @@ body, html {
134150
.leaflet-control-screenshot-button:hover {
135151
background: #f4f4f4;
136152
}
153+
154+
/* Settings control styling */
155+
.leaflet-control-settings {
156+
position: relative;
157+
}
158+
159+
.settings {
160+
position: absolute;
161+
top: 30px;
162+
left: -140px;
163+
background: white;
164+
border: 2px solid rgba(0,0,0,0.2);
165+
border-radius: 4px;
166+
padding: 5px;
167+
display: flex;
168+
flex-direction: column;
169+
z-index: 1000;
170+
box-shadow: 0 1px 5px rgba(0,0,0,0.4);
171+
}
172+
173+
.settings button {
174+
margin: 2px;
175+
padding: 5px 10px;
176+
cursor: pointer;
177+
border: 1px solid #ccc;
178+
border-radius: 3px;
179+
background: #f8f8f8;
180+
font-size: 12px;
181+
}
182+
183+
.settings button:hover {
184+
background: #e8e8e8;
185+
}
137186

0 commit comments

Comments
 (0)