diff --git a/Layout/default/ConstructionConsent/Form.php b/Layout/default/ConstructionConsent/Form.php
index 91b7cd7cf..e6e710ce3 100644
--- a/Layout/default/ConstructionConsent/Form.php
+++ b/Layout/default/ConstructionConsent/Form.php
@@ -153,26 +153,48 @@
-
+
-
-
- Vorschau:
-
-
![]()
+
+
+
+
-
-
+
+
+
+
+
+
+
+
![]()
file) ? "src=".$item->file->file->asDataUrl()."" : "" ?> />
+
+
+
+
+
@@ -272,8 +294,11 @@
var img_mimetype = plan_data.image_mimetype;
var img_base64 = plan_data.image_base64;
+ var file_id = plan_data.file_id;
$("#plan_preview").attr("src" ,"data:" + img_mimetype + ";base64," + img_base64);
+ $("#submit_plan_file_id").val(file_id);
+ $("#delete-rimo-plan").show();
} catch (error) {
console.log("Exception fetching plan preview:");
@@ -282,12 +307,27 @@
}
});
+
+ $("#consent_plan_image").change(() => {
+ var [file] = $("#consent_plan_image").prop("files");
+ if(file) {
+ $("#plan_preview").attr("src", URL.createObjectURL(file));
+ }
+ });
$("#constructionconsentproject_id").change(() => {
$("#adb_strasse_id").val("").change();
});
+ function deleteRimoPlan() {
+ $('#plan_adb_hausnummer_id').val("");
+ $("#submit_plan_file_id").val();
+ $("#plan_preview").attr("src", "");
+ $("#delete-rimo-plan").hide();
+
+ }
+
\ No newline at end of file
diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php
index e5cbf9873..f840c5328 100644
--- a/application/ConstructionConsent/ConstructionConsentController.php
+++ b/application/ConstructionConsent/ConstructionConsentController.php
@@ -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,
diff --git a/lib/Mapbox/StaticImageApi.php b/lib/Mapbox/StaticImageApi.php
index 1b7036a76..45fafe998 100644
--- a/lib/Mapbox/StaticImageApi.php
+++ b/lib/Mapbox/StaticImageApi.php
@@ -37,19 +37,60 @@ class Mapbox_StaticImageApi {
$path_fill_color = $paths["line_fill_color"];
$path_fill_opacity = $paths["line_fill_opacity"];
+ $path_count = 0;
+ $initial_path_count = 0;
foreach($paths["coords"] as $path) {
- if(!is_array($path)) {
- mfLoghandler::singleton()->debug("path not array: ".print_r($path, true));
+ $initial_path_count++;
+ //mfLoghandler::singleton()->debug(print_r($paths, true));
+
+ $skip_path = false;
+ // skip if coordinates are outside of 111 meters of middle point
+ // because mapbox only allows 100 paths max
+ foreach($path as $coords) {
+ $lat_less = $gps_lat;
+ $lat_more = $coords[0];
+ $long_less = $gps_long;
+ $long_more = $coords[1];
+
+ if($coords[0] < $gps_lat) {
+ $lat_less = $coords[0];
+ $lat_more = $gps_lat;
+ }
+ if($coords[1] < $gps_long) {
+ $long_less = $coords[1];
+ $long_more = $gps_long;
+ }
+
+ mfLoghandler::singleton()->debug(__METHOD__.": lat_more($lat_more) - lat_less($lat_less) = ".($lat_more - $lat_less));
+ mfLoghandler::singleton()->debug(__METHOD__.": long_more($long_more) - long_less($long_less) = ".($long_more - $long_less));
+
+ if($lat_more - $lat_less > 0.0005 || $long_more - $long_less > 0.0005) {
+ mfLoghandler::singleton()->debug(__METHOD__.": Skipping path");
+ $skip_path = true;
+ }
+
+ }
+ if($skip_path) continue;
+
+ if(!is_array($path) || !count($path)) {
+ mfLoghandler::singleton()->debug("path not array or empty: ".print_r($path, true));
continue;
}
- $path_enc_polyline = self::encodeCoordArrayToPolyline($path);
- if(!$path_enc_polyline) continue;
+ if($path_count > 99) break;
+ $path_count++;
- $path_parts[] = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity+$path_fill_color-$path_fill_opacity($path_enc_polyline)";
+ $path_enc_polyline = urlencode(self::encodeCoordArrayToPolyline($path));
+ //$path_enc_polyline = self::encodeCoordArrayToPolyline($path);
+ //if(!$path_enc_polyline) continue;
+ //$pp = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity+$path_fill_color-$path_fill_opacity($path_enc_polyline)"
+ $pp = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity($path_enc_polyline)";
+ $path_parts[] = $pp;
}
}
+ mfLoghandler::singleton()->debug(__METHOD__.": path count: $path_count | initial path count: $initial_path_count");
+
// build url
$url_opt_parts = [];
if($pin_part) $url_opt_parts[] = $pin_part;
@@ -64,7 +105,8 @@ class Mapbox_StaticImageApi {
$url .= "/".implode(",", $url_opt_parts);
}
- $url .= "/auto/{$size_x}x{$size_y}?access_token=$access_token";
+ $url .= "/$gps_long,$gps_lat,$zoom/{$size_x}x{$size_y}?access_token=$access_token";
+ //$url .= "/auto/{$size_x}x{$size_y}?access_token=$access_token";
mfLoghandler::singleton()->debug($url);
//exit;
@@ -78,6 +120,7 @@ class Mapbox_StaticImageApi {
$ctx = stream_context_create($ctx_opts);
$response = file_get_contents($url, false, $ctx);
+ //fLoghandler::singleton()->debug(print_r($response, true));
if($response === false) {
return null;
@@ -123,6 +166,7 @@ class Mapbox_StaticImageApi {
mfLoghandler::singleton()->debug(__METHOD__.": encoded polyline: $encodedString");
- return str_replace("?", "%3f", $encodedString);
+ //return str_replace("?", "%3f", $encodedString);
+ return $encodedString;
}
}
\ No newline at end of file
diff --git a/lib/Rimoapi/Rimoapi.php b/lib/Rimoapi/Rimoapi.php
index 847fcc99a..dafa4bf6a 100644
--- a/lib/Rimoapi/Rimoapi.php
+++ b/lib/Rimoapi/Rimoapi.php
@@ -430,5 +430,39 @@ class Rimoapi {
return $resp_data;
}
+ public static function getBuildingGeoJson($building_id) {
+ if(!$building_id) return false;
+
+ $log = mfLoghandler::singleton();
+
+ $params = [];
+ $params['apiKey'] = RIMO_API_JSON_APIKEY;
+ $params['buildingId'] = $building_id;
+
+ $ctx_opts = [
+ 'http' => [
+ 'method' => 'GET',
+ 'header' => 'accept: application/json'
+ ]
+ ];
+
+ $qs = http_build_query($params);
+
+ $getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_JSON_FOR_BUILDING;
+
+ $get_url = $getFileEp."?".$qs;
+ $ctx = stream_context_create($ctx_opts);
+ $log->debug(__METHOD__.": Getting GeoJson from Rimo: $get_url");
+ $response = file_get_contents($get_url, false, $ctx);
+
+ if($response === false) {
+ $log->error("Error retrieving GeoJson from RIMO for $building_id");
+ return false;
+ }
+
+ $resp_data = json_decode($response);
+ return $resp_data;
+ }
+
}
\ No newline at end of file