PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/WV15/InfoWindow.php

https://bitbucket.org/webvariants/wvmaps
PHP | 127 lines | 83 code | 26 blank | 18 comment | 9 complexity | d27c5920ab3efd1260a4b2a25c270e6d MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
  4. *
  5. * This file is released under the terms of the MIT license. You can find the
  6. * complete text in the attached LICENSE file or online at:
  7. *
  8. * http://www.opensource.org/licenses/mit-license.php
  9. */
  10. class WV15_InfoWindow {
  11. const DEFAULT_WINDOW = 'DEFAULT_WINDOW';
  12. const CUSTOM_WINDOW = 'CUSTOM_WINDOW';
  13. private $content; ///< string
  14. private $disableAutoPan; ///< boolean - optional
  15. private $maxWidth; ///< integer - optional
  16. private $pixelOffset; ///< WV15_Size - optional
  17. private $position; ///< WV15_LatLng - optional
  18. private $zIndex; ///< integer - optional
  19. private $hideAnchorOnOpen; ///< boolean - optional
  20. private $showOnLoad; ///< boolean - optional
  21. private $id; ///< string - optional
  22. private $type; ///< string
  23. public function __construct($content, $type = self::DEFAULT_WINDOW) {
  24. $this->setContent($content);
  25. $this->setType($type);
  26. $this->disableAutoPan = false;
  27. $this->maxWidth = null;
  28. $this->pixelOffset = null;
  29. $this->position = null;
  30. $this->zIndex = null;
  31. $this->id = md5($content.mt_rand(0, 1000));
  32. $this->hideAnchorOnOpen = false;
  33. $this->showOnLoad = false;
  34. }
  35. public function setContent($content) {
  36. $this->content = $content;
  37. }
  38. public function setDisableAutoPan($value) {
  39. $this->disableAutoPan = (boolean) $value;
  40. }
  41. public function setMaxWidth($maxWidth) {
  42. $this->maxWidth = (int) $maxWidth;
  43. }
  44. /**
  45. * set the offset of the window
  46. *
  47. * @param WV15_Size $pixelOffset
  48. */
  49. public function setPixelOffset(WV15_Size $pixelOffset) {
  50. $this->pixelOffset = $pixelOffset;
  51. }
  52. /**
  53. * set the geo position of the infowindow
  54. *
  55. * @param WV15_LatLng $positon
  56. */
  57. public function setPosition(WV15_LatLng $positon) {
  58. $this->position = $positon;
  59. }
  60. public function setZIndex($zIndex) {
  61. $this->zIndex = (int) $zIndex;
  62. }
  63. public function setType($type) {
  64. if ($type != self::DEFAULT_WINDOW && $type != self::CUSTOM_WINDOW) {
  65. throw new Exception('WV_Infowindow: Type '.$type.' is not valid.');
  66. }
  67. $this->type = $type;
  68. }
  69. public function setHideAnchorOnOpen($value) {
  70. $this->hideAnchorOnOpen = (boolean) $value;
  71. }
  72. public function setShowOnLoad($value) {
  73. $this->showOnLoad = (boolean) $value;
  74. }
  75. public function getId() {
  76. return $this->id;
  77. }
  78. public function __toString() {
  79. $base = array(
  80. 'hideAnchorOnOpen' => $this->hideAnchorOnOpen,
  81. 'showOnLoad' => $this->showOnLoad,
  82. 'id' => $this->id,
  83. 'type' => $this->type
  84. );
  85. $options = array(
  86. 'content' => $this->content,
  87. );
  88. if ($this->disableAutoPan) $options['disableAutoPan'] = true;
  89. if ($this->maxWidth) $options['maxWidth'] = $this->maxWidth;
  90. if ($this->zIndex) $options['zIndex'] = $this->zIndex;
  91. $options = json_encode($options);
  92. $options = substr($options, 0, -1);
  93. if ($this->pixelOffset) $options .= ',"pixelOffset":'.$this->pixelOffset;
  94. if ($this->position) $options .= ',"position":'.$this->position;
  95. $options .= '}';
  96. $base = json_encode($base);
  97. $base = substr($base, 0, -1);
  98. $base .= ',"options":'.$options;
  99. return $base.'}';
  100. }
  101. }