public static function GeolocationGeometryPolygon::generateSampleValue in Geolocation Field 8.3
Generates placeholder field values.
Useful when populating site with placeholder content during site building or profiling.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
Return value
array An associative array of values.
Overrides GeolocationGeometryBase::generateSampleValue
File
- modules/
geolocation_geometry/ src/ Plugin/ Field/ FieldType/ GeolocationGeometryPolygon.php, line 37
Class
- GeolocationGeometryPolygon
- Plugin implementation of the 'geolocation' field type.
Namespace
Drupal\geolocation_geometry\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$reference_point = self::getRandomCoordinates();
$coordinates = [];
for ($i = 1; $i <= 16; $i++) {
$coordinates[] = self::getRandomCoordinates($reference_point);
}
$center_point = self::getCenterFromCoordinates($coordinates);
usort($coordinates, function ($a, $b) use ($center_point) {
return self::sortCoordinatesByAngle($a, $b, $center_point);
});
// POLYGONS need to be closed.
$coordinates[] = $coordinates[0];
$values['geojson'] = '{
"type": "Polygon",
"coordinates": [
[';
foreach ($coordinates as $coordinate) {
$values['geojson'] .= '[' . $coordinate['longitude'] . ', ' . $coordinate['latitude'] . '],';
}
$values['geojson'] = rtrim($values['geojson'], ',');
$values['geojson'] .= ']]}';
return $values;
}