Welcome to the React Map Application repository! This application integrates the Mappable World API to provide an interactive map experience with search functionality, location suggestions, and draggable markers.
- Overview
- Features
- Demo
- Getting Started
- Usage
- Project Structure
- Technologies Used
- Contributing
- License
- Acknowledgements
- Contact
This application demonstrates how to build a secure, map-based React application using the Mappable World API. It includes both frontend and backend components to ensure that sensitive API keys are handled securely.
- Interactive Map: Display an interactive map centered on a default location.
- Secure API Key Handling: API keys are stored securely on the server side using sessions.
- Search Functionality: Users can search for locations with real-time suggestions.
- Location Suggestions: Autocomplete suggestions are provided as the user types.
- Geocoding: Selected locations are geocoded to display the precise location on the map.
- Draggable Marker: A marker is placed on the map, which users can drag to different locations.
- Responsive Design: The application is responsive and works on various screen sizes.
Follow these instructions to set up and run the project locally.
- Node.js (v14 or higher): Download and install Node.js
- npm (comes with Node.js)
- Mappable World API Key: Sign up or log in to get an API key for Mappable World.
-
Clone the repository
git clone https://github.com/Implication-web-components/react-map-application.git cd react-map-application -
Install dependencies
npm install
-
Create a
.envfileIn the root directory, create a
.envfile and add the following variables:SESSION_SECRET=your_secret_key # Replace with a secure session key PORT=5000 # Port number for the backend server NODE_ENV=development # Set to "production" for live deployment
To start both the backend server and the frontend development server concurrently, use:
npm run dev- The backend server will run on
http://localhost:5000. - The frontend development server will run on
http://localhost:5173.
To build the frontend for production and serve it using the Express server:
-
Build the frontend:
npm run build
-
Start the server:
npm start
The Express server will serve both the API and the frontend static files on http://localhost:5000.
Upon starting the application:
- Open your web browser and navigate to
http://localhost:5000. - You will be prompted to enter your Mappable World API key.
- Enter your API key and click Load Map.
Note: The API key is stored securely in the server session and is not exposed to the client.
- Use the search input at the top-left corner to search for locations.
- As you type, location suggestions will appear.
- Click on a suggestion to center the map on that location.
- Draggable Marker: A marker is placed at the center of the map, which you can drag to any location.
- Map Movement: You can pan and zoom the map using your mouse or touch gestures.
- Marker Info: The marker includes an interactive info window.
react-map-application/
├── src/
│ ├── App.tsx # Main application component
│ ├── index.tsx # Entry point for React rendering
│ └── mappable.ts # Module for initializing Mappable World components
├── dist/ # Compiled static files for production
├── server.js # Express server handling backend logic
├── package.json # Project dependencies and scripts
├── vite.config.js # Configuration for Vite
├── tsconfig.json # TypeScript configuration
└── ...
- src/: Source code for the React application.
- App.tsx: Main application component, containing map, search, and API key handling logic.
- index.tsx: Main entry point for rendering the React application.
- mappable.ts: Module that initializes and configures Mappable components and settings.
- dist/: Contains the production build of the frontend generated by Vite.
- server.js: Express server for backend functions, handling API key management and request proxies.
- package.json: Lists project dependencies and defines key project scripts.
- vite.config.js: Configuration for Vite, specifying settings for development and production builds.
- tsconfig.json: Configures TypeScript options.
- Frontend:
- React
- TypeScript
- Vite
- Lodash.debounce
- Backend:
- Node.js
- Express
- Express-session
- Axios
- Map Services:
- Mappable World API
- Others:
- dotenv (for managing environment variables)
- Concurrently (for running scripts concurrently)
Contributions are welcome! Please follow these steps:
-
Fork the repository
Click the "Fork" button at the top right of the repository page.
-
Clone your fork
git clone https://github.com/your-username/react-map-application.git
-
Create a branch
git checkout -b feature/your-feature-name
-
Make your changes
-
Commit your changes
git commit -m "Add your commit message" -
Push to your fork
git push origin feature/your-feature-name
-
Create a Pull Request
Go to the original repository and click on "Pull Requests", then "New Pull Request".
- Use TypeScript for type safety.
- ESLint rules are applied to maintain code consistency.
- Prettier is recommended for code formatting.
This project is licensed under the Apache License, Version 2.0.
© 2024 2SA Authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Additionally, this project includes the Mappable library, © 2024 Mappable authors.
This project is licensed under Apache 2.0, which may include rights associated with the Mappable library.
All files related to this library are distributed "AS IS" with no additional warranties.
- Mappable World for providing the map API.
- React for the frontend framework.
- Express for the backend framework.
- Vite for the development server and build tool.
- Author: Sultan Alyami
- Email: ssl55@hotmail.com
- GitHub: sultanaalyami
- LinkedIn: LinkedIn