summaryrefslogtreecommitdiff
path: root/protected/extensions/egmap/kml
diff options
context:
space:
mode:
Diffstat (limited to 'protected/extensions/egmap/kml')
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLFeed.php394
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLIconStyle.php74
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLLineString.php86
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLLineStyle.php86
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLNode.php139
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLPlacemark.php76
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLPoint.php95
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLPolyStyle.php61
-rw-r--r--protected/extensions/egmap/kml/EGMapKMLPolygon.php131
9 files changed, 1142 insertions, 0 deletions
diff --git a/protected/extensions/egmap/kml/EGMapKMLFeed.php b/protected/extensions/egmap/kml/EGMapKMLFeed.php
new file mode 100644
index 0000000..f787225
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLFeed.php
@@ -0,0 +1,394 @@
+<?php
+/**
+ *
+ * EGMapKMLFeed Class
+ *
+ * KML Feed Creator
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+/**
+ *
+ * List of currently supported KML tags by Google Maps v3
+ * ----------------------------------------------
+ * <kml>
+ * <atom:author>
+ * <atom:link>
+ * <atom:name>
+ * -----------------------------------------------
+ * Example
+ * ------------------------------------------------
+ <Document>
+ <atom:author>
+ <atom:name>J. K. Rowling</atom:name>
+ </atom:author>
+ <atom:link href="http://www.harrypotter.com" />
+ <Style id="myStyleId"></Style>
+ <Placemark></Placemark>
+ </Document>
+ ------------------------------------------------
+ * <Placemark>
+ * <styleUrl>
+ * <name>
+ * <description>
+ * <Point>
+ * <coordinates>
+ * ------------------------------------------------
+ * Example
+ * ------------------------------------------------
+ <Placemark>
+ <styleUrl>#myIconStyleID</styleUrl>
+ <name>
+ <description>
+ <![CDATA[
+ This is an image
+ <img src="icon.jpg">
+ and we have a link http://www.google.com.
+ ]]>
+ </description>
+ <Point>
+ <coordinates>-90.86948943473118,48.25450093195546</coordinates>
+ </Point>
+ </Placemark>
+ * ------------------------------------------------
+ * <Style>
+ * <IconStyle id="myIconStyleID>
+ * <Icon>
+ * <PolyStyle id="myPolyStyleID">
+ * <color>
+ * <colorMode>
+ * <LineStyle>
+ * <color>
+ * <width>
+ *
+ *
+ * ------------------------------------------------
+ * Examples
+ * ------------------------------------------------
+ <Document>
+ <Style id="restaurantStyle">
+ <IconStyle id="restuarantIcon">
+ <Icon>
+ <href>http://maps.google.com/mapfiles/kml/pal2/icon63.png</href>
+ </Icon>
+ </IconStyle>
+ </Style>
+ ------------------------------------------------
+ <Style id="examplePolyStyle">
+ <PolyStyle>
+ <color>ff0000cc</color>
+ <colorMode>random</colorMode>
+ </PolyStyle>
+ </Style>
+ ------------------------------------------------
+ <Style id="linestyleExample">
+ <LineStyle>
+ <color>7f0000ff</color>
+ <width>4</width>
+ </LineStyle>
+ </Style>
+ </Document>
+ * ------------------------------------------------
+ * <LatLonBox>
+ * <north>
+ * <south>
+ * <east>
+ * <west>
+ * ------------------------------------------------
+ * Example
+ * ------------------------------------------------
+ <Document>
+ <LatLonBox>
+ <north>48.25475939255556</north>
+ <south>48.25207367852141</south>
+ <east>-90.86591508839973</east>
+ <west>-90.8714285289695</west>
+ </LatLonBox>
+ </Document>
+ ------------------------------------------------
+ * <NetworkLink>
+ * <Link>
+ * <refreshMode>
+ * <refreshInterval>
+ * <viewRefreshTime>
+ * ------------------------------------------------
+ * Example
+ * ------------------------------------------------
+ <Document>
+ <NetworkLink>
+ <name>NE US Radar</name>
+ <Link>
+ <href>http://www.example.com/geotiff/NE/MergedReflectivityQComposite.kml</href>
+ <refreshMode>onInterval</refreshMode> // headers HTTP only compatible with mode "onExpire"
+ <refreshInterval>30</refreshInterval>
+ <viewRefreshMode>onStop</viewRefreshMode>
+ <viewRefreshTime>7</viewRefreshTime>
+ </Link>
+ </NetworkLink>
+ </Document>
+ * ------------------------------------------------
+ * <Polygon>
+ * <outerBoundaryIs>
+ * <LinearRing>
+ * <coordinates>
+ * <LineString>
+ * <coordinates>
+ * ------------------------------------------------
+ * Example
+ * ------------------------------------------------
+ <Placemark>
+ <Polygon>
+ <innerBoundaryIs> // only supported here
+ <LinearRing>
+ <coordinates>
+ -122.366212,37.818977,30
+ -122.365424,37.819294,30
+ </coordinates>
+ </LinearRing>
+ </innerBoundaryIs>
+ </Polygon>
+ </Placemark>
+ <Placemark>
+ <name>unextruded</name>
+ <LineString>
+ <coordinates>
+ -122.364383,37.824664,0 -122.364152,37.824322,0
+ </coordinates>
+ </LineString>
+ </Placemark>
+ ------------------------------------------------
+ * Other supported tags by Google Maps v3
+ * <range>
+ * <ScreenOverlay>
+ * <size>
+ * <Snippet>
+ * <value>
+ * <longitude>
+ * <open>
+ * <outline>
+ * <expires>
+ * <fill>
+ * <heading>
+ * <hotSpot>
+ * <latitude>
+ */
+class EGMapKMLFeed {
+ /**
+ *
+ * Holds all tags on the feed
+ * @var unknown_type
+ */
+ protected $elements;
+
+ const STYLE_ICON = 'Icon'; // when using addStyle Array it specifies is an IconStyle
+ const STYLE_LINE = 'Line'; // when using addStyle Array it specifies is an LineStyle
+ const STYLE_POLY = 'Poly'; // when using addStyle Array it specifies is an PolyStyle
+ /**
+ *
+ * constructor
+ */
+ function __construct(){
+ $this->elements = new CMap();
+ }
+ /**
+ *
+ * ATOM style author
+ * @param string $name
+ */
+ public function setAuthor( $name ){
+ if( null === $this->elements->itemAt('head') )
+ $this->elements->add('head', new CMap() );
+ $item = '<atom:author><atom:name>'.$name.'</atom:name></atom:author>';
+
+ $this->elements->itemAt('head')->add('author', $item);
+
+ }
+ /**
+ *
+ * ATOM style link
+ * @param string $url
+ */
+ public function setLink( $url ){
+ if( null === $this->elements->itemAt('head') )
+ $this->elements->add('head', new CMap() );
+ $validator = new CUrlValidator();
+ if(!$validator->validateValue($url))
+ throw new CException( Yii::t('EGMap', 'EGMapKMLFeed.setLink Url does not seem to valid') );
+ $item = '<atom:link href="'.$url.'" />';
+ $this->elements->itemAt('head')->add('link', $item);
+ }
+ /**
+ *
+ * Adding an externally created Tag at the end of its 'body' section
+ * Note: this method does not validates the tag
+ * @param EGMapKMLNode $tag
+ * @return string id of the inserted Tag
+ */
+ public function addTag( EGMapKMLNode $tag ){
+ if( null === $this->elements->itemAt('body') )
+ $this->elements->add('body', new CMap() );
+
+ $name = uniqid();
+
+ $this->elements->itemAt('body')->add(uniqid(), $tag->toXML());
+
+ return $name;
+ }
+ /**
+ *
+ * Removes inserted tag name from specific section
+ * sections can be head, body, styles, and placemark
+ * @param string $tagName to be removed
+ * @param string $section where to remove the tag
+ */
+ public function removeTag( $tagName, $section ){
+ foreach($this->elements as $map)
+ {
+ if($map->itemAt($section)){
+ $map->itemAt($section)->remove($tagName);
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ *
+ * This method is to add style tags as arrays
+ * the style nodes are represented as the following:
+ * <pre>
+ * // Icon
+ * $nodes = array( 'href'=>'http://url');
+ * // Line
+ * $nodes = array( 'color'=>'#FFAA00','width'=>2);
+ * // Polyline
+ * $nodes = array( 'color'=>'#FFAA00','colorMode'=>'random' );
+ * </pre>
+ * @param string $styleId id of the style
+ * @param string $styleType the type of the style
+ * @param array $nodes the tags to insert
+ */
+ public function addStyleArray( $styleId, $styleType = self::STYLE_ICON, $nodes = array() ){
+ $item = '<Style id="'.$styleId.'">';
+ switch ($styleType){
+ case self::STYLE_ICON:
+ case self::STYLE_LINE:
+ case self::STYLE_POLY:
+ $item .= CHtml::openTag($styleType.'Style');
+ break;
+ default:
+ throw new CException( Yii::t('EGMap','KML Style not supported') );
+ }
+ $item .= $this->batchNodeCreate($nodes);
+
+ $item .= CHtml::closeTag($styleType.'Style');
+ $item .= '</Style>';
+
+ if( null === $this->elements->itemAt('styles') )
+ $this->elements->add( 'styles', new CMap() );
+
+ $this->elements->itemAt('styles')->add( $styleId, $item );
+ }
+ /**
+ * Adds a placemark on array structure
+ * Example:
+ * <pre>
+ * $nodes = array(
+ * 'name'=>array('content'=>'testing'),
+ * 'description'=>array('content'=>'This marker has <b>HTML</b>'),
+ * 'styleUrl'=>array('content'=>'#style2'),
+ * 'Point'=>array('children'=>array(
+ * 'coordinates'=>array('content'=>'2.9087440013885635,39.719588117933185,0'))));
+ *
+ * $kml->addPlacemark($nodes);
+ * </pre>
+ * @param array $nodes the tags to insert
+ */
+ public function addPlacemarkArray( $nodes = array() ){
+ $item = '<Placemark>';
+
+ $item .= $this->batchNodeCreate($nodes);
+
+ $item .= '</Placemark>';
+
+ if( null === $this->elements->itemAt('body') )
+ $this->elements->add( 'body', new CMap() );
+
+ $name = uniqid();
+
+ $this->elements->itemAt('body')->add( $name, $item );
+
+ return $name;
+
+ }
+ /**
+ *
+ * Converts array given tags to its XML representation
+ * Note: It does not check for correct array structure
+ *
+ * @param array $tags
+ */
+ public function batchNodeCreate( $tags ){
+ $result = '';
+ if(is_array( $tags) ){
+ foreach($tags as $tag=>$el){
+ $result .= CHtml::openTag($tag, (isset($el['attributes']) && is_array($el['attributes'])? $el['attributes']:array()));
+ $result .= isset($el['content'])? ($tag=='description'? '<![CDATA['. $el['content'].']]>': $el['content']) : '';
+ $result .= isset($el['children']) && is_array($el['children'])? $this->batchNodeCreate($el['children']) : '';
+ $result .= CHtml::closeTag($tag);
+ }
+ }
+ return $result;
+ }
+ /**
+ *
+ * Generates the feed
+ */
+ public function generateFeed( ){
+ // you can choose between the both, as both of them work correctly
+ // Google Earth MIME/TYPE
+ // header('Content-type: application/vnd.google-earth.kml+xml');
+ header("Content-type: text/xml");
+
+ echo '<kml xmlns="http://earth.google.com/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">';
+ echo '<Document>';
+ $this->renderItems(array('head', 'body','styles','placemarks'));
+ echo '</Document>';
+ echo '</kml>';
+ }
+ /**
+ *
+ * Render tags by sections
+ * @param array | string sections to render $sections
+ */
+ public function renderItems( $sections ){
+
+ if(!is_array($sections)) $sections = array( $sections );
+
+ foreach( $sections as $section ){
+ if(null === $this->elements->itemAt($section)) continue;
+
+ foreach($this->elements->itemAt($section) as $tag)
+ echo $tag;
+ }
+ }
+}
diff --git a/protected/extensions/egmap/kml/EGMapKMLIconStyle.php b/protected/extensions/egmap/kml/EGMapKMLIconStyle.php
new file mode 100644
index 0000000..1ca1779
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLIconStyle.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ *
+ * EGMapKMLIconStyle Class
+ *
+ * KML Icon Style tag object
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLIconStyle extends EGMapKMLNode {
+ /**
+ *
+ * Style id
+ * @var string
+ */
+ public $id;
+ /**
+ *
+ * Url of the image
+ * Must be an absolute URL
+ * @var string
+ */
+ public $href;
+ /**
+ *
+ * Class constructor
+ * @param string $id style id
+ * @param string $iconId icon id
+ * @param string $href absolute URL of the image
+ */
+ public function __construct($id, $iconId = null, $href = null){
+
+ $this->tag = 'IconStyle';
+ $this->id = $id;
+ $this->tagId = $iconId;
+ $this->href = $href;
+ }
+ /**
+ * (non-PHPdoc)
+ * @see EGMapKMLNode::toXML()
+ */
+ public function toXML(){
+
+ $icon = new EGMapKMLNode('Icon');
+ if(!is_null($this->href))
+ $icon->addChild( new EGMapKMLNode('href', $this->href ) );
+ $this->addChild($icon);
+ $result = CHtml::openTag( 'Style', array( 'id'=>$this->id ) );
+ $result .= parent::toXML();
+ $result .= CHtml::closeTag('Style');
+
+ return $result;
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLLineString.php b/protected/extensions/egmap/kml/EGMapKMLLineString.php
new file mode 100644
index 0000000..79b8bd0
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLLineString.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ *
+ * EGMapKMLLineString Class
+ *
+ * KML LineString tag object
+ *
+ * Defines a connected set of line segments. Use <LineStyle> to specify the color, color mode, and width
+ * of the line. When a LineString is extruded, the line is extended to the ground, forming a polygon that
+ * looks somewhat like a wall or fence. For extruded LineStrings, the line itself uses the current LineStyle,
+ * and the extrusion uses the current PolyStyle.
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLLineString extends EGMapKMLNode{
+ /**
+ *
+ * Two or more coordinate tuples, each consisting of floating point values for longitude, latitude, and
+ * altitude. The altitude component is optional. Insert a space between tuples.
+ * Do not include spaces within a tuple.
+ * @var array
+ */
+ protected $coordinates = array();
+ /**
+ *
+ * Class constructor
+ * @param array $coordinates
+ */
+ public function __construct( $coordinates = array() ){
+ $this->tag = 'LineString';
+ if(is_array($coordinates)) $this->coordinates = $coordinates;
+ }
+ /**
+ *
+ * Adds a coordenate to the array
+ * @param float | numeric string $latitude
+ * @param float | numeric string $longitude
+ * @param float | numeric string $elevation
+ */
+ public function addCoordenate( $latitude, $longitude, $elevation ){
+ $this->coordinates[] = $longitude.','.$latitude.','.$elevation;
+ }
+ /**
+ *
+ * Adds array of coordenates
+ * @param array $coords
+ * @throws CException
+ */
+ public function addCoordenates( $coords ){
+ if(!is_array( $coords) )
+ throw new CException( Yii::t('EGMap','Coordinates parameter must be of type array and are required'));
+ foreach($coords as $coord){
+ $this->coordinates[] = $coord;
+ }
+ }
+ /**
+ * (non-PHPdoc)
+ * @see EGMapKMLNode::toXML()
+ */
+ public function toXML(){
+ $this->addChild(new EGMapKMLNode('altitudeMode','relative'));
+ $this->addChild( new EGMapKMLNode('coordinates', $this->coordinates) );
+ return parent::toXML();
+ }
+
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLLineStyle.php b/protected/extensions/egmap/kml/EGMapKMLLineStyle.php
new file mode 100644
index 0000000..3a6eae6
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLLineStyle.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ *
+ * EGMapKMLLineStyle Class
+ *
+ * KML LineStyle tag object
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLLineStyle extends EGMapKMLNode{
+ /**
+ *
+ * Style id
+ * @var string
+ */
+ public $id;
+ /**
+ *
+ * Color node
+ * Color and opacity (alpha) values are expressed in hexadecimal notation.
+ * The range of values for any one color is 0 to 255 (00 to ff). For alpha, 00 is fully transparent and ff is fully opaque.
+ * The order of expression is aabbggrr, where aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); rr=red (00 to ff).
+ * For example, if you want to apply a blue color with 50 percent opacity to an overlay, you would specify the following: <color>7fff0000</color>,
+ * where alpha=0x7f, blue=0xff, green=0x00, and red=0x00.
+ *
+ * @var string color
+ */
+ public $color;
+ /**
+ *
+ * Width of the line, in pixels.
+ * @var numeric string
+ */
+ public $width;
+ /**
+ *
+ * Class constructor
+ * @param string $id
+ * @param string $lineId
+ * @param string $color
+ * @param string $width
+ */
+ public function __construct($id, $lineId = null, $color = null, $width = null){
+
+ $this->tag = 'LineStyle';
+ $this->id = $id;
+ $this->tagId = $lineId;
+ $this->color = $color;
+ $this->width = $width;
+ }
+ /**
+ * (non-PHPdoc)
+ * @see EGMapKMLNode::toXML()
+ */
+ public function toXML(){
+
+ $this->checkNode( 'color' );
+ $this->checkNode( 'width' );
+
+ $result = CHtml::openTag( 'Style', array( 'id'=>$this->id ) );
+ $result .= parent::toXML();
+ $result .= CHtml::closeTag('Style');
+
+ return $result;
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLNode.php b/protected/extensions/egmap/kml/EGMapKMLNode.php
new file mode 100644
index 0000000..1013ff5
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLNode.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ *
+ * EGMapKMLNode Class
+ *
+ * KML node base class
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLNode {
+ /**
+ *
+ * Tag name
+ * @var string
+ */
+ public $tag;
+ /**
+ *
+ * Tag id
+ * @var string
+ */
+ public $tagId;
+ /**
+ *
+ * Tag content
+ * @var string
+ */
+ public $content;
+ /**
+ *
+ * Tag attributes
+ * @var array
+ */
+ public $attributes = array();
+ /**
+ *
+ * Child nodes collection
+ * @var array $nodes
+ */
+ protected $nodes = array(); // children
+ /**
+ *
+ * Class constructor
+ * @param string $tag name
+ * @param string $content
+ */
+ public function __construct($tag, $content = null){
+ $this->tag = $tag;
+ $this->content = $content;
+ }
+ /**
+ *
+ * Adds a child node to the tag
+ * @param EGMapKMLNode $node
+ */
+ public function addChild( EGMapKMLNode $node ){
+ $this->nodes[] = $node;
+ }
+ /**
+ *
+ * Clears all added children
+ */
+ public function clearChildren(){
+ $this->nodes = array();
+ }
+ /**
+ *
+ * @return well formatted XML KML tags
+ */
+ public function toXML(){
+ $result = '';
+
+ if (is_array($this->attributes))
+ $this->attributes['id'] = $this->tagId;
+ else $this->attributes = array();
+
+ $result .= CHtml::openTag($this->tag, (is_array($this->attributes)? $this->attributes:array()));
+ if(null !== $this->content && !empty($this->content))
+ {
+ if($this->tag === 'description'){
+ $result .= '<![CDATA['. $this->content.']]>';
+ }
+ else if(is_array($this->content)){
+ // arrays are separated by carriage return
+ // they can also be separated by spaces
+ $result .= implode(PHP_EOL, $this->content);
+ }
+ else
+ $result .= $this->content;
+ }
+ $result .= $this->renderChildren();
+ $result .= CHtml::closeTag($this->tag);
+
+ return $result;
+ }
+ /**
+ *
+ * Renders children tags
+ */
+ protected function renderChildren()
+ {
+ $children = '';
+ if( isset($this->nodes) && is_array($this->nodes) ){
+ foreach( $this->nodes as $node )
+ $children .= $node->toXML();
+ }
+ return $children;
+ }
+ /**
+ *
+ * Checks if a node name property has null value
+ * if not then create a node
+ * @param string $node
+ */
+ protected function checkNode( $node ){
+ if(!is_null($this->$node))
+ $this->nodes[] = new EGMapKMLNode($node, $this->$node);
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLPlacemark.php b/protected/extensions/egmap/kml/EGMapKMLPlacemark.php
new file mode 100644
index 0000000..300df14
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLPlacemark.php
@@ -0,0 +1,76 @@
+<?php
+/**
+ *
+ * EGMapKMLPlacemark Class
+ *
+ * KML Placemark tag object
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLPlacemark extends EGMapKMLNode {
+ /**
+ *
+ * Name node
+ * @var string
+ */
+ public $name;
+ /**
+ *
+ * Description node contents
+ * @var string
+ */
+ public $description;
+ /**
+ *
+ * styleUrl link (ie #styleID) content
+ * @var unknown_type
+ */
+ public $styleUrl;
+ /**
+ *
+ * Class constructor
+ * @param string $name
+ * @param string $description
+ * @param string $styleUrl
+ * @param string $nodes
+ */
+ public function __construct( $name, $description = null, $styleUrl = null, $nodes = array() ){
+ $this->tag = 'Placemark';
+ $this->name = $name;
+ $this->description = $description;
+ $this->styleUrl = $styleUrl;
+ $this->nodes = is_array($nodes)?$nodes:array();
+ }
+ /**
+ * (non-PHPdoc)
+ * @see EGMapKMLNode::toXML()
+ */
+ public function toXML(){
+
+ $this->checkNode( 'name' );
+ $this->checkNode( 'description' );
+ $this->checkNode( 'styleUrl' );
+
+ return parent::toXML();
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLPoint.php b/protected/extensions/egmap/kml/EGMapKMLPoint.php
new file mode 100644
index 0000000..5212f4d
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLPoint.php
@@ -0,0 +1,95 @@
+<?php
+/**
+ *
+ * EGMapKMLPoint Class
+ *
+ * KML Point tag object
+ *
+ * A geographic location defined by longitude, latitude, and (optional) altitude.
+ * When a Point is contained by a Placemark, the point itself determines the position
+ * of the Placemark's name and icon. When a Point is extruded, it is connected to the
+ * ground with a line. This "tether" uses the current LineStyle.
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLPoint extends EGMapKMLNode{
+ /**
+ *
+ * Latitude coord
+ * @var string
+ */
+ public $latitude;
+ /**
+ *
+ * Longitude coord
+ * @var string
+ */
+ public $longitude;
+ /**
+ *
+ * Elevation
+ * @var unknown_type
+ */
+ public $elevation;
+ /**
+ *
+ * Boolean value. Specifies whether to connect the point to the ground with a line. To extrude a Point,
+ * the value for <altitudeMode> must be either relativeToGround, relativeToSeaFloor, or absolute.
+ * The point is extruded toward the center of the Earth's sphere.
+ * Enter description here ...
+ * @var boolean
+ */
+ public $extrude;
+ /**
+ *
+ * Enter description here ...
+ * @param string $latitude
+ * @param string $longitude
+ * @param string $elevation
+ */
+ public function __construct($latitude, $longitude, $elevation = 0){
+ $this->tag = 'Point';
+ $this->latitude = $latitude;
+ $this->longitude = $longitude;
+ $this->elevation = $elevation;
+ }
+ /**
+ * (non-PHPdoc)
+ * @see EGMapKMLNode::toXML()
+ */
+ public function toXML(){
+ $this->checkNode('extrude');
+ /**
+ * coordinate
+ * A single tuple consisting of floating point values for longitude, latitude, and altitude (in that order).
+ * Longitude and latitude values are in degrees
+ * altitude values (optional) are in meters above sea level
+ * Do not include spaces between the three values that describe a coordinate.
+ */
+ if(!is_null($this->latitude) && !is_null($this->longitude))
+ $this->addChild(new EGMapKMLNode('coordinates', $this->longitude.','.$this->latitude.','.$this->elevation));
+
+
+ return parent::toXML();
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLPolyStyle.php b/protected/extensions/egmap/kml/EGMapKMLPolyStyle.php
new file mode 100644
index 0000000..63d4f0f
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLPolyStyle.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ *
+ * EGMapKMLPolyStyle Class
+ *
+ * KML PolyStyle tag object
+ *
+ * @see EGMapKMLStyle
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLPolyStyle extends EGMapKMLLineStyle {
+ /**
+ *
+ * Values for <colorMode> are normal (no effect) and random. A value of random applies a random linear scale to the base <color> as follows.
+ * To achieve a truly random selection of colors, specify a base <color> of white (ffffffff).
+ * If you specify a single color component (for example, a value of ff0000ff for red),
+ * random color values for that one component (red) will be selected. In this case,
+ * the values would range from 00 (black) to ff (full red). If you specify values for two or
+ * for all three color components, a random linear scale is applied to each color component,
+ * with results ranging from black to the maximum values specified for each component.
+ * The opacity of a color comes from the alpha component of <color> and is never randomized.
+ * @var string color Mode
+ */
+ public $colorMode;
+ /**
+ *
+ * Class Constructor
+ * @param string $id
+ * @param string $polyId
+ * @param string $color
+ * @param string $colorMode
+ */
+ public function __construct($id, $polyId = null, $color = null, $colorMode = null){
+ $this->tag = 'PolyStyle';
+ $this->id = $id;
+ $this->tagId = $polyId;
+ $this->color = $color;
+ $this->colorMode = $colorMode;
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/egmap/kml/EGMapKMLPolygon.php b/protected/extensions/egmap/kml/EGMapKMLPolygon.php
new file mode 100644
index 0000000..230dbb5
--- /dev/null
+++ b/protected/extensions/egmap/kml/EGMapKMLPolygon.php
@@ -0,0 +1,131 @@
+<?php
+/**
+ *
+ * EGMapKMLPolygon Class
+ *
+ * KML Polygon tag object
+ *
+ * A Polygon is defined by an outer boundary and 0 or more inner boundaries. The boundaries, in turn, are defined
+ * by LinearRings. When a Polygon is extruded, its boundaries are connected to the ground to form additional polygons,
+ * which gives the appearance of a building or a box. Extruded Polygons use <PolyStyle> for their color, color mode, and fill.
+ * The <coordinates> for polygons must be specified in counterclockwise order. Polygons follow the "right-hand rule,"
+ * which states that if you place the fingers of your right hand in the direction in which the coordinates are specified,
+ * your thumb points in the general direction of the geometric normal for the polygon.
+ *
+ *
+ * @author Antonio Ramirez Cobos
+ * @link www.ramirezcobos.com
+ *
+ *
+ * @copyright
+ *
+ * Copyright (c) 2010 Antonio Ramirez Cobos
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+class EGMapKMLPolygon extends EGMapKMLNode{
+ /**
+ * <Polygon>
+ * <innerBoundaryIs> // only supported here
+ * <LinearRing>
+ * <coordinates>
+ * -122.366212,37.818977,30
+ * -122.365424,37.819294,30
+ * </coordinates>
+ * </LinearRing>
+ * </innerBoundaryIs>
+ * </Polygon>
+ * Another way
+ * <MultiGeometry>
+ * <Polygon>
+ * <outerBoundaryIs>
+ * <LinearRing>
+ * <coordinates>-122.1,37.4,0 -122.0,37.4,0 -122.0,37.5,0 -122.1,37.5,0 -122.1,37.4,0</coordinates>
+ * </LinearRing>
+ * </outerBoundaryIs>
+ * </Polygon>
+ * </MultiGeometry>
+ *
+ * <outerBoundaryIs> (required)
+ * Contains a <LinearRing> element.
+ * <innerBoundaryIs>
+ * Contains a <LinearRing> element.
+ * A Polygon can contain multiple <innerBoundaryIs> elements,
+ * which create multiple cut-outs inside the Polygon.
+ */
+ /**
+ *
+ * Coordinates array
+ * @var array
+ */
+ protected $coordinates = array();
+ /**
+ *
+ * outerBoundaryIs = true
+ * innerBoundaryIs = false
+ * @var boolean
+ */
+ protected $boundary;
+
+ /**
+ *
+ * Enter description here ...
+ * @param boolean $outerBoundaryIs
+ * @param array $coordinates
+ */
+ public function __construct( $outerBoundaryIs = false, $coordinates = array() ){
+
+ $this->tag = 'Polygon';
+ $this->boundary = $outerBoundaryIs;
+ if(is_array($coordinates)) $this->coordinates = $coordinates;
+ }
+ /**
+ *
+ * Adds a coordenate to the array
+ * @param float | numeric string $latitude
+ * @param float | numeric string $longitude
+ * @param float | numeric string $elevation
+ */
+ public function addCoordenate( $latitude, $longitude, $elevation ){
+ $this->coordinates[] = $longitude.','.$latitude.','.$elevation;
+ }
+ /**
+ *
+ * Adds array of coordenates
+ * @param array $coords
+ * @throws CException
+ */
+ public function addCoordenates( $coords ){
+ if(!is_array( $coords) )
+ throw new CException( Yii::t('EGMap','Coordinates parameter must be of type array'));
+ foreach($coords as $coord){
+ $this->coordinates[] = $coord;
+ }
+ }
+ /**
+ * (non-PHPdoc)
+ * @see EGMapKMLNode::toXML()
+ */
+ public function toXML(){
+ $node = new EGMapKMLNode('LinearRing');
+ $node->addChild(new EGMapKMLNode('coordinates', $this->coordinates ));
+ $parentNode = new EGMapKMLNode(($this->boundary?'outerBoundaryIs':'innerBoundaryIs'));
+ $parentNode->addChild( $node );
+ $this->addChild( $parentNode );
+
+ return parent::toXML();
+ }
+
+} \ No newline at end of file