diff --git a/js/src/gis_data_editor.ts b/js/src/gis_data_editor.ts index 9a8445ebc5..b5cc1af755 100644 --- a/js/src/gis_data_editor.ts +++ b/js/src/gis_data_editor.ts @@ -7,7 +7,6 @@ import { ajaxShowMessage } from './modules/ajax-message.ts'; * @fileoverview functions used in GIS data editor * * @requires jQuery - * */ let gisEditorLoaded = false; @@ -22,24 +21,196 @@ function closeGISEditor () { }); } -/** - * Returns the HTML for a data point. - * - * @param {number} pointNumber point number - * @param {string} prefix prefix of the name - * @return {string} the HTML for a data point - */ -function addDataPoint (pointNumber, prefix) { - return '
' + - window.sprintf(window.Messages.strPointN, (pointNumber + 1)) + ': ' + +function withIndex (prefix: string, ...index: Array): string { + let result = prefix; + for (let i = 0; i < index.length; ++i) { + result += '[' + index[i] + ']'; + } + + return result; +} + +function makeDataLengthInput (prefix: string, length: number): string { + return ''; +} + +function makeAddButton (prefix: string, cls: string, label: string, type: string): string { + return ( + '' + + '+ ' + label + + '' + ); +} + +function makeCoordinateInputs (prefix: string, data): string { + return ( '' + ' '; + ' ' + + ' ' + ); +} + +function makePointNInputs (prefix: string, index: number, data): string { + return ( + window.Messages.strPoint + ' ' + (index + 1) + ': ' + + makeCoordinateInputs(withIndex(prefix, index), data) + ); +} + +function makePointInputs (prefix: string, data): string { + return ( + window.Messages.strPoint + ': ' + + makeCoordinateInputs(prefix, data) + ); +} + +function makeMultiPointInputs (prefix: string, data): string { + const d = data || []; + const inputs = []; + let i = 0; + while (d[i] || i < 1) { + inputs.push(makePointNInputs(prefix, i, d[i])); + ++i; + } + + return ( + inputs.join('
') + + makeDataLengthInput(prefix, i) + + makeAddButton(prefix, 'addPoint', window.Messages.strAddPoint, 'POINT') + ); +} + +function makeLineStringInputs (prefix: string, data, type: string): string { + const d = data || []; + const inputs = []; + let i = 0; + const min = type === 'POLYGON' || type === 'MULTIPOLYGON' ? 4 : 2; + while (d[i] || i < min) { + inputs.push(makePointNInputs(prefix, i, d[i])); + ++i; + } + + return ( + inputs.join('
') + + makeDataLengthInput(prefix, i) + + makeAddButton(prefix, 'addPoint', window.Messages.strAddPoint, 'LINESTRING') + ); +} + +function makeMultiLineStringInputs (prefix: string, data): string { + const d = data || []; + const inputs = []; + let i = 0; + while (d[i] || i < 1) { + inputs.push( + window.Messages.strLineString + ' ' + (i + 1) + ':', + makeLineStringInputs(withIndex(prefix, i), d[i], 'MULTILINESTRING') + ); + + ++i; + } + + return ( + inputs.join('
') + + makeDataLengthInput(prefix, i) + '
' + + makeAddButton(prefix, 'addLine', window.Messages.strAddLineString, 'MULTILINESTRING') + ); +} + +function makePolygonInputs (prefix: string, data, type: string): string { + const d = data || []; + const inputs = []; + let i = 0; + while (d[i] || i < 1) { + inputs.push( + (i === 0 ? window.Messages.strOuterRing : window.Messages.strInnerRing + ' ' + i) + ':', + makeLineStringInputs(withIndex(prefix, i), d[i], type) + ); + + ++i; + } + + return ( + inputs.join('
') + + makeDataLengthInput(prefix, i) + '
' + + makeAddButton(prefix, 'addLine', window.Messages.strAddInnerRing, 'POLYGON') + ); +} + +function makeMultiPolygonInputs (prefix: string, data): string { + const d = data || []; + const inputs = []; + let i = 0; + while (d[i] || i < 1) { + inputs.push( + window.Messages.strPolygon + ' ' + (i + 1) + ':', + makePolygonInputs(withIndex(prefix, i), d[i], 'MULTIPOLYGON') + ); + + ++i; + } + + return ( + inputs.join('
') + + makeDataLengthInput(prefix, i) + '
' + + makeAddButton(prefix, 'addPolygon', window.Messages.strAddPolygon, 'MULTIPOLYGON') + ); +} + +const INPUTS_GENERATOR = { + POINT: makePointInputs, + MULTIPOINT: makeMultiPointInputs, + LINESTRING: makeLineStringInputs, + MULTILINESTRING: makeMultiLineStringInputs, + POLYGON: makePolygonInputs, + MULTIPOLYGON: makeMultiPolygonInputs, +}; + +function makeGeometryCollectionGeometryInputs (prefix: string, index: number, data): string { + const type = data ? data.gis_type : 'POINT'; + const fn = INPUTS_GENERATOR[type]; + const $geomType = $('#gis_type_template').contents().filter('select').clone(); + const select = $geomType.get(0) as HTMLSelectElement; + select.value = type || 'POINT'; + select.selectedOptions[0].setAttribute('selected', 'selected'); + select.setAttribute('name', withIndex(prefix, index, 'gis_type')); + + return ( + window.Messages.strGeometry + ' ' + (index + 1) + ': ' + + select.outerHTML + '
' + + fn(withIndex(prefix, index, type), data ? data[type] : null, type) + ); +} + +function makeGeometryCollectionInputs (prefix: string, data): string { + let i = 0; + let inputs = []; + while (data[i]) { + inputs.push(makeGeometryCollectionGeometryInputs(prefix, i, data[i])); + ++i; + } + + return ( + inputs.join('
') + + makeDataLengthInput('gis_data[GEOMETRYCOLLECTION]', i) + '
' + + makeAddButton(prefix, 'addGeom', window.Messages.strAddGeometry, 'GEOMETRYCOLLECTION') + ); +} + +function makeGeometryInputs (gisData): string { + const type = gisData.gis_type; + const geometry = gisData[0][type]; + const fn = INPUTS_GENERATOR[type]; + + return fn(withIndex('gis_data', 0, type), geometry, type); } /** @@ -94,21 +265,35 @@ function loadJSAndGISEditor (resolve) { * @param inputName name of the input field */ function loadGISEditor (value, field, type, inputName) { - var $gisEditor = $('#gis_editor'); - $.post('index.php?route=/gis-data-editor', { + const $gisEditor = $('#gis_editor'); + const data = { 'field': field, 'value': value, 'type': type, 'input_name': inputName, - 'get_gis_editor': true, 'ajax_request': true, - 'server': CommonParams.get('server') - }, function (data) { - if (typeof data !== 'undefined' && data.success === true) { - $gisEditor.html(data.gis_editor); - initGISEditorVisualization(); - } else { + 'server': CommonParams.get('server'), + }; + $.post('index.php?route=/gis-data-editor', data, function (data) { + if (typeof data === 'undefined' || data.success !== true) { ajaxShowMessage(data.error, false); + + return; + } + + $gisEditor.html(data.gis_editor); + initGISEditorVisualization(); + + const gisData = $('#gis_data').data('gisData'); + if (gisData) { + let html; + if (gisData.gis_type === 'GEOMETRYCOLLECTION') { + html = makeGeometryCollectionInputs('gis_data', gisData); + } else { + html = makeGeometryInputs(gisData); + } + + $('#gis_data').append(html); } }, 'json'); } @@ -147,12 +332,15 @@ function openGISEditor (value, field, type, inputName) { * Prepare and insert the GIS data in Well Known Text format * to the input field. */ -function insertDataAndClose () { - var $form = $('form#gis_data_editor_form'); - var inputName = $form.find('input[name=\'input_name\']').val(); +function insertDataAndClose (event) { + event.preventDefault(); - var argsep = CommonParams.get('arg_separator'); - $.post('index.php?route=/gis-data-editor', $form.serialize() + argsep + 'generate=true' + argsep + 'ajax_request=true', function (data) { + const $form = $('form#gis_data_editor_form'); + const inputName = $form.find('input[name=\'input_name\']').val(); + + const argsep = CommonParams.get('arg_separator'); + const params = $form.serialize() + argsep + 'generate=true' + argsep + 'ajax_request=true'; + $.post('index.php?route=/gis-data-editor', params, function (data) { if (typeof data !== 'undefined' && data.success === true) { $('input[name=\'' + inputName + '\']').val(data.result); } else { @@ -163,6 +351,163 @@ function insertDataAndClose () { closeGISEditor(); } +function onCoordinateEdit (data) { + if (typeof data === 'undefined' || data.success !== true) { + ajaxShowMessage(data.error, false); + + return; + } + + $('#gis_data_textarea').val(data.result); + $('#placeholder').empty().removeClass('hasSVG').html(data.visualization); + $('#openlayersmap').empty(); + /* TODO: the gis_data_editor should rather return JSON than JS code to eval */ + // eslint-disable-next-line no-eval + eval(data.openLayers); + initGISEditorVisualization(); +} + +/** + * Handles adding data points + */ +function addPoint () { + const $a = $(this); + const prefix = $a.data('prefix'); + + // Find the number of points + const $noOfPointsInput = $('input[name=\'' + prefix + '[data_length]' + '\']'); + const noOfPoints = parseInt(($noOfPointsInput.val() as string), 10); + + // Add the new data point + const html = makePointNInputs(prefix, noOfPoints, null); + $a.before('
', html); + $noOfPointsInput.val(noOfPoints + 1); + + updateResult(); +} + +/** + * Handles adding linestrings and inner rings + */ +function addLineStringOrInnerRing () { + const $a = $(this); + const prefix = $a.data('prefix'); + const type = $a.data('geometryType'); + + // Find the number of lines + const $noOfLinesInput = $('input[name=\'' + prefix + '[data_length]' + '\']'); + const noOfLines = parseInt(($noOfLinesInput.val() as string), 10); + + const label = type === 'MULTILINESTRING' ? window.Messages.strLineString : window.Messages.strInnerRing; + + const n = type === 'MULTILINESTRING' ? noOfLines + 1 : noOfLines; + const html = makeLineStringInputs(withIndex(prefix, noOfLines), null, type); + $a.before(label + ' ' + n + ':
', html, '
'); + $noOfLinesInput.val(noOfLines + 1); + + updateResult(); +} + +/** + * Handles adding polygons + */ +function addPolygon () { + const $a = $(this); + const prefix = $a.data('prefix'); + // Find the number of polygons + const $noOfPolygonsInput = $('input[name=\'' + prefix + '[data_length]' + '\']'); + const noOfPolygons = parseInt(($noOfPolygonsInput.val() as string), 10); + + const html = makePolygonInputs(withIndex(prefix, noOfPolygons), null, 'MULTIPOLYGON'); + $a.before(window.Messages.strPolygon + ' ' + (noOfPolygons + 1) + ':
', html, '
'); + $noOfPolygonsInput.val(noOfPolygons + 1); + + updateResult(); +} + +/** + * Handles adding geoms + */ +function addGeometry () { + const $a = $(this); + const $noOfGeomsInput = $('input[name="gis_data[GEOMETRYCOLLECTION][data_length]"]'); + const noOfGeoms = parseInt(($noOfGeomsInput.val() as string), 10); + + const html = makeGeometryCollectionGeometryInputs('gis_data', noOfGeoms, null); + $a.before(html, '
'); + $noOfGeomsInput.val(noOfGeoms + 1); + + updateResult(); +} + +/** + * Update the form on change of the GIS type. + */ +function onGeometryTypeChange () { + const $gisEditor = $('#gis_editor'); + const prefix = $(this).attr('name').match(/^(.*)\[gis_type\]$/)[1]; + + const inputs = $('[name^="' + prefix + '"]', $gisEditor).toArray(); + const type = $(this).val() as string; + const match = $(this).attr('name').match(/^gis_data\[(\d+)\]/); + const parent = inputs[0].parentNode; + if (match) { // Geometry of GeometryCollection changed + const last = inputs[inputs.length - 1]; + for (;;) { + const next = inputs[0].nextSibling; + parent.removeChild(next); + if (next.nodeType === Node.ELEMENT_NODE && next.contains(last)) { + break; + } + } + + for (;;) { + const next = inputs[0].nextSibling; + if ( + !next || + (next.nodeType === Node.TEXT_NODE && !/^\s+$/.test(next.textContent)) || + (next.nodeType !== Node.TEXT_NODE && + next.nodeName !== 'A' && + next.nodeName !== 'BR' && + !(next as HTMLElement).classList.contains('addGeom')) + ) { + break; + } + + parent.removeChild(next); + } + + const index = Number(match[1]); + $(inputs[0] as HTMLSelectElement).attr('name', withIndex('gis_data', index, 'gis_type')); + + const fn = INPUTS_GENERATOR[type]; + const html = fn(withIndex(prefix, type), null, type); + $(inputs[0]).after('
', html, '
'); + } else { // Entire geometry changed + let html; + if (type === 'GEOMETRYCOLLECTION') { + html = makeGeometryCollectionInputs(prefix, {}); + } else { + html = makeGeometryInputs({ 'gis_type': type, '0': {} }); + } + + const template = $('#gis_data > template'); + $('#gis_data').empty().append(template, html); + } + + updateResult(); +} + +/** + * Trigger asynchronous calls on data change and update the output. + */ +function updateResult () { + const $form = $('form#gis_data_editor_form'); + const argsep = CommonParams.get('arg_separator'); + const data = $form.serialize() + argsep + 'generate=true' + argsep + 'ajax_request=true'; + $.post('index.php?route=/gis-data-editor', data, onCoordinateEdit, 'json'); +} + /** * Unbind all event handlers before tearing down a page */ @@ -179,181 +524,21 @@ AJAX.registerTeardown('gis_data_editor.js', function () { }); AJAX.registerOnload('gis_data_editor.js', function () { - /** - * Prepares and insert the GIS data to the input field on clicking 'copy'. - */ - $(document).on('click', '#gis_editor input[name=\'gis_data[save]\']', function (event) { - event.preventDefault(); - insertDataAndClose(); - }); + $(document).on('click', '#gis_editor input[name=\'gis_data[save]\']', insertDataAndClose); + $(document).on('submit', '#gis_editor', insertDataAndClose); - /** - * Prepares and insert the GIS data to the input field on pressing 'enter'. - */ - $(document).on('submit', '#gis_editor', function (event) { - event.preventDefault(); - insertDataAndClose(); - }); + $(document).on('change', '#gis_editor input[type=\'text\']', updateResult); + $(document).on('change', '#gis_editor select.gis_type', onGeometryTypeChange); + $(document).on( + 'click', + '#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor', + () => closeGISEditor() + ); - /** - * Trigger asynchronous calls on data change and update the output. - */ - $(document).on('change', '#gis_editor input[type=\'text\']', function () { - var $form = $('form#gis_data_editor_form'); - var argsep = CommonParams.get('arg_separator'); - $.post('index.php?route=/gis-data-editor', $form.serialize() + argsep + 'generate=true' + argsep + 'ajax_request=true', function (data) { - if (typeof data !== 'undefined' && data.success === true) { - $('#gis_data_textarea').val(data.result); - $('#placeholder').empty().removeClass('hasSVG').html(data.visualization); - $('#openlayersmap').empty(); - /* TODO: the gis_data_editor should rather return JSON than JS code to eval */ - // eslint-disable-next-line no-eval - eval(data.openLayers); - initGISEditorVisualization(); - } else { - ajaxShowMessage(data.error, false); - } - }, 'json'); - }); - - /** - * Update the form on change of the GIS type. - */ - $(document).on('change', '#gis_editor select.gis_type', function () { - var $gisEditor = $('#gis_editor'); - var $form = $('form#gis_data_editor_form'); - - var argsep = CommonParams.get('arg_separator'); - $.post('index.php?route=/gis-data-editor', $form.serialize() + argsep + 'get_gis_editor=true' + argsep + 'ajax_request=true', function (data) { - if (typeof data !== 'undefined' && data.success === true) { - $gisEditor.html(data.gis_editor); - initGISEditorVisualization(); - } else { - ajaxShowMessage(data.error, false); - } - }, 'json'); - }); - - /** - * Handles closing of the GIS data editor. - */ - $(document).on('click', '#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor', function () { - closeGISEditor(); - }); - - /** - * Handles adding data points - */ - $(document).on('click', '#gis_editor a.addJs.addPoint', function () { - var $a = $(this); - var name = $a.attr('name'); - // Eg. name = gis_data[0][MULTIPOINT][add_point] => prefix = gis_data[0][MULTIPOINT] - var prefix = name.substring(0, name.length - 11); - // Find the number of points - var $noOfPointsInput = $('input[name=\'' + prefix + '[no_of_points]' + '\']'); - var noOfPoints = parseInt(($noOfPointsInput.val() as string), 10); - // Add the new data point - var html = addDataPoint(noOfPoints, prefix); - $a.before(html); - $noOfPointsInput.val(noOfPoints + 1); - }); - - /** - * Handles adding linestrings and inner rings - */ - $(document).on('click', '#gis_editor a.addJs.addLine', function () { - var $a = $(this); - var name = $a.attr('name'); - - // Eg. name = gis_data[0][MULTILINESTRING][add_line] => prefix = gis_data[0][MULTILINESTRING] - var prefix = name.substring(0, name.length - 10); - var type = prefix.slice(prefix.lastIndexOf('[') + 1, prefix.lastIndexOf(']')); - - // Find the number of lines - var $noOfLinesInput = $('input[name=\'' + prefix + '[no_of_lines]' + '\']'); - var noOfLines = parseInt(($noOfLinesInput.val() as string), 10); - - // Add the new linesting of inner ring based on the type - var html = '
'; - var noOfPoints; - if (type === 'MULTILINESTRING') { - html += window.Messages.strLineString + ' ' + (noOfLines + 1) + ':'; - noOfPoints = 2; - } else { - html += window.Messages.strInnerRing + ' ' + noOfLines + ':'; - noOfPoints = 4; - } - - html += ''; - for (var i = 0; i < noOfPoints; i++) { - html += addDataPoint(i, (prefix + '[' + noOfLines + ']')); - } - - html += '+ ' + - window.Messages.strAddPoint + '
'; - - $a.before(html); - $noOfLinesInput.val(noOfLines + 1); - }); - - /** - * Handles adding polygons - */ - $(document).on('click', '#gis_editor a.addJs.addPolygon', function () { - var $a = $(this); - var name = $a.attr('name'); - // Eg. name = gis_data[0][MULTIPOLYGON][add_polygon] => prefix = gis_data[0][MULTIPOLYGON] - var prefix = name.substring(0, name.length - 13); - // Find the number of polygons - var $noOfPolygonsInput = $('input[name=\'' + prefix + '[no_of_polygons]' + '\']'); - var noOfPolygons = parseInt(($noOfPolygonsInput.val() as string), 10); - - // Add the new polygon - var html = window.Messages.strPolygon + ' ' + (noOfPolygons + 1) + ':
'; - html += '' + - '
' + window.Messages.strOuterRing + ':' + - ''; - - for (var i = 0; i < 4; i++) { - html += addDataPoint(i, (prefix + '[' + noOfPolygons + '][0]')); - } - - html += '+ ' + - window.Messages.strAddPoint + '
' + - '+ ' + - window.Messages.strAddInnerRing + '

'; - - $a.before(html); - $noOfPolygonsInput.val(noOfPolygons + 1); - }); - - /** - * Handles adding geoms - */ - $(document).on('click', '#gis_editor a.addJs.addGeom', function () { - var $a = $(this); - var prefix = 'gis_data[GEOMETRYCOLLECTION]'; - // Find the number of geoms - var $noOfGeomsInput = $('input[name=\'' + prefix + '[geom_count]' + '\']'); - var noOfGeoms = parseInt(($noOfGeomsInput.val() as string), 10); - - var html1 = window.Messages.strGeometry + ' ' + (noOfGeoms + 1) + ':
'; - var $geomType = $('#gis_type_template').contents().filter('select').clone(); - $geomType.attr('name', 'gis_data[' + noOfGeoms + '][gis_type]').val('POINT'); - var html2 = '
' + window.Messages.strPoint + ': ' + - '' + - ' ' + - '

'; - - $a.before(html1, $geomType, html2); - $noOfGeomsInput.val(noOfGeoms + 1); - }); + $(document).on('click', '#gis_editor a.addJs.addPoint', addPoint); + $(document).on('click', '#gis_editor a.addJs.addLine', addLineStringOrInnerRing); + $(document).on('click', '#gis_editor a.addJs.addPolygon', addPolygon); + $(document).on('click', '#gis_editor a.addJs.addGeom', addGeometry); }); declare global { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5cc4ab75d1..b02cba0e9f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3495,16 +3495,6 @@ parameters: count: 1 path: src/Controllers/Export/Template/UpdateController.php - - - message: "#^Cannot access offset 'add_geom' on mixed\\.$#" - count: 1 - path: src/Controllers/GisDataEditorController.php - - - - message: "#^Cannot access offset 'geom_count' on mixed\\.$#" - count: 2 - path: src/Controllers/GisDataEditorController.php - - message: "#^Cannot cast mixed to int\\.$#" count: 1 @@ -3520,11 +3510,6 @@ parameters: count: 1 path: src/Controllers/GisDataEditorController.php - - - message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#" - count: 1 - path: src/Controllers/GisDataEditorController.php - - message: "#^Parameter \\#1 \\$showGitRevision of class PhpMyAdmin\\\\Git constructor expects bool, mixed given\\.$#" count: 1 @@ -10821,7 +10806,7 @@ parameters: path: src/Gis/GisGeometry.php - - message: "#^Cannot access offset 'geom_count' on mixed\\.$#" + message: "#^Cannot access offset 'data_length' on mixed\\.$#" count: 1 path: src/Gis/GisGeometryCollection.php @@ -10841,7 +10826,7 @@ parameters: path: src/Gis/GisLineString.php - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" + message: "#^Cannot access offset 'data_length' on mixed\\.$#" count: 1 path: src/Gis/GisLineString.php @@ -10886,13 +10871,8 @@ parameters: path: src/Gis/GisMultiLineString.php - - message: "#^Cannot access offset 'no_of_lines' on mixed\\.$#" - count: 1 - path: src/Gis/GisMultiLineString.php - - - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" - count: 1 + message: "#^Cannot access offset 'data_length' on mixed\\.$#" + count: 2 path: src/Gis/GisMultiLineString.php - @@ -10916,7 +10896,7 @@ parameters: path: src/Gis/GisMultiLineString.php - - message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'no_of_points'\\|int\\<0, max\\>, array\\{x\\: float, y\\: float\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" + message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'data_length'\\|int\\<0, max\\>, array\\{x\\: float, y\\: float\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" count: 1 path: src/Gis/GisMultiLineString.php @@ -10941,7 +10921,7 @@ parameters: path: src/Gis/GisMultiPoint.php - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" + message: "#^Cannot access offset 'data_length' on mixed\\.$#" count: 1 path: src/Gis/GisMultiPoint.php @@ -10990,6 +10970,11 @@ parameters: count: 1 path: src/Gis/GisMultiPolygon.php + - + message: "#^Cannot access offset 'data_length' on mixed\\.$#" + count: 3 + path: src/Gis/GisMultiPolygon.php + - message: "#^Cannot access offset 'inner' on mixed\\.$#" count: 5 @@ -11000,21 +10985,6 @@ parameters: count: 5 path: src/Gis/GisMultiPolygon.php - - - message: "#^Cannot access offset 'no_of_lines' on mixed\\.$#" - count: 1 - path: src/Gis/GisMultiPolygon.php - - - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" - count: 1 - path: src/Gis/GisMultiPolygon.php - - - - message: "#^Cannot access offset 'no_of_polygons' on mixed\\.$#" - count: 1 - path: src/Gis/GisMultiPolygon.php - - message: "#^Cannot access offset 'pointOnSurface' on mixed\\.$#" count: 2 @@ -11036,7 +11006,7 @@ parameters: path: src/Gis/GisMultiPolygon.php - - message: "#^Cannot access offset int on non\\-empty\\-array\\<'no_of_lines'\\|int, array\\{no_of_points\\: int\\<0, max\\>, 0\\?\\: array\\{x\\: float, y\\: float\\}\\}\\|int\\<1, max\\>\\>\\|int\\<1, max\\>\\.$#" + message: "#^Cannot access offset int on non\\-empty\\-array\\<'data_length'\\|int, array\\{data_length\\: int\\<0, max\\>, 0\\?\\: array\\{x\\: float, y\\: float\\}\\}\\|int\\<1, max\\>\\>\\|int\\<1, max\\>\\.$#" count: 1 path: src/Gis/GisMultiPolygon.php @@ -11046,7 +11016,7 @@ parameters: path: src/Gis/GisMultiPolygon.php - - message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'no_of_points'\\|int\\<0, max\\>, array\\{x\\: float, y\\: float\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" + message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'data_length'\\|int\\<0, max\\>, array\\{x\\: float, y\\: float\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" count: 1 path: src/Gis/GisMultiPolygon.php @@ -11121,13 +11091,8 @@ parameters: path: src/Gis/GisPolygon.php - - message: "#^Cannot access offset 'no_of_lines' on mixed\\.$#" - count: 1 - path: src/Gis/GisPolygon.php - - - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" - count: 1 + message: "#^Cannot access offset 'data_length' on mixed\\.$#" + count: 2 path: src/Gis/GisPolygon.php - @@ -11146,7 +11111,7 @@ parameters: path: src/Gis/GisPolygon.php - - message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'no_of_points'\\|int\\<0, max\\>, array\\{x\\: float, y\\: float\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" + message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'data_length'\\|int\\<0, max\\>, array\\{x\\: float, y\\: float\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" count: 1 path: src/Gis/GisPolygon.php @@ -20631,7 +20596,7 @@ parameters: path: test/classes/FooterTest.php - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" + message: "#^Cannot access offset 'data_length' on mixed\\.$#" count: 2 path: test/classes/Gis/Ds/PolygonTest.php @@ -20641,13 +20606,8 @@ parameters: path: test/classes/Gis/Ds/PolygonTest.php - - message: "#^Cannot access offset 'no_of_lines' on mixed\\.$#" - count: 1 - path: test/classes/Gis/GisMultiPolygonTest.php - - - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" - count: 1 + message: "#^Cannot access offset 'data_length' on mixed\\.$#" + count: 2 path: test/classes/Gis/GisMultiPolygonTest.php - @@ -20656,7 +20616,7 @@ parameters: path: test/classes/Gis/GisMultiPolygonTest.php - - message: "#^Cannot access offset 'no_of_points' on mixed\\.$#" + message: "#^Cannot access offset 'data_length' on mixed\\.$#" count: 1 path: test/classes/Gis/GisPolygonTest.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5e511e5b55..9bb55d87ad 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6362,7 +6362,7 @@ $tempPoint[1] - + $tempPoint[0] $tempPoint[0] $tempPoint[1] @@ -6396,8 +6396,8 @@ $dataRow[$i] - - + + @@ -6429,8 +6429,8 @@ $dataRow[$i] - - + + isset(self::$instance) @@ -6438,7 +6438,7 @@ - + @@ -6480,9 +6480,9 @@ $dataRow[$k] $dataRow[$k] $dataRow[$k][$i] - - - + + + $labelPoint[0] @@ -6560,9 +6560,9 @@ $dataRow[$k] $dataRow[$k] $dataRow[$k][$i] - - - + + + isset(self::$instance) @@ -6600,8 +6600,8 @@ - - + + $noOfLines @@ -14657,8 +14657,8 @@ - - + + providerForIsOuterRing diff --git a/src/Controllers/GisDataEditorController.php b/src/Controllers/GisDataEditorController.php index 51b6e4bd71..d0138b24e3 100644 --- a/src/Controllers/GisDataEditorController.php +++ b/src/Controllers/GisDataEditorController.php @@ -13,7 +13,6 @@ use PhpMyAdmin\Http\ServerRequest; use function array_merge; use function in_array; -use function intval; use function is_array; use function mb_strtoupper; use function preg_match; @@ -88,15 +87,6 @@ class GisDataEditorController extends AbstractController return; } - $geomCount = 1; - if ($geomType === 'GEOMETRYCOLLECTION') { - $geomCount = isset($gisData[$geomType]['geom_count']) - ? intval($gisData[$geomType]['geom_count']) : 1; - if (isset($gisData[$geomType]['add_geom'])) { - $geomCount++; - } - } - $templateOutput = $this->template->render('gis_data_editor_form', [ 'width' => $visualization->getWidth(), 'height' => $visualization->getHeight(), @@ -108,7 +98,6 @@ class GisDataEditorController extends AbstractController 'column_type' => mb_strtoupper($type), 'gis_types' => self::GIS_TYPES, 'geom_type' => $geomType, - 'geom_count' => $geomCount, 'gis_data' => $gisData, 'result' => $result, ]); diff --git a/src/Controllers/JavaScriptMessagesController.php b/src/Controllers/JavaScriptMessagesController.php index 921a3546c0..d1b8660364 100644 --- a/src/Controllers/JavaScriptMessagesController.php +++ b/src/Controllers/JavaScriptMessagesController.php @@ -489,14 +489,16 @@ final class JavaScriptMessagesController 'strX' => __('X'), 'strY' => __('Y'), 'strPoint' => __('Point'), - 'strPointN' => __('Point %d'), 'strLineString' => __('Linestring'), 'strPolygon' => __('Polygon'), 'strGeometry' => __('Geometry'), 'strInnerRing' => __('Inner ring'), 'strOuterRing' => __('Outer ring'), 'strAddPoint' => __('Add a point'), + 'strAddLineString' => __('Add a linestring'), 'strAddInnerRing' => __('Add an inner ring'), + 'strAddPolygon' => __('Add a polygon'), + 'strAddGeometry' => __('Add geometry'), 'strYes' => __('Yes'), 'strCopyEncryptionKey' => __('Do you want to copy encryption key?'), 'strEncryptionKey' => __('Encryption key'), diff --git a/src/Gis/GisGeometryCollection.php b/src/Gis/GisGeometryCollection.php index 25a436da36..7888dc0550 100644 --- a/src/Gis/GisGeometryCollection.php +++ b/src/Gis/GisGeometryCollection.php @@ -237,7 +237,7 @@ class GisGeometryCollection extends GisGeometry */ public function generateWkt(array $gisData, int $index, string|null $empty = ''): string { - $geomCount = $gisData['GEOMETRYCOLLECTION']['geom_count'] ?? 1; + $geomCount = $gisData['GEOMETRYCOLLECTION']['data_length'] ?? 1; $wkt = 'GEOMETRYCOLLECTION('; /** @infection-ignore-all */ for ($i = 0; $i < $geomCount; $i++) { @@ -283,7 +283,7 @@ class GisGeometryCollection extends GisGeometry // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' $geomCol = mb_substr($wkt, 19, -1); $wktGeometries = $this->explodeGeomCol($geomCol); - $params = ['srid' => $data['srid'], 'GEOMETRYCOLLECTION' => ['geom_count' => count($wktGeometries)]]; + $params = ['srid' => $data['srid'], 'GEOMETRYCOLLECTION' => ['data_length' => count($wktGeometries)]]; foreach ($wktGeometries as $wktGeometry) { $gisObj = GisFactory::fromWkt($wktGeometry); diff --git a/src/Gis/GisLineString.php b/src/Gis/GisLineString.php index aef251c083..9b6051a708 100644 --- a/src/Gis/GisLineString.php +++ b/src/Gis/GisLineString.php @@ -240,7 +240,7 @@ class GisLineString extends GisGeometry */ public function generateWkt(array $gisData, int $index, string|null $empty = ''): string { - $noOfPoints = $gisData[$index]['LINESTRING']['no_of_points'] ?? 2; + $noOfPoints = $gisData[$index]['LINESTRING']['data_length'] ?? 2; if ($noOfPoints < 2) { $noOfPoints = 2; } @@ -275,7 +275,7 @@ class GisLineString extends GisGeometry $pointsArr = $this->extractPoints1d($linestring, null); $noOfPoints = count($pointsArr); - $coords = ['no_of_points' => $noOfPoints]; + $coords = ['data_length' => $noOfPoints]; /** @infection-ignore-all */ for ($i = 0; $i < $noOfPoints; $i++) { $coords[$i] = ['x' => $pointsArr[$i][0], 'y' => $pointsArr[$i][1]]; diff --git a/src/Gis/GisMultiLineString.php b/src/Gis/GisMultiLineString.php index 63ea416a9c..dc496b8e76 100644 --- a/src/Gis/GisMultiLineString.php +++ b/src/Gis/GisMultiLineString.php @@ -269,7 +269,7 @@ class GisMultiLineString extends GisGeometry { $dataRow = $gisData[$index]['MULTILINESTRING'] ?? null; - $noOfLines = $dataRow['no_of_lines'] ?? 1; + $noOfLines = $dataRow['data_length'] ?? 1; if ($noOfLines < 1) { $noOfLines = 1; } @@ -277,7 +277,7 @@ class GisMultiLineString extends GisGeometry $wkt = 'MULTILINESTRING('; /** @infection-ignore-all */ for ($i = 0; $i < $noOfLines; $i++) { - $noOfPoints = $dataRow[$i]['no_of_points'] ?? 2; + $noOfPoints = $dataRow[$i]['data_length'] ?? 2; if ($noOfPoints < 2) { $noOfPoints = 2; } @@ -339,12 +339,12 @@ class GisMultiLineString extends GisGeometry // Trim to remove leading 'MULTILINESTRING((' and trailing '))' $wktMultilinestring = mb_substr($wkt, 17, -2); $wktLinestrings = explode('),(', $wktMultilinestring); - $coords = ['no_of_lines' => count($wktLinestrings)]; + $coords = ['data_length' => count($wktLinestrings)]; foreach ($wktLinestrings as $j => $wktLinestring) { $points = $this->extractPoints1d($wktLinestring, null); $noOfPoints = count($points); - $coords[$j] = ['no_of_points' => $noOfPoints]; + $coords[$j] = ['data_length' => $noOfPoints]; /** @infection-ignore-all */ for ($i = 0; $i < $noOfPoints; $i++) { $coords[$j][$i] = ['x' => $points[$i][0], 'y' => $points[$i][1]]; diff --git a/src/Gis/GisMultiPoint.php b/src/Gis/GisMultiPoint.php index 23b58da215..fbf0562a61 100644 --- a/src/Gis/GisMultiPoint.php +++ b/src/Gis/GisMultiPoint.php @@ -253,7 +253,7 @@ class GisMultiPoint extends GisGeometry */ public function generateWkt(array $gisData, int $index, string|null $empty = ''): string { - $noOfPoints = $gisData[$index]['MULTIPOINT']['no_of_points'] ?? 1; + $noOfPoints = $gisData[$index]['MULTIPOINT']['data_length'] ?? 1; if ($noOfPoints < 1) { $noOfPoints = 1; } @@ -309,7 +309,7 @@ class GisMultiPoint extends GisGeometry $points = $this->extractPoints1d($wktPoints, null); $noOfPoints = count($points); - $coords = ['no_of_points' => $noOfPoints]; + $coords = ['data_length' => $noOfPoints]; /** @infection-ignore-all */ for ($i = 0; $i < $noOfPoints; $i++) { $coords[$i] = ['x' => $points[$i][0], 'y' => $points[$i][1]]; diff --git a/src/Gis/GisMultiPolygon.php b/src/Gis/GisMultiPolygon.php index d713972b3a..f0d7c13847 100644 --- a/src/Gis/GisMultiPolygon.php +++ b/src/Gis/GisMultiPolygon.php @@ -303,7 +303,7 @@ class GisMultiPolygon extends GisGeometry { $dataRow = $gisData[$index]['MULTIPOLYGON'] ?? null; - $noOfPolygons = $dataRow['no_of_polygons'] ?? 1; + $noOfPolygons = $dataRow['data_length'] ?? 1; if ($noOfPolygons < 1) { $noOfPolygons = 1; } @@ -311,14 +311,14 @@ class GisMultiPolygon extends GisGeometry $wkt = 'MULTIPOLYGON('; /** @infection-ignore-all */ for ($k = 0; $k < $noOfPolygons; $k++) { - $noOfLines = $dataRow[$k]['no_of_lines'] ?? 1; + $noOfLines = $dataRow[$k]['data_length'] ?? 1; if ($noOfLines < 1) { $noOfLines = 1; } $wkt .= '('; for ($i = 0; $i < $noOfLines; $i++) { - $noOfPoints = $dataRow[$k][$i]['no_of_points'] ?? 4; + $noOfPoints = $dataRow[$k][$i]['data_length'] ?? 4; if ($noOfPoints < 4) { $noOfPoints = 4; } @@ -448,15 +448,15 @@ class GisMultiPolygon extends GisGeometry // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' $wktMultiPolygon = mb_substr($wkt, 15, -3); $wktPolygons = explode(')),((', $wktMultiPolygon); - $coords = ['no_of_polygons' => count($wktPolygons)]; + $coords = ['data_length' => count($wktPolygons)]; foreach ($wktPolygons as $k => $wktPolygon) { $wktRings = explode('),(', $wktPolygon); - $coords[$k] = ['no_of_lines' => count($wktRings)]; + $coords[$k] = ['data_length' => count($wktRings)]; foreach ($wktRings as $j => $wktRing) { $points = $this->extractPoints1d($wktRing, null); $noOfPoints = count($points); - $coords[$k][$j] = ['no_of_points' => $noOfPoints]; + $coords[$k][$j] = ['data_length' => $noOfPoints]; /** @infection-ignore-all */ for ($i = 0; $i < $noOfPoints; $i++) { $coords[$k][$j][$i] = ['x' => $points[$i][0], 'y' => $points[$i][1]]; diff --git a/src/Gis/GisPolygon.php b/src/Gis/GisPolygon.php index d27dc096d4..2d2af32e32 100644 --- a/src/Gis/GisPolygon.php +++ b/src/Gis/GisPolygon.php @@ -264,7 +264,7 @@ class GisPolygon extends GisGeometry */ public function generateWkt(array $gisData, int $index, string|null $empty = ''): string { - $noOfLines = $gisData[$index]['POLYGON']['no_of_lines'] ?? 1; + $noOfLines = $gisData[$index]['POLYGON']['data_length'] ?? 1; if ($noOfLines < 1) { $noOfLines = 1; } @@ -272,7 +272,7 @@ class GisPolygon extends GisGeometry $wkt = 'POLYGON('; /** @infection-ignore-all */ for ($i = 0; $i < $noOfLines; $i++) { - $noOfPoints = $gisData[$index]['POLYGON'][$i]['no_of_points'] ?? 4; + $noOfPoints = $gisData[$index]['POLYGON'][$i]['data_length'] ?? 4; if ($noOfPoints < 4) { $noOfPoints = 4; } @@ -308,12 +308,12 @@ class GisPolygon extends GisGeometry // Trim to remove leading 'POLYGON((' and trailing '))' $wktPolygon = mb_substr($wkt, 9, -2); $wktRings = explode('),(', $wktPolygon); - $coords = ['no_of_lines' => count($wktRings)]; + $coords = ['data_length' => count($wktRings)]; foreach ($wktRings as $j => $wktRing) { $points = $this->extractPoints1d($wktRing, null); $noOfPoints = count($points); - $coords[$j] = ['no_of_points' => $noOfPoints]; + $coords[$j] = ['data_length' => $noOfPoints]; /** @infection-ignore-all */ for ($i = 0; $i < $noOfPoints; $i++) { $coords[$j][$i] = ['x' => $points[$i][0], 'y' => $points[$i][1]]; diff --git a/templates/gis_data_editor_form.twig b/templates/gis_data_editor_form.twig index 7a57b8b852..739a66a367 100644 --- a/templates/gis_data_editor_form.twig +++ b/templates/gis_data_editor_form.twig @@ -42,11 +42,7 @@ {# End of header section #} {# Data section #} -
- {% if geom_type == 'GEOMETRYCOLLECTION' %} - - {% endif %} - +
- - {% if geom_count > 0 %} - {% for a in 0..geom_count - 1 %} - {% if gis_data[a] is not null %} - {% if geom_type == 'GEOMETRYCOLLECTION' %} -

- {{ 'Geometry %d:'|trans|format(a + 1) }} -
- {% if gis_data[a]['gis_type'] is not null %} - {% set type = gis_data[a]['gis_type'] %} - {% else %} - {% set type = gis_types[0] %} - {% endif %} - - {% else %} - {% set type = geom_type %} - {% endif %} - - {% if type == 'POINT' %} -
- {% trans 'Point:' %} - - - {% elseif type == 'MULTIPOINT' or type == 'LINESTRING' %} - {% set no_of_points = gis_data[a][type]['no_of_points'] ?? 1 %} - {% if type == 'LINESTRING' and no_of_points < 2 %} - {% set no_of_points = 2 %} - {% endif %} - {% if type == 'MULTIPOINT' and no_of_points < 1 %} - {% set no_of_points = 1 %} - {% endif %} - - - {% for i in 0..no_of_points - 1 %} -
- {{ 'Point %d:'|trans|format(i + 1) }} - - - {% endfor %} - {% trans '+ Add a point' %} - {% elseif type == 'MULTILINESTRING' or type == 'POLYGON' %} - {% set no_of_lines = gis_data[a][type]['no_of_lines'] ?? 1 %} - {% if no_of_lines < 1 %} - {% set no_of_lines = 1 %} - {% endif %} - - - {% for i in 0..no_of_lines - 1 %} -
- {% if type == 'MULTILINESTRING' %} - {{ 'Linestring %d:'|trans|format(i + 1) }} - {% elseif i == 0 %} - {% trans 'Outer ring:' %} - {% else %} - {{ 'Inner ring %d:'|trans|format(i) }} - {% endif %} - - {% set no_of_points = gis_data[a][type][i]['no_of_points'] ?? 2 %} - {% if type == 'MULTILINESTRING' and no_of_points < 2 %} - {% set no_of_points = 2 %} - {% endif %} - {% if type == 'POLYGON' and no_of_points < 4 %} - {% set no_of_points = 4 %} - {% endif %} - - - {% for j in 0..no_of_points - 1 %} -
- {{ 'Point %d:'|trans|format(j + 1) }} - - - {% endfor %} - + {% trans 'Add a point' %} - {% endfor %} -
- - + {{- type == 'MULTILINESTRING' ? 'Add a linestring'|trans : 'Add an inner ring'|trans }} - - {% elseif type == 'MULTIPOLYGON' %} - {% set no_of_polygons = gis_data[a][type]['no_of_polygons'] ?? 1 %} - {% if no_of_polygons < 1 %} - {% set no_of_polygons = 1 %} - {% endif %} - - - {% for k in 0..no_of_polygons - 1 %} -
- {{ 'Polygon %d:'|trans|format(k + 1) }} - {% set no_of_lines = gis_data[a][type][k]['no_of_lines'] ?? 1 %} - {% if no_of_lines < 1 %} - {% set no_of_lines = 1 %} - {% endif %} - - - {% for i in 0..no_of_lines - 1 %} -

- {% if i == 0 %} - {% trans 'Outer ring:' %} - {% else %} - {{ 'Inner ring %d:'|trans|format(i) }} - {% endif %} - - {% set no_of_points = gis_data[a][type][k][i]['no_of_points'] ?? 4 %} - {% if no_of_points < 4 %} - {% set no_of_points = 4 %} - {% endif %} - - - {% for j in 0..no_of_points - 1 %} -
- {{ 'Point %d:'|trans|format(j + 1) }} - - - {% endfor %} - + {% trans 'Add a point' %} - {% endfor %} -
- + {% trans 'Add an inner ring' %} -
- {% endfor %} -
- + {% trans 'Add a polygon' %} - {% endif %} - {% endif %} - {% endfor %} - {% endif %} - {% if geom_type == 'GEOMETRYCOLLECTION' %} -

- + {% trans 'Add geometry' %} - {% endif %}
{# End of data section #} diff --git a/test/classes/Gis/Ds/PolygonTest.php b/test/classes/Gis/Ds/PolygonTest.php index 1e38fb70df..bc9b6478e8 100644 --- a/test/classes/Gis/Ds/PolygonTest.php +++ b/test/classes/Gis/Ds/PolygonTest.php @@ -22,9 +22,9 @@ class PolygonTest extends AbstractTestCase { return [ 'POLYGON' => [ - 'no_of_lines' => 2, + 'data_length' => 2, 0 => [ - 'no_of_points' => 5, + 'data_length' => 5, 0 => ['x' => 35, 'y' => 10], 1 => ['x' => 10, 'y' => 20], 2 => ['x' => 15, 'y' => 40], @@ -32,7 +32,7 @@ class PolygonTest extends AbstractTestCase 4 => ['x' => 35, 'y' => 10], ], 1 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 20, 'y' => 30], 1 => ['x' => 35, 'y' => 32], 2 => ['x' => 30, 'y' => 20], @@ -145,8 +145,8 @@ class PolygonTest extends AbstractTestCase public static function providerForTestGetPointOnSurface(): array { $temp = self::getData(); - unset($temp['POLYGON'][0]['no_of_points']); - unset($temp['POLYGON'][1]['no_of_points']); + unset($temp['POLYGON'][0]['data_length']); + unset($temp['POLYGON'][1]['data_length']); return [[Polygon::fromXYArray($temp['POLYGON'][0])], [Polygon::fromXYArray($temp['POLYGON'][1])]]; } diff --git a/test/classes/Gis/GisGeometryCollectionTest.php b/test/classes/Gis/GisGeometryCollectionTest.php index a40a510f54..a081be64db 100644 --- a/test/classes/Gis/GisGeometryCollectionTest.php +++ b/test/classes/Gis/GisGeometryCollectionTest.php @@ -73,7 +73,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase $temp1 = [ 0 => [ 'gis_type' => 'LINESTRING', - 'LINESTRING' => ['no_of_points' => 2, 0 => ['x' => 5.02,'y' => 8.45], 1 => ['x' => 6.14,'y' => 0.15]], + 'LINESTRING' => ['data_length' => 2, 0 => ['x' => 5.02,'y' => 8.45], 1 => ['x' => 6.14,'y' => 0.15]], ], ]; @@ -82,7 +82,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase [ 'gis_type' => 'GEOMETRYCOLLECTION', 'srid' => '0', - 'GEOMETRYCOLLECTION' => ['geom_count' => '1'], + 'GEOMETRYCOLLECTION' => ['data_length' => '1'], 0 => ['gis_type' => 'POINT'], ], 0, @@ -93,7 +93,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase [ 'gis_type' => 'GEOMETRYCOLLECTION', 'srid' => '0', - 'GEOMETRYCOLLECTION' => ['geom_count' => '1'], + 'GEOMETRYCOLLECTION' => ['data_length' => '1'], 0 => ['gis_type' => 'LINESTRING'], ], 0, @@ -104,7 +104,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase [ 'gis_type' => 'GEOMETRYCOLLECTION', 'srid' => '0', - 'GEOMETRYCOLLECTION' => ['geom_count' => '1'], + 'GEOMETRYCOLLECTION' => ['data_length' => '1'], 0 => ['gis_type' => 'POLYGON'], ], 0, @@ -115,7 +115,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase [ 'gis_type' => 'GEOMETRYCOLLECTION', 'srid' => '0', - 'GEOMETRYCOLLECTION' => ['geom_count' => '1'], + 'GEOMETRYCOLLECTION' => ['data_length' => '1'], 0 => ['gis_type' => 'MULTIPOINT'], ], 0, @@ -126,7 +126,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase [ 'gis_type' => 'GEOMETRYCOLLECTION', 'srid' => '0', - 'GEOMETRYCOLLECTION' => ['geom_count' => '1'], + 'GEOMETRYCOLLECTION' => ['data_length' => '1'], 0 => ['gis_type' => 'MULTILINESTRING'], ], 0, @@ -137,7 +137,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase [ 'gis_type' => 'GEOMETRYCOLLECTION', 'srid' => '0', - 'GEOMETRYCOLLECTION' => ['geom_count' => '1'], + 'GEOMETRYCOLLECTION' => ['data_length' => '1'], 0 => ['gis_type' => 'MULTIPOLYGON'], ], 0, @@ -181,11 +181,11 @@ class GisGeometryCollectionTest extends GisGeomTestCase . ')', [ 'srid' => 0, - 'GEOMETRYCOLLECTION' => ['geom_count' => 6], + 'GEOMETRYCOLLECTION' => ['data_length' => 6], 0 => [ 'gis_type' => 'LINESTRING', 'LINESTRING' => [ - 'no_of_points' => 2, + 'data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15], ], @@ -193,15 +193,15 @@ class GisGeometryCollectionTest extends GisGeomTestCase 1 => [ 'gis_type' => 'MULTILINESTRING', 'MULTILINESTRING' => [ - 'no_of_lines' => 2, + 'data_length' => 2, 0 => [ - 'no_of_points' => 3, + 'data_length' => 3, 0 => ['x' => 36.0, 'y' => 14.0], 1 => ['x' => 47.0, 'y' => 23.0], 2 => ['x' => 62.0, 'y' => 75.0], ], 1 => [ - 'no_of_points' => 3, + 'data_length' => 3, 0 => ['x' => 36.0, 'y' => 10.0], 1 => ['x' => 17.0, 'y' => 23.0], 2 => ['x' => 178.0, 'y' => 53.0], @@ -211,7 +211,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase 2 => [ 'gis_type' => 'MULTIPOINT', 'MULTIPOINT' => [ - 'no_of_points' => 2, + 'data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15], ], @@ -219,11 +219,11 @@ class GisGeometryCollectionTest extends GisGeomTestCase 3 => [ 'gis_type' => 'MULTIPOLYGON', 'MULTIPOLYGON' => [ - 'no_of_polygons' => 2, + 'data_length' => 2, 0 => [ - 'no_of_lines' => 2, + 'data_length' => 2, 0 => [ - 'no_of_points' => 5, + 'data_length' => 5, 0 => ['x' => 35.0, 'y' => 10.0], 1 => ['x' => 10.0, 'y' => 20.0], 2 => ['x' => 15.0, 'y' => 40.0], @@ -231,7 +231,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase 4 => ['x' => 35.0, 'y' => 10.0], ], 1 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 20.0, 'y' => 30.0], 1 => ['x' => 35.0, 'y' => 32.0], 2 => ['x' => 30.0, 'y' => 20.0], @@ -239,9 +239,9 @@ class GisGeometryCollectionTest extends GisGeomTestCase ], ], 1 => [ - 'no_of_lines' => 1, + 'data_length' => 1, 0 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 123.0, 'y' => 0.0], 1 => ['x' => 23.0, 'y' => 30.0], 2 => ['x' => 17.0, 'y' => 63.0], @@ -254,9 +254,9 @@ class GisGeometryCollectionTest extends GisGeomTestCase 5 => [ 'gis_type' => 'POLYGON', 'POLYGON' => [ - 'no_of_lines' => 2, + 'data_length' => 2, 0 => [ - 'no_of_points' => 5, + 'data_length' => 5, 0 => ['x' => 35.0, 'y' => 10.0], 1 => ['x' => 10.0, 'y' => 20.0], 2 => ['x' => 15.0, 'y' => 40.0], @@ -264,7 +264,7 @@ class GisGeometryCollectionTest extends GisGeomTestCase 4 => ['x' => 35.0, 'y' => 10.0], ], 1 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 20.0, 'y' => 30.0], 1 => ['x' => 35.0, 'y' => 32.0], 2 => ['x' => 30.0, 'y' => 20.0], diff --git a/test/classes/Gis/GisLineStringTest.php b/test/classes/Gis/GisLineStringTest.php index 8ab7e9ee11..91833737c5 100644 --- a/test/classes/Gis/GisLineStringTest.php +++ b/test/classes/Gis/GisLineStringTest.php @@ -30,7 +30,7 @@ class GisLineStringTest extends GisGeomTestCase $temp1 = [ 0 => [ 'LINESTRING' => [ - 'no_of_points' => 2, + 'data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15], ], @@ -38,21 +38,21 @@ class GisLineStringTest extends GisGeomTestCase ]; $temp2 = $temp1; - $temp2[0]['LINESTRING']['no_of_points'] = 3; + $temp2[0]['LINESTRING']['data_length'] = 3; $temp2[0]['LINESTRING'][2] = ['x' => 1.56]; $temp3 = $temp2; - $temp3[0]['LINESTRING']['no_of_points'] = -1; + $temp3[0]['LINESTRING']['data_length'] = -1; $temp4 = $temp3; - $temp4[0]['LINESTRING']['no_of_points'] = 3; + $temp4[0]['LINESTRING']['data_length'] = 3; unset($temp4[0]['LINESTRING'][2]['x']); return [ [$temp1, 0, null, 'LINESTRING(5.02 8.45,6.14 0.15)'], // if a coordinate is missing, default is empty string [$temp2, 0, null, 'LINESTRING(5.02 8.45,6.14 0.15,1.56 )'], - // if no_of_points is not valid, it is considered as 2 + // if data_length is not valid, it is considered as 2 [$temp3, 0, null, 'LINESTRING(5.02 8.45,6.14 0.15)'], // missing coordinates are replaced with provided values (3rd parameter) [$temp4, 0, '0', 'LINESTRING(5.02 8.45,6.14 0.15,0 0)'], @@ -101,7 +101,7 @@ class GisLineStringTest extends GisGeomTestCase 'srid' => 124, 0 => [ 'LINESTRING' => [ - 'no_of_points' => 2, + 'data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15], ], @@ -114,7 +114,7 @@ class GisLineStringTest extends GisGeomTestCase 'srid' => 0, 0 => [ 'LINESTRING' => [ - 'no_of_points' => 1, + 'data_length' => 1, 0 => [ 'x' => 0, 'y' => 0, diff --git a/test/classes/Gis/GisMultiLineStringTest.php b/test/classes/Gis/GisMultiLineStringTest.php index 4a4c12872c..d1a8745458 100644 --- a/test/classes/Gis/GisMultiLineStringTest.php +++ b/test/classes/Gis/GisMultiLineStringTest.php @@ -30,9 +30,9 @@ class GisMultiLineStringTest extends GisGeomTestCase $temp = [ 0 => [ 'MULTILINESTRING' => [ - 'no_of_lines' => 2, - 0 => ['no_of_points' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15]], - 1 => ['no_of_points' => 2, 0 => ['x' => 1.23, 'y' => 4.25], 1 => ['x' => 9.15, 'y' => 0.47]], + 'data_length' => 2, + 0 => ['data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15]], + 1 => ['data_length' => 2, 0 => ['x' => 1.23, 'y' => 4.25], 1 => ['x' => 9.15, 'y' => 0.47]], ], ], ]; @@ -41,10 +41,10 @@ class GisMultiLineStringTest extends GisGeomTestCase unset($temp1[0]['MULTILINESTRING'][1][1]['y']); $temp2 = $temp; - $temp2[0]['MULTILINESTRING']['no_of_lines'] = 0; + $temp2[0]['MULTILINESTRING']['data_length'] = 0; $temp3 = $temp; - $temp3[0]['MULTILINESTRING'][1]['no_of_points'] = 1; + $temp3[0]['MULTILINESTRING'][1]['data_length'] = 1; return [ [$temp, 0, null, 'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'], @@ -121,9 +121,9 @@ class GisMultiLineStringTest extends GisGeomTestCase 'srid' => 124, 0 => [ 'MULTILINESTRING' => [ - 'no_of_lines' => 2, - 0 => ['no_of_points' => 2, 0 => ['x' => 5.02,'y' => 8.45], 1 => ['x' => 6.14,'y' => 0.15]], - 1 => ['no_of_points' => 2, 0 => ['x' => 1.23,'y' => 4.25], 1 => ['x' => 9.15,'y' => 0.47]], + 'data_length' => 2, + 0 => ['data_length' => 2, 0 => ['x' => 5.02,'y' => 8.45], 1 => ['x' => 6.14,'y' => 0.15]], + 1 => ['data_length' => 2, 0 => ['x' => 1.23,'y' => 4.25], 1 => ['x' => 9.15,'y' => 0.47]], ], ], ], diff --git a/test/classes/Gis/GisMultiPointTest.php b/test/classes/Gis/GisMultiPointTest.php index 7f9676f01b..6e7473c693 100644 --- a/test/classes/Gis/GisMultiPointTest.php +++ b/test/classes/Gis/GisMultiPointTest.php @@ -32,7 +32,7 @@ class GisMultiPointTest extends GisGeomTestCase $gisData1 = [ 0 => [ 'MULTIPOINT' => [ - 'no_of_points' => 2, + 'data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 1.56, 'y' => 4.36], ], @@ -40,7 +40,7 @@ class GisMultiPointTest extends GisGeomTestCase ]; $gisData2 = $gisData1; - $gisData2[0]['MULTIPOINT']['no_of_points'] = -1; + $gisData2[0]['MULTIPOINT']['data_length'] = -1; return [ [$gisData1, 0, null, 'MULTIPOINT(5.02 8.45,1.56 4.36)'], @@ -101,7 +101,7 @@ class GisMultiPointTest extends GisGeomTestCase 'srid' => 124, 0 => [ 'MULTIPOINT' => [ - 'no_of_points' => 2, + 'data_length' => 2, 0 => ['x' => 5.02, 'y' => 8.45], 1 => ['x' => 6.14, 'y' => 0.15], ], diff --git a/test/classes/Gis/GisMultiPolygonTest.php b/test/classes/Gis/GisMultiPolygonTest.php index 86c774982d..81b9dd408f 100644 --- a/test/classes/Gis/GisMultiPolygonTest.php +++ b/test/classes/Gis/GisMultiPolygonTest.php @@ -29,11 +29,11 @@ class GisMultiPolygonTest extends GisGeomTestCase { return [ 'MULTIPOLYGON' => [ - 'no_of_polygons' => 2, + 'data_length' => 2, 0 => [ - 'no_of_lines' => 2, + 'data_length' => 2, 0 => [ - 'no_of_points' => 5, + 'data_length' => 5, 0 => ['x' => 35, 'y' => 10], 1 => ['x' => 10, 'y' => 20], 2 => ['x' => 15, 'y' => 40], @@ -41,7 +41,7 @@ class GisMultiPolygonTest extends GisGeomTestCase 4 => ['x' => 35, 'y' => 10], ], 1 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 20, 'y' => 30], 1 => ['x' => 35, 'y' => 32], 2 => ['x' => 30, 'y' => 20], @@ -49,9 +49,9 @@ class GisMultiPolygonTest extends GisGeomTestCase ], ], 1 => [ - 'no_of_lines' => 1, + 'data_length' => 1, 0 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 123, 'y' => 0], 1 => ['x' => 23, 'y' => 30], 2 => ['x' => 17, 'y' => 63], @@ -87,13 +87,13 @@ class GisMultiPolygonTest extends GisGeomTestCase $temp = [0 => self::getData()]; $temp1 = $temp; - $temp1[0]['MULTIPOLYGON']['no_of_polygons'] = 0; + $temp1[0]['MULTIPOLYGON']['data_length'] = 0; $temp2 = $temp; - $temp2[0]['MULTIPOLYGON'][1]['no_of_lines'] = 0; + $temp2[0]['MULTIPOLYGON'][1]['data_length'] = 0; $temp3 = $temp; - $temp3[0]['MULTIPOLYGON'][1][0]['no_of_points'] = 3; + $temp3[0]['MULTIPOLYGON'][1][0]['data_length'] = 3; return [ [ diff --git a/test/classes/Gis/GisPolygonTest.php b/test/classes/Gis/GisPolygonTest.php index cfe089b307..afb9e10178 100644 --- a/test/classes/Gis/GisPolygonTest.php +++ b/test/classes/Gis/GisPolygonTest.php @@ -29,9 +29,9 @@ class GisPolygonTest extends GisGeomTestCase { return [ 'POLYGON' => [ - 'no_of_lines' => 2, + 'data_length' => 2, 0 => [ - 'no_of_points' => 5, + 'data_length' => 5, 0 => ['x' => 35, 'y' => 10], 1 => ['x' => 10, 'y' => 20], 2 => ['x' => 15, 'y' => 40], @@ -39,7 +39,7 @@ class GisPolygonTest extends GisGeomTestCase 4 => ['x' => 35, 'y' => 10], ], 1 => [ - 'no_of_points' => 4, + 'data_length' => 4, 0 => ['x' => 20, 'y' => 30], 1 => ['x' => 35, 'y' => 32], 2 => ['x' => 30, 'y' => 20], @@ -77,10 +77,10 @@ class GisPolygonTest extends GisGeomTestCase unset($temp1[0]['POLYGON'][1][3]['y']); $temp2 = $temp; - $temp2[0]['POLYGON']['no_of_lines'] = 0; + $temp2[0]['POLYGON']['data_length'] = 0; $temp3 = $temp; - $temp3[0]['POLYGON'][1]['no_of_points'] = 3; + $temp3[0]['POLYGON'][1]['data_length'] = 3; return [ [$temp, 0, null, 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))'],