I am trying to output, from a single request, a geojson structure like so:
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-1.102108, 52.671813],
[-1.142189,52.620366]
],
[
[-1.102108, 52.671813],
[-1.447277, 52.939653]
],
[
[-1.102108, 52.671813],
[-1.447277, 52.914816]
],
[
[-1.102108, 52.671813],
[-1.884783, 52.509112]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [
[-1.102108, 52.671813],
[-1.142189, 52.620366],
[-1.447277, 52.939653],
[-1.447277, 52.914816],
[-1.884783, 52.509112]
]
}
}
]
I have the multilinestring part sorted, and i know how to get the data for the multipoint part, bit i cant find a way, from the single elements api endpoint, how to add the multipoint feature onto the end of the returned array / json.
Here is my elements api endpoint :
'geojson' => function() {
function getCoordinates(UserModel $user){
$return = array();
foreach ($user->connections as $connection) {
$return[] = array(array($user->longitude,$user->latitude),array($connection->longitude,$connection->latitude));
}
return $return;
}
return [
'elementType' => ElementType::User,
'paginate' => false,
'transformer' => function(UserModel $user) {
return [
"type" => "Feature",
"geometry" => array("type" => "MultiLineString", "coordinates" => getCoordinates($user)),
"properties" => array("name" => "Test")
];
},
];
},
I know i can probably do this using two requests, but i want to do it in one.