Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / tbl_gis_visualization.php
blob5c54b2f98459ad5e6226d38e70cdaba89c319386
1 <?php
2 /**
3 * handles creation of the GIS visualizations.
5 * @package phpMyAdmin
6 */
8 /**
9 * do not import request variable into global scope
10 * @ignore
12 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
13 define('PMA_NO_VARIABLES_IMPORT', true);
16 require_once './libraries/common.inc.php';
18 $GLOBALS['js_include'][] = 'openlayers/OpenLayers.js';
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';
22 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
24 // Allows for resending headers even after sending some data
25 ob_start();
27 // Runs common work
28 require_once './libraries/db_common.inc.php';
29 $url_params['goto'] = $cfg['DefaultTabDatabase'];
30 $url_params['back'] = 'sql.php';
32 // Import visualization functions
33 require_once './libraries/gis_visualization.lib.php';
35 // Execute the query and return the result
36 $result = PMA_DBI_try_query($sql_query);
37 // Get the meta data of results
38 $meta = PMA_DBI_get_fields_meta($result);
40 // Find the candidate fields for label column and spatial column
41 $labelCandidates = array(); $spatialCandidates = array();
42 foreach ($meta as $column_meta) {
43 if ($column_meta->type == 'geometry') {
44 $spatialCandidates[] = $column_meta->name;
45 } else {
46 $labelCandidates[] = $column_meta->name;
50 // Get settings if any posted
51 $visualizationSettings = array();
52 if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
53 $visualizationSettings = $_REQUEST['visualizationSettings'];
56 if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
57 $visualizationSettings['labelColumn'] = '';
60 // If spatial column is not set, use first geometric colum as spatial column
61 if (! isset($visualizationSettings['spatialColumn'])) {
62 $visualizationSettings['spatialColumn'] = $spatialCandidates[0];
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);
69 $data = array();
70 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
71 $data[] = $row;
74 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
75 if (! isset($_REQUEST['displayVisualization'])) {
76 $visualizationSettings['choice'] = 'useBaseLayer';
77 foreach ($data as $row) {
78 if ($row['srid'] == 0) {
79 unset($visualizationSettings['choice']);
80 break;
85 if (isset($_REQUEST['saveToFile'])) {
86 $file_name = $_REQUEST['fileName'];
87 if ($file_name == '') {
88 $file_name = $visualizationSettings['spatialColumn'];
91 $save_format = $_REQUEST['fileFormat'];
92 PMA_GIS_save_to_file($data, $visualizationSettings, $save_format, $file_name);
93 exit();
96 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8) ? false : true;
97 $format = $svg_support ? 'svg' : 'png';
99 // get the chart and settings after chart generation
100 $visualization = PMA_GIS_visualization_results($data, $visualizationSettings, $format);
103 * Displays the page
106 <!-- Display visulalization options -->
107 <div id="div_view_options">
108 <form method="post" action="tbl_gis_visualization.php">
109 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
110 <fieldset>
111 <legend><?php echo __('Display GIS Visualization'); ?></legend>
112 <div id="placeholder" style="width:<?php echo($visualizationSettings['width']); ?>px;height:<?php echo($visualizationSettings['height']); ?>px;">
113 <?php echo $visualization; ?>
114 </div>
115 <div id="openlayersmap"></div>
116 <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
118 <script type="text/javascript" src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
119 <script language="javascript" type="text/javascript">
120 function drawOpenLayers() {
121 var options = {
122 projection: new OpenLayers.Projection("EPSG:900913"),
123 displayProjection: new OpenLayers.Projection("EPSG:4326"),
124 units: "m",
125 numZoomLevels: 18,
126 maxResolution: 156543.0339,
127 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),
128 restrictedExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)
130 var map = new OpenLayers.Map('openlayersmap', options);
132 // create OSM layer
133 var layerNone = new OpenLayers.Layer.Boxes("None", {isBaseLayer: true});
134 var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
135 var layerOsmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
136 var layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
137 map.addLayers([layerMapnik, layerOsmarender, layerCycleMap, layerNone]);
139 // create a vector layer
140 var vectorLayer = new OpenLayers.Layer.Vector("Data");
141 var bound;
142 <?php echo (PMA_GIS_visualization_results($data, $visualizationSettings, 'ol')); ?>
143 map.addLayer(vectorLayer);
145 map.zoomToExtent(bound);
146 if (map.getZoom() < 2) {
147 map.zoomTo(2);
149 map.addControl(new OpenLayers.Control.LayerSwitcher());
150 map.addControl(new OpenLayers.Control.MousePosition());
152 </script>
154 <input type="hidden" name="sql_query" id="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
156 <table class="gis_table">
157 <tr><td><label for="width"><?php echo __("Width"); ?></label></td>
158 <td><input type="text" name="visualizationSettings[width]" id="width" value="<?php echo (isset($visualizationSettings['width']) ? htmlspecialchars($visualizationSettings['width']) : ''); ?>" /></td>
159 </tr>
161 <tr><td><label for="height"><?php echo __("Height"); ?></label></td>
162 <td><input type="text" name="visualizationSettings[height]" id="height" value="<?php echo (isset($visualizationSettings['height']) ? htmlspecialchars($visualizationSettings['height']) : ''); ?>" /></td>
163 </tr>
165 <tr><td><label for="labelColumn"><?php echo __("Label column"); ?></label></td>
166 <td><select name="visualizationSettings[labelColumn]" id="labelColumn">
167 <option value=""><?php echo __("-- None --"); ?></option>
168 <?php
169 foreach ($labelCandidates as $labelCandidate) {
170 echo('<option value="' . htmlspecialchars($labelCandidate) . '"');
171 if ($labelCandidate == $visualizationSettings['labelColumn']) {
172 echo(' selected="selected"');
174 echo('>' . htmlspecialchars($labelCandidate) . '</option>');
177 </select></td>
178 </tr>
180 <tr><td><label for="spatial Column"><?php echo __("Spatial column"); ?></label></td>
181 <td><select name="visualizationSettings[spatialColumn]" id="spatialColumn">
182 <?php
183 foreach ($spatialCandidates as $spatialCandidate) {
184 echo('<option value="' . htmlspecialchars($spatialCandidate) . '"');
185 if ($spatialCandidate == $visualizationSettings['spatialColumn']) {
186 echo(' selected="selected"');
188 echo('>' . htmlspecialchars($spatialCandidate) . '</option>');
191 </select></td>
192 </tr>
193 <tr><td class="choice" colspan="2">
194 <input type="checkbox" name="visualizationSettings[choice]" id="choice" value="useBaseLayer"
195 <?php
196 if (isset($visualizationSettings['choice'])) {
197 echo(' checked="checked"');
201 <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
202 </td></tr>
203 <tr><td></td>
204 <td class="button"><input type="submit" name="displayVisualization" value="<?php echo __('Redraw'); ?>" /></td>
205 </tr>
206 <tr><td class="save"><?php echo __("Save to file"); ?></td></tr>
207 <tr><td><label for="fileName"><?php echo __("File name"); ?></label></td>
208 <td><input type="text" name="fileName" id="fileName" /></td>
209 </tr>
210 <tr><td><label for="fileFormat"><?php echo __("Format"); ?></label></td>
211 <td><select name="fileFormat" id="fileFormat">
212 <option value="png">PNG</option>
213 <option value="pdf">PDF</option>
214 <?php
215 if ($svg_support) {
216 echo ('<option value="svg" selected="selected">SVG</option>');
219 </select></td>
220 </tr>
221 <tr><td></td>
222 <td class="button"><input type="submit" name="saveToFile" value="<?php echo __('Save'); ?>" /></td>
223 </tr>
224 </table>
225 </fieldset>
226 </form>
227 </div>
228 <?php
230 * Displays the footer
232 require './libraries/footer.inc.php';