ConstructionConsent: Plan from Mapbox with Rimo coords
This commit is contained in:
@@ -153,26 +153,48 @@
|
||||
|
||||
<hr />
|
||||
|
||||
<h4>Planskizze / Bilddatei</h4>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label">Planskizze / Bilddatei</label>
|
||||
<label class="col-lg-2 col-form-label"></label>
|
||||
<div class="col-lg-10">
|
||||
<label for="plan_adb_hausnummer_id">Plan aus Rimo holen</label>
|
||||
<select class="form-control" name="plan_adb_hausnummer_id" id="plan_adb_hausnummer_id">
|
||||
<?php if(isset($item) && $item->plan_adb_hausnummer_id): ?>
|
||||
<option value="<?=$item->plan_adb_hausnummer_id?>" selected="selected"><?=$item->plan_adb_hausnummer->street->name?> <?=$item->plan_adb_hausnummer->hausnummer?>, <?=$item->plan_adb_hausnummer->street->gemeinde->name?></option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
Vorschau:
|
||||
<div class="card">
|
||||
<div class="card-body" id="rimo-plan-container">
|
||||
<img id="plan_preview" style="max-width: 1200px;" />
|
||||
<h5 class="card-header">Plan aus Rimo laden</h5>
|
||||
<div class="card-body">
|
||||
|
||||
<select class="form-control" name="plan_adb_hausnummer_id" id="plan_adb_hausnummer_id">
|
||||
<?php if(isset($item) && $item->plan_adb_hausnummer_id): ?>
|
||||
<option value="<?=$item->plan_adb_hausnummer_id?>" selected="selected"><?=$item->plan_adb_hausnummer->street->name?> <?=$item->plan_adb_hausnummer->hausnummer?>, <?=$item->plan_adb_hausnummer->street->gemeinde->name?></option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<label>Oder Plan hochladen</label>
|
||||
<input type="file" class="form-control" name="consent_plan_image" id="consent_plan_image" />
|
||||
<div class="card">
|
||||
<h5 class="card-header">Oder Plan hochladen</h5>
|
||||
<div class="card-body">
|
||||
<input type="file" class="form-control" name="consent_plan_image" id="consent_plan_image" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<h5 class="card-header">Plan Vorschau</h5>
|
||||
<div class="card-body" id="rimo-plan-container">
|
||||
<input type="hidden" name="submit_plan_file_id" id="submit_plan_file_id" value="" />
|
||||
<img id="plan_preview" style="max-width: 1200px;" <?=($item->file) ? "src=".$item->file->file->asDataUrl()."" : "" ?> />
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
<button type="button" class="btn btn-outline-danger hidden" id="delete-rimo-plan" onclick="deleteRimoPlan()">
|
||||
<i class="far fa-fw fa-trash-alt"></i> Plan löschen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user