You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7KB

  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC
  4. * @link http://2amigos.us
  5. * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  6. */
  7. namespace dosamigos\leaflet\layers;
  8. use dosamigos\leaflet\types\LatLngBounds;
  9. use yii\web\JsExpression;
  10. /**
  11. * ImageOverlay it is used to load and display a single image over specific bounds of the map
  12. *
  13. * @see http://leafletjs.com/reference.html#imageoverlay
  14. * @author Antonio Ramirez <amigo.cobos@gmail.com>
  15. * @link http://www.ramirezcobos.com/
  16. * @link http://www.2amigos.us/
  17. * @package extensions\leafletjs\layers
  18. */
  19. /**
  20. * @property string $name
  21. */
  22. class ImageOverlay extends Layer
  23. {
  24. /**
  25. * @var string the image Url
  26. */
  27. public $imageUrl;
  28. /**
  29. * @var LatLngBounds
  30. */
  31. private $_bounds;
  32. /**
  33. * @param LatLngBounds $bounds
  34. */
  35. public function setImageBounds(LatLngBounds $bounds)
  36. {
  37. $this->_bounds = $bounds;
  38. }
  39. /**
  40. * @return LatLngBounds
  41. */
  42. public function getImageBounds()
  43. {
  44. return $this->_bounds;
  45. }
  46. /**
  47. * Returns the javascript ready code for the object to render
  48. * @return \yii\web\JsExpression
  49. */
  50. public function encode()
  51. {
  52. $name = $this->name;
  53. $imageUrl = $this->imageUrl;
  54. $bounds = $this->getImageBounds()->encode();
  55. $options = $this->getOptions();
  56. $map = $this->map;
  57. $js = "L.imageOverlay('$imageUrl', $bounds, $options)" . ($map !== null ? ".addTo($map);" : "");
  58. if (!empty($name)) {
  59. $js = "var $name = $js" . ($map !== null ? "" : ";");
  60. }
  61. return new JsExpression($js);
  62. }
  63. }