trait GeometryBoundaryTrait in Geolocation Field 8.3
Trait Geometry Boundary.
Hierarchy
- trait \Drupal\geolocation_geometry\GeometryBoundaryTrait
2 files declare their use of GeometryBoundaryTrait
- GeoBoundaryArgument.php in modules/
geolocation_geometry/ src/ Plugin/ views/ argument/ GeoBoundaryArgument.php - GeoBoundaryFilter.php in modules/
geolocation_geometry/ src/ Plugin/ views/ filter/ GeoBoundaryFilter.php
File
- modules/
geolocation_geometry/ src/ GeometryBoundaryTrait.php, line 8
Namespace
Drupal\geolocation_geometryView source
trait GeometryBoundaryTrait {
/**
* Gets the query fragment for adding a boundary field to a query.
*
* @param string $table_name
* The proximity table name.
* @param string $field_id
* The proximity field ID.
* @param string $placeholder
* Placeholder SQL.
*
* @return string
* The fragment to enter to actual query.
*/
public static function getGeometryBoundaryQueryFragment(string $table_name, string $field_id, string $placeholder) : string {
// Define the field name.
$field_point = "{$table_name}.{$field_id}_geometry";
/*
* Google Maps shows a map, not a globe. Therefore it will never flip over
* the poles, but it will move across -180°/+180° longitude.
* So latitude will always have north larger than south, but east not
* necessarily larger than west.
*/
return 'ST_Contains(
ST_GeomFromGeoJSON(' . $placeholder . '),
' . $field_point . '
)';
}
/**
* Gets the value placeholder.
*
* @param string $placeholder
* SQL placeholder.
* @param string|float $filter_lat_north_east
* The latitude to filter for.
* @param string|float $filter_lng_north_east
* The longitude to filter for.
* @param string|float $filter_lat_south_west
* The latitude to filter for.
* @param string|float $filter_lng_south_west
* The longitude to filter for.
*
* @return array
* Placeholder array.
*/
public static function getGeometryBoundaryQueryValue(string $placeholder, $filter_lat_north_east, $filter_lng_north_east, $filter_lat_south_west, $filter_lng_south_west) : array {
return [
$placeholder => '{"type": "Polygon","coordinates": [[
[' . $filter_lng_south_west . ', ' . $filter_lat_south_west . '],
[' . $filter_lng_north_east . ', ' . $filter_lat_south_west . '],
[' . $filter_lng_north_east . ', ' . $filter_lat_north_east . '],
[' . $filter_lng_south_west . ', ' . $filter_lat_north_east . '],
[' . $filter_lng_south_west . ', ' . $filter_lat_south_west . ']
]]}',
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GeometryBoundaryTrait:: |
public static | function | Gets the query fragment for adding a boundary field to a query. | |
GeometryBoundaryTrait:: |
public static | function | Gets the value placeholder. |