Skip to content

Commit 2a8b96c

Browse files
author
xavier
committed
Fix ListStyle issues
1 parent 07d1ad5 commit 2a8b96c

4 files changed

Lines changed: 57 additions & 22 deletions

File tree

libKML/KMLBuilder.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,12 @@ function buildListItemType($listItemTypeXMLObject) {
411411
function buildItemIcon($itemIconXMLObject) {
412412
$itemIcon = new ItemIcon();
413413

414-
$itemIconContent = $itemIconXMLObject->children();
415-
foreach($itemIconContent as $key => $value) {
414+
foreach($itemIconXMLObject as $key => $value) {
416415
if ($key == 'state') {
417-
416+
$itemIcon->setState(new ItemIconState((string)$value));
418417
} elseif ($key == 'href') {
419-
$itemIcon->setHref($value->__toString());
420-
}
418+
$itemIcon->setHref((string)$value);
419+
}
421420
}
422421

423422
return $itemIcon;
@@ -433,21 +432,10 @@ function buildListStyle($listStyleXMLObject) {
433432
$listStyle->setListItemType(buildListItemType($value));
434433
} elseif ($key == 'bgColor') {
435434
$listStyle->setBgColor($value->__toString());
436-
} elseif ($key == 'ItemIcon') {
437-
// foreach($value as $item) {
438-
// $listStyle->addItemIcon();
439-
// }
440-
$itemIcon = new ItemIcon();
441-
442-
if (isset($value->state)) {
443-
$itemIcon->setState((string)$value->state);
444-
}
445-
446-
if (isset($value->href)) {
447-
$itemIcon->setHref((string)$value->href);
448-
}
449-
450-
$listStyle->addItemIcon($itemIcon);
435+
} elseif ($key == 'ItemIcon') {
436+
$listStyle->addItemIcon(buildItemIcon($value));
437+
} elseif ($key == 'maxSnippetLines') {
438+
$listStyle->setMaxSnippetLines((string)$value);
451439
}
452440
}
453441

libKML/field_types/ItemIconState.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
namespace libKML;
23

34
/*
45
* To change this template, choose Tools | Templates
@@ -12,6 +13,36 @@
1213
*/
1314
class ItemIconState {
1415

16+
public static $ITEM_ICON_STATE_OPEN = 0;
17+
public static $ITEM_ICON_STATE_CLOSED = 1;
18+
public static $ITEM_ICON_STATE_ERROR = 2;
19+
public static $ITEM_ICON_STATE_FETCHING0 = 3;
20+
public static $ITEM_ICON_STATE_FETCHING1 = 4;
21+
public static $ITEM_ICON_STATE_FETCHING2 = 5;
22+
23+
public static $ITEM_ICON_STATE = array('open','closed','error','fetching0','fetching1','fetching2');
24+
25+
private $state = 0;
26+
27+
public function __construct($state) {
28+
$this->setStateFromString($state);
29+
}
30+
31+
public function setState($state) {
32+
$this->state = $state;
33+
}
34+
35+
public function getState() {
36+
return $this->state;
37+
}
38+
39+
public function setStateFromString($string) {
40+
$this->state = array_search($string, ItemIconState::$ITEM_ICON_STATE);
41+
}
42+
43+
public function __toString() {
44+
return (string) ItemIconState::$ITEM_ICON_STATE[$this->state];
45+
}
1546
}
1647

1748
?>

libKML/sub_styles/ItemIcon.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace libKML;
33

44
/**
5-
* Icon class
5+
* ItemIcon class
66
*/
77

88
class ItemIcon extends KMLObject {
@@ -13,7 +13,7 @@ class ItemIcon extends KMLObject {
1313
public function __toString() {
1414

1515
$output = array();
16-
16+
1717
$output[] = sprintf("<ItemIcon%s>",
1818
isset($this->id)?sprintf(" id=\"%s\"", $this->id):"");
1919

@@ -25,6 +25,8 @@ public function __toString() {
2525
$output[] = sprintf("\t<state>%s</state>", $this->state->__toString());
2626
}
2727

28+
$output[] = "</ItemIcon>";
29+
2830
return implode("\n", $output);
2931
}
3032

libKML/sub_styles/ListStyle.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class ListStyle extends SubStyle {
1010
private $listItemType;
1111
private $bgColor;
1212
private $itemIcons = array();
13+
private $maxSnippetLines;
14+
1315

1416
public function addItemIcon($itemIcon) {
1517
$this->itemIcons[] = $itemIcon;
@@ -33,6 +35,10 @@ public function __toString() {
3335
$output[] = sprintf("<bgColor>%s</bgColor>", $this->bgColor);
3436
}
3537

38+
if (isset($this->maxSnippetLines)) {
39+
$output[] = sprintf("<maxSnippetLines>%s</maxSnippetLines>", $this->maxSnippetLines);
40+
}
41+
3642
if (count($this->itemIcons)) {
3743
foreach($this->itemIcons as $itemIcon) {
3844
$output[] = $itemIcon->__toString();
@@ -68,5 +74,13 @@ public function setItemIcons($itemIcons) {
6874
$this->itemIcons = $itemIcons;
6975
}
7076

77+
public function setMaxSnippetLines($maxSnippetLines) {
78+
$this->maxSnippetLines = $maxSnippetLines;
79+
}
80+
81+
public function getMaxSnippetLines() {
82+
return $this->maxSnippetLines;
83+
}
84+
7185
}
7286
?>

0 commit comments

Comments
 (0)