up demo links and map controls
This commit is contained in:
parent
589235a978
commit
f76bded4e4
13 changed files with 499 additions and 527 deletions
|
@ -163,6 +163,9 @@ class DemoResource:
|
|||
<a href="/demo">← Back to Map</a>
|
||||
<a href="/">API Information</a>
|
||||
<a href="/event">View Events</a>
|
||||
<a href="https://source.cipherbliss.com/tykayn/oedb-backend" target="_blank" title="View Source Code on Cipherbliss">
|
||||
<i class="fas fa-code-branch"></i> Source
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h1>Edit Event</h1>
|
||||
|
@ -242,6 +245,11 @@ class DemoResource:
|
|||
// Add navigation controls
|
||||
map.addControl(new maplibregl.NavigationControl());
|
||||
|
||||
// Add attribution control with OpenStreetMap attribution
|
||||
map.addControl(new maplibregl.AttributionControl({{
|
||||
customAttribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
|
||||
}}));
|
||||
|
||||
// Add marker for event location
|
||||
let marker = new maplibregl.Marker({{
|
||||
draggable: true
|
||||
|
@ -448,6 +456,35 @@ class DemoResource:
|
|||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 300px;
|
||||
}
|
||||
.map-style-control {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
z-index: 1;
|
||||
}
|
||||
.map-style-control button {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
padding: 5px 10px;
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
.map-style-control button:hover {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
.map-style-control button.active {
|
||||
background: #0078ff;
|
||||
color: white;
|
||||
border-color: #0056b3;
|
||||
}
|
||||
h2 { margin-top: 0; }
|
||||
ul { padding-left: 20px; }
|
||||
a { color: #0078ff; text-decoration: none; }
|
||||
|
@ -470,16 +507,56 @@ class DemoResource:
|
|||
<ul>
|
||||
<li><a href="/demo/by-what" target="_blank">/demo/by-what - Events by Type</a></li>
|
||||
<li><a href="/demo/map-by-what" target="_blank">/demo/map-by-what - Map by Event Type</a></li>
|
||||
<li><a href="/event?what=music" target="_blank">Search Music Events</a></li>
|
||||
<li><a href="/event?what=sport" target="_blank">Search Sport Events</a></li>
|
||||
</ul>
|
||||
<p><a href="/demo/add" class="add-event-btn" style="display: block; text-align: center; margin-top: 15px; padding: 8px; background-color: #0078ff; color: white; border-radius: 4px; font-weight: bold;">+ Add New Event</a></p>
|
||||
<p><a href="https://source.cipherbliss.com/tykayn/oedb-backend" target="_blank">Source Code on Cipherbliss</a></p>
|
||||
<p style="text-align: center; margin-top: 10px;">
|
||||
<a href="https://source.cipherbliss.com/tykayn/oedb-backend" target="_blank" title="View Source Code on Cipherbliss" style="font-size: 24px;">
|
||||
<i class="fas fa-code-branch"></i>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="map-style-control">
|
||||
<h4 style="margin-top: 0; margin-bottom: 10px;">Map Style</h4>
|
||||
<button id="style-default" class="active">Default</button>
|
||||
<button id="style-osm-vector">OSM Vector</button>
|
||||
<button id="style-osm-raster">OSM Raster</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Initialize the map
|
||||
// Map style URLs
|
||||
const mapStyles = {
|
||||
default: 'https://demotiles.maplibre.org/style.json',
|
||||
osmVector: 'https://cdn.jsdelivr.net/gh/openmaptiles/osm-bright-gl-style@master/style-cdn.json',
|
||||
osmRaster: {
|
||||
version: 8,
|
||||
sources: {
|
||||
'osm-raster': {
|
||||
type: 'raster',
|
||||
tiles: [
|
||||
'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
|
||||
],
|
||||
tileSize: 256,
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
|
||||
}
|
||||
},
|
||||
layers: [
|
||||
{
|
||||
id: 'osm-raster-layer',
|
||||
type: 'raster',
|
||||
source: 'osm-raster',
|
||||
minzoom: 0,
|
||||
maxzoom: 19
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize the map with default style
|
||||
const map = new maplibregl.Map({
|
||||
container: 'map',
|
||||
style: 'https://demotiles.maplibre.org/style.json',
|
||||
style: mapStyles.default,
|
||||
center: [2.3522, 48.8566], // Default center (Paris)
|
||||
zoom: 4
|
||||
});
|
||||
|
@ -487,6 +564,72 @@ class DemoResource:
|
|||
// Add navigation controls
|
||||
map.addControl(new maplibregl.NavigationControl());
|
||||
|
||||
// Add attribution control with OpenStreetMap attribution
|
||||
map.addControl(new maplibregl.AttributionControl({
|
||||
customAttribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
|
||||
}));
|
||||
|
||||
// Style switcher functionality
|
||||
let currentStyle = 'default';
|
||||
let eventsData = null;
|
||||
|
||||
document.getElementById('style-default').addEventListener('click', () => {
|
||||
if (currentStyle !== 'default') {
|
||||
switchMapStyle('default');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('style-osm-vector').addEventListener('click', () => {
|
||||
if (currentStyle !== 'osmVector') {
|
||||
switchMapStyle('osmVector');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('style-osm-raster').addEventListener('click', () => {
|
||||
if (currentStyle !== 'osmRaster') {
|
||||
switchMapStyle('osmRaster');
|
||||
}
|
||||
});
|
||||
|
||||
function switchMapStyle(styleName) {
|
||||
// Update active button
|
||||
document.querySelectorAll('.map-style-control button').forEach(button => {
|
||||
button.classList.remove('active');
|
||||
});
|
||||
document.getElementById(`style-${styleName.replace('osm', 'osm-')}`).classList.add('active');
|
||||
|
||||
// Save current center and zoom
|
||||
const center = map.getCenter();
|
||||
const zoom = map.getZoom();
|
||||
|
||||
// Save events data if already loaded
|
||||
if (map.getSource('events')) {
|
||||
try {
|
||||
eventsData = map.getSource('events')._data;
|
||||
} catch (e) {
|
||||
console.error('Error saving events data:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply new style
|
||||
map.setStyle(mapStyles[styleName]);
|
||||
|
||||
// Restore center and zoom after style is loaded
|
||||
map.once('style.load', () => {
|
||||
map.setCenter(center);
|
||||
map.setZoom(zoom);
|
||||
|
||||
// Restore events data if available
|
||||
if (eventsData) {
|
||||
addEventsToMap(eventsData);
|
||||
} else {
|
||||
fetchEvents();
|
||||
}
|
||||
});
|
||||
|
||||
currentStyle = styleName;
|
||||
}
|
||||
|
||||
// Fetch events when the map is loaded
|
||||
map.on('load', function() {
|
||||
fetchEvents();
|
||||
|
@ -688,8 +831,19 @@ class DemoResource:
|
|||
resp.content_type = 'text/html'
|
||||
|
||||
# Fetch events from the API
|
||||
response = requests.get('http://localhost/event?limit=1000')
|
||||
events_data = response.json()
|
||||
try:
|
||||
response = requests.get('/event?limit=1000')
|
||||
if response.status_code == 200 and response.text:
|
||||
events_data = response.json()
|
||||
else:
|
||||
logger.error(f"Error fetching events: Status code {response.status_code}, Response: {response.text}")
|
||||
events_data = {"features": []}
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error parsing JSON response: {e}")
|
||||
events_data = {"features": []}
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching events: {e}")
|
||||
events_data = {"features": []}
|
||||
|
||||
# Group events by "what" type
|
||||
events_by_what = defaultdict(list)
|
||||
|
@ -933,6 +1087,9 @@ class DemoResource:
|
|||
<a href="/">Home</a>
|
||||
<a href="/demo">Demo Map</a>
|
||||
<a href="/demo/by-what">Events by Type</a>
|
||||
<a href="https://source.cipherbliss.com/tykayn/oedb-backend" target="_blank" title="View Source Code on Cipherbliss">
|
||||
<i class="fas fa-code-branch"></i> Source
|
||||
</a>
|
||||
</div>
|
||||
<p>This map shows events from the OpenEventDatabase filtered by their type.</p>
|
||||
<p>Use the filter panel on the right to show/hide different event types.</p>
|
||||
|
@ -964,6 +1121,11 @@ class DemoResource:
|
|||
// Add navigation controls
|
||||
map.addControl(new maplibregl.NavigationControl());
|
||||
|
||||
// Add attribution control with OpenStreetMap attribution
|
||||
map.addControl(new maplibregl.AttributionControl({
|
||||
customAttribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
|
||||
}));
|
||||
|
||||
// Store all events and their types
|
||||
let allEvents = null;
|
||||
let eventTypes = new Set();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue