Merge #17049 - Fix gis visualization save file

Pull-request: #17049

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-08-10 15:02:38 +02:00
commit 6c2083e207
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
7 changed files with 63 additions and 51 deletions

View File

@ -88,8 +88,11 @@ final class GisVisualizationController extends AbstractController
// Get settings if any posted // Get settings if any posted
$visualizationSettings = []; $visualizationSettings = [];
// Download as PNG/SVG/PDF use _GET and the normal form uses _POST
if (Core::isValid($_POST['visualizationSettings'], 'array')) { if (Core::isValid($_POST['visualizationSettings'], 'array')) {
$visualizationSettings = $_POST['visualizationSettings']; $visualizationSettings = $_POST['visualizationSettings'];
} elseif (Core::isValid($_GET['visualizationSettings'], 'array')) {
$visualizationSettings = $_GET['visualizationSettings'];
} }
// Check mysql version // Check mysql version
@ -174,6 +177,8 @@ final class GisVisualizationController extends AbstractController
'saveToFile' => true, 'saveToFile' => true,
'session_max_rows' => $rows, 'session_max_rows' => $rows,
'pos' => $pos, 'pos' => $pos,
'visualizationSettings[spatialColumn]' => $visualizationSettings['spatialColumn'],
'visualizationSettings[labelColumn]' => $visualizationSettings['labelColumn'],
] ]
)); ));
$html = $this->template->render('table/gis_visualization/gis_visualization', [ $html = $this->template->render('table/gis_visualization/gis_visualization', [

View File

@ -16,6 +16,7 @@ use function imagestring;
use function json_encode; use function json_encode;
use function mb_strlen; use function mb_strlen;
use function mb_substr; use function mb_substr;
use function round;
use function trim; use function trim;
/** /**
@ -110,28 +111,26 @@ class GisLineString extends GisGeometry
$points_arr = $this->extractPoints($linesrting, $scale_data); $points_arr = $this->extractPoints($linesrting, $scale_data);
foreach ($points_arr as $point) { foreach ($points_arr as $point) {
if (! isset($temp_point)) { if (isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section // draw line section
imageline( imageline(
$image, $image,
(int) $temp_point[0], (int) round($temp_point[0]),
(int) $temp_point[1], (int) round($temp_point[1]),
(int) $point[0], (int) round($point[0]),
(int) $point[1], (int) round($point[1]),
$color $color
); );
$temp_point = $point;
} }
$temp_point = $point;
} }
// print label if applicable // print label if applicable
if (isset($label) && trim($label) != '') { if (isset($label) && trim($label) != '') {
imagestring( imagestring(
$image, $image,
1, 1,
$points_arr[1][0], (int) round($points_arr[1][0]),
$points_arr[1][1], (int) round($points_arr[1][1]),
trim($label), trim($label),
$black $black
); );
@ -178,9 +177,7 @@ class GisLineString extends GisGeometry
$points_arr = $this->extractPoints($linesrting, $scale_data); $points_arr = $this->extractPoints($linesrting, $scale_data);
foreach ($points_arr as $point) { foreach ($points_arr as $point) {
if (! isset($temp_point)) { if (isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section // draw line section
$pdf->Line( $pdf->Line(
$temp_point[0], $temp_point[0],
@ -189,8 +186,8 @@ class GisLineString extends GisGeometry
$point[1], $point[1],
$line $line
); );
$temp_point = $point;
} }
$temp_point = $point;
} }
// print label // print label
if (isset($label) && trim($label) != '') { if (isset($label) && trim($label) != '') {
@ -270,8 +267,8 @@ class GisLineString extends GisGeometry
$result = 'var style = new ol.style.Style({' $result = 'var style = new ol.style.Style({'
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')'; . 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
if ($label) { if (trim($label) !== '') {
$text_style = ['text' => $label]; $text_style = ['text' => trim($label)];
$result .= ', text: new ol.style.Text(' . json_encode($text_style) . ')'; $result .= ', text: new ol.style.Text(' . json_encode($text_style) . ')';
} }

View File

@ -17,6 +17,7 @@ use function imagestring;
use function json_encode; use function json_encode;
use function mb_strlen; use function mb_strlen;
use function mb_substr; use function mb_substr;
use function round;
use function trim; use function trim;
/** /**
@ -123,20 +124,18 @@ class GisMultiLineString extends GisGeometry
foreach ($linestirngs as $linestring) { foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, $scale_data); $points_arr = $this->extractPoints($linestring, $scale_data);
foreach ($points_arr as $point) { foreach ($points_arr as $point) {
if (! isset($temp_point)) { if (isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section // draw line section
imageline( imageline(
$image, $image,
(int) $temp_point[0], (int) round($temp_point[0]),
(int) $temp_point[1], (int) round($temp_point[1]),
(int) $point[0], (int) round($point[0]),
(int) $point[1], (int) round($point[1]),
$color $color
); );
$temp_point = $point;
} }
$temp_point = $point;
} }
unset($temp_point); unset($temp_point);
// print label if applicable // print label if applicable
@ -144,8 +143,8 @@ class GisMultiLineString extends GisGeometry
imagestring( imagestring(
$image, $image,
1, 1,
$points_arr[1][0], (int) round($points_arr[1][0]),
$points_arr[1][1], (int) round($points_arr[1][1]),
trim($label), trim($label),
$black $black
); );
@ -198,9 +197,7 @@ class GisMultiLineString extends GisGeometry
foreach ($linestirngs as $linestring) { foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, $scale_data); $points_arr = $this->extractPoints($linestring, $scale_data);
foreach ($points_arr as $point) { foreach ($points_arr as $point) {
if (! isset($temp_point)) { if (isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section // draw line section
$pdf->Line( $pdf->Line(
$temp_point[0], $temp_point[0],
@ -209,8 +206,8 @@ class GisMultiLineString extends GisGeometry
$point[1], $point[1],
$line $line
); );
$temp_point = $point;
} }
$temp_point = $point;
} }
unset($temp_point); unset($temp_point);
// print label // print label
@ -299,8 +296,8 @@ class GisMultiLineString extends GisGeometry
$row = 'var style = new ol.style.Style({' $row = 'var style = new ol.style.Style({'
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')'; . 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
if ($label) { if (trim($label) !== '') {
$text_style = ['text' => $label]; $text_style = ['text' => trim($label)];
$row .= ', text: new ol.style.Text(' . json_encode($text_style) . ')'; $row .= ', text: new ol.style.Text(' . json_encode($text_style) . ')';
} }

View File

@ -16,6 +16,7 @@ use function imagestring;
use function json_encode; use function json_encode;
use function mb_strlen; use function mb_strlen;
use function mb_substr; use function mb_substr;
use function round;
use function trim; use function trim;
/** /**
@ -115,7 +116,16 @@ class GisMultiPoint extends GisGeometry
continue; continue;
} }
imagearc($image, (int) $point[0], (int) $point[1], 7, 7, 0, 360, $color); imagearc(
$image,
(int) round($point[0]),
(int) round($point[1]),
7,
7,
0,
360,
$color
);
} }
// print label for each point // print label for each point
if ((isset($label) && trim($label) != '') if ((isset($label) && trim($label) != '')
@ -124,8 +134,8 @@ class GisMultiPoint extends GisGeometry
imagestring( imagestring(
$image, $image,
1, 1,
$points_arr[0][0], (int) round($points_arr[0][0]),
$points_arr[0][1], (int) round($points_arr[0][1]),
trim($label), trim($label),
$black $black
); );
@ -282,9 +292,9 @@ class GisMultiPoint extends GisGeometry
. 'fill: fill,' . 'fill: fill,'
. 'stroke: stroke'; . 'stroke: stroke';
if ($label) { if (trim($label) !== '') {
$text_style = [ $text_style = [
'text' => $label, 'text' => trim($label),
'offsetY' => -9, 'offsetY' => -9,
]; ];
$result .= ',text: new ol.style.Text(' . json_encode($text_style) . ')'; $result .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';

View File

@ -21,6 +21,7 @@ use function json_encode;
use function mb_strlen; use function mb_strlen;
use function mb_strpos; use function mb_strpos;
use function mb_substr; use function mb_substr;
use function round;
use function trim; use function trim;
/** /**
@ -168,8 +169,8 @@ class GisMultiPolygon extends GisGeometry
imagestring( imagestring(
$image, $image,
1, 1,
$points_arr[2], (int) round($label_point[0]),
$points_arr[3], (int) round($label_point[1]),
trim((string) $label), trim((string) $label),
$black $black
); );
@ -347,8 +348,8 @@ class GisMultiPolygon extends GisGeometry
. 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),' . 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),'
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')'; . 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
if ($label) { if (trim($label) !== '') {
$text_style = ['text' => $label]; $text_style = ['text' => trim($label)];
$row .= ',text: new ol.style.Text(' . json_encode($text_style) . ')'; $row .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';
} }

View File

@ -15,6 +15,7 @@ use function imagestring;
use function json_encode; use function json_encode;
use function mb_strlen; use function mb_strlen;
use function mb_substr; use function mb_substr;
use function round;
use function trim; use function trim;
/** /**
@ -112,8 +113,8 @@ class GisPoint extends GisGeometry
if ($points_arr[0][0] != '' && $points_arr[0][1] != '') { if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
imagearc( imagearc(
$image, $image,
(int) $points_arr[0][0], (int) round($points_arr[0][0]),
(int) $points_arr[0][1], (int) round($points_arr[0][1]),
7, 7,
7, 7,
0, 0,
@ -125,8 +126,8 @@ class GisPoint extends GisGeometry
imagestring( imagestring(
$image, $image,
1, 1,
$points_arr[0][0], (int) round($points_arr[0][0]),
$points_arr[0][1], (int) round($points_arr[0][1]),
trim($label), trim($label),
$black $black
); );
@ -282,9 +283,9 @@ class GisPoint extends GisGeometry
. 'fill: fill,' . 'fill: fill,'
. 'stroke: stroke'; . 'stroke: stroke';
if ($label) { if (trim($label) !== '') {
$text_style = [ $text_style = [
'text' => $label, 'text' => trim($label),
'offsetY' => -9, 'offsetY' => -9,
]; ];
$result .= ',text: new ol.style.Text(' . json_encode($text_style) . ')'; $result .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';

View File

@ -24,6 +24,7 @@ use function mb_strpos;
use function mb_substr; use function mb_substr;
use function min; use function min;
use function pow; use function pow;
use function round;
use function sqrt; use function sqrt;
use function trim; use function trim;
@ -150,8 +151,8 @@ class GisPolygon extends GisGeometry
imagestring( imagestring(
$image, $image,
1, 1,
$points_arr[2], (int) round($points_arr[2]),
$points_arr[3], (int) round($points_arr[3]),
trim($label), trim($label),
$black $black
); );
@ -309,8 +310,8 @@ class GisPolygon extends GisGeometry
$row = 'var style = new ol.style.Style({' $row = 'var style = new ol.style.Style({'
. 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),' . 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),'
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')'; . 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
if ($label) { if (trim($label) !== '') {
$text_style = ['text' => $label]; $text_style = ['text' => trim($label)];
$row .= ',text: new ol.style.Text(' . json_encode($text_style) . ')'; $row .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';
} }
$row .= '});'; $row .= '});';