Skip to content

HTTPS clone URL

Subversion checkout URL

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