Skip to content

Instantly share code, notes, and snippets.

@dib258
Created January 17, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dib258/9c18316846c1b91d04d081ff7e645ddf to your computer and use it in GitHub Desktop.
Save dib258/9c18316846c1b91d04d081ff7e645ddf to your computer and use it in GitHub Desktop.
Extract database to script node
<?php
protected function extractMarkerstoJson() {
$markersArray = [];
foreach($this->markers as $marker) {
$markerObject = new stdClass();
$markerObject->id = $marker->id;
$markerObject->type = $marker->type;
$markerObject->subtype = $marker->subtype;
$markerObject->coordinates = [];
foreach($marker->coordinates()->get() as $coordinate) {
$coordinateArray = [$coordinate->latitude, $coordinate->longitude];
$markerObject->coordinates[] = $coordinateArray;
}
$markersArray[] = $markerObject;
}
return json_encode($markersArray);
}
protected function extractPolygonsToJson() {
$polygonsArray = [];
foreach($this->polygons as $polygon) {
$polygonObject = new stdClass();
$polygonObject->id = $polygon->id;
$polygonObject->type = $polygon->type;
$polygonObject->subtype = $polygon->subtype;
$polygonObject->coordinates = [];
foreach($polygon->coordinates()->get() as $coordinate) {
$coordinateArray = [$coordinate->latitude, $coordinate->longitude];
$polygonObject->coordinates[] = $coordinateArray;
}
$polygonsArray[] = $polygonObject;
}
return json_encode($polygonsArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment