├── .phpcq.lock
├── .phpcq.yaml.dist
├── CHANGELOG.md
├── LICENSE
├── README.md
├── composer.json
├── phpcs.xml.dist
└── src
└── Netzmacht
└── LeafletPHP
├── Assert
├── Assertion.php
└── InvalidArgumentException.php
├── Assets.php
├── Assets
├── AbstractAssets.php
├── Collector.php
├── GeneratesHtml.php
└── SimpleAssets.php
├── Definition.php
├── Definition
├── AbstractDefinition.php
├── AbstractLayer.php
├── Control.php
├── Control
│ ├── AbstractControl.php
│ ├── Attribution.php
│ ├── Layers.php
│ ├── Scale.php
│ └── Zoom.php
├── EventsTrait.php
├── Group
│ ├── FeatureGroup.php
│ ├── GeoJson.php
│ └── LayerGroup.php
├── HasEvents.php
├── HasLabel.php
├── HasOptions.php
├── HasPopup.php
├── HasRemovableLayers.php
├── LabelTrait.php
├── Layer.php
├── Map.php
├── MapObject.php
├── OptionsTrait.php
├── PopupTrait.php
├── Raster
│ ├── ImageOverlay.php
│ └── TileLayer.php
├── Type
│ ├── AbstractIcon.php
│ ├── DivIcon.php
│ ├── Icon.php
│ └── ImageIcon.php
├── UI
│ ├── Marker.php
│ └── Popup.php
├── Vector.php
└── Vector
│ ├── Circle.php
│ ├── CircleMarker.php
│ ├── Path.php
│ ├── PathOptionsTrait.php
│ ├── Polygon.php
│ ├── Polyline.php
│ ├── Rectangle.php
│ └── Renderer.php
├── Encoder
├── AbstractEncoder.php
├── ControlEncoder.php
├── EncodeHelperTrait.php
├── GroupEncoder.php
├── MapEncoder.php
├── RasterEncoder.php
├── TypeEncoder.php
├── UIEncoder.php
└── VectorEncoder.php
├── Leaflet.php
├── Plugins
├── Ajax
│ └── GeoJsonAjax.php
├── ExtraMarkers
│ └── ExtraMarkersIcon.php
├── FullScreen
│ └── FullScreenControl.php
├── LeafletProviders
│ ├── HereProvider.php
│ ├── MapBoxProvider.php
│ ├── OpenWeatherMapProvider.php
│ ├── Provider.php
│ └── ThunderforestProvider.php
├── Loading
│ ├── LoadingControl.php
│ └── SpinJsLoadingControl.php
├── MarkerCluster
│ └── MarkerClusterGroup.php
├── Omnivore
│ ├── Csv.php
│ ├── GeoJson.php
│ ├── Gpx.php
│ ├── Kml.php
│ ├── Omnivore.php
│ ├── OmnivoreLayer.php
│ ├── Polyline.php
│ ├── TopoJson.php
│ └── Wkt.php
└── OverpassLayer
│ ├── MinZoomIndicatorOptions.php
│ └── OverpassLayer.php
└── Value
├── GeoJson
├── AbstractFeature.php
├── ConvertsToGeoJsonFeature.php
├── Feature.php
├── FeatureCollection.php
├── FeatureTrait.php
├── GeoJsonFeature.php
├── GeoJsonObject.php
├── Geometry.php
└── StaticFeature.php
├── LatLng.php
└── LatLngBounds.php
/.phpcq.lock:
--------------------------------------------------------------------------------
1 | {"plugins":{"composer-require-checker":{"api-version":"1.0.0","version":"1.0.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.0.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8"}},"checksum":{"type":"sha-512","value":"5b0fd8cd5e0f5761c53b9d5375b6f6ba50f148468896248f823cc2a48361adfd872556066764b1b544ff51ffd5de60d6f9a75050db00b257d807976ac761bc3a"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}}},"phpmd":{"api-version":"1.0.0","version":"1.0.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"88e267b9c36b2edc85e924717606b626e005ac8d97b1f65f5331e2a3b3894dec2cf124f6187541bf759d026477b6d94daacc5d5c81bb09714a68ffabe5698dc5"},"tools":{"phpmd":{"version":"2.11.1","url":"https://github.com/phpmd/phpmd/releases/download/2.11.1/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":null}}},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}}},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}}},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.6.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.6.2/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.6.2/phpcs.phar.asc"},"phpcbf":{"version":"3.6.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.6.2/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.6.2/phpcbf.phar.asc"}}},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.23.1","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.23.1/composer-normalize.phar","requirements":{"php":{"php":"^7.4 || ^8.0"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.23.1/composer-normalize.phar.asc"}}}},"tools":[]}
--------------------------------------------------------------------------------
/.phpcq.yaml.dist:
--------------------------------------------------------------------------------
1 | phpcq:
2 | repositories:
3 | - https://phpcq.github.io/repository/repository.json
4 | directories:
5 | - src
6 |
7 | plugins:
8 | composer-require-checker:
9 | version: ^1.0
10 | signed: false
11 | phpmd:
12 | version: ^1.0
13 | signed: false
14 | requirements:
15 | phpmd:
16 | signed: false
17 | phpcpd:
18 | version: ^1.1
19 | signed: false
20 | phploc:
21 | version: ^1.0
22 | signed: false
23 | phpcs:
24 | version: ^1.0
25 | signed: false
26 | composer-normalize:
27 | version: ^1.0
28 | signed: false
29 |
30 | trusted-keys:
31 | # composer require checker
32 | - 033E5F8D801A2F8D
33 | # sb@sebastian-bergmann.de
34 | - 4AA394086372C20A
35 | # magl@magll.net
36 | - D2CCAC42F6295E7D
37 | # PHP_CodeSniffer
38 | - 31C7E470E2138192
39 | # Composer normalize
40 | - C00543248C87FB13
41 | # phpmd
42 | - 0F9684B8B16B7AB0
43 |
44 | tasks:
45 | fix:
46 | - composer-normalize-fix
47 | - phpcbf
48 |
49 | verify:
50 | - composer-require-checker
51 | - composer-normalize
52 |
53 | analyze:
54 | - phploc
55 | - phpcpd
56 | - phpmd
57 | - phpcs
58 |
59 | default:
60 | - verify
61 | - analyze
62 |
63 | phpcpd:
64 | plugin: phpcpd
65 |
66 | phpmd:
67 | config:
68 | ruleset:
69 | - vendor/phpcq/coding-standard/phpmd/ruleset.xml
70 |
71 | composer-normalize:
72 | config:
73 | ignore_output:
74 | - '#Root package is not of type "project", we will not installing Contao extensions\.#'
75 |
76 | composer-require-checker:
77 | plugin: composer-require-checker
78 |
79 | phpcs:
80 | plugin: phpcs
81 | config: &phpcs-config
82 | standard: ~
83 |
84 | phpcbf:
85 | plugin: phpcs
86 | config:
87 | <<: *phpcs-config
88 | fix: true
89 |
90 | composer-normalize-fix:
91 | plugin: composer-normalize
92 | config:
93 | dry_run: false
94 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | #Changelog
3 |
4 | ## 1.1.1 - 2022-02-22
5 |
6 | ### Changed
7 |
8 | - Bump dependencies of symfony
9 |
10 | ## 1.1.0 - 2018-12-18
11 |
12 | ### Added
13 |
14 | - Added OpenWeatherMapProvider which allows to set the api key.
15 | - Added ThunderforestProvider which allows to set the api key for thunderforest.
16 | - Added support for MapBox accessToken.
17 |
18 | ### Deprecated
19 |
20 | - Calling MapBoxProvider user and name setting is deprecated and without any affect anymore (Mapbox API v3).
21 |
22 | ### Fixed
23 |
24 | - Marker is not rendered when using custom icon (#3)
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | PHP Leaflet library
3 | ===================
4 |
5 | [](https://travis-ci.org/netzmacht/php-leaflet)
6 | [](http://packagist.org/packages/netzmacht/php-leaflet)
7 | [](http://packagist.org/packages/netzmacht/php-leaflet)
8 | [](http://packagist.org/packages/netzmacht/php-leaflet)
9 | [](https://github.com/contao-community-alliance/coding-standard)
10 |
11 | This library provides a PHP API to setup the Leaflet map definitions. The goal of the library is to provide a handy way
12 | to handle dynamic map configurations working in a PHP context.
13 |
14 | Install
15 | -------
16 |
17 | You can install the library using composer:
18 |
19 | ```
20 | $ php composer.phar require netzmacht/php-leaflet
21 | ```
22 |
23 | Features
24 | --------
25 |
26 | This library provides different components:
27 |
28 | - Definition classes to define the leaflet map with all layers, controls and so on.
29 | - Value classes which have real behaviour and can be used to handle LatLng or GeoJSON features.
30 | - The Encoder component to convert the PHP leaflet definition into javascript.
31 | - Support for several Leaflet plugins.
32 | - Assets handling to autoload all required javascripts and css files from all plugins.
33 |
34 | Before you start
35 | ----------------
36 |
37 | - The definition classes has some mixed behaviours. There useful behaviour is implemented. Some method creates just
38 | javascript method calls.
39 | - The goal is to have a close reflection of the Javascript API. Since the languages differs there are some changes
40 | which you should be aware of.
41 |
42 | Requirements
43 | ------------
44 |
45 | This library requires PHP 5.6 and the symfony event dispatcher. The event dispatcher is used by the
46 | [php-javascript-builder](https://github.com/netzmacht/php-javascript-builder) which encodes the PHP definition.
47 |
48 | Example
49 | -------
50 |
51 | ```php
52 |
53 | /*
54 | * 1. Setup the encoder
55 | */
56 |
57 | // The event dispatcher
58 | $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
59 |
60 | // All encoders are event subscribers.
61 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\ControlEncoder());
62 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\GroupEncoder());
63 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\MapEncoder());
64 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\RasterEncoder());
65 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\TypeEncoder());
66 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\UIEncoder());
67 | $dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\VectorEncoder());
68 |
69 | // Create a custom factory for the javascript builder which uses the event dispatcher.
70 | // The order of the registered encoders are important! Only change if you know what you do.
71 | $factory = function(Output $output) use ($dispatcher) {
72 | $encoder = new ChainEncoder();
73 |
74 | $encoder
75 | ->register(new \Netzmacht\JavascriptBuilder\Encoder\MultipleObjectsEncoder())
76 | ->register(new \Netzmacht\JavascriptBuilder\Symfony\EventDispatchingEncoder($dispatcher))
77 | ->register(new \Netzmacht\JavascriptBuilder\Encoder\JavascriptEncoder($output));
78 |
79 | return $encoder;
80 | };
81 |
82 | $builder = new \Netzmacht\JavascriptBuilder\Builder($factory);
83 | $leaflet = new \Netzmacht\LeafletPHP\leaflet($builder, $dispatcher);
84 |
85 | /*
86 | * 2. Create the map definitions
87 | */
88 | $map = new \Netzmacht\LeafletPHP\Definition\Map('html_id', 'map');
89 | $map
90 | ->setZoom(12)
91 | ->addControl(...)
92 | ->addLayer(...);
93 |
94 | /*
95 | * 3. Build the javascript
96 | */
97 |
98 | // Will return javascript with following local vars: "map", "layers", "controls", "icons".
99 | echo $leaflet->build($map);
100 |
101 | ```
102 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "netzmacht/php-leaflet",
3 | "description": "PHP leaflet definition and javascript generator",
4 | "license": "LGPL-3.0-or-later",
5 | "type": "library",
6 | "keywords": [
7 | "leaflet",
8 | "maps",
9 | "javascript",
10 | "library"
11 | ],
12 | "authors": [
13 | {
14 | "name": "David Molineus",
15 | "email": "david.molineus@netzmacht.de"
16 | }
17 | ],
18 | "require": {
19 | "php": "^7.1 || ^8.0",
20 | "ext-json": "*",
21 | "beberlei/assert": "~2.0 || ^3.0",
22 | "netzmacht/php-javascript-builder": "~1.0",
23 | "symfony/event-dispatcher": "^4.4 || ^5.1"
24 | },
25 | "require-dev": {
26 | "phpcq/coding-standard": "^2.1",
27 | "phpcq/runner-bootstrap": "^1.0@dev"
28 | },
29 | "autoload": {
30 | "psr-0": {
31 | "Netzmacht\\LeafletPHP\\": "src/"
32 | }
33 | },
34 | "extra": {
35 | "branch-alias": {
36 | "dev-develop": "1.2.x-dev",
37 | "dev-master": "1.1.x-dev"
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/phpcs.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assert/Assertion.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Assert;
14 |
15 | use Assert\Assertion as BaseAssertion;
16 |
17 | /**
18 | * Project owns Assertion class.
19 | *
20 | * @package Netzmacht\LeafletPHP\Assert
21 | */
22 | class Assertion extends BaseAssertion
23 | {
24 | /**
25 | * The exception class.
26 | *
27 | * @var string
28 | */
29 | protected static $exceptionClass = 'Netzmacht\LeafletPHP\Assert\InvalidArgumentException';
30 | }
31 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assert/InvalidArgumentException.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Assert;
14 |
15 | use Assert\InvalidArgumentException as ParentInvalidArgumentException;
16 |
17 | /**
18 | * Class InvalidArgumentException.
19 | *
20 | * @package Netzmacht\LeafletPHP\Assert
21 | */
22 | class InvalidArgumentException extends ParentInvalidArgumentException
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assets.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP;
14 |
15 | /**
16 | * Interface Assets describes the result of the leaflet building.
17 | *
18 | * @package Netzmacht\LeafletPHP
19 | */
20 | interface Assets
21 | {
22 | const TYPE_SOURCE = 'source';
23 | const TYPE_FILE = 'file';
24 | const TYPE_URL = 'url';
25 |
26 | /**
27 | * Add a javascript.
28 | *
29 | * @param string $script Javascript source.
30 | * @param string $type The resource type.
31 | *
32 | * @return $this
33 | */
34 | public function addJavascript($script, $type = self::TYPE_SOURCE);
35 |
36 | /**
37 | * Add a stylesheet.
38 | *
39 | * @param string $stylesheet The stylesheet.
40 | * @param string $type The resource type.
41 | *
42 | * @return $this
43 | */
44 | public function addStylesheet($stylesheet, $type = self::TYPE_FILE);
45 |
46 | /**
47 | * Set the map javascript.
48 | *
49 | * @param string $map The map javscript.
50 | *
51 | * @return $this
52 | */
53 | public function setMap($map);
54 |
55 | /**
56 | * Get the map javascript.
57 | *
58 | * @return string
59 | */
60 | public function getMap();
61 | }
62 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assets/AbstractAssets.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Assets;
14 |
15 | use Netzmacht\LeafletPHP\Assets;
16 |
17 | /**
18 | * Class AbstractAssets is a base implementation of the assets interface. It also implements the GeneratesHtml
19 | * interface.
20 | *
21 | * @package Netzmacht\LeafletPHP\Assets
22 | */
23 | abstract class AbstractAssets implements Assets, GeneratesHtml
24 | {
25 | /**
26 | * The stylesheets.
27 | *
28 | * @var string
29 | */
30 | private $stylesheets = '';
31 |
32 | /**
33 | * The java scripts.
34 | *
35 | * @var string
36 | */
37 | private $javaScripts = '';
38 |
39 | /**
40 | * Line separator.
41 | *
42 | * @var string
43 | */
44 | private $separator = "\n";
45 |
46 | /**
47 | * Map javascript.
48 | *
49 | * @var string
50 | */
51 | private $map;
52 |
53 | /**
54 | * Get the separator.
55 | *
56 | * @return string
57 | */
58 | public function getSeparator()
59 | {
60 | return $this->separator;
61 | }
62 |
63 | /**
64 | * Set the separator.
65 | *
66 | * @param string $separator The line separator.
67 | *
68 | * @return $this
69 | */
70 | public function setSeparator($separator)
71 | {
72 | $this->separator = $separator;
73 |
74 | return $this;
75 | }
76 |
77 | /**
78 | * {@inheritdoc}
79 | */
80 | public function setMap($map)
81 | {
82 | $this->map = $map;
83 |
84 | return $this;
85 | }
86 |
87 | /**
88 | * {@inheritdoc}
89 | */
90 | public function getMap()
91 | {
92 | return $this->map;
93 | }
94 |
95 | /**
96 | * {@inheritdoc}
97 | */
98 | public function getMapHtml()
99 | {
100 | return sprintf('', $this->getMap());
101 | }
102 |
103 | /**
104 | * {@inheritdoc}
105 | */
106 | public function getScriptsHtml()
107 | {
108 | return $this->javaScripts;
109 | }
110 |
111 | /**
112 | * {@inheritdoc}
113 | */
114 | public function getStylesHtml()
115 | {
116 | return $this->stylesheets;
117 | }
118 |
119 | /**
120 | * {@inheritdoc}
121 | */
122 | public function getHtml($includeMap = true)
123 | {
124 | return $this->getStylesHtml()
125 | . $this->separator
126 | . $this->getScriptsHtml()
127 | . ($includeMap ? ($this->separator . $this->getMapHtml()) : '');
128 | }
129 |
130 | /**
131 | * Append style.
132 | *
133 | * @param string $style The style to be appended.
134 | *
135 | * @return $this
136 | */
137 | protected function appendStyle($style)
138 | {
139 | $this->stylesheets .= $style;
140 |
141 | return $this;
142 | }
143 |
144 | /**
145 | * Append script.
146 | *
147 | * @param string $script The script to be added.
148 | *
149 | * @return $this
150 | */
151 | protected function appendScript($script)
152 | {
153 | $this->javaScripts .= $script;
154 |
155 | return $this;
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assets/Collector.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Assets;
14 |
15 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeValueEvent;
16 | use Netzmacht\LeafletPHP\Assets;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19 |
20 | /**
21 | * Class LibrariesCollector is used to collect all required libraries of the compiled map.
22 | *
23 | * @package Netzmacht\LeafletPHP
24 | */
25 | class Collector implements EventSubscriberInterface
26 | {
27 | /**
28 | * {@inheritdoc}
29 | */
30 | public static function getSubscribedEvents()
31 | {
32 | return array(
33 | EncodeValueEvent::NAME => 'collect'
34 | );
35 | }
36 |
37 | /**
38 | * Assets instance.
39 | *
40 | * @var Assets
41 | */
42 | private $assets;
43 |
44 | /**
45 | * Library stylesheets.
46 | *
47 | * @var array
48 | */
49 | private $stylesheets = array();
50 |
51 | /**
52 | * Library javascripts.
53 | *
54 | * @var array
55 | */
56 | private $javascripts = array();
57 |
58 | /**
59 | * Already added libraries.
60 | *
61 | * @var array
62 | */
63 | private $libraries = array();
64 |
65 | /**
66 | * Construct.
67 | *
68 | * @param Assets $assets The assets instance.
69 | * @param array $javascripts Registered javascripts.
70 | * @param array $stylesheets Registered stylesheets.
71 | */
72 | public function __construct(Assets $assets, array $javascripts, array $stylesheets)
73 | {
74 | $this->assets = $assets;
75 | $this->javascripts = $javascripts;
76 | $this->stylesheets = $stylesheets;
77 | }
78 |
79 | /**
80 | * Collect all libraries.
81 | *
82 | * @param EncodeValueEvent $event The subscribed event.
83 | *
84 | * @return void
85 | */
86 | public function collect(EncodeValueEvent $event)
87 | {
88 | $value = $event->getValue();
89 |
90 | if ($value instanceof Definition) {
91 | foreach ($value->getRequiredLibraries() as $library) {
92 | if (isset($this->libraries[$library])) {
93 | continue;
94 | }
95 |
96 | if (isset($this->stylesheets[$library])) {
97 | foreach ($this->stylesheets[$library] as $asset) {
98 | $this->assets->addStylesheet($asset[0], $asset[1]);
99 | }
100 | }
101 |
102 | if (isset($this->javascripts[$library])) {
103 | foreach ($this->javascripts[$library] as $asset) {
104 | $this->assets->addJavascript($asset[0], $asset[1]);
105 | }
106 | }
107 |
108 | $this->libraries[$library] = true;
109 | }
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assets/GeneratesHtml.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Assets;
14 |
15 | /**
16 | * Interface GeneratesHtml describes an Assets object which generates the assets output.
17 | *
18 | * @package Netzmacht\LeafletPHP\Assets
19 | */
20 | interface GeneratesHtml
21 | {
22 | /**
23 | * Get map javascript with script tags.
24 | *
25 | * @return string
26 | */
27 | public function getMapHtml();
28 |
29 | /**
30 | * Get scripts html.
31 | *
32 | * @return string
33 | */
34 | public function getScriptsHtml();
35 |
36 | /**
37 | * Get styles html.
38 | *
39 | * @return string
40 | */
41 | public function getStylesHtml();
42 |
43 | /**
44 | * Get html.
45 | *
46 | * @param bool $includeMap Also include the map.
47 | *
48 | * @return string
49 | */
50 | public function getHtml($includeMap = true);
51 | }
52 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Assets/SimpleAssets.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Assets;
14 |
15 | /**
16 | * Class SimpleAssets is a simple assets implementation.
17 | *
18 | * @package Netzmacht\LeafletPHP\Assets
19 | */
20 | class SimpleAssets extends AbstractAssets
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public function addJavascript($script, $type = self::TYPE_SOURCE)
26 | {
27 | switch ($type) {
28 | case static::TYPE_FILE:
29 | $this->appendScript(sprintf('', $script));
30 | break;
31 |
32 | case static::TYPE_URL:
33 | $this->appendScript(sprintf('', $script));
34 | break;
35 |
36 | default:
37 | $this->appendScript(sprintf('', $script));
38 | break;
39 | }
40 | }
41 |
42 | /**
43 | * {@inheritdoc}
44 | */
45 | public function addStylesheet($stylesheet, $type = self::TYPE_FILE)
46 | {
47 | switch ($type) {
48 | case static::TYPE_FILE:
49 | $this->appendStyle(sprintf('', $stylesheet));
50 | break;
51 |
52 | case static::TYPE_URL:
53 | $this->appendStyle(sprintf('', $stylesheet));
54 | break;
55 |
56 | default:
57 | $this->appendStyle(sprintf('', $stylesheet));
58 | break;
59 | }
60 |
61 | return $this;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP;
14 |
15 | use Netzmacht\JavascriptBuilder\Type\Call\MethodCall;
16 |
17 | /**
18 | * Interface Definition is the base interface for leaflet map definitions.
19 | *
20 | * @package Netzmacht\LeafletPHP
21 | */
22 | interface Definition
23 | {
24 | /**
25 | * Get the type of the definition.
26 | *
27 | * @return string
28 | */
29 | public static function getType();
30 |
31 | /**
32 | * Get all required javascript libraries.
33 | *
34 | * @return array
35 | */
36 | public static function getRequiredLibraries();
37 |
38 | /**
39 | * Get the identifier.
40 | *
41 | * @return string
42 | */
43 | public function getId();
44 |
45 | /**
46 | * Get all method calls.
47 | *
48 | * @return MethodCall[]
49 | */
50 | public function getMethodCalls();
51 |
52 | /**
53 | * Allow dynamic method calls.
54 | *
55 | * As Javascript is a prototype based language and methods can be plugged in, support it by the magic call method.
56 | *
57 | * @param string $name The method name.
58 | * @param array $arguments List of arguments.
59 | *
60 | * @return $this
61 | */
62 | public function __call($name, array $arguments);
63 | }
64 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/AbstractDefinition.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\JavascriptBuilder\Type\Call\MethodCall;
16 | use Netzmacht\LeafletPHP\Definition;
17 |
18 | /**
19 | * Class AbstractDefinition is a basic definition implementation.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition
22 | */
23 | abstract class AbstractDefinition implements Definition
24 | {
25 | /**
26 | * {@inheritdoc}
27 | */
28 | public static function getRequiredLibraries()
29 | {
30 | return array('leaflet');
31 | }
32 |
33 | /**
34 | * Control identifier.
35 | *
36 | * The control name is used as identifier and javascript variable suffix.
37 | *
38 | * @var string
39 | */
40 | private $identifier;
41 |
42 | /**
43 | * Method calls.
44 | *
45 | * @var MethodCall[]
46 | */
47 | protected $methods = array();
48 |
49 | /**
50 | * Construct.
51 | *
52 | * @param string $identifier The element id..
53 | */
54 | public function __construct($identifier)
55 | {
56 | $this->identifier = $identifier;
57 | }
58 |
59 | /**
60 | * Get the name.
61 | *
62 | * @return string
63 | */
64 | public function getId()
65 | {
66 | return $this->identifier;
67 | }
68 |
69 | /**
70 | * Add a method call.
71 | *
72 | * @param string $name Method name.
73 | * @param array $arguments Method arguments.
74 | *
75 | * @return $this
76 | */
77 | protected function addMethod($name, array $arguments = array())
78 | {
79 | $this->methods[] = new MethodCall($this, $name, $arguments);
80 |
81 | return $this;
82 | }
83 |
84 | /**
85 | * Get all method calls.
86 | *
87 | * @return MethodCall[]
88 | */
89 | public function getMethodCalls()
90 | {
91 | return $this->methods;
92 | }
93 |
94 | /**
95 | * {@inheritdoc}
96 | */
97 | public function __call($name, array $arguments)
98 | {
99 | return $this->addMethod($name, $arguments);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/AbstractLayer.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Bas class for the layer implementation.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | abstract class AbstractLayer extends AbstractDefinition implements Layer
21 | {
22 | use LabelTrait;
23 | use OptionsTrait;
24 | use PopupTrait;
25 |
26 | /**
27 | * The connected map.
28 | *
29 | * @var Map
30 | */
31 | protected $map;
32 |
33 | /**
34 | * Add layer to the map.
35 | *
36 | * Instead create an addTo method, it's assigned to the map.
37 | * This is required so that the encoder knows the relation between the map and the layer.
38 | *
39 | * @param Map $map The leaflet map.
40 | *
41 | * @return $this
42 | */
43 | public function addTo(Map $map)
44 | {
45 | $this->map = $map;
46 | $map->addLayer($this);
47 |
48 | return $this->addMethod('addTo', array($map));
49 | }
50 |
51 | /**
52 | * Get the map.
53 | *
54 | * @return Map|null
55 | */
56 | public function getMap()
57 | {
58 | return $this->map;
59 | }
60 |
61 | /**
62 | * Remove the layer from the map.
63 | *
64 | * @return $this
65 | */
66 | public function remove()
67 | {
68 | if (!$this->map) {
69 | return $this;
70 | }
71 |
72 | return $this->removeFrom($this->map);
73 | }
74 |
75 | /**
76 | * Remove the layer from a container.
77 | *
78 | * @param HasRemovableLayers $container The container.
79 | *
80 | * @return $this
81 | */
82 | public function removeFrom(HasRemovableLayers $container)
83 | {
84 | $container->removeLayer($this);
85 |
86 | return $this;
87 | }
88 |
89 | /**
90 | * Set the pane option.
91 | *
92 | * @param string $name The name of the pane.
93 | *
94 | * @return $this
95 | */
96 | public function setPane($name)
97 | {
98 | return $this->setOption('pane', $name);
99 | }
100 |
101 | /**
102 | * Get the pane option.
103 | *
104 | * This method does not work like L.Layer.getPane which returns a pane defined in the map.
105 | * Use getMap()->getPane('name') instead.
106 | *
107 | * @return string.
108 | */
109 | public function getPane()
110 | {
111 | return $this->getOption('pane', 'overlayPane');
112 | }
113 |
114 | /**
115 | * Set the names of non bubbling events.
116 | *
117 | * @param array $events The name of events.
118 | *
119 | * @return $this
120 | */
121 | public function setNonBubblingEvents(array $events)
122 | {
123 | return $this->setOption('nonBubblingEvents', $events);
124 | }
125 |
126 | /**
127 | * Get the non bubbling events option.
128 | *
129 | * @return array
130 | */
131 | public function getNonBubblingEvents()
132 | {
133 | return $this->getOption('nonBubblingEvents', []);
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Control.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\LeafletPHP\Definition;
16 |
17 | /**
18 | * Interface Control describe the Controls.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition
21 | */
22 | interface Control extends Definition, MapObject
23 | {
24 | /**
25 | * Get options of the control.
26 | *
27 | * @return mixed
28 | */
29 | public function getOptions();
30 | }
31 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Control/AbstractControl.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Control;
14 |
15 | use Netzmacht\LeafletPHP\Definition\AbstractDefinition;
16 | use Netzmacht\LeafletPHP\Definition\Control;
17 | use Netzmacht\LeafletPHP\Definition\HasOptions;
18 | use Netzmacht\LeafletPHP\Definition\Map;
19 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
20 |
21 | /**
22 | * Basic control class.
23 | *
24 | * @package Netzmacht\LeafletPHP\Control
25 | */
26 | abstract class AbstractControl extends AbstractDefinition implements Control, HasOptions
27 | {
28 | use OptionsTrait;
29 |
30 | const POSITION_TOP_LEFT = 'topleft';
31 | const POSITION_TOP_RIGHT = 'topright';
32 | const POSITION_BOTTOM_LEFT = 'bottomleft';
33 | const POSITION_BOTTOM_RIGHT = 'bottomright';
34 |
35 | /**
36 | * Default position.
37 | *
38 | * @var string
39 | */
40 | protected $defaultPosition = self::POSITION_TOP_RIGHT;
41 |
42 | /**
43 | * Set position.
44 | *
45 | * @param string $position Position.
46 | *
47 | * @return $this
48 | */
49 | public function setPosition($position)
50 | {
51 | return $this->setOption('position', $position);
52 | }
53 |
54 | /**
55 | * Get the position.
56 | *
57 | * @return string
58 | */
59 | public function getPosition()
60 | {
61 | return $this->getOption('position', $this->defaultPosition);
62 | }
63 |
64 | /**
65 | * Add control to the map.
66 | *
67 | * @param Map $map The leaflet map.
68 | *
69 | * @return $this
70 | */
71 | public function addTo(Map $map)
72 | {
73 | $map->addControl($this);
74 |
75 | return $this->addMethod('addTo', array($map));
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Control/Attribution.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Control;
14 |
15 | /**
16 | * Attribution control.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\Control
19 | */
20 | class Attribution extends AbstractControl
21 | {
22 | /**
23 | * Attributions.
24 | *
25 | * @var array
26 | */
27 | private $attributions = array();
28 |
29 | /**
30 | * {@inheritdoc}
31 | */
32 | public static function getType()
33 | {
34 | return 'Control.Attribution';
35 | }
36 |
37 | /**
38 | * Set the prefix.
39 | *
40 | * @param string $prefix The attribution prefix.
41 | *
42 | * @return $this
43 | * @see http://leafletjs.com/reference.html#control-attribution-prefix
44 | */
45 | public function setPrefix($prefix)
46 | {
47 | return $this->setOption('prefix', $prefix);
48 | }
49 |
50 | /**
51 | * Get the prefix.
52 | *
53 | * @return string
54 | * @see http://leafletjs.com/reference.html#control-attribution-prefix
55 | */
56 | public function getPrefix()
57 | {
58 | return $this->getOption('prefix', 'Leaflet');
59 | }
60 |
61 | /**
62 | * Add a attribution.
63 | *
64 | * @param string $attribution Attribution text. Can contain html.
65 | *
66 | * @return $this
67 | * @see http://leafletjs.com/reference.html#control-attribution-addattribution
68 | */
69 | public function addAttribution($attribution)
70 | {
71 | $this->attributions[] = $attribution;
72 |
73 | return $this;
74 | }
75 |
76 | /**
77 | * Remove attribution.
78 | *
79 | * @param string $attribution The attribution.
80 | *
81 | * @return $this
82 | */
83 | public function removeAttribution($attribution)
84 | {
85 | $key = array_search($attribution, $this->attributions);
86 |
87 | if ($key !== false) {
88 | unset($this->attributions[$key]);
89 | } else {
90 | $this->addMethod('removeAttribution', array($attribution));
91 | }
92 |
93 | return $this;
94 | }
95 |
96 | /**
97 | * Get all attributions.
98 | *
99 | * @return array
100 | */
101 | public function getAttributions()
102 | {
103 | return $this->attributions;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Control/Layers.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Control;
14 |
15 | use Netzmacht\LeafletPHP\Definition\EventsTrait;
16 | use Netzmacht\LeafletPHP\Definition\Layer;
17 |
18 | /**
19 | * Layers control.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\Control
22 | */
23 | class Layers extends AbstractControl
24 | {
25 | use EventsTrait;
26 |
27 | const EVENT_BASE_LAYER_CHANGE = 'baselayerchange';
28 | const EVENT_OVERLAY_ADD = 'overlayadd';
29 | const EVENT_OVERLAY_REMOVE = 'overlayremove';
30 |
31 | /**
32 | * Base layers.
33 | *
34 | * @var Layer[]
35 | */
36 | private $baseLayers = array();
37 |
38 | /**
39 | * Overlay layers.
40 | *
41 | * @var Layer[]
42 | */
43 | private $overlays = array();
44 |
45 | /**
46 | * Construct.
47 | *
48 | * @param string $identifier The identifier.
49 | * @param Layer[] $baseLayers Base layers.
50 | * @param Layer[] $overlays Overlay layers.
51 | */
52 | public function __construct($identifier, $baseLayers = array(), $overlays = array())
53 | {
54 | parent::__construct($identifier);
55 |
56 | foreach ($baseLayers as $layer) {
57 | $this->addBaseLayer($layer);
58 | }
59 |
60 | foreach ($overlays as $layer) {
61 | $this->addOverlay($layer);
62 | }
63 | }
64 |
65 | /**
66 | * {@inheritdoc}
67 | */
68 | public static function getType()
69 | {
70 | return 'Control.Layers';
71 | }
72 |
73 | /**
74 | * Set initial collapsed state.
75 | *
76 | * @param bool $state The collapsed state.
77 | *
78 | * @return $this
79 | * @see http://leafletjs.com/reference.html#control-layers-collapsed
80 | */
81 | public function setCollapsed($state)
82 | {
83 | return $this->setOption('collapsed', (bool) $state);
84 | }
85 |
86 | /**
87 | * Get initial collapsed state.
88 | *
89 | * @return bool
90 | * @see http://leafletjs.com/reference.html#control-layers-collapsed
91 | */
92 | public function isCollapsed()
93 | {
94 | return $this->getOption('collapsed', true);
95 | }
96 |
97 | /**
98 | * Set initial collapsed state.
99 | *
100 | * @param bool $state The collapsed state.
101 | *
102 | * @return $this
103 | * @see http://leafletjs.com/reference.html#control-layers-autozindex
104 | */
105 | public function setAutoZIndex($state)
106 | {
107 | return $this->setOption('autoZIndex', (bool) $state);
108 | }
109 |
110 | /**
111 | * Get initial collapsed state.
112 | *
113 | * @return bool
114 | * @see http://leafletjs.com/reference.html#control-layers-autozindex
115 | */
116 | public function isAutoZIndex()
117 | {
118 | return $this->getOption('autoZIndex', true);
119 | }
120 |
121 | /**
122 | * Add a base layer.
123 | *
124 | * @param Layer $layer A Layer.
125 | *
126 | * @return $this
127 | * @see http://leafletjs.com/reference.html#control-layers-addbaselayer
128 | */
129 | public function addBaseLayer(Layer $layer)
130 | {
131 | $this->baseLayers[] = $layer;
132 |
133 | return $this;
134 | }
135 |
136 | /**
137 | * Get all base layers.
138 | *
139 | * @return Layer[]
140 | * @see http://leafletjs.com/reference.html#control-layers-addbaselayer
141 | */
142 | public function getBaseLayers()
143 | {
144 | return $this->baseLayers;
145 | }
146 |
147 | /**
148 | * Add an overlay layer.
149 | *
150 | * @param Layer $layer A Layer.
151 | *
152 | * @return $this
153 | * @see http://leafletjs.com/reference.html#control-layers-addoverlay
154 | */
155 | public function addOverlay(Layer $layer)
156 | {
157 | $this->overlays[] = $layer;
158 |
159 | return $this;
160 | }
161 |
162 | /**
163 | * Get all overlay layers.
164 | *
165 | * @return Layer[]
166 | * @see http://leafletjs.com/reference.html#control-layers-addoverlay
167 | */
168 | public function getOverlays()
169 | {
170 | return $this->overlays;
171 | }
172 |
173 | /**
174 | * Remove a layer.
175 | *
176 | * @param Layer $layer Layer to be removed.
177 | *
178 | * @return $this
179 | */
180 | public function removeLayer(Layer $layer)
181 | {
182 | $key = array_search($layer, $this->baseLayers);
183 | if ($key !== false) {
184 | unset($this->baseLayers[$key]);
185 | }
186 |
187 | $key = array_search($layer, $this->overlays);
188 | if ($key !== false) {
189 | unset($this->overlays[$key]);
190 | }
191 |
192 | return $this;
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Control/Scale.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Control;
14 |
15 | /**
16 | * Scale control.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\Control
19 | */
20 | class Scale extends AbstractControl
21 | {
22 | /**
23 | * Default position.
24 | *
25 | * @var string
26 | */
27 | protected $defaultPosition = self::POSITION_BOTTOM_LEFT;
28 |
29 | /**
30 | * {@inheritdoc}
31 | */
32 | public static function getType()
33 | {
34 | return 'Control.Scale';
35 | }
36 |
37 | /**
38 | * Set the max width.
39 | *
40 | * @param int $width Max width of the control in pixels.
41 | *
42 | * @return $this
43 | * @see http://leafletjs.com/reference.html#control-scale-maxwidth
44 | */
45 | public function setMaxWidth($width)
46 | {
47 | return $this->setOption('maxWidth', (int) $width);
48 | }
49 |
50 | /**
51 | * Get the max width.
52 | *
53 | * @return int
54 | * @see http://leafletjs.com/reference.html#control-scale-maxwidth
55 | */
56 | public function getMaxWidth()
57 | {
58 | return $this->getOption('maxWidth', 100);
59 | }
60 |
61 | /**
62 | * Enable or disable the metric scale.
63 | *
64 | * @param bool $scale Enable or disable the scale.
65 | *
66 | * @return $this
67 | * @see http://leafletjs.com/reference.html#control-scale-metric
68 | */
69 | public function setMetric($scale)
70 | {
71 | return $this->setOption('metric', (bool) $scale);
72 | }
73 |
74 | /**
75 | * Check if metric scale is enabled.
76 | *
77 | * @return bool
78 | * @see http://leafletjs.com/reference.html#control-scale-metric
79 | */
80 | public function isMetric()
81 | {
82 | return $this->getOption('metric', true);
83 | }
84 |
85 | /**
86 | * Enable or disable the imperial scale.
87 | *
88 | * @param bool $scale Enable or disable the scale.
89 | *
90 | * @return $this
91 | * @see http://leafletjs.com/reference.html#control-scale-imperial
92 | */
93 | public function setImperial($scale)
94 | {
95 | return $this->setOption('imperial', (bool) $scale);
96 | }
97 |
98 | /**
99 | * Check if imperial scale is enabled.
100 | *
101 | * @return bool
102 | * @see http://leafletjs.com/reference.html#control-scale-imperial
103 | */
104 | public function isImperial()
105 | {
106 | return $this->getOption('imperial', true);
107 | }
108 |
109 | /**
110 | * Set update when idle.
111 | *
112 | * @param bool $update If true the control is updated on moveend.
113 | *
114 | * @return $this
115 | * @see http://leafletjs.com/reference.html#control-scale-updatewhenidle
116 | */
117 | public function setUpdateWhenIdle($update)
118 | {
119 | return $this->setOption('updateWhenIdle', (bool) $update);
120 | }
121 |
122 | /**
123 | * Check if update when idle is enabled.
124 | *
125 | * @return bool
126 | * @see http://leafletjs.com/reference.html#control-scale-updatewhenidle
127 | */
128 | public function isUpdateWhenIdle()
129 | {
130 | return $this->getOption('updateWhenIdle', false);
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Control/Zoom.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Control;
14 |
15 | /**
16 | * Zoom control.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\Control
19 | */
20 | class Zoom extends AbstractControl
21 | {
22 | /**
23 | * Default position.
24 | *
25 | * @var string
26 | */
27 | protected $defaultPosition = self::POSITION_TOP_LEFT;
28 |
29 | /**
30 | * {@inheritdoc}
31 | */
32 | public static function getType()
33 | {
34 | return 'Control.Zoom';
35 | }
36 |
37 | /**
38 | * Set text on the zoom in button.
39 | *
40 | * @param string $value The text.
41 | *
42 | * @return $this
43 | * @see http://leafletjs.com/reference.html#control-zoom-zoomintext
44 | */
45 | public function setZoomInText($value)
46 | {
47 | return $this->setOption('zoomInText', $value);
48 | }
49 |
50 | /**
51 | * Get the text on the zoom in button.
52 | *
53 | * @return string
54 | * @see http://leafletjs.com/reference.html#control-zoom-zoomintext
55 | */
56 | public function getZoomInText()
57 | {
58 | return $this->getOption('zoomInText', '+');
59 | }
60 |
61 | /**
62 | * Set text on the zoom out button.
63 | *
64 | * @param string $value The text.
65 | *
66 | * @return $this
67 | * @see http://leafletjs.com/reference.html#control-zoom-zoomouttext
68 | */
69 | public function setZoomOutText($value)
70 | {
71 | return $this->setOption('zoomOutText', $value);
72 | }
73 |
74 | /**
75 | * Set title on the zoom in button.
76 | *
77 | * @param string $value The title.
78 | *
79 | * @return $this
80 | * @see http://leafletjs.com/reference.html#control-zoom-zoomintitle
81 | */
82 | public function setZoomInTitle($value)
83 | {
84 | return $this->setOption('zoomInTitle', $value);
85 | }
86 |
87 | /**
88 | * Get the text on the zoom out button.
89 | *
90 | * @return string
91 | * @see http://leafletjs.com/reference.html#control-zoom-zoomouttext
92 | */
93 | public function getZoomOutText()
94 | {
95 | return $this->getOption('zoomOutText', '-');
96 | }
97 |
98 | /**
99 | * Get the title on the zoom in button.
100 | *
101 | * @return string
102 | * @see http://leafletjs.com/reference.html#control-zoom-zoomintitle
103 | */
104 | public function getZoomInTitle()
105 | {
106 | return $this->getOption('zoomInTitle', 'Zoom in');
107 | }
108 |
109 |
110 | /**
111 | * Set title on the zoom out button.
112 | *
113 | * @param string $value The title.
114 | *
115 | * @return $this
116 | * @see http://leafletjs.com/reference.html#control-zoom-zoomouttitle
117 | */
118 | public function setZoomOutTitle($value)
119 | {
120 | return $this->setOption('zoomOutTitle', $value);
121 | }
122 |
123 | /**
124 | * Get the title on the zoom out button.
125 | *
126 | * @return string
127 | * @see http://leafletjs.com/reference.html#control-zoom-zoomouttitle
128 | */
129 | public function getZoomOutTitle()
130 | {
131 | return $this->getOption('zoomOutTitle', 'Zoom out');
132 | }
133 |
134 | /**
135 | * Call enable method.
136 | *
137 | * @return $this
138 | */
139 | public function enable()
140 | {
141 | return $this->addMethod('enable');
142 | }
143 |
144 | /**
145 | * Call disable method.
146 | *
147 | * @return $this
148 | */
149 | public function disable()
150 | {
151 | return $this->addMethod('disable');
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/EventsTrait.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
16 | use Netzmacht\JavascriptBuilder\Type\Expression;
17 |
18 | /**
19 | * Class EventsTrait can be added to definitions which supports the addMethod function.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition
22 | */
23 | trait EventsTrait
24 | {
25 | /**
26 | * Add an event listener.
27 | *
28 | * @param string $event The event name.
29 | * @param AnonymousFunction|Expression $closure The callback.
30 | *
31 | * @return $this
32 | *
33 | * @SuppressWarnings(PHPMD.ShortMethodName)
34 | */
35 | public function on($event, $closure)
36 | {
37 | return $this->addMethod('on', array($event, $closure));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Group/FeatureGroup.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Group;
14 |
15 | use Netzmacht\LeafletPHP\Definition\EventsTrait;
16 | use Netzmacht\LeafletPHP\Definition\HasEvents;
17 |
18 | /**
19 | * Class FeatureGroup map object.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\Group
22 | */
23 | class FeatureGroup extends LayerGroup implements HasEvents
24 | {
25 | use EventsTrait;
26 |
27 | /**
28 | * {@inheritdoc}
29 | */
30 | public static function getType()
31 | {
32 | return 'FeatureGroup';
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Group/GeoJson.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Group;
14 |
15 | use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
16 | use Netzmacht\JavascriptBuilder\Type\Expression;
17 | use Netzmacht\LeafletPHP\Value\GeoJson\ConvertsToGeoJsonFeature;
18 | use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
19 | use Netzmacht\LeafletPHP\Value\GeoJson\GeoJsonFeature;
20 | use Netzmacht\LeafletPHP\Value\GeoJson\StaticFeature;
21 | use Netzmacht\LeafletPHP\Definition\HasOptions;
22 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
23 | use Netzmacht\LeafletPHP\Definition\Vector\PathOptionsTrait;
24 |
25 | /**
26 | * Class GeoJSON representation.
27 | *
28 | * @package Netzmacht\LeafletPHP\Definition\Group
29 | */
30 | class GeoJson extends FeatureGroup implements HasOptions, ConvertsToGeoJsonFeature
31 | {
32 | use PathOptionsTrait;
33 | use OptionsTrait;
34 |
35 | /**
36 | * Data being added as constructor argument.
37 | *
38 | * @var FeatureCollection
39 | */
40 | private $data;
41 |
42 | /**
43 | * {@inheritdoc}
44 | */
45 | public function __construct($identifier)
46 | {
47 | parent::__construct($identifier);
48 |
49 | $this->data = new FeatureCollection();
50 | }
51 |
52 | /**
53 | * {@inheritdoc}
54 | */
55 | public static function getType()
56 | {
57 | return 'GeoJSON';
58 | }
59 |
60 | /**
61 | * Set point to layer function.
62 | *
63 | * @param Expression|AnonymousFunction $function The function callback.
64 | *
65 | * @return $this
66 | */
67 | public function setPointToLayer($function)
68 | {
69 | return $this->setOption('pointToLayer', $function);
70 | }
71 |
72 | /**
73 | * Set on each feature function.
74 | *
75 | * @param Expression|AnonymousFunction $function The function callback.
76 | *
77 | * @return $this
78 | */
79 | public function setOnEachFeature($function)
80 | {
81 | return $this->setOption('onEachFeature', $function);
82 | }
83 |
84 | /**
85 | * Add data.
86 | *
87 | * @param GeoJsonFeature|array $feature Add geo json data.
88 | * @param bool $asArgument If true the data is set as constructor argument instead of method call.
89 | *
90 | * @return $this
91 | */
92 | public function addData($feature, $asArgument = false)
93 | {
94 | if ($asArgument) {
95 | if ($feature instanceof GeoJsonFeature) {
96 | $this->data->addFeature($feature);
97 | } else {
98 | $this->data->addFeature(new StaticFeature($feature));
99 | }
100 | } else {
101 | $this->addMethod('addData', array($feature));
102 | }
103 |
104 | return $this;
105 | }
106 |
107 | /**
108 | * Get all data which is added by the construct argument.
109 | *
110 | * @return FeatureCollection
111 | */
112 | public function getInitializationData()
113 | {
114 | return $this->data;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Group/LayerGroup.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Group;
14 |
15 | use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
16 | use Netzmacht\JavascriptBuilder\Type\Call\MethodCall;
17 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
18 | use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
19 | use Netzmacht\LeafletPHP\Value\GeoJson\ConvertsToGeoJsonFeature;
20 | use Netzmacht\LeafletPHP\Value\GeoJson\GeoJsonFeature;
21 | use Netzmacht\LeafletPHP\Definition\Layer;
22 | use Netzmacht\LeafletPHP\Definition\Map;
23 |
24 | /**
25 | * Basic layer group class.
26 | *
27 | * @package Netzmacht\LeafletPHP\Definition\Group
28 | */
29 | class LayerGroup extends AbstractLayer implements ConvertsToGeoJsonFeature
30 | {
31 | /**
32 | * Get the type of the definition.
33 | *
34 | * @return mixed
35 | */
36 | public static function getType()
37 | {
38 | return 'LayerGroup';
39 | }
40 |
41 | /**
42 | * Layers.
43 | *
44 | * @var Layer[]
45 | */
46 | private $layers = array();
47 |
48 | /**
49 | * Add a layer to the group.
50 | *
51 | * @param Layer $layer Layer being added.
52 | *
53 | * @return $this
54 | */
55 | public function addLayer(Layer $layer)
56 | {
57 | $this->layers[] = $layer;
58 |
59 | return $this;
60 | }
61 |
62 | /**
63 | * Get all layers.
64 | *
65 | * @return Layer[]
66 | */
67 | public function getLayers()
68 | {
69 | return $this->layers;
70 | }
71 |
72 | /**
73 | * Check if layer is part of the group.
74 | *
75 | * @param Layer $layer The layer being checked.
76 | *
77 | * @return bool
78 | */
79 | public function hasLayer(Layer $layer)
80 | {
81 | return in_array($layer, $this->layers);
82 | }
83 |
84 | /**
85 | * Apply a closure to the layer.
86 | *
87 | * @param AnonymousFunction $closure The anonymous function.
88 | *
89 | * @return $this
90 | */
91 | public function eachLayer(AnonymousFunction $closure)
92 | {
93 | return $this->addMethod('eachLayer', array($closure));
94 | }
95 |
96 | /**
97 | * {@inheritdoc}
98 | */
99 | public function toGeoJsonFeature()
100 | {
101 | $collection = new FeatureCollection();
102 |
103 | foreach ($this->getLayers() as $layer) {
104 | if ($layer instanceof GeoJsonFeature) {
105 | $collection->addFeature($layer);
106 | } elseif ($layer instanceof ConvertsToGeoJsonFeature) {
107 | $collection->addFeature($layer->toGeoJsonFeature());
108 | }
109 | }
110 |
111 | return $collection;
112 | }
113 |
114 | /**
115 | * {@inheritdoc}
116 | */
117 | public function convertsFullyToGeoJson()
118 | {
119 | foreach ($this->getLayers() as $layer) {
120 | if ($layer instanceof GeoJsonFeature) {
121 | // Layer is a geo json feature, it is fully a geo json object
122 | continue;
123 | } elseif ($layer instanceof ConvertsToGeoJsonFeature) {
124 | // check children of the layer.
125 | if (!$layer->convertsFullyToGeoJson()) {
126 | return false;
127 | }
128 | } else {
129 | // Unknown layer, return false.
130 | return false;
131 | }
132 | }
133 |
134 | return true;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/HasEvents.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
16 |
17 | /**
18 | * Interface HasEvents describes elements which have events which can be subscribed.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition
21 | */
22 | interface HasEvents
23 | {
24 | /**
25 | * Add an event listener.
26 | *
27 | * @param string $event The event name.
28 | * @param AnonymousFunction $closure The callback.
29 | *
30 | * @return $this
31 | *
32 | * @SuppressWarnings(PHPMD.ShortMethodName)
33 | */
34 | public function on($event, $closure);
35 | }
36 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/HasLabel.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Interface HasLabel describes the label feature.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | interface HasLabel
21 | {
22 | /**
23 | * Set the label.
24 | *
25 | * @param string $label The new label.
26 | *
27 | * @return $this
28 | */
29 | public function setLabel($label);
30 |
31 | /**
32 | * Get elements label.
33 | *
34 | * @return string
35 | */
36 | public function getLabel();
37 | }
38 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/HasOptions.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Interface HasOptions describes elements which have options.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | interface HasOptions
21 | {
22 | /**
23 | * Get all defined options. It does not contain default values which were not set.
24 | *
25 | * @return array
26 | */
27 | public function getOptions();
28 |
29 | /**
30 | * Set options by calling options methods.
31 | *
32 | * If a set method does not exists it ignores the option.
33 | * The setter method should handle the converting from native value to expected value.
34 | *
35 | * @param array $options Options being added.
36 | *
37 | * @return $this
38 | */
39 | public function setOptions(array $options);
40 |
41 | /**
42 | * Set an option.
43 | *
44 | * @param string $name Name of the option.
45 | * @param mixed $value Value of the option.
46 | *
47 | * @return $this
48 | */
49 | public function setOption($name, $value);
50 |
51 | /**
52 | * Get an option.
53 | *
54 | * @param string $name Name of the option.
55 | * @param mixed $default Default value if no option is set.
56 | *
57 | * @return null
58 | */
59 | public function getOption($name, $default = null);
60 |
61 | /**
62 | * Remove an option.
63 | *
64 | * @param string $name Name of the option.
65 | *
66 | * @return $this
67 | */
68 | public function removeOption($name);
69 | }
70 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/HasPopup.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\LeafletPHP\Definition\UI\Popup;
16 |
17 | /**
18 | * Interface HasPopup describes definitions which can open a popup.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition
21 | */
22 | interface HasPopup
23 | {
24 | /**
25 | * Set the popup content.
26 | *
27 | * @param string $content The popup content.
28 | *
29 | * @return $this
30 | */
31 | public function setPopupContent($content);
32 |
33 | /**
34 | * Get the popup content.
35 | *
36 | * @return string
37 | */
38 | public function getPopupContent();
39 |
40 | /**
41 | * Bind marker to a popup.
42 | *
43 | * @param Popup|string $popup The popup.
44 | * @param array|null $options Optional popup options.
45 | *
46 | * @return $this
47 | */
48 | public function bindPopup($popup, $options = null);
49 |
50 | /**
51 | * Get bound popup.
52 | *
53 | * @return Popup|string
54 | */
55 | public function getPopup();
56 |
57 | /**
58 | * Get popup options.
59 | *
60 | * @return array|null
61 | */
62 | public function getPopupOptions();
63 |
64 | /**
65 | * Unbind a popup.
66 | *
67 | * @return $this
68 | */
69 | public function unbindPopup();
70 | }
71 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/HasRemovableLayers.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Interface HasRemovableLayers describes definitions which contain layers which can be removed.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | interface HasRemovableLayers
21 | {
22 | /**
23 | * Remove a layer.
24 | *
25 | * @param Layer $layer The layer being removed.
26 | *
27 | * @return $this
28 | */
29 | public function removeLayer(Layer $layer);
30 | }
31 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/LabelTrait.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Class LabelTrait is a trait implementation of the HasLabel interface.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | trait LabelTrait
21 | {
22 | /**
23 | * The label.
24 | *
25 | * @var string
26 | */
27 | private $label;
28 |
29 | /**
30 | * Set the label.
31 | *
32 | * @param string $label The new label.
33 | *
34 | * @return $this
35 | */
36 | public function setLabel($label)
37 | {
38 | $this->label = $label;
39 |
40 | return $this;
41 | }
42 |
43 | /**
44 | * Get elements label.
45 | *
46 | * @return string
47 | */
48 | public function getLabel()
49 | {
50 | return $this->label ?: $this->getId();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Layer.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\LeafletPHP\Definition;
16 |
17 | /**
18 | * Interface Layer describes map layers.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition
21 | */
22 | interface Layer extends Definition, HasLabel, MapObject
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/MapObject.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Interface MapObject describes elements which can be added to a map.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | interface MapObject
21 | {
22 | /**
23 | * Add object to the map.
24 | *
25 | * @param Map $map The map.
26 | *
27 | * @return $this
28 | */
29 | public function addTo(Map $map);
30 | }
31 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/OptionsTrait.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Class OptionsTrait implements the HasOptions interface as a trait.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | trait OptionsTrait
21 | {
22 | /**
23 | * Options of the control.
24 | *
25 | * @var array
26 | */
27 | private $options = array();
28 |
29 | /**
30 | * Get all defined options. It does not contain default values which were not set.
31 | *
32 | * @return array
33 | */
34 | public function getOptions()
35 | {
36 | return $this->options;
37 | }
38 |
39 | /**
40 | * Set options by calling options methods.
41 | *
42 | * If a set method does not exists it ignores the option.
43 | * The setter method should handle the converting from native value to expected value.
44 | *
45 | * @param array $options Options being added.
46 | *
47 | * @return $this
48 | */
49 | public function setOptions(array $options)
50 | {
51 | foreach ($options as $name => $value) {
52 | $method = 'set' . ucfirst($name);
53 |
54 | if (method_exists($this, $method)) {
55 | $this->$method($value);
56 | } else {
57 | $this->options[$name] = $value;
58 | }
59 | }
60 |
61 | return $this;
62 | }
63 |
64 | /**
65 | * Set an option.
66 | *
67 | * @param string $name Name of the option.
68 | * @param mixed $value Value of the option.
69 | *
70 | * @return $this
71 | */
72 | public function setOption($name, $value)
73 | {
74 | $this->options[$name] = $value;
75 |
76 | return $this;
77 | }
78 |
79 | /**
80 | * Get an option.
81 | *
82 | * @param string $name Name of the option.
83 | * @param mixed $default Default value if no option is set.
84 | *
85 | * @return mixed
86 | */
87 | public function getOption($name, $default = null)
88 | {
89 | if (isset($this->options[$name])) {
90 | return $this->options[$name];
91 | }
92 |
93 | return $default;
94 | }
95 |
96 | /**
97 | * Remove an option.
98 | *
99 | * @param string $name Name of the option.
100 | *
101 | * @return $this
102 | */
103 | public function removeOption($name)
104 | {
105 | unset($this->options[$name]);
106 |
107 | return $this;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/PopupTrait.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | use Netzmacht\LeafletPHP\Definition\UI\Popup;
16 |
17 | /**
18 | * Class PopupTrait is an implementation of the HasPopup interface an can be used as trait.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition
21 | */
22 | trait PopupTrait
23 | {
24 | /**
25 | * The bind popup.
26 | *
27 | * @var Popup|string
28 | */
29 | private $popup;
30 |
31 | /**
32 | * Popup content.
33 | *
34 | * @var string
35 | */
36 | private $popupContent;
37 |
38 | /**
39 | * Popup options.
40 | *
41 | * @var array|null
42 | */
43 | private $popupOptions;
44 |
45 | /**
46 | * Set the popup content.
47 | *
48 | * @param string $content The popup content.
49 | *
50 | * @return $this
51 | */
52 | public function setPopupContent($content)
53 | {
54 | $this->popupContent = $content;
55 |
56 | return $this->addMethod('setPopupContent', array($content));
57 | }
58 |
59 | /**
60 | * Get the popup content.
61 | *
62 | * @return string
63 | */
64 | public function getPopupContent()
65 | {
66 | return $this->popupContent;
67 | }
68 |
69 | /**
70 | * Bind marker to a popup.
71 | *
72 | * @param Popup|string $popup The popup.
73 | * @param array|null $options Optional popup options.
74 | *
75 | * @return $this
76 | */
77 | public function bindPopup($popup, $options = null)
78 | {
79 | $this->popup = $popup;
80 | $this->popupOptions = $options;
81 |
82 | if (!empty($options)) {
83 | return $this->addMethod('binPopup', array($popup, $options));
84 | }
85 |
86 | return $this->addMethod('bindPopup', array($popup));
87 | }
88 |
89 | /**
90 | * Get bound popup.
91 | *
92 | * @return Popup|string
93 | */
94 | public function getPopup()
95 | {
96 | return $this->popup;
97 | }
98 |
99 | /**
100 | * Get popup options.
101 | *
102 | * @return array|null
103 | */
104 | public function getPopupOptions()
105 | {
106 | return $this->popupOptions;
107 | }
108 |
109 | /**
110 | * Unbind a popup.
111 | *
112 | * @return $this
113 | */
114 | public function unbindPopup()
115 | {
116 | $this->popup = null;
117 |
118 | return $this->addMethod('unbindPopup');
119 | }
120 |
121 | /**
122 | * Call the isPopupOpen method.
123 | *
124 | * @return $this
125 | */
126 | public function isPopupOpen()
127 | {
128 | return $this->addMethod('isPopupOpen');
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Raster/ImageOverlay.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Raster;
14 |
15 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 | use Netzmacht\LeafletPHP\Value\LatLngBounds;
18 |
19 | /**
20 | * ImageOverlay layer.
21 | *
22 | * @package Netzmacht\LeafletPHP\Definition\Raster
23 | */
24 | class ImageOverlay extends AbstractLayer implements HasOptions
25 | {
26 | /**
27 | * Image url.
28 | *
29 | * @var string
30 | */
31 | private $imageUrl;
32 |
33 | /**
34 | * Image bounds.
35 | *
36 | * @var LatLngBounds
37 | */
38 | private $imageBounds;
39 |
40 | /**
41 | * ImageOverlay constructor.
42 | *
43 | * @param string $identifier Layer identifier.
44 | * @param string $imageUrl Image url.
45 | * @param LatLngBounds $imageBounds Image bounds.
46 | */
47 | public function __construct($identifier, $imageUrl, LatLngBounds $imageBounds = null)
48 | {
49 | parent::__construct($identifier);
50 |
51 | $this->imageUrl = $imageUrl;
52 | $this->imageBounds = $imageBounds;
53 | }
54 |
55 | /**
56 | * {@inheritDoc}
57 | */
58 | public static function getType()
59 | {
60 | return 'ImageOverlay';
61 | }
62 |
63 | /**
64 | * Get imageUrl.
65 | *
66 | * @return string
67 | */
68 | public function getUrl()
69 | {
70 | return $this->imageUrl;
71 | }
72 |
73 | /**
74 | * Set imageUrl.
75 | *
76 | * @param string $imageUrl ImageUrl.
77 | *
78 | * @return $this
79 | */
80 | public function setUrl($imageUrl)
81 | {
82 | $this->imageUrl = $imageUrl;
83 |
84 | return $this;
85 | }
86 |
87 | /**
88 | * Get imageBounds.
89 | *
90 | * @return LatLngBounds
91 | */
92 | public function getBounds()
93 | {
94 | return $this->imageBounds;
95 | }
96 |
97 | /**
98 | * Set imageBounds.
99 | *
100 | * @param LatLngBounds $imageBounds ImageBounds.
101 | *
102 | * @return $this
103 | */
104 | public function setBounds($imageBounds)
105 | {
106 | $this->imageBounds = $imageBounds;
107 |
108 | return $this;
109 | }
110 |
111 | /**
112 | * Set the opacity of the image overlay.
113 | *
114 | * @param float $opacity Image opacity between 0 and 1.
115 | *
116 | * @return $this
117 | * @see http://leafletjs.com/reference.html#imageoverlay-opacity
118 | */
119 | public function setOpacity($opacity)
120 | {
121 | return $this->setOption('opacity', (float) $opacity);
122 | }
123 |
124 | /**
125 | * Get the opacity of the image overlay.
126 | *
127 | * @return float
128 | * @see http://leafletjs.com/reference.html#imageoverlay-opacity
129 | */
130 | public function getOpacity()
131 | {
132 | return $this->getOption('opacity', 1.0);
133 | }
134 |
135 | /**
136 | * Set the attribution of the image overlay.
137 | *
138 | * @param string $attribution The attribution text of the image overlay.
139 | *
140 | * @return $this
141 | * @see http://leafletjs.com/reference.html#imageoverlay-attribution
142 | */
143 | public function setAttribution($attribution)
144 | {
145 | return $this->setOption('attribution', (string) $attribution);
146 | }
147 |
148 | /**
149 | * Get the attribution of the image overlay.
150 | *
151 | * @return string
152 | * @see http://leafletjs.com/reference.html#imageoverlay-attribution
153 | */
154 | public function getAttribution()
155 | {
156 | return $this->getOption('attribution', '');
157 | }
158 |
159 | /**
160 | * Set the alt option.
161 | *
162 | * @param string $alt Alternate text.
163 | *
164 | * @return $this
165 | */
166 | public function setAlt($alt)
167 | {
168 | return $this->setOption('alt', (string) $alt);
169 | }
170 |
171 | /**
172 | * Get the alternate text.
173 | *
174 | * @return string
175 | */
176 | public function getAlt()
177 | {
178 | return $this->getOption('alt', '');
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Type/AbstractIcon.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Type;
14 |
15 | use Netzmacht\LeafletPHP\Definition\AbstractDefinition;
16 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
17 |
18 | /**
19 | * Class AbstractIcon is the base icon implementation.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\Type
22 | */
23 | abstract class AbstractIcon extends AbstractDefinition implements Icon
24 | {
25 | use OptionsTrait;
26 |
27 | /**
28 | * Default class name.
29 | *
30 | * @var string
31 | */
32 | protected static $defaultClassName = '';
33 |
34 | /**
35 | * {@inheritdoc}
36 | */
37 | public function setIconSize($size)
38 | {
39 | return $this->setOption('iconSize', $size);
40 | }
41 |
42 | /**
43 | * {@inheritdoc}
44 | */
45 | public function getIconSize()
46 | {
47 | return $this->getOption('iconSize');
48 | }
49 |
50 | /**
51 | * {@inheritdoc}
52 | */
53 | public function setIconAnchor($point)
54 | {
55 | return $this->setOption('iconAnchor', $point);
56 | }
57 |
58 | /**
59 | * {@inheritdoc}
60 | */
61 | public function getIconAnchor()
62 | {
63 | return $this->getOption('iconAnchor');
64 | }
65 |
66 | /**
67 | * {@inheritdoc}
68 | */
69 | public function setPopupAnchor($point)
70 | {
71 | return $this->setOption('popupAnchor', $point);
72 | }
73 |
74 | /**
75 | * {@inheritdoc}
76 | */
77 | public function getPopupAnchor()
78 | {
79 | return $this->getOption('popupAnchor');
80 | }
81 |
82 | /**
83 | * {@inheritdoc}
84 | */
85 | public function setClassName($className)
86 | {
87 | return $this->setOption('className', $className);
88 | }
89 |
90 | /**
91 | * {@inheritdoc}
92 | */
93 | public function getClassName()
94 | {
95 | return $this->getOption('className', static::$defaultClassName);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Type/DivIcon.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Type;
14 |
15 | /**
16 | * Class DivIcon represents an div based icon.
17 | *
18 | * @see http://leafletjs.com/reference.html#divicon
19 | * @package Netzmacht\LeafletPHP\Definition\Type
20 | */
21 | class DivIcon extends AbstractIcon
22 | {
23 | /**
24 | * Default class name.
25 | *
26 | * @var string
27 | */
28 | protected static $defaultClassName = 'leaflet-div-icon';
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public static function getType()
34 | {
35 | return 'DivIcon';
36 | }
37 |
38 | /**
39 | * Set icon html.
40 | *
41 | * @param string $html The icon html.
42 | *
43 | * @return $this
44 | */
45 | public function setHtml($html)
46 | {
47 | return $this->setOption('html', $html);
48 | }
49 |
50 | /**
51 | * Get icon html.
52 | *
53 | * @return string
54 | */
55 | public function getHtml()
56 | {
57 | return $this->getOption('html', '');
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Type/Icon.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Type;
14 |
15 | use Netzmacht\LeafletPHP\Definition;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 |
18 | /**
19 | * Interface describes Icon objects for Leaflet.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\Type
22 | */
23 | interface Icon extends Definition, HasOptions
24 | {
25 | /**
26 | * The icon size as point.
27 | *
28 | * @param array $size The icon size as point.
29 | *
30 | * @return $this
31 | * @see http://leafletjs.com/reference.html#divicon-iconsize
32 | */
33 | public function setIconSize($size);
34 |
35 | /**
36 | * Get the icon size.
37 | *
38 | * @return array|null
39 | * @see http://leafletjs.com/reference.html#divicon-iconsize
40 | */
41 | public function getIconSize();
42 |
43 | /**
44 | * The coordinates of the "tip" of the icon (relative to its top left corner).
45 | *
46 | * @param array $point The coordinates as point.
47 | *
48 | * @return $this
49 | * @see http://leafletjs.com/reference.html#divicon-iconanchor
50 | */
51 | public function setIconAnchor($point);
52 |
53 | /**
54 | * Get the icon anchor.
55 | *
56 | * @return array|null
57 | * @see http://leafletjs.com/reference.html#divicon-iconanchor
58 | */
59 | public function getIconAnchor();
60 |
61 | /**
62 | * The coordinates of the point from which popups will "open", relative to the icon anchor.
63 | *
64 | * @param array $point The coordinates as point.
65 | *
66 | * @return $this
67 | * @see http://leafletjs.com/reference.html#divicon-popupanchor
68 | */
69 | public function setPopupAnchor($point);
70 |
71 | /**
72 | * Get the icon anchor.
73 | *
74 | * @return array|null
75 | * @see http://leafletjs.com/reference.html#divicon-popupanchor
76 | */
77 | public function getPopupAnchor();
78 |
79 | /**
80 | * Set a custom class name to assign to the icon.
81 | *
82 | * @param string $className The custom class name.
83 | *
84 | * @return $this
85 | * @see http://leafletjs.com/reference.html#divicon-classname
86 | */
87 | public function setClassName($className);
88 |
89 | /**
90 | * Get the class name.
91 | *
92 | * @return string
93 | */
94 | public function getClassName();
95 | }
96 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Type/ImageIcon.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Type;
14 |
15 | /**
16 | * Class Icon describes an leaflet icon.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\Type
19 | */
20 | class ImageIcon extends AbstractIcon
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Icon';
28 | }
29 |
30 | /**
31 | * Construct.
32 | *
33 | * @param string $identifier Icon identifier.
34 | * @param string $iconUrl Icon url.
35 | */
36 | public function __construct($identifier, $iconUrl)
37 | {
38 | parent::__construct($identifier);
39 |
40 | $this->setIconUrl($iconUrl);
41 | }
42 |
43 | /**
44 | * Set the icon url.
45 | *
46 | * @param string $url The icon url.
47 | *
48 | * @return $this
49 | * @see http://leafletjs.com/reference.html#icon-iconurl
50 | */
51 | public function setIconUrl($url)
52 | {
53 | return $this->setOption('iconUrl', $url);
54 | }
55 |
56 | /**
57 | * Get the icon url.
58 | *
59 | * @return string
60 | * @see http://leafletjs.com/reference.html#icon-iconurl
61 | */
62 | public function getIconUrl()
63 | {
64 | return $this->getOption('iconUrl');
65 | }
66 |
67 | /**
68 | * Set the icon retina url.
69 | *
70 | * @param string $url The icon url.
71 | *
72 | * @return $this
73 | * @see http://leafletjs.com/reference.html#icon-iconretinaurl
74 | */
75 | public function setIconRetinaUrl($url)
76 | {
77 | return $this->setOption('iconRetinaUrl', $url);
78 | }
79 |
80 | /**
81 | * Get the icon retina url.
82 | *
83 | * @return string
84 | * @see http://leafletjs.com/reference.html#icon-iconretinaurl
85 | */
86 | public function getIconRetinaUrl()
87 | {
88 | return $this->getOption('iconRetinaUrl');
89 | }
90 |
91 | /**
92 | * Set the shadow url.
93 | *
94 | * @param string $url The shadow url.
95 | *
96 | * @return $this
97 | * @see http://leafletjs.com/reference.html#shadow-shadowurl
98 | */
99 | public function setShadowUrl($url)
100 | {
101 | return $this->setOption('shadowUrl', $url);
102 | }
103 |
104 | /**
105 | * Get the shadow url.
106 | *
107 | * @return string
108 | * @see http://leafletjs.com/reference.html#shadow-shadowurl
109 | */
110 | public function getShadowUrl()
111 | {
112 | return $this->getOption('shadowUrl');
113 | }
114 |
115 | /**
116 | * Set the shadow retina url.
117 | *
118 | * @param string $url The shadow url.
119 | *
120 | * @return $this
121 | * @see http://leafletjs.com/reference.html#shadow-shadowretinaurl
122 | */
123 | public function setShadowRetinaUrl($url)
124 | {
125 | return $this->setOption('shadowRetinaUrl', $url);
126 | }
127 |
128 | /**
129 | * Get the shadow retina url.
130 | *
131 | * @return string
132 | * @see http://leafletjs.com/reference.html#shadow-shadowretinaurl
133 | */
134 | public function getShadowRetinaUrl()
135 | {
136 | return $this->getOption('shadowRetinaUrl');
137 | }
138 |
139 | /**
140 | * The shadow size as point.
141 | *
142 | * @param array $size The shadow size as point.
143 | *
144 | * @return $this
145 | * @see http://leafletjs.com/reference.html#divshadow-shadowsize
146 | */
147 | public function setShadowSize($size)
148 | {
149 | return $this->setOption('shadowSize', $size);
150 | }
151 |
152 | /**
153 | * Get the shadow size.
154 | *
155 | * @return array|null
156 | * @see http://leafletjs.com/reference.html#divshadow-shadowsize
157 | */
158 | public function getShadowSize()
159 | {
160 | return $this->getOption('shadowSize');
161 | }
162 |
163 | /**
164 | * The coordinates of the "tip" of the shadow (relative to its top left corner).
165 | *
166 | * @param array $point The coordinates as point.
167 | *
168 | * @return $this
169 | * @see http://leafletjs.com/reference.html#divshadow-shadowanchor
170 | */
171 | public function setShadowAnchor($point)
172 | {
173 | return $this->setOption('shadowAnchor', $point);
174 | }
175 |
176 | /**
177 | * Get the shadow anchor.
178 | *
179 | * @return array|null
180 | * @see http://leafletjs.com/reference.html#divshadow-shadowanchor
181 | */
182 | public function getShadowAnchor()
183 | {
184 | return $this->getOption('shadowAnchor');
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition;
14 |
15 | /**
16 | * Interface Vector describes basic vector layers.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition
19 | */
20 | interface Vector extends Layer, HasOptions
21 | {
22 | /**
23 | * Get latitude longitude list.
24 | *
25 | * @return array
26 | */
27 | public function getLatLngs();
28 | }
29 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector/Circle.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Vector;
14 |
15 | /**
16 | * Class Circle represents a circle object on the map.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\Vector
19 | */
20 | class Circle extends CircleMarker
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Circle';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector/CircleMarker.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Vector;
14 |
15 | use Netzmacht\LeafletPHP\Value\GeoJson\Geometry;
16 | use Netzmacht\LeafletPHP\Value\LatLng;
17 |
18 | /**
19 | * Class CircleMarker represents a circle marker object.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\Vector
22 | */
23 | class CircleMarker extends Path implements Geometry
24 | {
25 | /**
26 | * {@inheritdoc}
27 | */
28 | public static function getType()
29 | {
30 | return 'CircleMarker';
31 | }
32 |
33 | /**
34 | * The lat lng.
35 | *
36 | * @var LatLng|null
37 | */
38 | private $latLng = null;
39 |
40 | /**
41 | * The radius in meters.
42 | *
43 | * @var int
44 | */
45 | private $radius = 0;
46 |
47 | /**
48 | * Get the lat lang.
49 | *
50 | * @return LatLng|null
51 | */
52 | public function getLatLng()
53 | {
54 | return $this->latLng;
55 | }
56 |
57 | /**
58 | * Set the lat lang position.
59 | *
60 | * @param LatLng $latLng The coordinate.
61 | *
62 | * @return $this
63 | */
64 | public function setLatLng(LatLng $latLng)
65 | {
66 | $this->latLng = $latLng;
67 |
68 | return $this;
69 | }
70 |
71 | /**
72 | * Get the radius.
73 | *
74 | * @return int
75 | */
76 | public function getRadius()
77 | {
78 | return $this->radius;
79 | }
80 |
81 | /**
82 | * Set the radius.
83 | *
84 | * @param int $radius The radius in meters.
85 | *
86 | * @return $this
87 | */
88 | public function setRadius($radius)
89 | {
90 | $this->radius = (int) $radius;
91 |
92 | return $this;
93 | }
94 |
95 | /**
96 | * {@inheritdoc}
97 | */
98 | public function jsonSerialize()
99 | {
100 | return array(
101 | 'type' => 'Point',
102 | 'coordinates' => $this->getLatLng() ? $this->getLatLng()->toGeoJson(): null
103 | );
104 | }
105 |
106 | /**
107 | * {@inheritdoc}
108 | */
109 | public function toGeoJsonFeature()
110 | {
111 | $feature = $this->createFeature();
112 | $feature->setProperty('radius', $this->getRadius());
113 |
114 | return $feature;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector/Path.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Vector;
14 |
15 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
16 | use Netzmacht\LeafletPHP\Value\GeoJson\ConvertsToGeoJsonFeature;
17 | use Netzmacht\LeafletPHP\Value\GeoJson\FeatureTrait;
18 | use Netzmacht\LeafletPHP\Definition\HasEvents;
19 | use Netzmacht\LeafletPHP\Definition\EventsTrait;
20 | use Netzmacht\LeafletPHP\Definition\HasOptions;
21 | use Netzmacht\LeafletPHP\Definition\HasPopup;
22 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
23 | use Netzmacht\LeafletPHP\Definition\PopupTrait;
24 | use Netzmacht\LeafletPHP\Definition\Vector;
25 |
26 | /**
27 | * Abstract class Path for path based elements.
28 | *
29 | * @package Netzmacht\LeafletPHP\Definition\Vector
30 | */
31 | abstract class Path extends AbstractLayer implements HasEvents, HasPopup, ConvertsToGeoJsonFeature
32 | {
33 | use OptionsTrait;
34 | use EventsTrait;
35 | use PathOptionsTrait;
36 | use FeatureTrait;
37 |
38 | /**
39 | * The click event.
40 | *
41 | * @see http://leafletjs.com/reference.html#path-click
42 | */
43 | const EVENT_CLICK = 'click';
44 |
45 | /**
46 | * The dblclick event.
47 | *
48 | * @see http://leafletjs.com/reference.html#path-dblclick
49 | */
50 | const EVENT_DOUBLE_CLICK = 'dblclick';
51 |
52 | /**
53 | * The mousedown event.
54 | *
55 | * @see http://leafletjs.com/reference.html#path-mousedown
56 | */
57 | const EVENT_MOUSE_DOWM = 'mousedown';
58 |
59 | /**
60 | * The mouseover event.
61 | *
62 | * @see http://leafletjs.com/reference.html#path-mouseover
63 | */
64 | const EVENT_MOUSE_OVER = 'mouseover';
65 |
66 | /**
67 | * The mouseout event.
68 | *
69 | * @see http://leafletjs.com/reference.html#path-mouseout
70 | */
71 | const EVENT_MOUSE_OUT = 'mouseout';
72 |
73 | /**
74 | * The contextmenu event.
75 | *
76 | * @see http://leafletjs.com/reference.html#path-contextmenu
77 | */
78 | const EVENT_CONTEXT_MENU = 'contextmenu';
79 |
80 | /**
81 | * The add event.
82 | *
83 | * @see http://leafletjs.com/reference.html#path-add
84 | */
85 | const EVENT_ADD = 'add';
86 |
87 | /**
88 | * The remove event.
89 | *
90 | * @see http://leafletjs.com/reference.html#path-remove
91 | */
92 | const EVENT_REMOVE = 'remove';
93 |
94 | /**
95 | * The popupopen event.
96 | *
97 | * @see http://leafletjs.com/reference.html#path-popupopen
98 | */
99 | const EVENT_POPUP_OPEN = 'popupopen';
100 |
101 | /**
102 | * The popupclose event.
103 | *
104 | * @see http://leafletjs.com/reference.html#path-popupclose
105 | */
106 | const EVENT_POPUP_CLOSE = 'popupclose';
107 |
108 | /**
109 | * Get the type of the definition.
110 | *
111 | * @return string
112 | */
113 | public static function getType()
114 | {
115 | return 'Path';
116 | }
117 |
118 | /**
119 | * Set the fil rule.
120 | *
121 | * @param string $rule Fill rule value. Supported are evenodd and nonzero.
122 | *
123 | * @return $this
124 | */
125 | public function setFillRule($rule)
126 | {
127 | return $this->setOption('fillRule', $rule);
128 | }
129 |
130 | /**
131 | * Get the fill rule.
132 | *
133 | * @return string
134 | */
135 | public function getFillRule()
136 | {
137 | return $this->getOption('fillRule', 'evenodd');
138 | }
139 |
140 | /**
141 | * Bring path to the front.
142 | *
143 | * @return $this
144 | * @see http://leafletjs.com/reference.html#path-bringtofront
145 | */
146 | public function bringToFront()
147 | {
148 | return $this->addMethod('bringToFront');
149 | }
150 |
151 | /**
152 | * Bring path to the back.
153 | *
154 | * @return $this
155 | * @see http://leafletjs.com/reference.html#path-bringtoback
156 | */
157 | public function bringToBack()
158 | {
159 | return $this->addMethod('bringToBack');
160 | }
161 |
162 | /**
163 | * Redraw the path.
164 | *
165 | * @return $this
166 | * @see http://leafletjs.com/reference.html#path-redraw
167 | */
168 | public function redraw()
169 | {
170 | return $this->addMethod('redraw');
171 | }
172 |
173 | /**
174 | * {@inheritdoc}
175 | */
176 | public function convertsFullyToGeoJson()
177 | {
178 | return true;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector/Polygon.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Vector;
14 |
15 | use Netzmacht\LeafletPHP\Value\LatLng;
16 |
17 | /**
18 | * Class Polygon represents a polygon on the map.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition\Vector
21 | */
22 | class Polygon extends Polyline
23 | {
24 | /**
25 | * {@inheritdoc}
26 | */
27 | public static function getType()
28 | {
29 | return 'Polygon';
30 | }
31 |
32 | /**
33 | * {@inheritdoc}
34 | */
35 | public function jsonSerialize()
36 | {
37 | if ($this->isFlat()) {
38 | return array(
39 | 'type' => $this->getGeoJsonType(),
40 | 'coordinates' => array(
41 | array_map(
42 | function (LatLng $latLng) {
43 | return $latLng->toGeoJson();
44 | },
45 | $this->getLatLngs()
46 | )
47 | )
48 | );
49 | }
50 |
51 | return array(
52 | 'type' => $this->getGeoJsonType(),
53 | 'coordinates' => array_map(
54 | function ($latLng) {
55 | return array(
56 | array_map(
57 | function (LatLng $latLng) {
58 | return $latLng->toGeoJson();
59 | },
60 | $latLng
61 | )
62 | );
63 | },
64 | $this->getLatLngs(false)
65 | )
66 | );
67 | }
68 |
69 | /**
70 | * Get the GeoJSON type.
71 | *
72 | * @return string
73 | */
74 | protected function getGeoJsonType()
75 | {
76 | return $this->isFlat() ? 'Polygon' : 'MultiPolygon';
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector/Rectangle.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Vector;
14 |
15 | use Netzmacht\LeafletPHP\Value\GeoJson\Feature;
16 | use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
17 | use Netzmacht\LeafletPHP\Value\GeoJson\FeatureTrait;
18 | use Netzmacht\LeafletPHP\Value\GeoJson\Geometry;
19 | use Netzmacht\LeafletPHP\Value\LatLngBounds;
20 |
21 | /**
22 | * Class Rectangle describes an rectangle on the map.
23 | *
24 | * @package Netzmacht\LeafletPHP\Definition\Vector
25 | */
26 | class Rectangle extends Polyline implements Geometry
27 | {
28 | use FeatureTrait;
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public static function getType()
34 | {
35 | return 'Rectangle';
36 | }
37 |
38 | /**
39 | * LatLng bounds which defines the rectangle.
40 | *
41 | * @var \Netzmacht\LeafletPHP\Value\LatLngBounds
42 | */
43 | private $bounds;
44 |
45 | /**
46 | * Construct.
47 | *
48 | * @param string $identifier The identifier.
49 | * @param LatLngBounds $latLngBounds The bounds which defines the rectangle.
50 | */
51 | public function __construct($identifier, LatLngBounds $latLngBounds)
52 | {
53 | parent::__construct($identifier);
54 |
55 | $this->bounds = $latLngBounds;
56 | }
57 |
58 | /**
59 | * {@inheritdoc}
60 | */
61 | public function getLatLngs($preferFlat = true)
62 | {
63 | return array(
64 | $this->bounds->getSouthWest(),
65 | $this->bounds->getNorthEast()
66 | );
67 | }
68 |
69 | /**
70 | * Get the bounds.
71 | *
72 | * @return LatLngBounds
73 | */
74 | public function getBounds()
75 | {
76 | return $this->bounds;
77 | }
78 |
79 | /**
80 | * Get definition as feature collection.
81 | *
82 | * @return Feature|FeatureCollection
83 | */
84 | public function jsonSerialize()
85 | {
86 | $bounds = $this->getBounds();
87 |
88 | // No rectangle support of geojson, so create a polygon
89 | return array(
90 | 'type' => 'Polygon',
91 | 'coordinates' => array(
92 | array(
93 | $bounds->getNorthEast()->toGeoJson(),
94 | $bounds->getNorthWest()->toGeoJson(),
95 | $bounds->getSouthWest()->toGeoJson(),
96 | $bounds->getSouthEast()->toGeoJson()
97 | )
98 | )
99 | );
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Definition/Vector/Renderer.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Definition\Vector;
14 |
15 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 |
18 | /**
19 | * Renderer class.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\Vector
22 | */
23 | class Renderer extends AbstractLayer implements HasOptions
24 | {
25 | /**
26 | * {@inheritDoc}
27 | */
28 | public static function getType()
29 | {
30 | return 'Renderer';
31 | }
32 |
33 | /**
34 | * Set padding.
35 | *
36 | * @param float $padding Padding.
37 | *
38 | * @return $this
39 | */
40 | public function setPadding($padding)
41 | {
42 | return $this->setOption('padding', (float) $padding);
43 | }
44 |
45 | /**
46 | * Get padding.
47 | *
48 | * @return float
49 | */
50 | public function getPadding()
51 | {
52 | return $this->getOption('padding', 0.1);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/AbstractEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Flags;
17 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeValueEvent;
18 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
19 | use Netzmacht\LeafletPHP\Definition;
20 | use Symfony\Component\EventDispatcher\EventSubscriberInterface;
21 |
22 | /**
23 | * Class AbstractEncoder delegates the encoding events to the encoder implementation.
24 | *
25 | * Add a encode method to the encoder to encode the definition.
26 | *
27 | * @package Netzmacht\LeafletPHP\Encoder
28 | */
29 | abstract class AbstractEncoder implements EventSubscriberInterface
30 | {
31 | /**
32 | * Encoded method reference.
33 | *
34 | * Used to ensure that methods are only encoded once.
35 | *
36 | * @var array
37 | */
38 | protected static $encodedMethods = array();
39 |
40 | /**
41 | * {@inheritdoc}
42 | */
43 | public static function getSubscribedEvents()
44 | {
45 | return array(
46 | EncodeValueEvent::NAME => array(
47 | array('handleEncode', 100),
48 | ),
49 | EncodeReferenceEvent::NAME => array(
50 | 'handleGetReference'
51 | ),
52 | );
53 | }
54 |
55 | /**
56 | * Handle compile event.
57 | *
58 | * @param EncodeValueEvent $event The subscribed event.
59 | *
60 | * @return void
61 | */
62 | public function handleEncode(EncodeValueEvent $event)
63 | {
64 | $definition = $event->getValue();
65 | if (!$definition instanceof Definition) {
66 | return;
67 | }
68 |
69 | $type = $definition->getType();
70 | $method = 'encode' . $this->convertTypeToMethod($type);
71 |
72 | if (method_exists($this, $method)) {
73 | $buffer = $this->$method($definition, $event->getEncoder(), $event->getJsonFlags());
74 |
75 | if ($buffer) {
76 | $event->addLine($buffer);
77 | $this->handleMethodCalls($definition, $event->getEncoder(), $event);
78 | }
79 |
80 | $event->setSuccessful();
81 | }
82 | }
83 |
84 | /**
85 | * Handle get reference event.
86 | *
87 | * @param EncodeReferenceEvent $event The event.
88 | *
89 | * @return void
90 | */
91 | public function handleGetReference(EncodeReferenceEvent $event)
92 | {
93 | $definition = $event->getObject();
94 |
95 | if ($definition instanceof Definition) {
96 | $this->setReference($definition, $event);
97 | }
98 | }
99 |
100 | /**
101 | * Convert definition type to method name.
102 | *
103 | * @param string $type The type as string.
104 | *
105 | * @return string
106 | */
107 | private function convertTypeToMethod($type)
108 | {
109 | $parts = explode('.', str_replace(['-', '_'], '.', $type));
110 | $parts = array_map('ucfirst', $parts);
111 |
112 | return implode('', $parts);
113 | }
114 |
115 | /**
116 | * Set the reference reference.
117 | *
118 | * @param Definition $definition The current definition.
119 | * @param EncodeReferenceEvent $event The get reference event.
120 | *
121 | * @return string
122 | */
123 | abstract public function setReference(Definition $definition, EncodeReferenceEvent $event);
124 |
125 | /**
126 | * Encode method calls.
127 | *
128 | * @param Definition $definition The current definition.
129 | * @param Encoder $encoder The encoder.
130 | * @param EncodeValueEvent $event The event.
131 | *
132 | * @return void
133 | */
134 | private function handleMethodCalls(Definition $definition, Encoder $encoder, EncodeValueEvent $event)
135 | {
136 | $hash = spl_object_hash($definition);
137 |
138 | if (!isset(static::$encodedMethods[$hash])) {
139 | static::$encodedMethods[$hash] = true;
140 |
141 | foreach ($definition->getMethodCalls() as $method) {
142 | $event->addLine($method->encode($encoder, Flags::CLOSE_STATEMENT));
143 | }
144 | }
145 | }
146 |
147 | /**
148 | * Get references of given values.
149 | *
150 | * @param array $values Set of values.
151 | * @param Encoder $encoder The encoder.
152 | *
153 | * @return array
154 | */
155 | protected function getReferences(array $values, Encoder $encoder)
156 | {
157 | return array_map(
158 | function ($value) use ($encoder) {
159 | return $encoder->encodeReference($value);
160 | },
161 | $values
162 | );
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/ControlEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Netzmacht\LeafletPHP\Definition\Control;
19 | use Netzmacht\LeafletPHP\Definition\Control\Attribution;
20 | use Netzmacht\LeafletPHP\Definition\Control\Layers;
21 | use Netzmacht\LeafletPHP\Definition\Control\Scale;
22 | use Netzmacht\LeafletPHP\Definition\Control\Zoom;
23 | use Netzmacht\LeafletPHP\Definition\Layer;
24 |
25 | /**
26 | * Class ControlEncoder encodes control elements.
27 | *
28 | * @package Netzmacht\LeafletPHP\Encoder
29 | */
30 | class ControlEncoder extends AbstractEncoder
31 | {
32 | /**
33 | * Compile scale object.
34 | *
35 | * @param Scale $scale The scale control.
36 | * @param Encoder $encoder The encoder.
37 | *
38 | * @return bool
39 | */
40 | public function encodeControlScale(Scale $scale, Encoder $encoder)
41 | {
42 | return $this->doControlEncode('scale', $scale, $encoder);
43 | }
44 |
45 | /**
46 | * Compile the zoom object.
47 | *
48 | * @param Zoom $zoom The zoom control.
49 | * @param Encoder $encoder The encoder.
50 | *
51 | * @return bool
52 | */
53 | public function encodeControlZoom(Zoom $zoom, Encoder $encoder)
54 | {
55 | return $this->doControlEncode('zoom', $zoom, $encoder);
56 | }
57 |
58 | /**
59 | * Compile attributions.
60 | *
61 | * @param Attribution $attribution The attributions.
62 | * @param Encoder $encoder The encoder.
63 | *
64 | * @return bool
65 | */
66 | public function encodeControlAttribution(Attribution $attribution, Encoder $encoder)
67 | {
68 | $result = $this->doControlEncode('attribution', $attribution, $encoder);
69 |
70 | foreach ($attribution->getAttributions() as $value) {
71 | $result .= sprintf(
72 | '%s.addAttribution(\'%s\');' . "\n",
73 | $encoder->encodeReference($attribution),
74 | $value
75 | );
76 | }
77 |
78 | return $result;
79 | }
80 |
81 | /**
82 | * Compile layer control.
83 | *
84 | * @param Layers $layers The layers control.
85 | * @param Encoder $encoder The encoder.
86 | *
87 | * @return bool
88 | */
89 | public function encodeControlLayers(Layers $layers, Encoder $encoder)
90 | {
91 | return sprintf(
92 | '%s = L.control.layers(%s, %s, %s);',
93 | $encoder->encodeReference($layers),
94 | $this->encodeLayersInformation($layers->getBaseLayers(), $encoder),
95 | $this->encodeLayersInformation($layers->getOverlays(), $encoder),
96 | $encoder->encodeValue($layers->getOptions())
97 | );
98 | }
99 |
100 | /**
101 | * {@inheritdoc}
102 | */
103 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
104 | {
105 | if ($definition instanceof Control) {
106 | $event->setReference('controls.' . $definition->getId());
107 | }
108 | }
109 |
110 | /**
111 | * Compile a control.
112 | *
113 | * @param string $type The control type.
114 | * @param Control $control The control definition.
115 | * @param Encoder $encoder The encoder.
116 | *
117 | * @return string
118 | */
119 | private function doControlEncode($type, Control $control, Encoder $encoder)
120 | {
121 | return sprintf(
122 | '%s = L.control.%s(%s);',
123 | $encoder->encodeReference($control),
124 | $type,
125 | $encoder->encodeArguments(array($control->getOptions()))
126 | );
127 | }
128 |
129 | /**
130 | * Get layer information, so that label is used.
131 | *
132 | * @param Layer[] $layers The layers.
133 | * @param Encoder $encoder The encoder.
134 | *
135 | * @return array
136 | */
137 | private function encodeLayersInformation($layers, Encoder $encoder)
138 | {
139 | $prepared = '';
140 |
141 | foreach ($layers as $layer) {
142 | if ($prepared) {
143 | $prepared .= ', ';
144 | }
145 |
146 | $prepared .= sprintf(
147 | '%s: %s',
148 | $encoder->encodeValue($layer->getLabel()),
149 | $encoder->encodeReference($layer)
150 | );
151 | }
152 |
153 | return '{' . $prepared . '}';
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/EncodeHelperTrait.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\Call\MethodCall;
17 | use Netzmacht\JavascriptBuilder\Flags;
18 | use Netzmacht\LeafletPHP\Definition\Control\AbstractControl;
19 |
20 | /**
21 | * Class EncoderHelperTrait provides helper to encode an definition.
22 | *
23 | * @package Netzmacht\LeafletPHP\Encoder
24 | */
25 | trait EncodeHelperTrait
26 | {
27 | /**
28 | * Encode method calls.
29 | *
30 | * @param MethodCall[] $methodCalls Method calls.
31 | * @param Encoder $encoder Javascript encoder.
32 | * @param null $flags Encoder flags.
33 | *
34 | * @return string
35 | */
36 | protected function encodeMethodCalls($methodCalls, Encoder $encoder, $flags = null)
37 | {
38 | $buffer = '';
39 | $flags = Flags::add(Flags::CLOSE_STATEMENT, $flags);
40 |
41 | foreach ($methodCalls as $call) {
42 | $buffer .= "\n" . $call->encode($encoder, $flags);
43 | }
44 |
45 | return $buffer;
46 | }
47 |
48 | /**
49 | * Encode an control.
50 | *
51 | * @param string $name Control name.
52 | * @param AbstractControl $control The control object.
53 | * @param Encoder $encoder Javascript encoder.
54 | * @param null $flags Encoder flags.
55 | *
56 | * @return string
57 | */
58 | protected function encodeSimpleControl($name, AbstractControl $control, Encoder $encoder, $flags = null)
59 | {
60 | $buffer = sprintf(
61 | '%s = L.%s(%s)%s',
62 | $encoder->encodeReference($control),
63 | $name,
64 | $encoder->encodeValue($control->getOptions()),
65 | $encoder->close($flags)
66 | );
67 |
68 | $buffer .= $this->encodeMethodCalls($control->getMethodCalls(), $encoder, $flags);
69 |
70 | return $buffer;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/GroupEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Netzmacht\LeafletPHP\Value\GeoJson\ConvertsToGeoJsonFeature;
19 | use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
20 | use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
21 | use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
22 | use Netzmacht\LeafletPHP\Definition\Layer;
23 | use Netzmacht\LeafletPHP\Plugins\Omnivore\OmnivoreLayer;
24 |
25 | /**
26 | * Class GroupEncoder encodes group elements.
27 | *
28 | * @package Netzmacht\LeafletPHP\Encoder
29 | */
30 | class GroupEncoder extends AbstractEncoder
31 | {
32 | /**
33 | * {@inheritdoc}
34 | */
35 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
36 | {
37 | if ($definition instanceof LayerGroup) {
38 | $event->setReference('layers.' . $definition->getId());
39 | }
40 | }
41 |
42 | /**
43 | * Compile the layer group.
44 | *
45 | * @param LayerGroup $layerGroup The layer group.
46 | * @param Encoder $builder The builder.
47 | *
48 | * @return bool
49 | */
50 | public function encodeLayerGroup(LayerGroup $layerGroup, Encoder $builder)
51 | {
52 | return $this->doGroupEncode('layerGroup', $layerGroup, $builder);
53 | }
54 |
55 | /**
56 | * Encode a feature group.
57 | *
58 | * @param FeatureGroup $featureGroup The layer group.
59 | * @param Encoder $encoder The builder.
60 | *
61 | * @return bool
62 | */
63 | public function encodeFeatureGroup(FeatureGroup $featureGroup, Encoder $encoder)
64 | {
65 | return $this->doGroupEncode('featureGroup', $featureGroup, $encoder);
66 | }
67 |
68 | /**
69 | * Encode a feature group.
70 | *
71 | * @param GeoJson $geoJson The layer group.
72 | * @param Encoder $encoder The builder.
73 | *
74 | * @return bool
75 | */
76 | public function encodeGeoJson(GeoJson $geoJson, Encoder $encoder)
77 | {
78 | $buffer = sprintf(
79 | '%s = L.geoJson(%s, %s);',
80 | $encoder->encodeReference($geoJson),
81 | $encoder->encodeValue($geoJson->getInitializationData()),
82 | $encoder->encodeValue($geoJson->getOptions())
83 | );
84 |
85 | foreach ($geoJson->getLayers() as $layer) {
86 | $buffer .= "\n" . sprintf(
87 | '%s.addLayer(%s);',
88 | $encoder->encodeReference($geoJson),
89 | $encoder->encodeReference($layer)
90 | );
91 | }
92 |
93 | return $buffer;
94 | }
95 |
96 | /**
97 | * Encode the group.
98 | *
99 | * @param string $type The group type.
100 | * @param LayerGroup $group The group instance.
101 | * @param Encoder $encoder The encoder.
102 | *
103 | * @return string
104 | */
105 | private function doGroupEncode($type, LayerGroup $group, Encoder $encoder)
106 | {
107 | return sprintf(
108 | '%s = L.%s(%s);',
109 | $encoder->encodeReference($group),
110 | $type,
111 | $this->encodeLayersInformation($group->getLayers(), $encoder)
112 | );
113 | }
114 |
115 | /**
116 | * Get layer information correctly encoded.
117 | *
118 | * @param Layer[] $layers The layers.
119 | * @param Encoder $encoder The encoder.
120 | *
121 | * @return array
122 | */
123 | private function encodeLayersInformation($layers, Encoder $encoder)
124 | {
125 | $layers = array_map(
126 | function ($layer) use ($encoder) {
127 | return $encoder->encodeReference($layer);
128 | },
129 | $layers
130 | );
131 |
132 | return '[' . implode(', ', $layers) . ']';
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/MapEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\JavascriptBuilder\Symfony\Event\GetObjectStackEvent;
18 | use Netzmacht\LeafletPHP\Definition;
19 | use Netzmacht\LeafletPHP\Definition\Control\Layers;
20 | use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
21 | use Netzmacht\LeafletPHP\Definition\Map;
22 |
23 | /**
24 | * Class MapEncoder encodes the map.
25 | *
26 | * @package Netzmacht\LeafletPHP\Encoder
27 | */
28 | class MapEncoder extends AbstractEncoder
29 | {
30 | use EncodeHelperTrait;
31 |
32 | /**
33 | * Store initialized maps.
34 | *
35 | * @var array
36 | */
37 | private $initialized = array();
38 |
39 | /**
40 | * {@inheritdoc}
41 | */
42 | public static function getSubscribedEvents()
43 | {
44 | $events = parent::getSubscribedEvents();
45 |
46 | $events[GetObjectStackEvent::NAME] = 'getStack';
47 |
48 | return $events;
49 | }
50 |
51 | /**
52 | * Get object stack of the map as far as possible.
53 | *
54 | * @param GetObjectStackEvent $event The subscribed event.
55 | *
56 | * @return void
57 | */
58 | public function getStack(GetObjectStackEvent $event)
59 | {
60 | $stack = array();
61 | $value = $event->getValue();
62 |
63 | if ($value instanceof Map) {
64 | foreach ($value->getControls() as $control) {
65 | if ($control instanceof Layers) {
66 | $this->addLayersToStack($control->getBaseLayers(), $stack);
67 | $this->addLayersToStack($control->getOverlays(), $stack);
68 | }
69 |
70 | $stack[] = $control;
71 | }
72 |
73 | $this->addLayersToStack($value->getLayers(), $stack);
74 |
75 | $event->setStack($stack);
76 | }
77 | }
78 |
79 | /**
80 | * Compile a map.
81 | *
82 | * @param Map $map The map.
83 | * @param Encoder $encoder The builder.
84 | *
85 | * @return void
86 | */
87 | public function encodeMap(Map $map, Encoder $encoder)
88 | {
89 | $output = $encoder->getOutput();
90 | $hash = spl_object_hash($map);
91 |
92 | if (!isset($this->initialized[$hash])) {
93 | $output->prepend(
94 | sprintf(
95 | '%s = L.map(%s);',
96 | $encoder->encodeReference($map),
97 | $encoder->encodeArguments(array($map->getElementId(), $map->getOptions()))
98 | )
99 | );
100 |
101 | $this->initialized[$hash] = true;
102 | } else {
103 | foreach ($map->getControls() as $control) {
104 | $encoder->encodeReference($control);
105 | }
106 |
107 | foreach ($map->getLayers() as $layer) {
108 | $encoder->encodeReference($layer);
109 | }
110 |
111 | $output->append($this->encodeMethodCalls($map->getMethodCalls(), $encoder));
112 | }
113 | }
114 |
115 | /**
116 | * {@inheritdoc}
117 | */
118 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
119 | {
120 | if ($definition instanceof Map) {
121 | $event->setReference('map');
122 | }
123 | }
124 |
125 | /**
126 | * Add layers to to the stack.
127 | *
128 | * @param array $layers The layers to be added.
129 | * @param array $stack The object stack being built.
130 | *
131 | * @return void
132 | */
133 | private function addLayersToStack($layers, &$stack)
134 | {
135 | foreach ($layers as $layer) {
136 | if ($layer instanceof LayerGroup) {
137 | $this->addLayersToStack($layer->getLayers(), $stack);
138 | }
139 |
140 | $stack[] = $layer;
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/RasterEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Netzmacht\LeafletPHP\Definition\Layer;
19 | use Netzmacht\LeafletPHP\Definition\Raster\TileLayer;
20 |
21 | /**
22 | * Class RasterEncoder encodes raster layers.
23 | *
24 | * @package Netzmacht\LeafletPHP\Encoder
25 | */
26 | class RasterEncoder extends AbstractEncoder
27 | {
28 | /**
29 | * {@inheritdoc}
30 | */
31 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
32 | {
33 | if ($definition instanceof Layer) {
34 | $event->setReference('layers.' . $definition->getId());
35 | }
36 | }
37 |
38 | /**
39 | * Encode a tile layer.
40 | *
41 | * @param TileLayer $layer The layer.
42 | * @param Encoder $builder The builder.
43 | *
44 | * @return bool
45 | */
46 | public function encodeTileLayer(TileLayer $layer, Encoder $builder)
47 | {
48 | return sprintf(
49 | '%s = L.tileLayer(%s);',
50 | $builder->encodeReference($layer),
51 | $builder->encodeArguments(array($layer->getUrl(), $layer->getOptions()))
52 | );
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/TypeEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Netzmacht\LeafletPHP\Definition\Type\AbstractIcon;
19 | use Netzmacht\LeafletPHP\Definition\Type\DivIcon;
20 | use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
21 | use Netzmacht\LeafletPHP\Plugins\ExtraMarkers\ExtraMarkersIcon;
22 |
23 | /**
24 | * Class TypeEncoder encodes type definitions.
25 | *
26 | * @package Netzmacht\LeafletPHP\Encoder
27 | */
28 | class TypeEncoder extends AbstractEncoder
29 | {
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
34 | {
35 | if ($definition instanceof AbstractIcon) {
36 | $event->setReference('icons.' . $definition->getId());
37 | }
38 | }
39 |
40 | /**
41 | * Encode the icon.
42 | *
43 | * @param ImageIcon $icon The icon.
44 | * @param Encoder $encoder The encoder.
45 | *
46 | * @return string
47 | */
48 | public function encodeIcon(ImageIcon $icon, Encoder $encoder)
49 | {
50 | return sprintf(
51 | '%s = L.icon(%s);',
52 | $encoder->encodeReference($icon),
53 | $encoder->encodeArguments(array($icon->getOptions()))
54 | );
55 | }
56 |
57 | /**
58 | * Encode the div icon.
59 | *
60 | * @param DivIcon $icon The div icon.
61 | * @param Encoder $encoder The encoder.
62 | *
63 | * @return string
64 | */
65 | public function encodeDivIcon(DivIcon $icon, Encoder $encoder)
66 | {
67 | return sprintf(
68 | '%s = L.divIcon(%s);',
69 | $encoder->encodeReference($icon),
70 | $encoder->encodeArguments(array($icon->getOptions()))
71 | );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/UIEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Netzmacht\LeafletPHP\Definition\UI\Marker;
19 | use Netzmacht\LeafletPHP\Definition\UI\Popup;
20 |
21 | /**
22 | * Class UIEncoder encodes ui elements.
23 | *
24 | * @package Netzmacht\LeafletPHP\Encoder
25 | */
26 | class UIEncoder extends AbstractEncoder
27 | {
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
34 | {
35 | if ($definition instanceof Marker) {
36 | $event->setReference('layers.' . $definition->getId());
37 | }
38 | }
39 |
40 | /**
41 | * Encode a marker.
42 | *
43 | * @param Marker $marker The marker.
44 | * @param Encoder $encoder The encoder.
45 | *
46 | * @return bool
47 | */
48 | public function encodeMarker(Marker $marker, Encoder $encoder)
49 | {
50 | return sprintf(
51 | '%s = L.marker(%s);',
52 | $encoder->encodeReference($marker),
53 | $encoder->encodeArguments(
54 | array(
55 | $marker->getLatLng(),
56 | $marker->getOptions()
57 | )
58 | )
59 | );
60 | }
61 |
62 | /**
63 | * Encode a marker.
64 | *
65 | * @param Popup $popup The popup.
66 | * @param Encoder $encoder The encoder.
67 | *
68 | * @return bool
69 | */
70 | public function encodePopup(Popup $popup, Encoder $encoder)
71 | {
72 | $source = $popup->getSource();
73 | $buffer = sprintf(
74 | '%s = L.popup(%s%s);',
75 | $encoder->encodeReference($popup),
76 | $encoder->encodeArray($popup->getOptions()),
77 | $source ? (', ' . $encoder->encodeReference($source)) : ''
78 | );
79 |
80 | $buffer .= $this->encodeMethodCalls($popup->getMethodCalls(), $encoder);
81 |
82 | return $buffer;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Encoder/VectorEncoder.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Encoder;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Symfony\Event\EncodeReferenceEvent;
17 | use Netzmacht\LeafletPHP\Definition;
18 | use Netzmacht\LeafletPHP\Definition\Layer;
19 | use Netzmacht\LeafletPHP\Definition\Vector;
20 | use Netzmacht\LeafletPHP\Definition\Vector\Circle;
21 | use Netzmacht\LeafletPHP\Definition\Vector\CircleMarker;
22 | use Netzmacht\LeafletPHP\Definition\Vector\Polygon;
23 | use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
24 | use Netzmacht\LeafletPHP\Definition\Vector\Rectangle;
25 |
26 | /**
27 | * Class VectorEncoder encodes the vector elements.
28 | *
29 | * @package Netzmacht\LeafletPHP\Encoder
30 | */
31 | class VectorEncoder extends AbstractEncoder
32 | {
33 | /**
34 | * {@inheritdoc}
35 | */
36 | public function setReference(Definition $definition, EncodeReferenceEvent $event)
37 | {
38 | if ($definition instanceof Vector) {
39 | $event->setReference('layers.vector_' . $definition->getId());
40 | }
41 | }
42 |
43 | /**
44 | * Compile a polyline.
45 | *
46 | * @param Polyline $polyline The polyline.
47 | * @param Encoder $builder The builder.
48 | *
49 | * @return string
50 | */
51 | public function encodePolyline(Polyline $polyline, Encoder $builder)
52 | {
53 | return $this->doVectorEncode('polyline', $polyline, $builder);
54 | }
55 |
56 | /**
57 | * Compile a polygon.
58 | *
59 | * @param Polygon $polygon The polygon.
60 | * @param Encoder $builder The builder.
61 | *
62 | * @return string
63 | */
64 | public function encodePolygon(Polygon $polygon, Encoder $builder)
65 | {
66 | return $this->doVectorEncode('polygon', $polygon, $builder);
67 | }
68 |
69 | /**
70 | * Compile a rectangle.
71 | *
72 | * @param Rectangle $rectangle The rectangle.
73 | * @param Encoder $builder The builder.
74 | *
75 | * @return string
76 | */
77 | public function encodeRectangle(Rectangle $rectangle, Encoder $builder)
78 | {
79 | return $this->doVectorEncode('rectangle', $rectangle, $builder);
80 | }
81 |
82 | /**
83 | * Compile a circle.
84 | *
85 | * @param Circle $circle The circle.
86 | * @param Encoder $builder The builder.
87 | *
88 | * @return string
89 | */
90 | public function encodeCircle(Circle $circle, Encoder $builder)
91 | {
92 | return $this->doCircleEncode('circle', $circle, $builder);
93 | }
94 |
95 | /**
96 | * Compile a circle marker.
97 | *
98 | * @param CircleMarker $circle The circle marker.
99 | * @param Encoder $builder The builder.
100 | *
101 | * @return string
102 | */
103 | public function encodeCircleMarker(CircleMarker $circle, Encoder $builder)
104 | {
105 | return $this->doCircleEncode('circleMarker', $circle, $builder);
106 | }
107 |
108 | /**
109 | * Encode a vector.
110 | *
111 | * @param string $type The type name.
112 | * @param Vector $vector The vector.
113 | * @param Encoder $builder The builder.
114 | *
115 | * @return string
116 | */
117 | private function doVectorEncode($type, Vector $vector, Encoder $builder)
118 | {
119 | return sprintf(
120 | '%s = L.%s(%s, %s);',
121 | $builder->encodeReference($vector),
122 | $type,
123 | $builder->encodeArray($vector->getLatLngs()),
124 | $builder->encodeValue($vector->getOptions())
125 | );
126 | }
127 |
128 | /**
129 | * Encode a circle.
130 | *
131 | * @param string $type The circle type.
132 | * @param CircleMarker $circle The circle object.
133 | * @param Encoder $builder The builder.
134 | *
135 | * @return array
136 | */
137 | private function doCircleEncode($type, CircleMarker $circle, Encoder $builder)
138 | {
139 | return sprintf(
140 | '%s = L.%s(%s);',
141 | $builder->encodeReference($circle),
142 | $type,
143 | $builder->encodeArguments(array($circle->getLatLng(), $circle, $circle->getOptions()))
144 | );
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Leaflet.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP;
14 |
15 | use Netzmacht\JavascriptBuilder\Builder;
16 | use Netzmacht\JavascriptBuilder\Encoder;
17 | use Netzmacht\LeafletPHP\Assets\Collector;
18 | use Netzmacht\LeafletPHP\Definition\Map;
19 | use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcherInter;
20 |
21 | /**
22 | * Class Leaflet provides a simple interface for building javascript from a map.
23 | *
24 | * @package Netzmacht\LeafletPHP
25 | */
26 | class Leaflet
27 | {
28 | /**
29 | * The javascript builder.
30 | *
31 | * @var Builder
32 | */
33 | private $javascriptBuilder;
34 |
35 | /**
36 | * Libraries stylesheets.
37 | *
38 | * @var array
39 | */
40 | private $stylesheets = array();
41 |
42 | /**
43 | * Libraries javascripts.
44 | *
45 | * @var array
46 | */
47 | private $javascripts = array();
48 |
49 | /**
50 | * Flags for built in json_encode.
51 | *
52 | * @var null
53 | */
54 | private $jsonEncodeFlags;
55 |
56 | /**
57 | * The event dispatcher used by the javascript builder.
58 | *
59 | * @var EventDispatcherInter The event dispatcher
60 | */
61 | private $eventDispatcher;
62 |
63 | /**
64 | * Construct.
65 | *
66 | * @param Builder $javascriptBuilder The javascript builder.
67 | * @param EventDispatcherInter $eventDispatcher The event dispatcher.
68 | * @param array $libraries Registered libraries.
69 | * @param null $jsonEncodeFlags Flags for built in json_encode.
70 | */
71 | public function __construct(
72 | Builder $javascriptBuilder,
73 | EventDispatcherInter $eventDispatcher,
74 | array $libraries = array(),
75 | $jsonEncodeFlags = null
76 | ) {
77 | $this->javascriptBuilder = $javascriptBuilder;
78 | $this->stylesheets = $libraries;
79 | $this->jsonEncodeFlags = $jsonEncodeFlags;
80 | $this->eventDispatcher = $eventDispatcher;
81 | }
82 |
83 | /**
84 | * Register a stylesheet for the library.
85 | *
86 | * @param string $name Library name.
87 | * @param string $source The stylesheet source.
88 | * @param string $type Resource type.
89 | *
90 | * @return $this
91 | */
92 | public function registerStylesheet($name, $source, $type = Assets::TYPE_FILE)
93 | {
94 | $this->stylesheets[$name][] = array($source, $type);
95 |
96 | return $this;
97 | }
98 |
99 | /**
100 | * Register a javascript for the library.
101 | *
102 | * @param string $name Library name.
103 | * @param string $source The javascript source.
104 | * @param string $type Resource type.
105 | *
106 | * @return $this
107 | */
108 | public function registerJavascript($name, $source, $type = Assets::TYPE_FILE)
109 | {
110 | $this->javascripts[$name][] = array($source, $type);
111 |
112 | return $this;
113 | }
114 |
115 | /**
116 | * Get all registered stylesheets.
117 | *
118 | * @return array
119 | */
120 | public function getStylesheets()
121 | {
122 | return $this->stylesheets;
123 | }
124 |
125 | /**
126 | * Get all registered javscripts.
127 | *
128 | * @return array
129 | */
130 | public function getJavascripts()
131 | {
132 | return $this->javascripts;
133 | }
134 |
135 | /**
136 | * Get the javascript encoder.
137 | *
138 | * @return Encoder
139 | */
140 | public function getJavascriptBuilder()
141 | {
142 | return $this->javascriptBuilder;
143 | }
144 |
145 | /**
146 | * Build map as a javascript resource.
147 | *
148 | * It always return the generated map no matter if an assets object is given or not. If you want to get the
149 | * combined generated assets, just use $assets->getHtml().
150 | *
151 | * @param Map $map The map being created.
152 | * @param Assets $assets Optional pass an assets instance which collects all required assets.
153 | *
154 | * @return string
155 | */
156 | public function build(Map $map, Assets $assets = null)
157 | {
158 | $prefix = 'var map, layers = {}, controls = {}, icons = {};' . "\n";
159 |
160 | if (!$assets) {
161 | return $prefix . $this->javascriptBuilder->encode($map, $this->jsonEncodeFlags);
162 | }
163 |
164 | $collector = new Collector($assets, $this->javascripts, $this->stylesheets);
165 | $this->eventDispatcher->addSubscriber($collector);
166 |
167 | $assets->setMap($prefix . $this->javascriptBuilder->encode($map, $this->jsonEncodeFlags));
168 |
169 | $this->eventDispatcher->removeSubscriber($collector);
170 |
171 | return $assets->getMap();
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Ajax/GeoJsonAjax.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Ajax;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
17 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
18 | use Netzmacht\JavascriptBuilder\Type\Expression;
19 | use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
20 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
21 | use Netzmacht\LeafletPHP\Definition\Vector\PathOptionsTrait;
22 |
23 | /**
24 | * Class GeoJsonAjax represents the Leaflet ajax pluging for geojson data.
25 | *
26 | * @package Netzmacht\LeafletPHP\Plugins\Ajax
27 | * @see https://github.com/calvinmetcalf/leaflet-ajax
28 | */
29 | class GeoJsonAjax extends FeatureGroup implements ConvertsToJavascript
30 | {
31 | use OptionsTrait;
32 | use PathOptionsTrait;
33 |
34 | const EVENT_DATA_LOADING = 'data:loading';
35 |
36 | const EVENT_DATA_PROGRESS = 'data:progress';
37 |
38 | const EVENT_DATA_LOADED = 'data:loaded';
39 |
40 | /**
41 | * {@inheritdoc}
42 | */
43 | public static function getType()
44 | {
45 | return 'Ajax';
46 | }
47 |
48 | /**
49 | * {@inheritdoc}
50 | */
51 | public static function getRequiredLibraries()
52 | {
53 | $libs = parent::getRequiredLibraries();
54 | $libs[] = 'leaflet-ajax';
55 |
56 | return $libs;
57 | }
58 |
59 | /**
60 | * Url to load.
61 | *
62 | * @var string
63 | */
64 | private $url;
65 |
66 | /**
67 | * Urls to load.
68 | *
69 | * @var array
70 | */
71 | private $urls = array();
72 |
73 | /**
74 | * Get the ajax url.
75 | *
76 | * @return string
77 | */
78 | public function getUrl()
79 | {
80 | return $this->url;
81 | }
82 |
83 | /**
84 | * Set ajax url which is used for the constructor.
85 | *
86 | * @param string $url Ajax url.
87 | *
88 | * @return $this
89 | */
90 | public function setUrl($url)
91 | {
92 | $this->url = $url;
93 |
94 | return $this;
95 | }
96 |
97 | /**
98 | * Add url via call addUrl method.
99 | *
100 | * @param string $url Url being added.
101 | *
102 | * @return $this
103 | */
104 | public function addUrl($url)
105 | {
106 | $this->urls[] = $url;
107 |
108 | $this->addMethod('addUrl', $url);
109 |
110 | return $this;
111 | }
112 |
113 | /**
114 | * Set point to layer function.
115 | *
116 | * @param Expression|AnonymousFunction $function The function callback.
117 | *
118 | * @return $this
119 | */
120 | public function setPointToLayer($function)
121 | {
122 | return $this->setOption('pointToLayer', $function);
123 | }
124 |
125 | /**
126 | * Set on each feature function.
127 | *
128 | * @param Expression|AnonymousFunction $function The function callback.
129 | *
130 | * @return $this
131 | */
132 | public function setOnEachFeature($function)
133 | {
134 | return $this->setOption('onEachFeature', $function);
135 | }
136 |
137 | /**
138 | * Set the data type option.
139 | *
140 | * @param string $dataType The data type option.
141 | *
142 | * @return $this
143 | */
144 | public function setDataType($dataType)
145 | {
146 | return $this->setOption('dataType', $dataType);
147 | }
148 |
149 | /**
150 | * Get the data type option.
151 | *
152 | * @return string|null
153 | */
154 | public function getDataType()
155 | {
156 | return $this->getOption('dataType');
157 | }
158 |
159 | /**
160 | * {@inheritdoc}
161 | */
162 | public function encode(Encoder $encoder, $flags = true)
163 | {
164 | $buffer = sprintf(
165 | '%s = L.geoJson.ajax(%s)%s',
166 | $encoder->encodeReference($this),
167 | $encoder->encodeArguments(
168 | array(
169 | $this->url,
170 | $this->getOptions()
171 | )
172 | ),
173 | $encoder->close($flags)
174 | );
175 |
176 | foreach ($this->getLayers() as $layer) {
177 | $buffer .= "\n";
178 | $buffer .= sprintf(
179 | '%s.addLayer(%s);',
180 | $encoder->encodeReference($this),
181 | $encoder->encodeReference($layer)
182 | );
183 | }
184 |
185 | return $buffer;
186 | }
187 |
188 | /**
189 | * {@inheritdoc}
190 | */
191 | public function convertsFullyToGeoJson()
192 | {
193 | return false;
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/ExtraMarkers/ExtraMarkersIcon.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\ExtraMarkers;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
17 | use Netzmacht\LeafletPHP\Definition\Type\AbstractIcon;
18 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
19 |
20 | /**
21 | * Class ExtraMarkers.
22 | *
23 | * @package Netzmacht\LeafletPHP\Plugins\ExtraMarkers
24 | */
25 | class ExtraMarkersIcon extends AbstractIcon implements ConvertsToJavascript
26 | {
27 | use EncodeHelperTrait;
28 |
29 | /**
30 | * {@inheritDoc}
31 | */
32 | public static function getType()
33 | {
34 | return 'ExtraMarkers.icon';
35 | }
36 |
37 | /**
38 | * {@inheritDoc}
39 | */
40 | public static function getRequiredLibraries()
41 | {
42 | $libs = parent::getRequiredLibraries();
43 | $libs[] = 'leaflet-extra-markers';
44 |
45 | return $libs;
46 | }
47 |
48 | /**
49 | * Set the icon class.
50 | *
51 | * @param string $iconClass The icon class.
52 | *
53 | * @return $this
54 | */
55 | public function setIcon($iconClass)
56 | {
57 | return $this->setOption('icon', $iconClass);
58 | }
59 |
60 | /**
61 | * Get the icon class.
62 | *
63 | * @return string
64 | */
65 | public function getIcon()
66 | {
67 | return $this->getOption('icon');
68 | }
69 |
70 | /**
71 | * Set the iconColor.
72 | *
73 | * @param string $iconColor The iconColor.
74 | *
75 | * @return $this
76 | */
77 | public function setIconColor($iconColor)
78 | {
79 | return $this->setOption('iconColor', $iconColor);
80 | }
81 |
82 | /**
83 | * Get the iconColor.
84 | *
85 | * @return string
86 | */
87 | public function getIconColor()
88 | {
89 | return $this->getOption('iconColor', 'white');
90 | }
91 |
92 | /**
93 | * Set the markerColor.
94 | *
95 | * @param string $markerColor The markerColor.
96 | *
97 | * @return $this
98 | */
99 | public function setMarkerColor($markerColor)
100 | {
101 | return $this->setOption('markerColor', $markerColor);
102 | }
103 |
104 | /**
105 | * Get the markerColor.
106 | *
107 | * @return string
108 | */
109 | public function getMarkerColor()
110 | {
111 | return $this->getOption('markerColor', 'blue');
112 | }
113 |
114 | /**
115 | * Set the shape.
116 | *
117 | * @param string $shape The shape.
118 | *
119 | * @return $this
120 | */
121 | public function setShape($shape)
122 | {
123 | return $this->setOption('shape', $shape);
124 | }
125 |
126 | /**
127 | * Get the shape.
128 | *
129 | * @return string
130 | */
131 | public function getShape()
132 | {
133 | return $this->getOption('shape', 'circle');
134 | }
135 |
136 | /**
137 | * Set the number.
138 | *
139 | * @param string $number The number.
140 | *
141 | * @return $this
142 | */
143 | public function setNumber($number)
144 | {
145 | return $this->setOption('number', $number);
146 | }
147 |
148 | /**
149 | * Get the number.
150 | *
151 | * @return string
152 | */
153 | public function getNumber()
154 | {
155 | return $this->getOption('number');
156 | }
157 |
158 | /**
159 | * Set the prefix.
160 | *
161 | * @param string $prefix The prefix.
162 | *
163 | * @return $this
164 | */
165 | public function setPrefix($prefix)
166 | {
167 | return $this->setOption('prefix', $prefix);
168 | }
169 |
170 | /**
171 | * Get the prefix.
172 | *
173 | * @return string
174 | */
175 | public function getPrefix()
176 | {
177 | return $this->getOption('prefix');
178 | }
179 |
180 | /**
181 | * {@inheritDoc}
182 | */
183 | public function encode(Encoder $encoder, $flags = null)
184 | {
185 | $buffer = sprintf(
186 | '%s = L.ExtraMarkers.icon(%s)%s',
187 | $encoder->encodeReference($this),
188 | $encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT),
189 | $encoder->close($flags)
190 | );
191 |
192 | $buffer .= $this->encodeMethodCalls($this->getMethodCalls(), $encoder, $flags);
193 |
194 | return $buffer;
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/FullScreen/FullScreenControl.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\FullScreen;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
17 | use Netzmacht\LeafletPHP\Definition\Control\AbstractControl;
18 | use Netzmacht\LeafletPHP\Definition\Map;
19 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
20 |
21 | /**
22 | * Class FullScreenControl integrates the fullscreen button of https://github.com/brunob/leaflet.fullscreen.
23 | *
24 | * @package Netzmacht\LeafletPHP\Plugins\FullScreen
25 | */
26 | class FullScreenControl extends AbstractControl implements ConvertsToJavascript
27 | {
28 | use EncodeHelperTrait;
29 |
30 | const MAP_EVENT_ENTER_FULLSCREEN = 'enterFullscreen';
31 |
32 | const MAP_EVENT_EXIT_FULLSCREEN = 'exitFullscreen';
33 |
34 | /**
35 | * Default position.
36 | *
37 | * @var string
38 | */
39 | protected $defaultPosition = self::POSITION_TOP_LEFT;
40 |
41 | /**
42 | * {@inheritdoc}
43 | */
44 | public static function getType()
45 | {
46 | return 'Control.FullScreen';
47 | }
48 |
49 | /**
50 | * {@inheritdoc}
51 | */
52 | public static function getRequiredLibraries()
53 | {
54 | $libs = parent::getRequiredLibraries();
55 | $libs[] = 'leaflet-fullscreen';
56 |
57 | return $libs;
58 | }
59 |
60 | /**
61 | * Set the button title.
62 | *
63 | * @param string $title The button title.
64 | *
65 | * @return $this
66 | */
67 | public function setTitle($title)
68 | {
69 | return $this->setOption('title', $title);
70 | }
71 |
72 | /**
73 | * Get the button title.
74 | *
75 | * @return string
76 | */
77 | public function getTitle()
78 | {
79 | return $this->getOption('title');
80 | }
81 |
82 | /**
83 | * Set force separate button option.
84 | *
85 | * @param bool $force If true the control button is displayed standalone.
86 | *
87 | * @return $this
88 | */
89 | public function setForceSeparateButton($force)
90 | {
91 | return $this->setOption('forceSeparateButton', (bool) $force);
92 | }
93 |
94 | /**
95 | * Check if force separate button option is set.
96 | *
97 | * @return $this
98 | */
99 | public function isForceSeparateButton()
100 | {
101 | return $this->getOption('forceSeparateButton', false);
102 | }
103 |
104 | /**
105 | * Set force separate button option.
106 | *
107 | * @param bool $force If true the control button is displayed standalone.
108 | *
109 | * @return $this
110 | */
111 | public function setForcePseudoFullScreen($force)
112 | {
113 | return $this->setOption('forcePseudoFullscreen', (bool) $force);
114 | }
115 |
116 | /**
117 | * Check if force separate button option is set.
118 | *
119 | * @return $this
120 | */
121 | public function isForcePseudoFullScreen()
122 | {
123 | return $this->getOption('forcePseudoFullscreen', false);
124 | }
125 |
126 | /**
127 | * {@inheritdoc}
128 | */
129 | public function encode(Encoder $encoder, $flags = null)
130 | {
131 | return $this->encodeSimpleControl('control.fullscreen', $this, $encoder, $flags);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/LeafletProviders/HereProvider.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\LeafletProviders;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
18 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
19 |
20 | /**
21 | * Provider plugin for the HERE provider.
22 | *
23 | * @package Netzmacht\LeafletPHP\Plugins\LeafletProviders
24 | */
25 | class HereProvider extends Provider implements HasOptions
26 | {
27 | use OptionsTrait;
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * Set the app id.
32 | *
33 | * @param string $appId The app id.
34 | *
35 | * @return $this
36 | */
37 | public function setAppId($appId)
38 | {
39 | return $this->setOption('app_id', $appId);
40 | }
41 |
42 | /**
43 | * Get the app id.
44 | *
45 | * @return string
46 | */
47 | public function getAppId()
48 | {
49 | return $this->getOption('app_id');
50 | }
51 |
52 | /**
53 | * Set the app code.
54 | *
55 | * @param string $code The app code.
56 | *
57 | * @return $this
58 | */
59 | public function setAppCode($code)
60 | {
61 | return $this->setOption('app_code', $code);
62 | }
63 |
64 | /**
65 | * Get the app code.
66 | *
67 | * @return string
68 | */
69 | public function getAppCode()
70 | {
71 | return $this->getOption('app_code');
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/LeafletProviders/MapBoxProvider.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\LeafletProviders;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
18 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
19 |
20 | /**
21 | * Provider plugin for the MaxBox.
22 | *
23 | * @package Netzmacht\LeafletPHP\Plugins\LeafletProviders
24 | */
25 | class MapBoxProvider extends Provider implements HasOptions
26 | {
27 | use OptionsTrait;
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * Get the key.
32 | *
33 | * @return string
34 | */
35 | public function getUser()
36 | {
37 | // @codingStandardsIgnoreStart
38 | @trigger_error(
39 | 'MapBoxProvider::getUser is deprecated and has no affect. Will be removed in 2.0.'
40 | );
41 | // @codingStandardsIgnoreEnd
42 |
43 | return '';
44 | }
45 |
46 | /**
47 | * Set the mapbox user..
48 | *
49 | * @param string $user Mapbox username.
50 | *
51 | * @return $this
52 | *
53 | * @SuppressWarnings(PHPMD.UnusedFormalParameter)
54 | */
55 | public function setUser($user)
56 | {
57 | // @codingStandardsIgnoreStart
58 | @trigger_error(
59 | 'MapBoxProvider::setUser is deprecated and has no affect. Will be removed in 2.0.'
60 | );
61 | // @codingStandardsIgnoreEnd
62 |
63 | return $this;
64 | }
65 |
66 | /**
67 | * Get the map name.
68 | *
69 | * @return string
70 | */
71 | public function getMapName()
72 | {
73 | // @codingStandardsIgnoreStart
74 | @trigger_error(
75 | 'MapBoxProvider::getMapName is deprecated and has no affect. Will be removed in 2.0.'
76 | );
77 | // @codingStandardsIgnoreEnd
78 |
79 | return '';
80 | }
81 |
82 | /**
83 | * Set the map name.
84 | *
85 | * @param string $mapName Mapbox map name.
86 | *
87 | * @return $this
88 | *
89 | * @SuppressWarnings(PHPMD.UnusedFormalParameter)
90 | */
91 | public function setMapName($mapName)
92 | {
93 | // @codingStandardsIgnoreStart
94 | @trigger_error(
95 | 'MapBoxProvider::setMapName is deprecated and has no affect. Will be removed in 2.0.'
96 | );
97 | // @codingStandardsIgnoreEnd
98 |
99 | return $this;
100 | }
101 |
102 | /**
103 | * Get access roken.
104 | *
105 | * @return string|null
106 | */
107 | public function getAccessToken()
108 | {
109 | return $this->getOption('accessToken');
110 | }
111 |
112 | /**
113 | * Set access token.
114 | *
115 | * @param string $accessToken AccessToken.
116 | *
117 | * @return $this
118 | */
119 | public function setAccessToken($accessToken)
120 | {
121 | return $this->setOption('accessToken', $accessToken);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/LeafletProviders/OpenWeatherMapProvider.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\LeafletProviders;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
18 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
19 |
20 | /**
21 | * Provider plugin for the OpenWeatherMap provider.
22 | *
23 | * @package Netzmacht\LeafletPHP\Plugins\LeafletProviders
24 | */
25 | class OpenWeatherMapProvider extends Provider implements HasOptions
26 | {
27 | use OptionsTrait;
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * Set the api key.
32 | *
33 | * @param string $apiKey The api key.
34 | *
35 | * @return $this
36 | */
37 | public function setApiKey($apiKey)
38 | {
39 | return $this->setOption('apiKey', $apiKey);
40 | }
41 |
42 | /**
43 | * Get the api key.
44 | *
45 | * @return string|null
46 | */
47 | public function getApiKey()
48 | {
49 | return $this->getOption('apiKey');
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/LeafletProviders/Provider.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\LeafletProviders;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
17 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
18 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
19 | use const JSON_FORCE_OBJECT;
20 |
21 | /**
22 | * Class Provider provides the L.tileLayer.provider plugin.
23 | *
24 | * @package Netzmacht\LeafletPHP\Plugins\LeafletProviders
25 | */
26 | class Provider extends AbstractLayer implements ConvertsToJavascript
27 | {
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public static function getRequiredLibraries()
34 | {
35 | $libs = parent::getRequiredLibraries();
36 | $libs[] = 'leaflet-providers';
37 |
38 | return $libs;
39 | }
40 |
41 | /**
42 | * Get the type of the definition.
43 | *
44 | * @return string
45 | */
46 | public static function getType()
47 | {
48 | return 'TileLayer.provider';
49 | }
50 |
51 | /**
52 | * Provider name.
53 | *
54 | * @var string
55 | */
56 | private $provider;
57 |
58 | /**
59 | * Variant name.
60 | *
61 | * @var string
62 | */
63 | private $variant;
64 |
65 | /**
66 | * Construct.
67 | *
68 | * @param string $identifier Element identifier.
69 | * @param string $provider Provider name.
70 | * @param string $variant Map variant.
71 | */
72 | public function __construct($identifier, $provider, $variant = null)
73 | {
74 | parent::__construct($identifier);
75 |
76 | $this->provider = $provider;
77 | $this->variant = $variant;
78 | }
79 |
80 | /**
81 | * Get the provider.
82 | *
83 | * @return string
84 | */
85 | public function getProvider()
86 | {
87 | return $this->provider;
88 | }
89 |
90 | /**
91 | * Get the variant.
92 | *
93 | * @return string
94 | */
95 | public function getVariant()
96 | {
97 | return $this->variant;
98 | }
99 |
100 | /**
101 | * {@inheritdoc}
102 | */
103 | public function encode(Encoder $encoder, $flags = null)
104 | {
105 | $name = $this->encodeName();
106 | $buffer = sprintf(
107 | '%s = L.tileLayer.provider(\'' . $name . '\', %s)' . $encoder->close($flags),
108 | $encoder->encodeReference($this),
109 | $encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT)
110 | );
111 |
112 | $buffer .= $this->encodeMethodCalls($this->getMethodCalls(), $encoder, $flags);
113 |
114 | return $buffer;
115 | }
116 |
117 | /**
118 | * Encode provider name.
119 | *
120 | * @return string
121 | */
122 | protected function encodeName()
123 | {
124 | $name = $this->getProvider();
125 |
126 | if ($this->getVariant()) {
127 | $name .= '.' . $this->getVariant();
128 |
129 | return $name;
130 | }
131 |
132 | return $name;
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/LeafletProviders/ThunderforestProvider.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\LeafletProviders;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\LeafletPHP\Definition\HasOptions;
17 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
18 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
19 |
20 | /**
21 | * Provider plugin for the Thunderforest provider.
22 | *
23 | * @package Netzmacht\LeafletPHP\Plugins\LeafletProviders
24 | */
25 | class ThunderforestProvider extends Provider implements HasOptions
26 | {
27 | use OptionsTrait;
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * Set the api key.
32 | *
33 | * @param string $appId The api key.
34 | *
35 | * @return $this
36 | */
37 | public function setApiKey($appId)
38 | {
39 | return $this->setOption('apikey', $appId);
40 | }
41 |
42 | /**
43 | * Get the api key.
44 | *
45 | * @return string
46 | */
47 | public function getApiKey()
48 | {
49 | return $this->getOption('apikey');
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Loading/LoadingControl.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Loading;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
17 | use Netzmacht\LeafletPHP\Definition\Control\AbstractControl;
18 | use Netzmacht\LeafletPHP\Definition\Control\Zoom;
19 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
20 |
21 | /**
22 | * Class LoadingControl represents the Leaflet.loading control plugin.
23 | *
24 | * @package Netzmacht\LeafletPHP\Plugins\Loading
25 | * @see https://github.com/ebrelsford/Leaflet.loading
26 | */
27 | class LoadingControl extends AbstractControl implements ConvertsToJavascript
28 | {
29 | use EncodeHelperTrait;
30 |
31 | /**
32 | * {@inheritdoc}
33 | */
34 | public static function getType()
35 | {
36 | return 'Control.Loading';
37 | }
38 |
39 | /**
40 | * {@inheritdoc}
41 | */
42 | public static function getRequiredLibraries()
43 | {
44 | $libs = parent::getRequiredLibraries();
45 | $libs[] = 'leaflet-loading';
46 |
47 | return $libs;
48 | }
49 |
50 | /**
51 | * Set separate mode.
52 | *
53 | * @param bool $separate Is separate from a zoom control.
54 | *
55 | * @return $this
56 | */
57 | public function setSeparate($separate)
58 | {
59 | if ($separate) {
60 | $this->setOption('zoomControl', null);
61 | }
62 |
63 | return $this->setOption('separate', (bool) $separate);
64 | }
65 |
66 | /**
67 | * Check if control is separate.
68 | *
69 | * @return bool
70 | */
71 | public function isSeparate()
72 | {
73 | return $this->getOption('separate', false);
74 | }
75 |
76 | /**
77 | * Set the zoom control.
78 | *
79 | * @param Zoom $zoom The zoom control.
80 | *
81 | * @return $this
82 | */
83 | public function setZoomControl(Zoom $zoom)
84 | {
85 | $this->setOption('separate', false);
86 |
87 | return $this->setOption('zoomControl', $zoom);
88 | }
89 |
90 | /**
91 | * Get the zoom control.
92 | *
93 | * @return Zoom|null
94 | */
95 | public function getZoomControl()
96 | {
97 | return $this->getOption('zoomControl');
98 | }
99 |
100 | /**
101 | * {@inheritdoc}
102 | */
103 | public function encode(Encoder $encoder, $flags = null)
104 | {
105 | return $this->encodeSimpleControl('Control.loading', $this, $encoder, $flags);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Loading/SpinJsLoadingControl.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Loading;
14 |
15 | /**
16 | * SpinJsLoadingControl is for the spin.js loading indicator.
17 | *
18 | * Instead of setting an option to the LoadingControl you have to use a separate class. Autoloading of spin.js library
19 | * causes this.
20 | *
21 | * @package Netzmacht\LeafletPHP\Plugins\Loading
22 | */
23 | class SpinJsLoadingControl extends LoadingControl
24 | {
25 | /**
26 | * {@inheritdoc}
27 | */
28 | public static function getRequiredLibraries()
29 | {
30 | $libs = parent::getRequiredLibraries();
31 | $libs[] = 'spin.js';
32 |
33 | return $libs;
34 | }
35 |
36 | /**
37 | * {@inheritdoc}
38 | */
39 | public function __construct($identifier)
40 | {
41 | parent::__construct($identifier);
42 |
43 | $this->setOption('spinjs', true);
44 | }
45 |
46 | /**
47 | * Set spin.js configuration.
48 | *
49 | * @param array $spin Spin.js configuration.
50 | *
51 | * @return $this
52 | * @see http://fgnass.github.io/spin.js/
53 | */
54 | public function setSpin(array $spin)
55 | {
56 | return $this->setOption('spin', $spin);
57 | }
58 |
59 | /**
60 | * Get spin options.
61 | *
62 | * @return array
63 | */
64 | public function getSpin()
65 | {
66 | return $this->getOption(
67 | 'spin',
68 | array(
69 | 'lines' => 7,
70 | 'length' => 3,
71 | 'width' => 3,
72 | 'radius' => 5,
73 | 'rotate' => 13,
74 | 'top' => '83%'
75 | )
76 | );
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/Csv.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class Csv creates the csv file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class Csv extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.Csv';
28 | }
29 |
30 | /**
31 | * Set the latfield option.
32 | *
33 | * @param string $field The csv field name.
34 | *
35 | * @return $this
36 | * @see https://github.com/mapbox/csv2geojson#api
37 | */
38 | public function setLatField($field)
39 | {
40 | return $this->setOption('latfield', $field);
41 | }
42 |
43 | /**
44 | * Get the latfield option.
45 | *
46 | * @return $this
47 | * @see https://github.com/mapbox/csv2geojson#api
48 | */
49 | public function getLatField()
50 | {
51 | return $this->getOption('latfield');
52 | }
53 |
54 | /**
55 | * Set the longfield option.
56 | *
57 | * @param string $field The csv field name.
58 | *
59 | * @return $this
60 | * @see https://github.com/mapbox/csv2geojson#api
61 | */
62 | public function setLongField($field)
63 | {
64 | return $this->setOption('longfield', $field);
65 | }
66 |
67 | /**
68 | * Get the longfield option.
69 | *
70 | * @return string|null
71 | * @see https://github.com/mapbox/csv2geojson#api
72 | */
73 | public function getLongField()
74 | {
75 | return $this->getOption('longfield');
76 | }
77 |
78 | /**
79 | * Set the csv delimiter option.
80 | *
81 | * @param string $field The csv field name.
82 | *
83 | * @return string|null
84 | * @see https://github.com/mapbox/csv2geojson#api
85 | */
86 | public function setDelimiterField($field)
87 | {
88 | return $this->setOption('delimiter', $field);
89 | }
90 |
91 | /**
92 | * Get the csv delimiter option.
93 | *
94 | * @return string|null
95 | * @see https://github.com/mapbox/csv2geojson#api
96 | */
97 | public function getDelimiterField()
98 | {
99 | return $this->getOption('delimiter');
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/GeoJson.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class GeoJson creates the GeoJSON file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class GeoJson extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.GeoJson';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/Gpx.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class Gpx creates the gpx file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class Gpx extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.Gpx';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/Kml.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class Kml creates the kml file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class Kml extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.Kml';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/Omnivore.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | use Netzmacht\LeafletPHP\Definition\Layer;
16 |
17 | /**
18 | * Class Omnivore represents the omnivore javascript namespace to create the file loading requests.
19 | *
20 | * It's just a factory facade for the different file types.
21 | *
22 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
23 | */
24 | class Omnivore
25 | {
26 | /**
27 | * Create a csv file loading request.
28 | *
29 | * @param string $layerId The layer id.
30 | * @param string $url The file url.
31 | * @param array $parserOptions Parser options.
32 | * @param Layer $customLayer Optional custom layer where the data is added.
33 | *
34 | * @return Csv
35 | */
36 | public static function csv($layerId, $url, $parserOptions = array(), Layer $customLayer = null)
37 | {
38 | return new Csv($layerId, $url, $parserOptions, $customLayer);
39 | }
40 |
41 | /**
42 | * Create a kml file loading request.
43 | *
44 | * @param string $layerId The layer id.
45 | * @param string $url The file url.
46 | *
47 | * @return Kml
48 | */
49 | public static function kml($layerId, $url)
50 | {
51 | return new Kml($layerId, $url);
52 | }
53 |
54 | /**
55 | * Create a gpx file loading request.
56 | *
57 | * @param string $layerId The layer id.
58 | * @param string $url The file url.
59 | * @param array $parserOptions Parser options.
60 | * @param Layer $customLayer Optional custom layer where the data is added.
61 | *
62 | * @return Gpx
63 | */
64 | public static function gpx($layerId, $url, $parserOptions = array(), Layer $customLayer = null)
65 | {
66 | return new Gpx($layerId, $url, $parserOptions, $customLayer);
67 | }
68 |
69 | /**
70 | * Create a geoJSON file loading request.
71 | *
72 | * @param string $layerId The layer id.
73 | * @param string $url The file url.
74 | * @param array $parserOptions Parser options.
75 | * @param Layer $customLayer Optional custom layer where the data is added.
76 | *
77 | * @return GeoJson
78 | */
79 | public static function geojson($layerId, $url, $parserOptions = array(), Layer $customLayer = null)
80 | {
81 | return new GeoJson($layerId, $url, $parserOptions, $customLayer);
82 | }
83 |
84 | /**
85 | * Create a wkt file loading request.
86 | *
87 | * @param string $layerId The layer id.
88 | * @param string $url The file url.
89 | * @param array $parserOptions Parser options.
90 | * @param Layer $customLayer Optional custom layer where the data is added.
91 | *
92 | * @return Wkt
93 | */
94 | public static function wkt($layerId, $url, $parserOptions = array(), Layer $customLayer = null)
95 | {
96 | return new Wkt($layerId, $url, $parserOptions, $customLayer);
97 | }
98 |
99 | /**
100 | * Create a TopoJSON file loading request.
101 | *
102 | * @param string $layerId The layer id.
103 | * @param string $url The file url.
104 | * @param array $parserOptions Parser options.
105 | * @param Layer $customLayer Optional custom layer where the data is added.
106 | *
107 | * @return TopoJson
108 | */
109 | public static function topojson($layerId, $url, $parserOptions = array(), Layer $customLayer = null)
110 | {
111 | return new TopoJson($layerId, $url, $parserOptions, $customLayer);
112 | }
113 |
114 | /**
115 | * Create a polyline file loading request.
116 | *
117 | * @param string $layerId The layer id.
118 | * @param string $url The file url.
119 | * @param array $parserOptions Parser options.
120 | * @param Layer $customLayer Optional custom layer where the data is added.
121 | *
122 | * @return Polyline
123 | */
124 | public static function polyline($layerId, $url, $parserOptions = array(), Layer $customLayer = null)
125 | {
126 | return new Polyline($layerId, $url, $parserOptions, $customLayer);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/OmnivoreLayer.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\Call\MethodCall;
17 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
18 | use Netzmacht\LeafletPHP\Assert\Assertion;
19 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
20 | use Netzmacht\LeafletPHP\Definition\EventsTrait;
21 | use Netzmacht\LeafletPHP\Definition\HasEvents;
22 | use Netzmacht\LeafletPHP\Definition\Layer;
23 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
24 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
25 |
26 | /**
27 | * Class OmnivoreLayer is the base omnivore layer providing support for a custom layer and options.
28 | *
29 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
30 | */
31 | abstract class OmnivoreLayer extends AbstractLayer implements ConvertsToJavascript, HasEvents
32 | {
33 | use OptionsTrait;
34 | use EventsTrait;
35 | use EncodeHelperTrait;
36 |
37 | /**
38 | * {@inheritdoc}
39 | */
40 | public static function getRequiredLibraries()
41 | {
42 | $libs = parent::getRequiredLibraries();
43 | $libs[] = 'leaflet-omnivore';
44 |
45 | return $libs;
46 | }
47 |
48 | /**
49 | * The url being loaded.
50 | *
51 | * @var string
52 | */
53 | private $url;
54 |
55 | /**
56 | * Custom layer.
57 | *
58 | * @var Layer
59 | */
60 | private $customLayer;
61 |
62 | /**
63 | * Construct.
64 | *
65 | * @param string $identifier The element id.
66 | * @param string $url The url being loaded.
67 | * @param array $parserOptions Parser options.
68 | * @param Layer $customLayer Optional custom layer.
69 | */
70 | public function __construct($identifier, $url, array $parserOptions = array(), Layer $customLayer = null)
71 | {
72 | parent::__construct($identifier);
73 |
74 | $this->customLayer = $customLayer;
75 | $this->url = $url;
76 |
77 | $this->setOptions($parserOptions);
78 | }
79 |
80 | /**
81 | * Get the url.
82 | *
83 | * @return string
84 | */
85 | public function getUrl()
86 | {
87 | return $this->url;
88 | }
89 |
90 | /**
91 | * Set the url.
92 | *
93 | * @param string $url The url being loaded.
94 | *
95 | * @return $this
96 | */
97 | public function setUrl($url)
98 | {
99 | $this->url = $url;
100 |
101 | return $this;
102 | }
103 |
104 | /**
105 | * Get the custom layer.
106 | *
107 | * @return Layer|null
108 | */
109 | public function getCustomLayer()
110 | {
111 | return $this->customLayer;
112 | }
113 |
114 | /**
115 | * Set the custom layer.
116 | *
117 | * @param Layer $customLayer The custom layer.
118 | *
119 | * @return $this
120 | */
121 | public function setCustomLayer(Layer $customLayer)
122 | {
123 | Assertion::count($this->getMethodCalls(), 0, 'Setting custom layer has to be done before any method call.');
124 |
125 | $this->customLayer = $customLayer;
126 |
127 | return $this;
128 | }
129 |
130 | /**
131 | * {@inheritdoc}
132 | */
133 | protected function addMethod($name, array $arguments = array())
134 | {
135 | if ($this->getCustomLayer()) {
136 | $this->methods[] = new MethodCall($this->getCustomLayer(), $name, $arguments);
137 | } else {
138 | parent::addMethod($name, $arguments);
139 | }
140 |
141 | return $this;
142 | }
143 |
144 | /**
145 | * {@inheritdoc}
146 | */
147 | public function encode(Encoder $encoder, $flags = null)
148 | {
149 | $template = '%s(%s, %s, %s)%s';
150 | $buffer = '';
151 |
152 | if ($this->getCustomLayer()) {
153 | $ref = $encoder->encodeReference($this->getCustomLayer());
154 | } else {
155 | $template = $encoder->encodeReference($this) . ' = ' . $template;
156 | $ref = 'null';
157 | }
158 |
159 | $buffer .= sprintf(
160 | $template,
161 | strtolower(static::getType()),
162 | $encoder->encodeValue($this->getUrl()),
163 | $encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT),
164 | $ref,
165 | $encoder->close($flags)
166 | );
167 |
168 | $buffer .= $this->encodeMethodCalls($this->getMethodCalls(), $encoder, $flags);
169 |
170 | return $buffer;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/Polyline.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class Polyline creates the encoded polyline file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class Polyline extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.Polyline';
28 | }
29 |
30 | /**
31 | * Set precision.
32 | *
33 | * @param int $precision Polyline decoding precision.
34 | *
35 | * @return $this
36 | */
37 | public function setPrecision($precision)
38 | {
39 | return $this->setOption('precision', $precision);
40 | }
41 |
42 | /**
43 | * Get precision.
44 | *
45 | * @return int
46 | */
47 | public function getPrecision()
48 | {
49 | return $this->getOption('precision', 1e5);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/TopoJson.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class TopoJson creates the TopoJSON file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class TopoJson extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.TopoJson';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/Omnivore/Wkt.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\Omnivore;
14 |
15 | /**
16 | * Class Kml creates the kml file loading request.
17 | *
18 | * @package Netzmacht\LeafletPHP\Plugins\Omnivore
19 | */
20 | class Wkt extends OmnivoreLayer
21 | {
22 | /**
23 | * {@inheritdoc}
24 | */
25 | public static function getType()
26 | {
27 | return 'Omnivore.Wkt';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/OverpassLayer/MinZoomIndicatorOptions.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\OverpassLayer;
14 |
15 | use Netzmacht\LeafletPHP\Definition\HasOptions;
16 | use Netzmacht\LeafletPHP\Definition\OptionsTrait;
17 |
18 | /**
19 | * Class MinZoomIndicatorOptions.
20 | *
21 | * @package Netzmacht\LeafletPHP\Plugins\OverpassLayer
22 | */
23 | class MinZoomIndicatorOptions implements HasOptions, \JsonSerializable
24 | {
25 | use OptionsTrait;
26 |
27 | /**
28 | * Set the position of the indicator.
29 | *
30 | * @param string $position Position.
31 | *
32 | * @return $this
33 | */
34 | public function setPosition($position)
35 | {
36 | return $this->setOption('position', $position);
37 | }
38 |
39 | /**
40 | * Get the position.
41 | *
42 | * @return string
43 | */
44 | public function getPosition()
45 | {
46 | return $this->getOption('position', 'bottomleft');
47 | }
48 |
49 | /**
50 | * Set the message of if no min zoom layer is assigned.
51 | *
52 | * @param string $minZoomMessageNoLayer MinZoomMessageNoLayer.
53 | *
54 | * @return $this
55 | */
56 | public function setMinZoomMessageNoLayer($minZoomMessageNoLayer)
57 | {
58 | return $this->setOption('minZoomMessageNoLayer', $minZoomMessageNoLayer);
59 | }
60 |
61 | /**
62 | * Get the minZoomMessageNoLayer.
63 | *
64 | * @return string
65 | */
66 | public function getMinZoomMessageNoLayer()
67 | {
68 | return $this->getOption('minZoomMessageNoLayer', 'no layer assigned');
69 | }
70 |
71 | /**
72 | * Set the message min zoom message.
73 | *
74 | * @param string $minZoomMessage Min zoom message.
75 | *
76 | * @return $this
77 | */
78 | public function setMinZoomMessage($minZoomMessage)
79 | {
80 | return $this->setOption('minZoomMessage', $minZoomMessage);
81 | }
82 |
83 | /**
84 | * Get the minZoomMessage.
85 | *
86 | * @return string
87 | */
88 | public function getMinZoomMessage()
89 | {
90 | return $this->getOption('minZoomMessage', 'current Zoom-Level: CURRENTZOOM all data at Level: MINZOOMLEVEL');
91 | }
92 |
93 | /**
94 | * {@inheritdoc}
95 | */
96 | public function jsonSerialize()
97 | {
98 | return $this->getOptions();
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Plugins/OverpassLayer/OverpassLayer.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Plugins\OverpassLayer;
14 |
15 | use Netzmacht\JavascriptBuilder\Encoder;
16 | use Netzmacht\JavascriptBuilder\Type\ConvertsToJavascript;
17 | use Netzmacht\JavascriptBuilder\Type\Expression;
18 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
19 | use Netzmacht\LeafletPHP\Encoder\EncodeHelperTrait;
20 |
21 | /**
22 | * Class OverpassLayer provides implementation of https://github.com/kartenkarsten/leaflet-layer-overpass.
23 | *
24 | * @package Netzmacht\LeafletPHP\Plugins\OverpassLayer
25 | */
26 | class OverpassLayer extends AbstractLayer implements ConvertsToJavascript
27 | {
28 | use EncodeHelperTrait;
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public static function getType()
34 | {
35 | return 'OverpassLayer';
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public static function getRequiredLibraries()
42 | {
43 | $libs = parent::getRequiredLibraries();
44 | $libs[] = 'leaflet-layer-overpass';
45 |
46 | return $libs;
47 | }
48 |
49 | /**
50 | * OverpassLayer constructor.
51 | *
52 | * @param string $identifier Indicator of the layer.
53 | * @param array $options Options.
54 | */
55 | public function __construct($identifier, array $options = [])
56 | {
57 | parent::__construct($identifier);
58 |
59 | $this->setOptions($options);
60 | }
61 |
62 | /**
63 | * Set the debug mode.
64 | *
65 | * @param bool $debug Debug mode.
66 | *
67 | * @return $this
68 | */
69 | public function setDebug($debug)
70 | {
71 | return $this->setOption('debug', (bool) $debug);
72 | }
73 |
74 | /**
75 | * Get debug mode.
76 | *
77 | * @return bool
78 | *
79 | * @SuppressWarnings(BooleanGetMethodName)
80 | */
81 | public function getDebug()
82 | {
83 | return $this->getOption('debug', false);
84 | }
85 |
86 | /**
87 | * Set the query.
88 | *
89 | * @param string $query Query.
90 | *
91 | * @return $this
92 | */
93 | public function setQuery($query)
94 | {
95 | return $this->setOption('query', $query);
96 | }
97 |
98 | /**
99 | * Get query.
100 | *
101 | * @return string
102 | */
103 | public function getQuery()
104 | {
105 | return $this->getOption('query', '(node(BBOX)[organic];node(BBOX)[second_hand];);out qt;');
106 | }
107 |
108 | /**
109 | * Set the endpoint.
110 | *
111 | * @param string $endpoint Endpoint.
112 | *
113 | * @return $this
114 | */
115 | public function setEndpoint($endpoint)
116 | {
117 | return $this->setOption('endpoint', $endpoint);
118 | }
119 |
120 | /**
121 | * Get endpoint.
122 | *
123 | * @return string
124 | */
125 | public function getEndpoint()
126 | {
127 | return $this->getOption('endpoint', '//overpass-api.de/api/');
128 | }
129 |
130 | /**
131 | * Set the callback.
132 | *
133 | * @param Expression $callback Callback.
134 | *
135 | * @return $this
136 | */
137 | public function setCallback(Expression $callback)
138 | {
139 | return $this->setOption('callback', $callback);
140 | }
141 |
142 | /**
143 | * Get callback.
144 | *
145 | * @return Expression|null
146 | */
147 | public function getCallback()
148 | {
149 | return $this->getOption('callback', null);
150 | }
151 |
152 | /**
153 | * Set the minZoom.
154 | *
155 | * @param int $minZoom MinZoom.
156 | *
157 | * @return $this
158 | */
159 | public function setMinZoom($minZoom)
160 | {
161 | return $this->setOption('minzoom', (int) $minZoom);
162 | }
163 |
164 | /**
165 | * Get minZoom.
166 | *
167 | * @return int
168 | */
169 | public function getMinZoom()
170 | {
171 | return $this->getOption('minzoom', 15);
172 | }
173 |
174 | /**
175 | * Get the min zoom indicator options.
176 | *
177 | * @return MinZoomIndicatorOptions
178 | */
179 | public function getMinZoomIndicatorOptions()
180 | {
181 | if (!$this->getOption('minZoomindicatorOptions')) {
182 | $this->setMinZoomIndicatorOptions(new MinZoomIndicatorOptions());
183 | }
184 |
185 | return $this->getOption('minZoomIndicatorOptions');
186 | }
187 |
188 | /**
189 | * Set the min zoom indicator options.
190 | *
191 | * @param MinZoomIndicatorOptions $minZoomIndicatorOptions Options.
192 | *
193 | * @return $this
194 | */
195 | public function setMinZoomIndicatorOptions(MinZoomIndicatorOptions $minZoomIndicatorOptions)
196 | {
197 | return $this->setOption('minZoomIndicatorOptions', $minZoomIndicatorOptions);
198 | }
199 |
200 | /**
201 | * {@inheritdoc}
202 | */
203 | public function encode(Encoder $encoder, $flags = null)
204 | {
205 | $buffer = sprintf(
206 | '%s = new L.OverPassLayer(%s, %s)%s',
207 | $encoder->encodeReference($this),
208 | $encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT),
209 | $encoder->encodeArray($this->getMinZoomIndicatorOptions()->getOptions(), JSON_FORCE_OBJECT),
210 | $encoder->close($flags)
211 | );
212 |
213 | $buffer .= $this->encodeMethodCalls($this->getMethodCalls(), $encoder, $flags);
214 |
215 | return $buffer;
216 | }
217 | }
218 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/AbstractFeature.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | use Netzmacht\LeafletPHP\Value\LatLngBounds;
16 |
17 | /**
18 | * Base feature class.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
21 | */
22 | abstract class AbstractFeature implements GeoJsonFeature
23 | {
24 | /**
25 | * Bounding box of the feature.
26 | *
27 | * @var LatLngBounds
28 | */
29 | private $boundingBox;
30 |
31 | /**
32 | * Get bounding box.
33 | *
34 | * @return LatLngBounds|null
35 | */
36 | public function getBoundingBox()
37 | {
38 | return $this->boundingBox;
39 | }
40 |
41 | /**
42 | * Set bounding box.
43 | *
44 | * @param LatLngBounds $boundingBox Bounding box.
45 | *
46 | * @return $this
47 | */
48 | public function setBoundingBox(LatLngBounds $boundingBox)
49 | {
50 | $this->boundingBox = $boundingBox;
51 |
52 | return $this;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/ConvertsToGeoJsonFeature.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * Interface FeatureCollectionAggregate describes a definition which can be converted to a feature collection.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
19 | */
20 | interface ConvertsToGeoJsonFeature
21 | {
22 | /**
23 | * Get definition as feature collection.
24 | *
25 | * @return GeoJsonFeature
26 | */
27 | public function toGeoJsonFeature();
28 |
29 | /**
30 | * Check if this object converts fully to geo json or other content is in it as well.
31 | *
32 | * @return bool
33 | */
34 | public function convertsFullyToGeoJson();
35 | }
36 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/Feature.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * A geo json feature.
17 | *
18 | * @see http://geojson.org/geojson-spec.html#feature-objects
19 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
20 | */
21 | class Feature extends AbstractFeature
22 | {
23 | /**
24 | * The identifier.
25 | *
26 | * @var string
27 | */
28 | private $identifier;
29 |
30 | /**
31 | * The geometry.
32 | *
33 | * @var Geometry
34 | */
35 | private $geometry;
36 |
37 | /**
38 | * Feature properties.
39 | *
40 | * @var array
41 | */
42 | private $properties = array();
43 |
44 | /**
45 | * Construct.
46 | *
47 | * @param Geometry $geometry The geometry.
48 | * @param string $identifier The optional identifier.
49 | */
50 | public function __construct(Geometry $geometry, $identifier = null)
51 | {
52 | $this->identifier = $identifier;
53 | $this->geometry = $geometry;
54 | }
55 |
56 | /**
57 | * Get the identifier.
58 | *
59 | * @return string
60 | */
61 | public function getIdentifier()
62 | {
63 | return $this->identifier;
64 | }
65 |
66 | /**
67 | * Get the geometry.
68 | *
69 | * @return Geometry
70 | */
71 | public function getGeometry()
72 | {
73 | return $this->geometry;
74 | }
75 |
76 | /**
77 | * Get all properties.
78 | *
79 | * @return array
80 | */
81 | public function getProperties()
82 | {
83 | return $this->properties;
84 | }
85 |
86 | /**
87 | * Set feature property.
88 | *
89 | * @param string $name The property name.
90 | * @param mixed $value The property value.
91 | *
92 | * @return $this
93 | */
94 | public function setProperty($name, $value)
95 | {
96 | $this->properties[$name] = $value;
97 |
98 | return $this;
99 | }
100 |
101 | /**
102 | * Get feature property.
103 | *
104 | * @param string $name The property name.
105 | *
106 | * @return $this
107 | */
108 | public function getProperty($name)
109 | {
110 | if (isset($this->properties[$name])) {
111 | return $this->properties[$name];
112 | }
113 |
114 | return null;
115 | }
116 |
117 | /**
118 | * Set feature properties.
119 | *
120 | * Properties are added. Existing properties are only overwritten if defined in the set.
121 | *
122 | * @param array $properties Properties.
123 | *
124 | * @return $this
125 | */
126 | public function setProperties($properties)
127 | {
128 | foreach ($properties as $name => $value) {
129 | $this->setProperty($name, $value);
130 | }
131 |
132 | return $this;
133 | }
134 |
135 |
136 | /**
137 | * {@inheritdoc}
138 | */
139 | public function jsonSerialize()
140 | {
141 | $data = array(
142 | 'type' => 'Feature',
143 | 'geometry' => $this->geometry,
144 | 'properties' => $this->properties ?: null
145 | );
146 |
147 | if ($this->getBoundingBox()) {
148 | $data['bbox'] = $this->getBoundingBox()->toGeoJson();
149 | }
150 |
151 | if ($this->identifier) {
152 | $data['id'] = $this->identifier;
153 | }
154 |
155 | return $data;
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/FeatureCollection.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * FeatureCollection describes a geo json feature collection.
17 | *
18 | * @see http://geojson.org/geojson-spec.html#feature-collection-objects
19 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
20 | */
21 | class FeatureCollection extends AbstractFeature implements \IteratorAggregate
22 | {
23 | /**
24 | * GeoJson features.
25 | *
26 | * @var GeoJsonFeature[]
27 | */
28 | private $features = array();
29 |
30 | /**
31 | * Construct.
32 | *
33 | * @param GeoJsonFeature[] $features GeoJson features.
34 | */
35 | public function __construct($features = array())
36 | {
37 | $this->addFeatures($features);
38 | }
39 |
40 | /**
41 | * Add a geo json feature.
42 | *
43 | * @param GeoJsonFeature $feature Feature being added.
44 | *
45 | * @return $this
46 | */
47 | public function addFeature(GeoJsonFeature $feature)
48 | {
49 | $this->features[] = $feature;
50 |
51 | return $this;
52 | }
53 |
54 | /**
55 | * Add multiple features.
56 | *
57 | * @param GeoJsonFeature[] $features GeoJson features.
58 | *
59 | * @return $this
60 | */
61 | public function addFeatures($features)
62 | {
63 | foreach ($features as $feature) {
64 | $this->addFeature($feature);
65 | }
66 |
67 | return $this;
68 | }
69 |
70 | /**
71 | * Get all features.
72 | *
73 | * @return Feature[]
74 | */
75 | public function getFeatures()
76 | {
77 | return $this->features;
78 | }
79 |
80 | /**
81 | * {@inheritdoc}
82 | */
83 | public function getIterator()
84 | {
85 | return new \ArrayIterator($this->features);
86 | }
87 |
88 | /**
89 | * {@inheritdoc}
90 | */
91 | public function jsonSerialize()
92 | {
93 | $data = array(
94 | 'type' => 'FeatureCollection',
95 | 'features' => $this->getFeatures()
96 | );
97 |
98 | if ($this->getBoundingBox()) {
99 | $data['bbox'] = $this->getBoundingBox()->toGeoJson();
100 | }
101 |
102 | return $data;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/FeatureTrait.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * Class FeatureTrait can be used to create a GeoJson feature of the definition.
17 | *
18 | * The definition must implement the HasOptions and Geometry interface.
19 | *
20 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
21 | */
22 | trait FeatureTrait
23 | {
24 | /**
25 | * Create feature of the given definition.
26 | *
27 | * @return Feature
28 | */
29 | protected function createFeature()
30 | {
31 | $feature = new Feature($this, $this->getId());
32 | $feature->setProperty('type', lcfirst(static::getType()));
33 | $feature->setProperty('options', $this->getOptions());
34 |
35 | return $feature;
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function toGeoJsonFeature()
42 | {
43 | return $this->createFeature();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/GeoJsonFeature.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * Interface GeoJsonFeature describes an object which represents a GeoJSON feature.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
19 | */
20 | interface GeoJsonFeature extends GeoJsonObject
21 | {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/GeoJsonObject.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * Interface GeoJsonObject is a marker for objects which a full geo json object representations.
17 | *
18 | * The difference between ConvertsToGeoJson and this interface is that ConvertsToGeoJson can also contain content
19 | * which is not convertable to the GeoJson format.
20 | *
21 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
22 | */
23 | interface GeoJsonObject extends \JsonSerializable
24 | {
25 | }
26 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/Geometry.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | /**
16 | * Interface Geometry is used to mark an object as a geometry feature. It extends the \JsonSerializable Interface.
17 | *
18 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
19 | * @see http://geojson.org/geojson-spec.html#geometry-objects
20 | */
21 | interface Geometry extends GeoJsonObject
22 | {
23 | }
24 |
--------------------------------------------------------------------------------
/src/Netzmacht/LeafletPHP/Value/GeoJson/StaticFeature.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright 2014-2018 netzmacht David Molineus
9 | * @license LGPL-3.0-or-later https://github.com/netzmacht/php-leaflet/blob/master/LICENSE
10 | * @filesource
11 | */
12 |
13 | namespace Netzmacht\LeafletPHP\Value\GeoJson;
14 |
15 | use Netzmacht\LeafletPHP\Definition\AbstractLayer;
16 |
17 | /**
18 | * Class StaticFeature is a hybrid of a layer and geojson feature which contains static geojson data.
19 | *
20 | * The geojson data could be an array or string.
21 | *
22 | * @package Netzmacht\LeafletPHP\Definition\GeoJson
23 | */
24 | class StaticFeature extends AbstractLayer implements GeoJsonFeature, ConvertsToGeoJsonFeature
25 | {
26 | /**
27 | * Get the type of the definition.
28 | *
29 | * @return string
30 | */
31 | public static function getType()
32 | {
33 | return 'StaticFeature';
34 | }
35 |
36 | /**
37 | * GeoJSON data.
38 | *
39 | * @var array|string
40 | */
41 | private $geoJson;
42 |
43 | /**
44 | * Construct.
45 | *
46 | * @param string $geoJson The GeoJSON data.
47 | */
48 | public function __construct($geoJson)
49 | {
50 | $this->geoJson = $geoJson;
51 | }
52 |
53 | /**
54 | * Get the GeoJSON data.
55 | *
56 | * @return array|string
57 | */
58 | public function getGeoJson()
59 | {
60 | return $this->geoJson;
61 | }
62 |
63 | /**
64 | * {@inheritdoc}
65 | */
66 | public function jsonSerialize()
67 | {
68 | if (is_array($this->geoJson)) {
69 | return $this->geoJson;
70 | }
71 |
72 | return json_decode($this->geoJson, true);
73 | }
74 |
75 | /**
76 | * {@inheritdoc}
77 | */
78 | public function toGeoJsonFeature()
79 | {
80 | return $this;
81 | }
82 |
83 | /**
84 | * {@inheritdoc}
85 | */
86 | public function convertsFullyToGeoJson()
87 | {
88 | return true;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------