π API Reference¶
Complete documentation of Chekameh's public API and functions.
π― Overview¶
Chekameh exposes several functions and events for extending functionality. All functions are called on the global window object.
π¨ UI Functions¶
Panel Management¶
openOverlay()¶
Opens the overlay and shows the panel.
Returns: void
Example:
Use Case: Show the panel when user interacts with content
closePanel()¶
Closes the panel and resets the navigation stack.
Returns: void
Example:
Use Case: Hide panel and return to normal map view
goBack()¶
Navigate back one level in the panel stack.
Returns: void
Example:
Use Case: Implement back button functionality
openCity(city)¶
Open a specific city's panel.
Parameters:
city(Object) - City object from CITIES array
Returns: void
Example:
Use Case: Programmatically open a city
openPoet(poet, city)¶
Open a specific poet's panel.
Parameters:
poet(Object) - Poet object from city's poets arraycity(Object) - Parent city object
Returns: void
Example:
Use Case: Show poet details
openWork(work, poet)¶
Open a specific work's panel.
Parameters:
work(Object) - Work object from poet's works arraypoet(Object) - Parent poet object
Returns: void
Example:
const city = CITIES[0];
const poet = city.poets[0];
const work = poet.works[0];
openWork(work, poet);
Use Case: Display poem text and details
renderPanel(panelData, showBack)¶
Internal function to render panel content.
Parameters:
panelData(Object) -{ type, data, city?, poet? }showBack(Boolean) - Whether to show back button
Returns: void
Example:
Note: Usually called internally; use openCity() etc. instead
Timeline/Era Management¶
updateEra(index)¶
Change the current era and update all UI elements.
Parameters:
index(Number) - Era index (0-5)
Returns: void
Example:
Use Case: Change era programmatically
setupTimeline()¶
Initialize the timeline slider (called automatically on page load).
Returns: void
Example:
Note: Automatically called during initialization
setupUI()¶
Initialize all UI components (called automatically on page load).
Returns: void
Example:
Note: Automatically called when DOM is ready
πΊοΈ Map Functions¶
Map Initialization¶
initMap()¶
Initialize the MapLibre GL JS map instance.
Returns: maplibregl.Map instance
Example:
Use Case: Access the map object for direct manipulation
createCityMarkers()¶
Create and display markers for the current era.
Returns: void
Example:
Use Case: Refresh markers when era changes
Map Controls¶
Zoom Controls¶
// These are built into MapLibre, accessed via map object
map.zoomIn();
map.zoomOut();
map.setZoom(12);
Pan/Navigation¶
// Pan to coordinates
map.flyTo({
center: [lon, lat],
zoom: 4,
duration: 1000,
});
// Set bounds
map.fitBounds(bounds);
π Data Access¶
Global Data Objects¶
ERAS¶
Array of era objects.
Structure:
[
{
name: "string", // Persian name
nameEn: "string", // English name
years: "string", // Year range
},
// ... 5 more eras
];
Example:
CITIES¶
Array of city objects.
Structure:
[
{
id: "string",
name: "string",
nameEn: "string",
lat: number,
lon: number,
eras: [numbers],
poets: [
{
id: "string",
name: "string",
nameEn: "string",
dates: "string",
emoji: "string",
bio: "string",
works: [
{
name: "string",
nameEn: "string",
desc: "string",
lines: ["string"],
},
],
},
],
},
// ... more cities
];
Example:
const bukhara = CITIES.find((c) => c.id === "bukhara");
console.log(bukhara.poets.length); // Number of poets
Global State¶
currentEra¶
Currently selected era index (0-5).
Type: Number
Example:
panelStack¶
Navigation history for the panel.
Type: Array<Object>
Structure:
[
{ type: "city", data: cityObject },
{ type: "poet", data: poetObject, city: cityObject },
// ... more entries
];
Example:
cityMarkers¶
Reference to created city marker objects.
Type: Object
Example:
π― Events¶
Custom Events¶
eraChanged¶
Fired when the era is changed.
Detail: eraIndex (Number)
Example:
document.addEventListener("eraChanged", (e) => {
console.log(`Era changed to: ${e.detail}`);
// Update custom UI
});
openCityPanel¶
Fired when a city should be opened (from map).
Detail: cityObject
Example:
document.addEventListener("openCityPanel", (e) => {
console.log(`Opening city: ${e.detail.name}`);
});
Browser Events¶
Timeline Slider Input¶
const slider = document.getElementById("timeline-slider");
slider.addEventListener("input", (e) => {
console.log(`New era index: ${e.target.value}`);
});
Panel Close Button¶
const closeBtn = document.getElementById("panel-close");
closeBtn.addEventListener("click", () => {
console.log("Panel closed");
});
City Marker Click¶
// Automatically dispatches openCityPanel event
// Or manually:
document.querySelector(".city-marker").addEventListener("click", () => {
// City marker clicked
});
π§ Utility Functions¶
Array Operations¶
Finding a City¶
Filtering Cities by Era¶
Finding a Poet¶
DOM Manipulation¶
Getting Elements¶
const panel = document.getElementById("panel");
const panelBody = document.getElementById("panel-body");
const slider = document.getElementById("timeline-slider");
Creating Elements¶
const card = document.createElement("div");
card.className = "poet-card";
card.textContent = "Poet Name";
π Extending the API¶
Adding a New Function¶
- Define the function in appropriate file (ui.js, map.js)
- Make it global if needed:
window.myFunction = myFunction; - Document it in this file
- Add event listeners if needed
- Test thoroughly
Example: Custom Analysis Function¶
// In data.js
function findPoetsByEra(eraIndex) {
return CITIES.filter((city) => city.eras.includes(eraIndex))
.flatMap((city) => city.poets)
.filter(
(poet, index, self) => self.findIndex((p) => p.id === poet.id) === index,
); // Remove duplicates
}
// Make global
window.findPoetsByEra = findPoetsByEra;
// Use
const safavidPoets = findPoetsByEra(5);
π Common Issues¶
Issue: Function not found¶
Solution: Ensure function is added to global scope
Issue: Data not updating¶
Solution: Manually call render functions after data changes
Issue: Events not firing¶
Solution: Check event names and ensure listeners are attached
π Related Documentation¶
Happy coding! π