You are here

public function IpGeoLocPluginStyleLeaflet::getCenter in IP Geolocation Views & Maps 8

Get the center of a lat/lon pair.

1 call to IpGeoLocPluginStyleLeaflet::getCenter()
IpGeoLocPluginStyleLeaflet::render in src/Plugin/views/style/IpGeoLocPluginStyleLeaflet.php
Transform the View result in a list of marker locations and render on map.

File

src/Plugin/views/style/IpGeoLocPluginStyleLeaflet.php, line 1271

Class

IpGeoLocPluginStyleLeaflet
Views Style plugin extension for Leaflet (if enabled).

Namespace

Drupal\ip_geoloc\Plugin\views\style

Code

public function getCenter($location) {
  if (empty($location->type) || $location->type == 'point') {
    $lat = isset($location->lat) ? $location->lat : (isset($location->latitude) ? $location->latitude : 0.0);
    $lon = isset($location->lon) ? $location->lon : (isset($location->longitude) ? $location->longitude : 0.0);
    return [
      'lat' => $lat,
      'lon' => $lon,
    ];
  }
  if (!empty($location->component[0]['points'][0])) {
    return $location->component[0]['points'][0];
  }
}