diff --git a/src/Plugin/Field/FieldFormatter/LatLonFormatter.php b/src/Plugin/Field/FieldFormatter/LatLonFormatter.php index 3ef7b62..0c5412c 100644 --- a/src/Plugin/Field/FieldFormatter/LatLonFormatter.php +++ b/src/Plugin/Field/FieldFormatter/LatLonFormatter.php @@ -39,6 +39,7 @@ class LatLonFormatter extends GeofieldDefaultFormatter { 'decimal' => $this->t("Decimal Format (17.76972)"), 'dms' => $this->t("DMS Format (17° 46' 11'' N)"), 'dm' => $this->t("DM Format (17° 46.19214' N)"), + 'wkt' => $this->t("WKT"), ]; } @@ -85,7 +86,11 @@ class LatLonFormatter extends GeofieldDefaultFormatter { foreach ($items as $delta => $item) { $output = ['#markup' => '']; $geom = $this->geoPhpWrapper->load($item->value); - if ($geom && $geom->getGeomType() == 'Point') { + if ($geom) { + // If the geometry is not a point, get the centroid. + if ($geom->getGeomType() != 'Point') { + $geom = $geom->centroid(); + } /* @var \Point $geom */ if ($this->getOutputFormat() == 'decimal') { $output = [ @@ -94,6 +99,11 @@ class LatLonFormatter extends GeofieldDefaultFormatter { '#lon' => $geom->x(), ]; } + elseif ($this->getOutputFormat() == 'wkt') { + $output = [ + '#markup' => "POINT({$geom->x()} {$geom->y()})", + ]; + } else { $components = $this->getDmsComponents($geom); $output = [