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.

54 lines
1.5KB

  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\LeafLet;
  9. use yii\helpers\Json;
  10. use yii\web\JsExpression;
  11. /**
  12. * Polygon is a class for drawing polygon overlays on a map
  13. *
  14. * @see http://leafletjs.com/reference.html#polygon
  15. * @author Antonio Ramirez <amigo.cobos@gmail.com>
  16. * @link http://www.ramirezcobos.com/
  17. * @link http://www.2amigos.us/
  18. * @package dosamigos\leaflet\layers
  19. */
  20. /**
  21. * @property string $name
  22. */
  23. class Polygon extends PolyLine
  24. {
  25. /**
  26. * @var bool whether to insert the layer at the bottom most position (z-index) on the map in reference to other
  27. * ui layers.
  28. */
  29. public $insertAtTheBottom = false;
  30. /**
  31. * Returns the javascript ready code for the object to render on the map.
  32. * To add a Polygon to the map, you need to use the special method [[LetLeaf::addPolygon]].
  33. * @return string
  34. */
  35. public function encode()
  36. {
  37. $latLngs = Json::encode($this->getLatLngstoArray(), LeafLet::JSON_OPTIONS);
  38. $options = $this->getOptions();
  39. $name = $this->name;
  40. $map = $this->map;
  41. $js = $this->bindPopupContent("L.polygon($latLngs, $options)") . ($map !== null ? ".addTo($map);" : "");
  42. if (!empty($name)) {
  43. $js = "var $name = $js" . ($map !== null ? "" : ";");
  44. }
  45. return new JsExpression($js);
  46. }
  47. }