Visitar URL original
Merge pull request #18704 from MoonE/gis-insert · phpmyadmin/phpmyadmin@6141990 · GitHub
Skip to content

Commit 6141990

Browse files
Merge pull request #18704 from MoonE/gis-insert
Refactor gis visualization ts code
2 parents 3c21a0e + 202f103 commit 6141990

13 files changed

Lines changed: 741 additions & 560 deletions

File tree

‎js/src/gis_data_editor.ts‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,29 @@ import { ajaxShowMessage } from './modules/ajax-message.ts';
1111

1212
let gisEditorLoaded = false;
1313

14+
let visualizationController;
15+
16+
function disposeGISEditorVisualization () {
17+
if (visualizationController) {
18+
visualizationController.dispose();
19+
visualizationController = undefined;
20+
}
21+
}
22+
23+
/**
24+
* Initialize the visualization in the GIS data editor.
25+
*/
26+
function initGISEditorVisualization () {
27+
visualizationController = new window.GisVisualizationController();
28+
}
29+
1430
/**
1531
* Closes the GIS data editor and perform necessary clean up work.
1632
*/
1733
function closeGISEditor () {
1834
$('#popup_background').fadeOut('fast');
1935
$('#gis_editor').fadeOut('fast', function () {
36+
disposeGISEditorVisualization();
2037
$(this).empty();
2138
});
2239
}
@@ -234,20 +251,6 @@ function makeGeometryInputs (gisData): string {
234251
return fn(withIndex('gis_data', 0, type), geometry, type);
235252
}
236253

237-
/**
238-
* Initialize the visualization in the GIS data editor.
239-
*/
240-
function initGISEditorVisualization () {
241-
window.storeGisSvgRef();
242-
// Loads either SVG or OSM visualization based on the choice
243-
window.selectVisualization();
244-
// Adds necessary styles to the div that contains the openStreetMap
245-
window.styleOSM();
246-
// Adds controllers for zooming and panning
247-
window.addZoomPanControllers();
248-
window.zoomAndPan();
249-
}
250-
251254
/**
252255
* Loads JavaScript files and the GIS editor.
253256
*
@@ -302,6 +305,8 @@ function loadGISEditor (value, field, type, inputName) {
302305
return;
303306
}
304307

308+
disposeGISEditorVisualization();
309+
305310
$gisEditor.html(data.gis_editor);
306311
initGISEditorVisualization();
307312

@@ -360,11 +365,13 @@ function insertDataAndClose () {
360365
const argsep = CommonParams.get('arg_separator');
361366
const params = $form.serialize() + argsep + 'generate=true' + argsep + 'ajax_request=true';
362367
$.post('index.php?route=/gis-data-editor', params, function (data) {
363-
if (typeof data !== 'undefined' && data.success === true) {
364-
$('input[name=\'' + inputName + '\']').val(data.result);
365-
} else {
368+
if (typeof data === 'undefined' || data.success !== true) {
366369
ajaxShowMessage(data.error, false);
370+
371+
return;
367372
}
373+
374+
$('input[name=\'' + inputName + '\']').val(data.result);
368375
}, 'json');
369376

370377
closeGISEditor();
@@ -377,9 +384,11 @@ function onCoordinateEdit (data) {
377384
return;
378385
}
379386

387+
disposeGISEditorVisualization();
388+
389+
$('#visualization-placeholder > .visualization-target-svg').html(data.visualization);
380390
$('#gis_data_textarea').val(data.result);
381-
$('#placeholder').empty().removeClass('hasSVG').html(data.visualization);
382-
$('#openlayersmap').empty();
391+
383392
/* TODO: the gis_data_editor should rather return JSON than JS code to eval */
384393
// eslint-disable-next-line no-eval
385394
eval(data.openLayers);

0 commit comments

Comments
 (0)