You are here

protected function GeofieldItem::populateComputedValues in Geofield 8

Populates computed variables.

1 call to GeofieldItem::populateComputedValues()
GeofieldItem::setValue in src/Plugin/Field/FieldType/GeofieldItem.php
Sets the data value.

File

src/Plugin/Field/FieldType/GeofieldItem.php, line 217

Class

GeofieldItem
Plugin implementation of the 'geofield' field type.

Namespace

Drupal\geofield\Plugin\Field\FieldType

Code

protected function populateComputedValues() {

  /* @var \Geometry $geom */
  $geom = \Drupal::service('geofield.geophp')
    ->load($this->value);
  if (!empty($geom) && !$geom
    ->isEmpty()) {

    /* @var \Point $centroid */
    $centroid = $geom
      ->getCentroid();
    $bounding = $geom
      ->getBBox();
    $this->geo_type = $geom
      ->geometryType();
    $this->lon = $centroid
      ->getX();
    $this->lat = $centroid
      ->getY();
    $this->left = $bounding['minx'];
    $this->top = $bounding['maxy'];
    $this->right = $bounding['maxx'];
    $this->bottom = $bounding['miny'];
    $this->geohash = substr($geom
      ->out('geohash'), 0, GEOFIELD_GEOHASH_LENGTH);
    $this->latlon = $centroid
      ->getY() . ',' . $centroid
      ->getX();
  }
}