Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 205 lines (179 sloc) 7.467 kb
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
1 <?php
2 /**
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
3 * handles creation of the GIS visualizations.
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
4 *
5 * @package phpMyAdmin
6 */
7
8 /**
9 * do not import request variable into global scope
10 * @ignore
11 */
12 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
13 define('PMA_NO_VARIABLES_IMPORT', true);
14 }
15
16 require_once './libraries/common.inc.php';
17
56d60fd @madhuracj Added OpenLayers library
madhuracj authored
18 $GLOBALS['js_include'][] = 'openlayers/OpenLayers.js';
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
19 $GLOBALS['js_include'][] = 'jquery/jquery.svg.js';
20 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
21 $GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.min.js';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
22 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
6ae969a @madhuracj Serve OpenStreetMap.js locally
madhuracj authored
23 $GLOBALS['js_include'][] = 'OpenStreetMap.js';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
24
aa72856 @madhuracj Output buffer handling for saving files.
madhuracj authored
25 // Allows for resending headers even after sending some data
26 ob_start();
27
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
28 // Runs common work
aa72856 @madhuracj Output buffer handling for saving files.
madhuracj authored
29 require_once './libraries/db_common.inc.php';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
30 $url_params['goto'] = $cfg['DefaultTabDatabase'];
31 $url_params['back'] = 'sql.php';
32
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
33 // Import visualization functions
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
34 require_once './libraries/gis_visualization.lib.php';
35
36 // Execute the query and return the result
37 $result = PMA_DBI_try_query($sql_query);
38 // Get the meta data of results
39 $meta = PMA_DBI_get_fields_meta($result);
40
41 // Find the candidate fields for label column and spatial column
42 $labelCandidates = array(); $spatialCandidates = array();
43 foreach ($meta as $column_meta) {
44 if ($column_meta->type == 'geometry') {
45 $spatialCandidates[] = $column_meta->name;
46 } else {
47 $labelCandidates[] = $column_meta->name;
48 }
49 }
50
51 // Get settings if any posted
52 $visualizationSettings = array();
53 if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
54 $visualizationSettings = $_REQUEST['visualizationSettings'];
55 }
56
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
57 if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visuali...
madhuracj authored
58 $visualizationSettings['labelColumn'] = '';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
59 }
60
61 // If spatial column is not set, use first geometric colum as spatial column
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
62 if (! isset($visualizationSettings['spatialColumn'])) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
63 $visualizationSettings['spatialColumn'] = $spatialCandidates[0];
64 }
65
66 // Convert geometric columns from bytes to text.
cb0eca2 @madhuracj Rename functions to match PEAR coding style
madhuracj authored
67 $modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings);
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
68 $modified_result = PMA_DBI_try_query($modified_query);
69
70 $data = array();
71 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
72 $data[] = $row;
73 }
74
1b2ed15 @madhuracj If all the rows contain SRID, use OpenStreetMaps on the initial loading
madhuracj authored
75 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
76 if (! isset($_REQUEST['displayVisualization'])) {
77 $visualizationSettings['choice'] = 'useBaseLayer';
78 foreach ($data as $row) {
79 if ($row['srid'] == 0) {
80 unset($visualizationSettings['choice']);
81 break;
82 }
83 }
84 }
85
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
86 if (isset($_REQUEST['saveToFile'])) {
87 $file_name = $_REQUEST['fileName'];
88 if ($file_name == '') {
89 $file_name = $visualizationSettings['spatialColumn'];
90 }
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
91
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
92 $save_format = $_REQUEST['fileFormat'];
cb0eca2 @madhuracj Rename functions to match PEAR coding style
madhuracj authored
93 PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
a2ff282 @madhuracj Save GIS visualization to file as SVG, PNG
madhuracj authored
94 exit();
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
95 }
96
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
97 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8) ? false : true;
98 $format = $svg_support ? 'svg' : 'png';
99
100 // get the chart and settings after chart generation
cb0eca2 @madhuracj Rename functions to match PEAR coding style
madhuracj authored
101 $visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $format);
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
102
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
103 /**
104 * Displays the page
105 */
106 ?>
107 <!-- Display visulalization options -->
108 <div id="div_view_options">
109 <form method="post" action="tbl_gis_visualization.php">
110 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
111 <fieldset>
112 <legend><?php echo __('Display GIS Visualization'); ?></legend>
322494d @madhuracj Style changes
madhuracj authored
113 <div id="placeholder" style="width:<?php echo($visualizationSettings['width']); ?>px;height:<?php echo($visualizationSettings['height']); ?>px;">
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
114 <?php echo $visualization; ?>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
115 </div>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
116 <div id="openlayersmap"></div>
3792b78 @madhuracj JavaScript code moved into .js file
madhuracj authored
117 <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
118
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
119 <script language="javascript" type="text/javascript">
120 function drawOpenLayers() {
cb0eca2 @madhuracj Rename functions to match PEAR coding style
madhuracj authored
121 <?php echo (PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol')); ?>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
122 }
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
123 </script>
3792b78 @madhuracj JavaScript code moved into .js file
madhuracj authored
124
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
125 <input type="hidden" name="sql_query" id="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
126
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
127 <table class="gis_table">
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
128 <tr><td><label for="width"><?php echo __("Width"); ?></label></td>
129 <td><input type="text" name="visualizationSettings[width]" id="width" value="<?php echo (isset($visualizationSettings['width']) ? htmlspecialchars($visualizationSettings['width']) : ''); ?>" /></td>
130 </tr>
131
132 <tr><td><label for="height"><?php echo __("Height"); ?></label></td>
133 <td><input type="text" name="visualizationSettings[height]" id="height" value="<?php echo (isset($visualizationSettings['height']) ? htmlspecialchars($visualizationSettings['height']) : ''); ?>" /></td>
134 </tr>
135
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
136 <tr><td><label for="labelColumn"><?php echo __("Label column"); ?></label></td>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
137 <td><select name="visualizationSettings[labelColumn]" id="labelColumn">
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visuali...
madhuracj authored
138 <option value=""><?php echo __("-- None --"); ?></option>
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
139 <?php
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
140 foreach ($labelCandidates as $labelCandidate) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
141 echo('<option value="' . htmlspecialchars($labelCandidate) . '"');
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
142 if ($labelCandidate == $visualizationSettings['labelColumn']) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
143 echo(' selected="selected"');
144 }
145 echo('>' . htmlspecialchars($labelCandidate) . '</option>');
146 }
147 ?>
148 </select></td>
149 </tr>
150
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
151 <tr><td><label for="spatial Column"><?php echo __("Spatial column"); ?></label></td>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
152 <td><select name="visualizationSettings[spatialColumn]" id="spatialColumn">
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
153 <?php
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
154 foreach ($spatialCandidates as $spatialCandidate) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
155 echo('<option value="' . htmlspecialchars($spatialCandidate) . '"');
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
156 if ($spatialCandidate == $visualizationSettings['spatialColumn']) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
157 echo(' selected="selected"');
158 }
159 echo('>' . htmlspecialchars($spatialCandidate) . '</option>');
160 }
161 ?>
162 </select></td>
163 </tr>
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visuali...
madhuracj authored
164 <tr><td class="choice" colspan="2">
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
165 <input type="checkbox" name="visualizationSettings[choice]" id="choice" value="useBaseLayer"
166 <?php
167 if (isset($visualizationSettings['choice'])) {
168 echo(' checked="checked"');
169 }
170 ?>
171 />
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visuali...
madhuracj authored
172 <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored
173 </td></tr>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored
174 <tr><td></td>
175 <td class="button"><input type="submit" name="displayVisualization" value="<?php echo __('Redraw'); ?>" /></td>
176 </tr>
177 <tr><td class="save"><?php echo __("Save to file"); ?></td></tr>
178 <tr><td><label for="fileName"><?php echo __("File name"); ?></label></td>
179 <td><input type="text" name="fileName" id="fileName" /></td>
180 </tr>
181 <tr><td><label for="fileFormat"><?php echo __("Format"); ?></label></td>
182 <td><select name="fileFormat" id="fileFormat">
183 <option value="png">PNG</option>
184 <option value="pdf">PDF</option>
185 <?php
186 if ($svg_support) {
187 echo ('<option value="svg" selected="selected">SVG</option>');
188 }
189 ?>
190 </select></td>
191 </tr>
192 <tr><td></td>
193 <td class="button"><input type="submit" name="saveToFile" value="<?php echo __('Save'); ?>" /></td>
194 </tr>
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored
195 </table>
196 </fieldset>
197 </form>
198 </div>
199 <?php
200 /**
201 * Displays the footer
202 */
203 require './libraries/footer.inc.php';
204
aa72856 @madhuracj Output buffer handling for saving files.
madhuracj authored
205 ?>
Something went wrong with that request. Please try again.