Okay, let's create a streamlined, testable version for an online HTML/JS compiler environment, focusing on core functionality and mocking the backend. We'll keep it in pure HTML/CSS/JS for maximum compatibility.
Core Concept:
- Simple Map: Show a map area (using
div and CSS) instead of a complex map library, since real map libraries aren't fully compatible with online editors.
- Mocked User Data: User locations are simulated and displayed as circles.
- User Profiles: When you click a user icon, a profile card appears.
- Purely Frontend: No backend required for the basic prototype.
1. HTML (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smoke Mates Finder (Online Prototype)</title>
<style>
body {
font-family: sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
#map-container {
width: 100%;
height: 500px;
background-color: #f0f0f0;
position: relative; /* For positioning user icons */
overflow: hidden;
}
.user-icon {
width: 30px;
height: 30px;
border-radius: 50%;
background-color: rgba(0, 150, 136, 0.8);
position: absolute;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-size: 14px;
}
.user-icon:hover {
opacity: 0.8;
}
#profile-card {
width: 300px;
background-color: white;
border: 1px solid #ccc;
padding: 20px;
position: fixed; /* or absolute */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none; /* Hidden by default */
z-index: 10; /* Ensure it's on top */
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
#profile-card .close-button {
position: absolute;
top: 5px;
right: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Smoke Mates Finder</h1>
<div id="map-container">
<!-- User icons will be added here dynamically -->
</div>
<div id="profile-card">
<span class="close-button" onclick="closeProfile()">X</span>
<h2 id="profile-name"></h2>
<p id="profile-bio"></p>
</div>
<script>
const mapContainer = document.getElementById('map-container');
const profileCard = document.getElementById('profile-card');
const profileName = document.getElementById('profile-name');
const profileBio = document.getElementById('profile-bio');
// Mock user data (lat/lng as % of map container width/height)
const users = [
{ id: 1, name: "Alice", bio: "Loves sunsets and chill vibes.", lat: 30, lng: 40 },
{ id: 2, name: "Bob", bio: "Looking for friends to smoke with after work.", lat: 70, lng: 20 },
{ id: 3, name: "Charlie", bio: "Enjoys deep conversations while smoking.", lat: 10, lng: 80 }
];
// Function to show profile
function showProfile(user) {
profileName.textContent = user.name;
profileBio.textContent = user.bio;
profileCard.style.display = 'block';
}
// Function to close profile
function closeProfile() {
profileCard.style.display = 'none';
}
// Create and add user icons to the map
users.forEach(user => {
const userIcon = document.createElement('div');
userIcon.classList.add('user-icon');
userIcon.textContent = user.name[0]; // Show initials for simplicity
userIcon.style.top = `${user.lat}%`;
userIcon.style.left = `${user.lng}%`;
userIcon.addEventListener('click', () => showProfile(user)); // Show profile
mapContainer.appendChild(userIcon);
});
</script>
</body>
</html>
2. How This Works:
map-container: A div with position: relative is the simulated map area.
user-icon: Each user icon is a div with position: absolute, allowing you to position it using percentages (top, left) within the map container. CSS styles it as a circle.
profile-card: This is the user profile card. It's initially hidden (display: none). It's positioned using position: fixed and transform: translate(-50%, -50%) to center it on the screen.
users Array: This is your mocked user data. lat and lng are represented as percentages of the map-container dimensions.
showProfile() Function: Takes a user object and populates the profile card with the user's name and bio. Then it sets profileCard.style.display = 'block' to show the card.
closeProfile() Function: Sets profileCard.style.display = 'none' to hide the card.
- Dynamic Icon Creation: The JavaScript loops through the
users array, creating a div for each user, setting its position, adding an event listener to show the profile, and appending it to the map-container.
3. How to Test:
- Copy the code into an online HTML/JS/CSS compiler like CodePen, JSFiddle, or CodeSandbox.
- Run the code.
- You should see a map-like area with circles representing users.
- Clicking a circle should show a profile card.
Explanation and Improvements:
- Simplicity: This avoids the need for external libraries that are hard to use in online environments.
- Relative Positioning:
lat and lng are percentages, so user positions will adjust when the map container size changes.
- Mock Data: This is crucial for testing without a backend.
- Clean Code: Uses
addEventListener for event handling, which is generally preferred.
- Profile Card Styling: The CSS centers the profile card nicely.
To Extend This:
- Add more users.
- Add user photos: Include an
img tag in the profile-card and a photo property in the user objects. You'll need placeholder image URLs.
- Simulate scrolling: Add CSS to the
map-container to enable scrolling.
Limitations:
- No Actual Mapping: This simulates a map. You won't see actual geographic locations or panning/zooming.
- Purely Frontend: No actual user data persistence or server-side logic.
- Basic Styling: The styling is minimal for demonstration purposes.
This should give you a good starting point for building a prototype that you can test in an online code editor. Remember to prioritize the core interaction (map + user profiles) in this initial version. Let me know if you want to add more features to this!