Screenshot
This project aims to create an interactive SVG map of Sri Lanka's districts and dynamically color each district based on its corresponding value from a MySQL database. The map will be hosted on a shared hosting platform, and the colors of the districts will be updated periodically based on the data retrieved from the database.
- Technologies Used
- Project Overview
- Getting Started
- Database Setup
- Data Retrieval and Map Coloring
- SVG Map
- Hosting
- Project Structure
- Contributing
- License
- HTML
- CSS
- JavaScript
- MySQL
- SVG
This project creates an SVG map of Sri Lanka with districts outlined. Each district is color-coded based on its corresponding value retrieved from a MySQL database. The map is hosted on a shared hosting platform, and the colors of the districts are periodically updated based on the data stored in the database.
To run this project, you need the following prerequisites:
- Web browser (e.g., Google Chrome, Mozilla Firefox)
- Text editor or Integrated Development Environment (IDE) for code editing
- Access to a MySQL database server
- Basic knowledge of HTML, CSS, JavaScript, and SQL
- Clone the project repository to your local machine:
git clone https://github.com/HMAHD/GeoChroma.git
- Connect to your MySQL database using a tool like MySQL Workbench or the MySQL command-line client.
- Create a new database (if it doesn't exist):
CREATE DATABASE your_database_name;
- Create the districts table to store district data:
CREATE TABLE districts (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
value INT NOT NULL
);
- Insert initial data into the districts table using the provided SQL script or your own data.
- Update PHP Script
- In the get_districts.php file, replace the database connection details (hostname, username, password, and database name) with your actual credentials.
- Host the Project
- Upload all project files (HTML, CSS, JavaScript, PHP, and SVG) to your web server.
The project uses JavaScript to fetch data from the MySQL database via a PHP script (get_districts.php
). The data is then used to update the colors of the SVG map's districts based on their corresponding values.
The fetchData()
function in script.js
is responsible for retrieving data from the database and calling the updateMapColors(data)
function to color the districts.
The SVG map (lkmap.svg
) contains the outlines of Sri Lanka's districts. Each district has a unique id
attribute that corresponds to the id
in the database. The id
is used to match the fetched data with the correct district in the SVG map.
To host the project on a shared hosting platform, follow these steps:
-
Upload all project files (HTML, CSS, JavaScript, PHP, and SVG) to the shared hosting server.
-
Ensure that the necessary PHP settings and modules are enabled on the hosting server to handle database connections and data retrieval.
-
Schedule periodic updates for the data retrieval process, either through a cron job or a custom solution using JavaScript intervals.
The project directory contains the following files:
index.html
: The main HTML file that displays the SVG map and includes the JavaScript code.styles.css
: CSS styles for the SVG map and other page elements.script.js
: JavaScript code responsible for fetching data, updating map colors, and periodic data updates.lkmap.svg
: SVG map file containing the outlines of Sri Lanka's districts.get_districts.php
: PHP script for fetching data from the MySQL database.update_data.php
: Update data in the database. In a single line, it performs the task of updating records in the database based on the input provided.
Contributions to this project are welcome. If you find any issues or have suggestions for improvements, feel free to create a pull request or raise an issue in the project repository.
This project is licensed under the MIT License. You can find the details in the LICENSE file.