Giter VIP home page Giter VIP logo

php-leaflet's Introduction

PHP Leaflet library

This library provides a PHP API to setup the Leaflet map definitions. The goal of the library is to provide a handy way to handle dynamic map configurations working in a PHP context.

Install

You can install the library using composer:

$ php composer.phar require netzmacht/php-leaflet

Features

This library provides different components:

  • Definition classes to define the leaflet map with all layers, controls and so on.
  • Value classes which have real behaviour and can be used to handle LatLng or GeoJSON features.
  • The Encoder component to convert the PHP leaflet definition into javscript.
  • Support for several Leaflet plugins.
  • Assets handling to autoload all required javascripts and css files from all plugins.

Before you start

  • The definition classes has some mixed behaviours. There useful behaviour is implemented. Some method creates just javascript method calls.
  • The goal is to have a close reflection of the Javascript API. Since the languages differs there are some changes which you should be aware of.

Requirements

This library requires PHP 5.4 and the symfony event dispatcher. The event dispatcher is used by the php-javascript-builder which encodes the PHP definition.

Example

/*
 * 1. Setup the encoder
 */

// The event dispatcher
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();

// All encoders are event subscribers.
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\ControlEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\GroupEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\MapEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\RasterEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\TypeEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\UIEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\VectorEncoder());

// Create a custom factory for the javascript builder which uses the event dispatcher.
// The order of the registered encoders are important! Only change if you know what you do.
$factory = function(Output $output) use ($dispatcher) {
    $encoder = new ChainEncoder();

    $encoder
        ->register(new \Netzmacht\JavascriptBuilder\Encoder\MultipleObjectsEncoder())
        ->register(new \Netzmacht\JavascriptBuilder\Symfony\EventDispatchingEncoder($dispatcher))
        ->register(new \Netzmacht\JavascriptBuilder\Encoder\JavascriptEncoder($output));

    return $encoder;
}; 

$builder = new \Netzmacht\JavascriptBuilder\Builder($factory);
$leaflet = new \Netzmacht\LeafletPHP\leaflet($builder, $dispatcher);

/*
 * 2. Create the map definitions
 */
$map = new \Netzmacht\LeafletPHP\Definition\Map('html_id', 'map');
$map
  ->setZoom(12)
  ->addControl(...)
  ->addLayer(...);
  
/*
 * 3. Build the javascript
 */

// Will return javascript with following local vars: "map", "layers", "controls", "icons".
echo $leaflet->build($map);

php-leaflet's People

Contributors

dmolineus avatar

Watchers

Hari Suherman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.