Download the PHP package mercynet/maps without Composer
On this page you can find all versions of the php package mercynet/maps. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mercynet/maps
More information about mercynet/maps
Files in mercynet/maps
Package maps
Short Description A package to load maps with support for Leaflet and Google Maps
License MIT
Informations about the package maps
=======
Maps
Maps is a PHP library designed to facilitate the integration and rendering of various map providers, such as Leaflet and Google Maps, in web applications. It adheres to SOLID principles, design patterns, and clean code practices, ensuring maintainability and scalability. The package allows developers to either use built-in views for map rendering or customize their own views by providing necessary data. It includes comprehensive tests using PestPHP to ensure reliability and correctness. The package is structured to be easily extendable, allowing the addition of more map providers in the future.
Installation
-
Clone the repository:
- Install dependencies using Composer:
Configuration
Configure your map providers in src/config/maps.php
:
Usage
Google Maps
To use Google Maps, ensure you have a valid API key. Add the API key to the GoogleMapConfig
class:
`
Example view file for Google Maps (src/Providers/GoogleMaps/Views/map.php
):
Leaflet
Example view file for Leaflet (src/Providers/Leaflet/Views/map.php
):
Creating a Map Provider
You can create a map using the specific map class (e.g., LeafletMap
):
`
Creating a Map Using Factory
You can create a map using the MapProviderFactory
:
`
Rendering a Map
To render a map, use the render method of the map class:
`
Setting a Custom View
To set a custom view for rendering the map, use the setCustomView
method:
`
Handling Exceptions
MapPackage provides custom exceptions to handle specific errors. Here are some examples:
InvalidCenterException
: Thrown when the center coordinates are invalid.InvalidZoomException
: Thrown when the zoom level is invalid.InvalidTileLayerException
: Thrown when the tile layer URL is invalid.InvalidMaxZoomException
: Thrown when the maximum zoom level is invalid.InvalidViewPathException
: Thrown when the custom view path is invalid.
Example of using exceptions:
`
Directory Structure
src/
: Contains the source code of the package.tests/
: Contains the tests.composer.json
: Composer configuration file.
Testing
To run the tests, use PestPHP:
`
Extending the Package
To add support for a new map provider, implement the MapInterface
interface:
`
Then, register the new provider with the MapProviderFactory
using a configuration file or a service provider. Here is an example using a configuration file:
Configuration File
Create a configuration file config/map_providers.php
:
`
License
This project is licensed under the MIT License. See the LICENSE
file for more details.