Skip to content
Newer
Older
100644 236 lines (209 sloc) 9.27 KB
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
1 <?php
2 /**
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 31, 2011
3 * handles creation of the GIS visualizations.
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
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
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
18 $GLOBALS['js_include'][] = 'jquery/jquery.svg.js';
19 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
20 $GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.min.js';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
21 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
22
aa72856 @madhuracj Output buffer handling for saving files.
madhuracj authored Jun 3, 2011
23 // Allows for resending headers even after sending some data
24 ob_start();
25
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
26 // Runs common work
aa72856 @madhuracj Output buffer handling for saving files.
madhuracj authored Jun 3, 2011
27 require_once './libraries/db_common.inc.php';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
28 $url_params['goto'] = $cfg['DefaultTabDatabase'];
29 $url_params['back'] = 'sql.php';
30
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
31 // Import visualization functions
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
32 require_once './libraries/gis_visualization.lib.php';
33
34 // Execute the query and return the result
35 $result = PMA_DBI_try_query($sql_query);
36 // Get the meta data of results
37 $meta = PMA_DBI_get_fields_meta($result);
38
39 // Find the candidate fields for label column and spatial column
40 $labelCandidates = array(); $spatialCandidates = array();
41 foreach ($meta as $column_meta) {
42 if ($column_meta->type == 'geometry') {
43 $spatialCandidates[] = $column_meta->name;
44 } else {
45 $labelCandidates[] = $column_meta->name;
46 }
47 }
48
49 // Get settings if any posted
50 $visualizationSettings = array();
51 if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
52 $visualizationSettings = $_REQUEST['visualizationSettings'];
53 }
54
55 // If label column is not set, use first non-geometric colum as label column
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
56 if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
57 $visualizationSettings['labelColumn'] = '';
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
58 }
59
60 // If spatial column is not set, use first geometric colum as spatial column
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
61 if (! isset($visualizationSettings['spatialColumn'])) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
62 $visualizationSettings['spatialColumn'] = $spatialCandidates[0];
63 }
64
65 // Convert geometric columns from bytes to text.
66 $modified_query = PMA_GIS_modify_query($sql_query, $visualizationSettings);
67 $modified_result = PMA_DBI_try_query($modified_query);
68
69 $data = array();
70 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
71 $data[] = $row;
72 }
73
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
74 if (isset($_REQUEST['saveToFile'])) {
75 $file_name = $_REQUEST['fileName'];
76 if ($file_name == '') {
77 $file_name = $visualizationSettings['spatialColumn'];
78 }
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
79
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
80 $save_format = $_REQUEST['fileFormat'];
81 PMA_GIS_save_to_file($data, $visualizationSettings, $save_format, $file_name);
a2ff282 @madhuracj Save GIS visualization to file as SVG, PNG
madhuracj authored Jun 2, 2011
82 exit();
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
83 }
84
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
85 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8) ? false : true;
86 $format = $svg_support ? 'svg' : 'png';
87
88 // get the chart and settings after chart generation
89 $visualization = PMA_GIS_visualization_results($data, $visualizationSettings, $format);
90
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
91 /**
92 * Displays the page
93 */
94 ?>
95 <!-- Display visulalization options -->
96 <div id="div_view_options">
97 <form method="post" action="tbl_gis_visualization.php">
98 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
99 <fieldset>
100 <legend><?php echo __('Display GIS Visualization'); ?></legend>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
101 <div id="placeholder" style="width:<?php echo($visualizationSettings['width']); ?>px;height:<?php echo($visualizationSettings['height']); ?>px;border:1px solid #aaa;float:right">
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
102 <?php echo $visualization; ?>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
103 </div>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
104 <div id="openlayersmap"></div>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
105 <?php
106 if ($format == 'svg') {
107 ?>
108 <script language="javascript" type="text/javascript">
109 $(document).ready(function(){
110 var $placeholder = $('#placeholder');
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
111 // add zoom out button
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
112 $('<div class="button" id="zoom_out"><?php echo __("zoom out"); ?></div>').appendTo($placeholder);
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
113 // add panning arrows
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
114 $('<img class="button" id="left_arrow" src="<?php echo($GLOBALS['pmaThemeImage']); ?>arrow-left.gif">').appendTo($placeholder);
115 $('<img class="button" id="right_arrow" src="<?php echo($GLOBALS['pmaThemeImage']); ?>arrow-right.gif">').appendTo($placeholder);
116 $('<img class="button" id="up_arrow" src="<?php echo($GLOBALS['pmaThemeImage']); ?>arrow-up.gif">').appendTo($placeholder);
117 $('<img class="button" id="down_arrow" src="<?php echo($GLOBALS['pmaThemeImage']); ?>arrow-down.gif">').appendTo($placeholder);
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
118 });
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
119 </script>
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
120
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
121 <script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
122 <script type="text/javascript" src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
123 <script language="javascript" type="text/javascript">
124 function drawOpenLayers() {
125 var options = {
126 projection: new OpenLayers.Projection("EPSG:900913"),
127 displayProjection: new OpenLayers.Projection("EPSG:4326"),
128 units: "m",
129 numZoomLevels: 18,
130 maxResolution: 156543.0339,
131 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),
132 restrictedExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)
133 };
134 var map = new OpenLayers.Map('openlayersmap', options);
135
136 // create OSM layer
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
137 var layerNone = new OpenLayers.Layer.Boxes("None", {isBaseLayer: true});
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
138 var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
139 var layerOsmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
140 var layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
141 map.addLayers([layerMapnik, layerOsmarender, layerCycleMap, layerNone]);
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
142
143 // create a vector layer
144 var vectorLayer = new OpenLayers.Layer.Vector("Data");
145 <?php echo (PMA_GIS_visualization_results($data, $visualizationSettings, 'ol')); ?>
146 map.addLayer(vectorLayer);
147
148 map.setCenter(new OpenLayers.LonLat(0, 0), 2);
149 map.addControl(new OpenLayers.Control.LayerSwitcher());
150 map.addControl(new OpenLayers.Control.MousePosition());
151 }
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
152 </script>
153 <?php
154 }
155 ?>
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
156 <input type="hidden" name="sql_query" id="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
157
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
158 <table class="gis_table">
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
159 <tr><td><label for="width"><?php echo __("Width"); ?></label></td>
160 <td><input type="text" name="visualizationSettings[width]" id="width" value="<?php echo (isset($visualizationSettings['width']) ? htmlspecialchars($visualizationSettings['width']) : ''); ?>" /></td>
161 </tr>
162
163 <tr><td><label for="height"><?php echo __("Height"); ?></label></td>
164 <td><input type="text" name="visualizationSettings[height]" id="height" value="<?php echo (isset($visualizationSettings['height']) ? htmlspecialchars($visualizationSettings['height']) : ''); ?>" /></td>
165 </tr>
166
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
167 <tr><td><label for="labelColumn"><?php echo __("Label column"); ?></label></td>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
168 <td><select name="visualizationSettings[labelColumn]" id="labelColumn">
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
169 <option value=""><?php echo __("-- None --"); ?></option>
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
170 <?php
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
171 foreach ($labelCandidates as $labelCandidate) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
172 echo('<option value="' . htmlspecialchars($labelCandidate) . '"');
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
173 if ($labelCandidate == $visualizationSettings['labelColumn']) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
174 echo(' selected="selected"');
175 }
176 echo('>' . htmlspecialchars($labelCandidate) . '</option>');
177 }
178 ?>
179 </select></td>
180 </tr>
181
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
182 <tr><td><label for="spatial Column"><?php echo __("Spatial column"); ?></label></td>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
183 <td><select name="visualizationSettings[spatialColumn]" id="spatialColumn">
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
184 <?php
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
185 foreach ($spatialCandidates as $spatialCandidate) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
186 echo('<option value="' . htmlspecialchars($spatialCandidate) . '"');
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
187 if ($spatialCandidate == $visualizationSettings['spatialColumn']) {
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
188 echo(' selected="selected"');
189 }
190 echo('>' . htmlspecialchars($spatialCandidate) . '</option>');
191 }
192 ?>
193 </select></td>
194 </tr>
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
195 <tr><td class="choice" colspan="2">
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
196 <input type="checkbox" name="visualizationSettings[choice]" id="choice" value="useBaseLayer"
197 <?php
198 if (isset($visualizationSettings['choice'])) {
199 echo(' checked="checked"');
200 }
201 ?>
202 />
9f4c4c9 @madhuracj Labels for visualizations with OpenStreetMaps. New icon for the 'Visu…
madhuracj authored Jun 14, 2011
203 <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
5f09cf5 @madhuracj Visualize GIS data with OpenStreetMap as a base layer
madhuracj authored Jun 12, 2011
204 </td></tr>
b2e498c @madhuracj Modify GIS data visualization to use SVG
madhuracj authored May 30, 2011
205 <tr><td></td>
206 <td class="button"><input type="submit" name="displayVisualization" value="<?php echo __('Redraw'); ?>" /></td>
207 </tr>
208 <tr><td class="save"><?php echo __("Save to file"); ?></td></tr>
209 <tr><td><label for="fileName"><?php echo __("File name"); ?></label></td>
210 <td><input type="text" name="fileName" id="fileName" /></td>
211 </tr>
212 <tr><td><label for="fileFormat"><?php echo __("Format"); ?></label></td>
213 <td><select name="fileFormat" id="fileFormat">
214 <option value="png">PNG</option>
215 <option value="pdf">PDF</option>
216 <?php
217 if ($svg_support) {
218 echo ('<option value="svg" selected="selected">SVG</option>');
219 }
220 ?>
221 </select></td>
222 </tr>
223 <tr><td></td>
224 <td class="button"><input type="submit" name="saveToFile" value="<?php echo __('Save'); ?>" /></td>
225 </tr>
11dd5bc @madhuracj GIS data visualization with flot library added.
madhuracj authored May 10, 2011
226 </table>
227 </fieldset>
228 </form>
229 </div>
230 <?php
231 /**
232 * Displays the footer
233 */
234 require './libraries/footer.inc.php';
235
aa72856 @madhuracj Output buffer handling for saving files.
madhuracj authored Jun 3, 2011
236 ?>
Something went wrong with that request. Please try again.