Download the PHP package myclar/kamel-php without Composer
On this page you can find all versions of the php package myclar/kamel-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package kamel-php
KML for PHP library (KamelPhp)
A PHP KML parser library initially developed as part of the WP-Trip-Summary WordPress plug-in. It is based on Stepan Daleky's KML parser on GitLab and has now been extracted as a separate library to ease up on the code base a bit.
About
Supported KML entities:
Kml
class (<kml>
root element);Folder
andDocument
classes (and elements) asContainer
types and direct children of the KML root;- Abstract
Feature
class and element, with support for the following attributes:id
,styleUrl
,name
,description
,open
,visibility
,address
,phoneNumber
; Placemark
class and element, with support forPoint
,Linestring
,LinearRing
,Polygon
andMultiGeometry
geometries as well asStyle
andExtendedData
.
Installation
Install the latest version with:
Using the parser directly
The parser class simply parses a KML string (or a file that contains a KML string) and returns an object graph:
Some samples:
- The built-in
Processor
- The current set of tests for the parser class
Using the processor
The processor class provides a simple and expedient way of traversing a KML document, while allowing a certain degree of customization. Its usage is not mandatory.
Limitations:
- Either root KML folder or root KML document is considered, not both (first it checks for a root folder and, if not found for a root document);
- A KML container is searched, in this order, for: folders, documents and placemarks;
- Neither folder, nor document metadata is stored;
- For a placemark, only the name and description metadata items are stored and reported;
- Order in which various document parts are processed cannot be altered;
- Visibility, as specified by the
visibility
feature attribute, is not accounted for.
In order to use the processor, you need to provide a mandatory delegate (a class implementing KamelPhp\KmlParser\Processor\Delegate
) which you can use to:
- control what gets reported back to you (
Delegate::shouldXYZ()
methods, e.g. returnfalse
fromDelegate::shouldProcessPointGeometry()
if you do not what to have KML points sent back to you.); - process KML primitives as they are found and reported back to you (e.g. implement
Delegate::processPoint()
to process KML points); - react when processing begins (
Delegate::begin()
) and ends (Delegate::end()
); - react when an error occurs (
Delegate::error()
).
As it may already be obvious, the way it works sort of breaks the tree structure, but that's perfectly acceptable in my use case - obtain relevant geometries for simple map drawing.
It's up to yo what the delegate does, either it stores the artefacts somewhere or it builds some representation in memory and provides a way to access it at the end. See here an example implementation.