/lib/WV15/InfoWindow.php
PHP | 127 lines | 83 code | 26 blank | 18 comment | 9 complexity | d27c5920ab3efd1260a4b2a25c270e6d MD5 | raw file
- <?php
- /*
- * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
- *
- * This file is released under the terms of the MIT license. You can find the
- * complete text in the attached LICENSE file or online at:
- *
- * http://www.opensource.org/licenses/mit-license.php
- */
- class WV15_InfoWindow {
- const DEFAULT_WINDOW = 'DEFAULT_WINDOW';
- const CUSTOM_WINDOW = 'CUSTOM_WINDOW';
- private $content; ///< string
- private $disableAutoPan; ///< boolean - optional
- private $maxWidth; ///< integer - optional
- private $pixelOffset; ///< WV15_Size - optional
- private $position; ///< WV15_LatLng - optional
- private $zIndex; ///< integer - optional
- private $hideAnchorOnOpen; ///< boolean - optional
- private $showOnLoad; ///< boolean - optional
- private $id; ///< string - optional
- private $type; ///< string
- public function __construct($content, $type = self::DEFAULT_WINDOW) {
- $this->setContent($content);
- $this->setType($type);
- $this->disableAutoPan = false;
- $this->maxWidth = null;
- $this->pixelOffset = null;
- $this->position = null;
- $this->zIndex = null;
- $this->id = md5($content.mt_rand(0, 1000));
- $this->hideAnchorOnOpen = false;
- $this->showOnLoad = false;
- }
- public function setContent($content) {
- $this->content = $content;
- }
- public function setDisableAutoPan($value) {
- $this->disableAutoPan = (boolean) $value;
- }
- public function setMaxWidth($maxWidth) {
- $this->maxWidth = (int) $maxWidth;
- }
- /**
- * set the offset of the window
- *
- * @param WV15_Size $pixelOffset
- */
- public function setPixelOffset(WV15_Size $pixelOffset) {
- $this->pixelOffset = $pixelOffset;
- }
- /**
- * set the geo position of the infowindow
- *
- * @param WV15_LatLng $positon
- */
- public function setPosition(WV15_LatLng $positon) {
- $this->position = $positon;
- }
- public function setZIndex($zIndex) {
- $this->zIndex = (int) $zIndex;
- }
- public function setType($type) {
- if ($type != self::DEFAULT_WINDOW && $type != self::CUSTOM_WINDOW) {
- throw new Exception('WV_Infowindow: Type '.$type.' is not valid.');
- }
- $this->type = $type;
- }
- public function setHideAnchorOnOpen($value) {
- $this->hideAnchorOnOpen = (boolean) $value;
- }
- public function setShowOnLoad($value) {
- $this->showOnLoad = (boolean) $value;
- }
- public function getId() {
- return $this->id;
- }
- public function __toString() {
- $base = array(
- 'hideAnchorOnOpen' => $this->hideAnchorOnOpen,
- 'showOnLoad' => $this->showOnLoad,
- 'id' => $this->id,
- 'type' => $this->type
- );
- $options = array(
- 'content' => $this->content,
- );
- if ($this->disableAutoPan) $options['disableAutoPan'] = true;
- if ($this->maxWidth) $options['maxWidth'] = $this->maxWidth;
- if ($this->zIndex) $options['zIndex'] = $this->zIndex;
- $options = json_encode($options);
- $options = substr($options, 0, -1);
- if ($this->pixelOffset) $options .= ',"pixelOffset":'.$this->pixelOffset;
- if ($this->position) $options .= ',"position":'.$this->position;
- $options .= '}';
- $base = json_encode($base);
- $base = substr($base, 0, -1);
- $base .= ',"options":'.$options;
- return $base.'}';
- }
- }