2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * handles creation of the GIS visualizations.
9 require_once 'libraries/common.inc.php';
12 require_once 'libraries/db_common.inc.php';
13 $url_params['goto'] = $cfg['DefaultTabDatabase'];
14 $url_params['back'] = 'sql.php';
16 // Import visualization functions
17 require_once 'libraries/tbl_gis_visualization.lib.php';
19 $response = PMA_Response
::getInstance();
20 // Throw error if no sql query is set
21 if (! isset($sql_query) ||
$sql_query == '') {
22 $response->isSuccess(false);
24 PMA_Message
::error(__('No SQL query was set to fetch data.'))
29 // Execute the query and return the result
30 $result = $GLOBALS['dbi']->tryQuery($sql_query);
31 // Get the meta data of results
32 $meta = $GLOBALS['dbi']->getFieldsMeta($result);
34 // Find the candidate fields for label column and spatial column
35 $labelCandidates = array(); $spatialCandidates = array();
36 foreach ($meta as $column_meta) {
37 if ($column_meta->type
== 'geometry') {
38 $spatialCandidates[] = $column_meta->name
;
40 $labelCandidates[] = $column_meta->name
;
44 // Get settings if any posted
45 $visualizationSettings = array();
46 if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
47 $visualizationSettings = $_REQUEST['visualizationSettings'];
50 if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
51 $visualizationSettings['labelColumn'] = '';
54 // If spatial column is not set, use first geometric colum as spatial column
55 if (! isset($visualizationSettings['spatialColumn'])) {
56 $visualizationSettings['spatialColumn'] = $spatialCandidates[0];
59 // Convert geometric columns from bytes to text.
60 $modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings);
61 $modified_result = $GLOBALS['dbi']->tryQuery($modified_query);
64 while ($row = $GLOBALS['dbi']->fetchAssoc($modified_result)) {
68 if (isset($_REQUEST['saveToFile'])) {
70 $file_name = $_REQUEST['fileName'];
71 if ($file_name == '') {
72 $file_name = $visualizationSettings['spatialColumn'];
75 $save_format = $_REQUEST['fileFormat'];
76 PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
80 $header = $response->getHeader();
81 $scripts = $header->getScripts();
82 $scripts->addFile('openlayers/OpenLayers.js');
83 $scripts->addFile('jquery/jquery.svg.js');
84 $scripts->addFile('tbl_gis_visualization.js');
85 $scripts->addFile('OpenStreetMap.js');
87 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
88 if (! isset($_REQUEST['displayVisualization'])) {
89 $visualizationSettings['choice'] = 'useBaseLayer';
90 foreach ($data as $row) {
91 if ($row['srid'] == 0) {
92 unset($visualizationSettings['choice']);
98 $svg_support = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
<= 8)
100 $format = $svg_support ?
'svg' : 'png';
102 // get the chart and settings after chart generation
103 $visualization = PMA_GIS_visualizationResults(
104 $data, $visualizationSettings, $format
111 $html = PMA_getHtmlForGisVisualization(
112 $url_params, $labelCandidates, $spatialCandidates,
113 $visualizationSettings, $sql_query, $visualization, $svg_support,
117 $response->addHTML($html);