ConstructionConsent: Plan from Mapbox with Rimo coords

This commit is contained in:
Frank Schubert
2025-01-20 13:59:22 +01:00
parent 27cc45e23c
commit 269456eed6
4 changed files with 207 additions and 26 deletions
@@ -247,24 +247,32 @@ class ConstructionConsentController extends mfBaseController {
return $this->editAction();
}
} else {
if($r->submit_plan_file_id) {
$file = new File($r->submit_plan_file_id);
}
}
if($file && $file->id) {
$ccf = ConstructionConsentFile::create([
'constructionconsent_id' => $id,
'file_id' => $file->id,
'filename' => "zustimmungserklärung-".$item->id."-plan.png",
'filename' => "zustimmungserklärung-" . $item->id . "-plan.png",
]);
// delete previous image
$img = ConstructionConsentFile::getFirst(["constructionconsent_id" => $id]);
if($img) {
if ($img) {
$img->file->delete();
$img->delete();
}
if(!$ccf->save()) {
$this->layout()->setFlash("Fehler beim Hochladen", "warning");
if (!$ccf->save()) {
$this->layout()->setFlash("Fehler beim Speichern des Plans", "warning");
}
}
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gespeichert", "success");
$this->redirect("ConstructionConsent", "View", ["id" => $id]);
@@ -571,11 +579,66 @@ class ConstructionConsentController extends mfBaseController {
$filename = "consent_plan_map_h{$adb_hausnummer_id}";
$bpi_file = PreorderFile::getFirst(["preorder_id" => $this->id, "filename" => $filename]);
/*$bpi_file = PreorderFile::getFirst(["preorder_id" => $this->id, "filename" => $filename]);
if($bpi_file) {
return $bpi_file;
}
}*/
// get trenches from rimo
$geodataResponse = Rimoapi::getBuildingGeoJson($hausnummer->rimo_id);
$this->log->debug(__METHOD__.": ".print_r($geodataResponse, true));
//return false;
if (is_object($geodataResponse)) {
if (property_exists($geodataResponse, "homeSection")) {
if (property_exists($geodataResponse->homeSection, "features") && is_array($geodataResponse->homeSection->features)) {
foreach ($geodataResponse->homeSection->features as $feature) {
$home_trench = [];
foreach ($feature->geometry->coordinates as $coords) {
$long = $coords[0];
$lat = $coords[1];
$home_trench[] = [$lat, $long];
}
if ($hausnummer->home_trench != $home_trench) {
$hausnummer->home_trench = json_encode($home_trench);
$hausnummer->save();
}
}
}
}
if (property_exists($geodataResponse, "borderPoint")) {
if (property_exists($geodataResponse->borderPoint, "features") && is_array($geodataResponse->borderPoint->features)) {
foreach ($geodataResponse->borderPoint->features as $feature) {
$coords = $feature->geometry->coordinates;
$long = $coords[0];
$lat = $coords[1];
if ($hausnummer->borderpoint_lat != $lat || $hausnummer->borderpoint_long != $long) {
$hausnummer->borderpoint_lat = $lat;
$hausnummer->borderpoint_long = $long;
$hausnummer->save();
}
}
}
}
if (property_exists($geodataResponse, "trenches") && $geodataResponse->trenches->features) {
$trenches = [];
foreach ($geodataResponse->trenches->features as $feature) {
$feature_coords = [];
foreach ($feature->geometry->coordinates as $coords) {
$long = $coords[0];
$lat = $coords[1];
$feature_coords[] = [$lat, $long];
}
$trenches[] = $feature_coords;
}
if (count($trenches)) {
$hausnummer->trenches = json_encode($trenches);
$hausnummer->save();
}
}
}
// get new Borderpoint Image from Mapbox API
$params = [
@@ -631,7 +694,7 @@ class ConstructionConsentController extends mfBaseController {
$file->mimetype = $file->getMimetype();
$file->save();
return ["image_mimetype" => $file->mimetype, "image_base64" => base64_encode($image_content)];
return ["image_mimetype" => $file->mimetype, "image_base64" => base64_encode($image_content), "file_id" => $file->id];
/*$pf = PreorderFile::create([
"preorder_id" => $this->id,