/** * 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); }
/** * 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; }
/** * 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(); }