/**
  * Returns the center of bounds of the
  * @return \dosamigos\google\maps\LatLng
  */
 public function getCenterOfBounds()
 {
     $path = ArrayHelper::getValue($this->options, 'path');
     return is_array($path) && !empty($path) ? LatLngBounds::getBoundsOfCoordinates($path)->getCenterCoordinates() : null;
 }
Example #2
0
 /**
  * @return LatLngBounds
  */
 public function getBoundsFromCenterAndZoom()
 {
     return LatLngBounds::getBoundsFromCenterAndZoom($this->center, $this->zoom, $this->width, $this->height);
 }
 /**
  * Returns the center of bounds
  * @return \dosamigos\google\maps\LatLng
  */
 public function getCenterOfBounds()
 {
     return LatLngBounds::getBoundsOfPolygons([$this])->getCenterCoordinates();
 }
 /**
  * Returns the boundaries of an array of Polygon objects
  * @param Polygon[] $polygons array of Polygons
  * @param float $margin margin factor for the bounds
  * @return LatLngBounds
  * @throws \yii\base\InvalidParamException
  */
 public static function getBoundsOfPolygons($polygons, $margin = 0.0)
 {
     $coords = [];
     /** @var Polygon $polygon */
     foreach ($polygons as $polygon) {
         if (!$polygon instanceof Polygon) {
             throw new InvalidParamException('"$polygons" must be an array of "' . Polygon::className() . '" objects');
         }
         // merge LatLng arrays
         $coords = ArrayHelper::merge($coords, $polygon->paths);
     }
     return LatLngBounds::getBoundsOfCoordinates($coords, $margin);
 }
Example #5
0
/* @var $locations common\models\Location[] */
/* @var $tickets [][] */
$this->title = 'Ticket Map';
$this->params['breadcrumbs'][] = ['label' => 'Tickets', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$markers = [];
foreach ($locations as $location) {
    $marker = new Marker(['title' => $location->fullName, 'position' => new LatLng(['lat' => $location->lat, 'lng' => $location->lng])]);
    $content = '<h4>' . Html::a($location->fullName, ['/location/view', 'id' => $location->id]) . '</h4><hr>';
    foreach ($tickets[$location->id] as $id => $title) {
        $content .= Html::a($title, ['view', 'id' => $id], ['class' => 'showModalButton']) . '<br>';
    }
    $marker->attachInfoWindow(new InfoWindow(['content' => $content]));
    $markers[] = $marker;
}
$bounds = LatLngBounds::getBoundsOfMarkers($markers);
$map = new Map(['center' => $bounds->getCenterCoordinates(), 'zoom' => $bounds->getZoom(250), 'width' => '100%', 'height' => '100%']);
foreach ($markers as $marker) {
    $map->addOverlay($marker);
}
?>

<div class="ticket-map">
    <p class="pull-right">
        <?php 
echo Html::a('<span class="glyphicon glyphicon-list"></span> List', ['index'], ['class' => 'btn btn-default btn-xs']);
?>
        <?php 
echo Html::a('<span class="glyphicon glyphicon-plus"></span> New Ticket', ['create'], ['class' => 'btn btn-success btn-xs showModalButton']);
?>
    </p>
 /**
  * Calculates the center of an array of coordinates according to its bounds
  *
  * @param LatLng[] $coords
  *
  * @return LatLng
  */
 public static function getCenterOfBounds($coords)
 {
     $bounds = LatLngBounds::getBoundsOfCoordinates($coords);
     return $bounds->getCenterCoordinates();
 }
 /**
  * Returns the center coordinates of the boundaries of an array of Markers
  *
  * @param Marker[] $markers
  *
  * @return LatLng
  */
 public static function getCenterCoordinates($markers)
 {
     $bounds = LatLngBounds::getBoundsOfMarkers($markers);
     return $bounds->getCenterCoordinates();
 }