ViewsBoundaryArgument.php in Geolocation Field 8.2
File
src/Plugin/geolocation/Location/ViewsBoundaryArgument.php
View source
<?php
namespace Drupal\geolocation\Plugin\geolocation\Location;
use Drupal\geolocation\LocationInterface;
use Drupal\geolocation\LocationBase;
use Drupal\geolocation\ViewsContextTrait;
class ViewsBoundaryArgument extends LocationBase implements LocationInterface {
use ViewsContextTrait;
public function getAvailableLocationOptions($context) {
$options = [];
if ($displayHandler = self::getViewsDisplayHandler($context)) {
foreach ($displayHandler
->getHandlers('argument') as $delta => $argument) {
if ($argument
->getPluginId() === 'geolocation_argument_boundary') {
$options[$delta] = $argument
->adminLabel();
}
}
}
return $options;
}
public function getCoordinates($location_option_id, array $location_option_settings, $context = NULL) {
if ($displayHandler = self::getViewsDisplayHandler($context)) {
$argument = $displayHandler
->getHandler('argument', $location_option_id);
if (empty($argument)) {
return FALSE;
}
$values = $argument
->getParsedBoundary();
$latitude = ($values['lat_south_west'] + $values['lat_north_east']) / 2;
$longitude = ($values['lng_south_west'] + $values['lng_north_east']) / 2;
if ($values['lng_south_west'] > $values['lng_north_east']) {
$longitude = $longitude == 0 ? 180 : fmod(fmod($longitude + 180 - -180, 360) + 360, 360) + -180;
}
return [
'lat' => $latitude,
'lng' => $longitude,
];
}
return parent::getCoordinates($location_option_id, $location_option_settings, $context);
}
}