/* @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>
/** * @param int $margin * @param int $default * * @return int */ public function getMarkersFittingZoom($margin = 0, $default = 14) { $markers = $this->getMarkers(); $bounds = LatLngBounds::getBoundsOfMarkers($markers, $margin); return $bounds->getZoom(min($this->width, $this->height), $default); }
/** * 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(); }