Skip to content

Commit 2eed7c3

Browse files
committed
Implementing balloon style and part of list style parsers
1 parent 3cfff7d commit 2eed7c3

7 files changed

Lines changed: 181 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace LibKml\Domain\FieldType;
4+
5+
class DisplayModeEnum {
6+
const NORMAL = 'normal';
7+
const RANDOM = 'random';
8+
}

src/Reader/Kml/SubStyle/BalloonStyleParser.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,34 @@
44

55
use LibKml\Domain\KmlObject;
66
use LibKml\Domain\SubStyle\BalloonStyle;
7+
use LibKml\Reader\Kml\FieldType\ColorParser;
78
use LibKml\Reader\Kml\KmlObjectParser;
9+
use SimpleXMLElement;
810

911
class BalloonStyleParser extends KmlObjectParser {
1012

1113
protected function buildKmlObject(): KmlObject {
1214
return new BalloonStyle();
1315
}
16+
17+
protected function loadValues(KmlObject &$kmlObject, SimpleXMLElement $element): void {
18+
parent::loadValues($kmlObject, $element);
19+
20+
if (isset($element->bgColor)) {
21+
$kmlObject->setBgColor(ColorParser::parse($element->bgColor));
22+
}
23+
24+
if (isset($element->textColor)) {
25+
$kmlObject->setTextColor(ColorParser::parse($element->textColor));
26+
}
27+
28+
if (isset($element->text)) {
29+
$kmlObject->setText($element->text);
30+
}
31+
32+
if (isset($element->displayMode)) {
33+
$kmlObject->setDisplayMode($element->displayMode);
34+
}
35+
}
36+
1437
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace LibKml\Reader\Kml\SubStyle\ColorStyle;
4+
5+
use LibKml\Domain\KmlObject;
6+
use LibKml\Reader\Kml\KmlObjectParser;
7+
use SimpleXMLElement;
8+
9+
abstract class ColorStyleParser extends KmlObjectParser {
10+
11+
protected function loadValues(KmlObject &$kmlObject, SimpleXMLElement $element): void {
12+
parent::loadValues($kmlObject, $element);
13+
14+
15+
}
16+
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace LibKml\Reader\Kml\SubStyle\ColorStyle;
4+
5+
use LibKml\Reader\Kml\FieldType\ColorParser;
6+
7+
class IconStyleParser extends ColorParser {
8+
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace LibKml\Reader\Kml\SubStyle;
4+
5+
use LibKml\Domain\KmlObject;
6+
use LibKml\Domain\SubStyle\ListStyle;
7+
use LibKml\Reader\Kml\KmlObjectParser;
8+
use SimpleXMLElement;
9+
10+
class ListStyleParser extends KmlObjectParser {
11+
12+
protected function buildKmlObject(): KmlObject {
13+
return new ListStyle();
14+
}
15+
16+
protected function loadValues(KmlObject &$kmlObject, SimpleXMLElement $element): void {
17+
parent::loadValues($kmlObject, $element);
18+
19+
if (isset($element->listItemType)) {
20+
$kmlObject->setListItemType($element->listItemType);
21+
}
22+
}
23+
24+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace LibKml\Tests\Reader\Kml\SubStyle;
4+
5+
use LibKml\Domain\FieldType\Color;
6+
use LibKml\Domain\FieldType\DisplayModeEnum;
7+
use LibKml\Domain\SubStyle\BalloonStyle;
8+
use LibKml\Reader\Kml\SubStyle\BalloonStyleParser;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class BalloonStyleParserTest extends TestCase {
12+
13+
const KML_BALLOON_STYLE = <<<'TAG'
14+
<BalloonStyle>
15+
<bgColor>ffffffbb</bgColor>
16+
<textColor>ff00aabb</textColor>
17+
<text>$[name]</text>
18+
<displayMode>random</displayMode>
19+
</BalloonStyle>
20+
TAG;
21+
22+
/**
23+
* @var BalloonStyleParser
24+
*/
25+
protected $balloonStyleParser;
26+
27+
protected $balloonStyleKmlElement;
28+
29+
/**
30+
* @var BalloonStyle
31+
*/
32+
protected $balloonStyle;
33+
34+
public function setUp() {
35+
$this->balloonStyleParser = new BalloonStyleParser();
36+
$this->balloonStyleKmlElement = simplexml_load_string(self::KML_BALLOON_STYLE);
37+
$this->balloonStyle = $this->balloonStyleParser->parse($this->balloonStyleKmlElement);
38+
}
39+
40+
public function testBgColor() {
41+
$color = Color::fromRGBA(0xbb, 0xff, 0xff, 1);
42+
43+
$this->assertEquals($color, $this->balloonStyle->getBgColor());
44+
}
45+
46+
public function testTextColor() {
47+
$color = Color::fromRGBA(0xbb, 0xaa, 0x00, 1);
48+
49+
$this->assertEquals($color, $this->balloonStyle->getTextColor());
50+
}
51+
52+
public function testText() {
53+
$this->assertEquals('$[name]', $this->balloonStyle->getText());
54+
}
55+
56+
public function testDisplayMode() {
57+
$this->assertEquals(DisplayModeEnum::RANDOM, $this->balloonStyle->getDisplayMode());
58+
}
59+
60+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace LibKml\Tests\Reader\Kml\SubStyle;
4+
5+
use LibKml\Domain\FieldType\ListItemType;
6+
use LibKml\Domain\SubStyle\ListStyle;
7+
use LibKml\Reader\Kml\SubStyle\ListStyleParser;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ListStyleParserTest extends TestCase {
11+
12+
const KML_BALLOON_STYLE = <<<'TAG'
13+
<ListStyle>
14+
<listItemType>radioFolder</listItemType>
15+
</ListStyle>
16+
TAG;
17+
18+
/**
19+
* @var ListStyleParser
20+
*/
21+
protected $listStyleParser;
22+
23+
protected $listStyleKmlElement;
24+
25+
/**
26+
* @var ListStyle
27+
*/
28+
protected $listStyle;
29+
30+
public function setUp() {
31+
$this->listStyleParser = new ListStyleParser();
32+
$this->listStyleKmlElement = simplexml_load_string(self::KML_BALLOON_STYLE);
33+
$this->listStyle = $this->listStyleParser->parse($this->listStyleKmlElement);
34+
}
35+
36+
public function testListItemType() {
37+
$this->assertEquals(ListItemType::RADIO_FOLDER, $this->listStyle->getListItemType());
38+
}
39+
40+
}

0 commit comments

Comments
 (0)