3 * handles creation of the GIS visualizations.
9 * do not import request variable into global scope
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
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
;
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);
70 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
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']);
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);
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);
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); ?
>
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; ?
>
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() {
122 projection
: new OpenLayers
.Projection("EPSG:900913"),
123 displayProjection
: new OpenLayers
.Projection("EPSG:4326"),
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
);
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");
142 <?php
echo (PMA_GIS_visualization_results($data, $visualizationSettings, 'ol')); ?
>
143 map
.addLayer(vectorLayer
);
145 map
.zoomToExtent(bound
);
146 if (map
.getZoom() < 2) {
149 map
.addControl(new OpenLayers
.Control
.LayerSwitcher());
150 map
.addControl(new OpenLayers
.Control
.MousePosition());
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
>
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
>
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
>
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>');
180 <tr
><td
><label
for="spatial Column"><?php
echo __("Spatial column"); ?
></label
></td
>
181 <td
><select name
="visualizationSettings[spatialColumn]" id
="spatialColumn">
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>');
193 <tr
><td
class="choice" colspan
="2">
194 <input type
="checkbox" name
="visualizationSettings[choice]" id
="choice" value
="useBaseLayer"
196 if (isset($visualizationSettings['choice'])) {
197 echo(' checked="checked"');
201 <label
for="choice"><?php
echo __("Use OpenStreetMaps as Base Layer"); ?
></label
>
204 <td
class="button"><input type
="submit" name
="displayVisualization" value
="<?php echo __('Redraw'); ?>" /></td
>
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
>
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
>
216 echo ('<option value="svg" selected="selected">SVG</option>');
222 <td
class="button"><input type
="submit" name
="saveToFile" value
="<?php echo __('Save'); ?>" /></td
>
230 * Displays the footer
232 require './libraries/footer.inc.php';