Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into
develop
This commit is contained in:
parent
6d3bf284d8
commit
dcd5e5f5d0
2 changed files with 119 additions and 14 deletions
105
htdocs/core/class/dolgeophp.class.php
Normal file
105
htdocs/core/class/dolgeophp.class.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* or see https://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/class/dolgeophp.class.php
|
||||
* \brief Absctraction class to manage a WYSIWYG editor
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage Geo processing
|
||||
* Usage: $dolgeophp=new DolGeoPHP($db);
|
||||
*/
|
||||
class DolGeoPHP
|
||||
{
|
||||
/**
|
||||
* @var DoliDB $db Database handler
|
||||
*/
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Create an object to build an HTML area to edit a large string content
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return data from a value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
* @return array Centroid
|
||||
*/
|
||||
public function parseGeoString($value)
|
||||
{
|
||||
$geom = geoPHP::load($value, 'wkt');
|
||||
$geojson = $geom->out('json');
|
||||
$centroid = $geom->getCentroid();
|
||||
$centroidjson = $centroid->out('json');
|
||||
|
||||
return array('geojson' => $geojson, 'centroid' => $centroid, 'centroidjson' => $centroidjson);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with x and y
|
||||
*
|
||||
* @param mixed $value Value
|
||||
* @return string X space Y
|
||||
*/
|
||||
public function getXYString($value)
|
||||
{
|
||||
$geom = geoPHP::load($value, 'wkt');
|
||||
$value = $geom->x().' '.$geom->y();
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with x and y
|
||||
*
|
||||
* @param mixed $value Value
|
||||
* @return string X space Y
|
||||
*/
|
||||
public function getPointString($value)
|
||||
{
|
||||
$geom = geoPHP::load($value, 'wkt');
|
||||
$value = get_class($geom) . ' : '. $geom->numPoints() . ' Points';
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return wkt
|
||||
*
|
||||
* @param string $geojson A json string
|
||||
* @return string X space Y
|
||||
*/
|
||||
public function getWkt($geojson)
|
||||
{
|
||||
$geom = geoPHP::load($geojson, 'json');
|
||||
$value_key = $geom->out('wkt');
|
||||
|
||||
return $value_key;
|
||||
}
|
||||
}
|
||||
|
|
@ -1712,14 +1712,14 @@ class ExtraFields
|
|||
//$out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty, '', '', $morecss, '', 0, 0, '');
|
||||
$out = $form->selectForForms($tmparray[0], $keyprefix.$key.$keysuffix, $value, $showempty, '', '', $morecss, '', 0, 0, '', $element.':options_'.$key);
|
||||
} elseif (in_array($type, ['point', 'multipts', 'linestrg', 'polygon'])) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeophp.class.php';
|
||||
$dolgeophp = new DolGeoPHP($this->db);
|
||||
$geojson = '{}';
|
||||
$centroidjson = getDolGlobalString('MAIN_INFO_SOCIETE_GEO_COORDINATES', '{}');
|
||||
if (!empty($value)) {
|
||||
$geom = geoPHP::load($value, 'wkt');
|
||||
$geojson = $geom->out('json');
|
||||
$centroid = $geom->getCentroid();
|
||||
$centroidjson = $centroid->out('json');
|
||||
$tmparray = $dolgeophp->parseGeoString($value);
|
||||
$geojson = $tmparray['geojson'];
|
||||
$centroidjson = $tmparray['centroidjson'];
|
||||
}
|
||||
if (!preg_match('/search_/', $keyprefix)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/geomapeditor.class.php';
|
||||
|
|
@ -2094,18 +2094,18 @@ class ExtraFields
|
|||
}
|
||||
}
|
||||
} elseif ($type == 'point') {
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
|
||||
if (!empty($value)) {
|
||||
$geom = geoPHP::load($value, 'wkt');
|
||||
$value = $geom->x().' '.$geom->y();
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeophp.class.php';
|
||||
$dolgeophp = new DolGeoPHP($this->db);
|
||||
$value = $dolgeophp->getXYString($value);
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
} elseif (in_array($type, ['multipts','linestrg', 'polygon'])) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
|
||||
if (!empty($value)) {
|
||||
$geom = geoPHP::load($value, 'wkt');
|
||||
$value = get_class($geom) . ' : '. $geom->numPoints() . ' Points';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeophp.class.php';
|
||||
$dolgeophp = new DolGeoPHP($this->db);
|
||||
$value = $dolgeophp->getPointString($value);
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
|
|
@ -2380,11 +2380,11 @@ class ExtraFields
|
|||
$value_key = GETPOST("options_".$key, 'restricthtml');
|
||||
} elseif (in_array($key_type, ['point', 'multipts', 'linestrg', 'polygon'])) {
|
||||
// construct point
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeophp.class.php';
|
||||
$geojson = GETPOST("options_".$key, 'restricthtml');
|
||||
if ($geojson != '{}') {
|
||||
$geom = geoPHP::load($geojson, 'json');
|
||||
$value_key = $geom->out('wkt');
|
||||
$dolgeophp = new DolGeoPHP($this->db);
|
||||
$value_key = $dolgeophp->getWkt($geojson);
|
||||
} else {
|
||||
$value_key = '';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue