1
var gisEditorLoaded=false;function closeGISEditor(){$("#popup_background").fadeOut("fast");$("#gis_editor").fadeOut("fast",function(){$(this).empty()})}function prepareJSVersion(){$("#gis_editor input[name='gis_data[save]']").val(PMA_messages.strCopy).insertAfter($("#gis_data_textarea")).before("<br/><br/>");$("#gis_data_editor").prepend('<a class="close_gis_editor" href="#">'+PMA_messages.strClose+"</a>");$('<a class="cancel_gis_editor" href="#"> '+PMA_messages.strCancel+"</a>").insertAfter($("input[name='gis_data[save]']"));$("div#gis_data_output p").remove();$("#gis_editor input.add").each(function(c){var b=$(this);b.addClass("addJs").removeClass("add");var a=b.attr("class");b.replaceWith('<a class="'+a+'" name="'+b.attr("name")+'" href="#">+ '+b.val()+"</a>")})}function addDataPoint(a,b){return"<br/>"+$.sprintf(PMA_messages.strPointN,(a+1))+': <label for="x">'+PMA_messages.strX+'</label><input type="text" name="'+b+"["+a+'][x]" value=""/><label for="y">'+PMA_messages.strY+'</label><input type="text" name="'+b+"["+a+'][y]" value=""/>'}function initGISEditorVisualization(){selectVisualization();styleOSM();loadSVG();addZoomPanControllers();zoomAndPan()}function loadJSAndGISEditor(j,h,e,c,a){var f=document.getElementsByTagName("head")[0];var g;var d=["js/jquery/jquery.svg.js","js/jquery/jquery.mousewheel.js","js/jquery/jquery.event.drag-2.0.js","js/tbl_gis_visualization.js"];for(var b=0;b<d.length;b++){g=document.createElement("script");g.type="text/javascript";g.src=d[b];f.appendChild(g)}g=document.createElement("script");g.type="text/javascript";g.onreadystatechange=function(){if(this.readyState=="complete"){loadGISEditor(j,h,e,c,a)}};g.onload=function(){loadGISEditor(j,h,e,c,a)};g.src="js/openlayers/OpenLayers.js";f.appendChild(g);gisEditorLoaded=true}function loadGISEditor(d,e,c,f,b){var a=$("#gis_editor");$.post("gis_data_editor.php",{field:e,value:d,type:c,input_name:f,get_gis_editor:true,token:b,ajax_request:true},function(g){if(g.success==true){a.html(g.gis_editor);initGISEditorVisualization();prepareJSVersion()}else{PMA_ajaxShowMessage(g.error,false)}},"json")}function openGISEditor(){var d=document.documentElement.clientWidth;var h=document.documentElement.clientHeight;var e=d*0.9;var g=h*0.9;var c=h/2-g/2;var b=d/2-e/2;var a=$("#gis_editor");var f=$("#popup_background");a.css({top:c,left:b,width:e,height:g});f.css({opacity:"0.7"});a.append('<div id="gis_data_editor"><img class="ajaxIcon" id="loadingMonitorIcon" src="'+pmaThemeImage+'ajax_clock_small.gif" alt=""/></div>');f.fadeIn("fast");a.fadeIn("fast")}function insertDataAndClose(){var a=$("form#gis_data_editor_form");var b=a.find("input[name='input_name']").val();$.post("gis_data_editor.php",a.serialize()+"&generate=true&ajax_request=true",function(c){if(c.success==true){$("input[name='"+b+"']").val(c.result)}else{PMA_ajaxShowMessage(c.error,false)}},"json");closeGISEditor()}AJAX.registerTeardown("gis_data_editor.js",function(){$("#gis_editor input[name='gis_data[save]']").die("click");$("#gis_editor").die("submit");$("#gis_editor").find("input[type='text']").die("change");$("#gis_editor select.gis_type").die("change");$("#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor").die("click");$("#gis_editor a.addJs.addPoint").die("click");$("#gis_editor a.addLine.addJs").die("click");$("#gis_editor a.addJs.addPolygon").die("click");$("#gis_editor a.addJs.addGeom").die("click")});AJAX.registerOnload("gis_data_editor.js",function(){$("span.open_gis_editor a").removeClass("formLinkSubmit");$("#gis_editor input[name='gis_data[save]']").live("click",function(event){event.preventDefault();insertDataAndClose()});$("#gis_editor").live("submit",function(event){event.preventDefault();insertDataAndClose()});$("#gis_editor").find("input[type='text']").live("change",function(){var $form=$("form#gis_data_editor_form");$.post("gis_data_editor.php",$form.serialize()+"&generate=true&ajax_request=true",function(data){if(data.success==true){$("#gis_data_textarea").val(data.result);$("#placeholder").empty().removeClass("hasSVG").html(data.visualization);$("#openlayersmap").empty();eval(data.openLayers);initGISEditorVisualization()}else{PMA_ajaxShowMessage(data.error,false)}},"json")});$("#gis_editor select.gis_type").live("change",function(event){var $gis_editor=$("#gis_editor");var $form=$("form#gis_data_editor_form");$.post("gis_data_editor.php",$form.serialize()+"&get_gis_editor=true&ajax_request=true",function(data){if(data.success==true){$gis_editor.html(data.gis_editor);initGISEditorVisualization();prepareJSVersion()}else{PMA_ajaxShowMessage(data.error,false)}},"json")});$("#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor").live("click",function(){closeGISEditor()});$("#gis_editor a.addJs.addPoint").live("click",function(){var $a=$(this);var name=$a.attr("name");var prefix=name.substr(0,name.length-11);var $noOfPointsInput=$("input[name='"+prefix+"[no_of_points]']");var noOfPoints=parseInt($noOfPointsInput.val());var html=addDataPoint(noOfPoints,prefix);$a.before(html);$noOfPointsInput.val(noOfPoints+1)});$("#gis_editor a.addLine.addJs").live("click",function(){var $a=$(this);var name=$a.attr("name");var prefix=name.substr(0,name.length-10);var type=prefix.slice(prefix.lastIndexOf("[")+1,prefix.lastIndexOf("]"));var $noOfLinesInput=$("input[name='"+prefix+"[no_of_lines]']");var noOfLines=parseInt($noOfLinesInput.val());var html="<br/>";if(type=="MULTILINESTRING"){html+=PMA_messages.strLineString+" "+(noOfLines+1)+":";var noOfPoints=2}else{html+=PMA_messages.strInnerRing+" "+noOfLines+":";var noOfPoints=4}html+='<input type="hidden" name="'+prefix+"["+noOfLines+'][no_of_points]" value="'+noOfPoints+'"/>';for(var i=0;i<noOfPoints;i++){html+=addDataPoint(i,(prefix+"["+noOfLines+"]"))}html+='<a class="addPoint addJs" name="'+prefix+"["+noOfLines+'][add_point]" href="#">+ '+PMA_messages.strAddPoint+"</a><br/>";$a.before(html);$noOfLinesInput.val(noOfLines+1)});$("#gis_editor a.addJs.addPolygon").live("click",function(){var $a=$(this);var name=$a.attr("name");var prefix=name.substr(0,name.length-13);var $noOfPolygonsInput=$("input[name='"+prefix+"[no_of_polygons]']");var noOfPolygons=parseInt($noOfPolygonsInput.val());var html=PMA_messages.strPolygon+" "+(noOfPolygons+1)+":<br/>";html+='<input type="hidden" name="'+prefix+"["+noOfPolygons+'][no_of_lines]" value="1"/><br/>'+PMA_messages.strOuterRing+':<input type="hidden" name="'+prefix+"["+noOfPolygons+'][0][no_of_points]" value="4"/>';for(var i=0;i<4;i++){html+=addDataPoint(i,(prefix+"["+noOfPolygons+"][0]"))}html+='<a class="addPoint addJs" name="'+prefix+"["+noOfPolygons+'][0][add_point]" href="#">+ '+PMA_messages.strAddPoint+'</a><br/><a class="addLine addJs" name="'+prefix+"["+noOfPolygons+'][add_line]" href="#">+ '+PMA_messages.strAddInnerRing+"</a><br/><br/>";$a.before(html);$noOfPolygonsInput.val(noOfPolygons+1)});$("#gis_editor a.addJs.addGeom").live("click",function(){var $a=$(this);var prefix="gis_data[GEOMETRYCOLLECTION]";var $noOfGeomsInput=$("input[name='"+prefix+"[geom_count]']");var noOfGeoms=parseInt($noOfGeomsInput.val());var html1=PMA_messages.strGeometry+" "+(noOfGeoms+1)+":<br/>";var $geomType=$("select[name='gis_data["+(noOfGeoms-1)+"][gis_type]']").clone();$geomType.attr("name","gis_data["+noOfGeoms+"][gis_type]").val("POINT");var html2="<br/>"+PMA_messages.strPoint+' :<label for="x"> '+PMA_messages.strX+' </label><input type="text" name="gis_data['+noOfGeoms+'][POINT][x]" value=""/><label for="y"> '+PMA_messages.strY+' </label><input type="text" name="gis_data['+noOfGeoms+'][POINT][y]" value=""/><br/><br/>';$a.before(html1);$geomType.insertBefore($a);$a.before(html2);$noOfGeomsInput.val(noOfGeoms+1)})});
b'\\ No newline at end of file'
1
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
* @fileoverview functions used in GIS data editor
9
var gisEditorLoaded = false;
12
* Closes the GIS data editor and perform necessary clean up work.
14
function closeGISEditor(){
15
$("#popup_background").fadeOut("fast");
16
$("#gis_editor").fadeOut("fast", function () {
22
* Prepares the HTML recieved via AJAX.
24
function prepareJSVersion() {
25
// Change the text on the submit button
26
$("#gis_editor input[name='gis_data[save]']")
27
.val(PMA_messages['strCopy'])
28
.insertAfter($('#gis_data_textarea'))
29
.before('<br/><br/>');
31
// Add close and cancel links
32
$('#gis_data_editor').prepend('<a class="close_gis_editor" href="#">' + PMA_messages['strClose'] + '</a>');
33
$('<a class="cancel_gis_editor" href="#"> ' + PMA_messages['strCancel'] + '</a>')
34
.insertAfter($("input[name='gis_data[save]']"));
36
// Remove the unnecessary text
37
$('div#gis_data_output p').remove();
39
// Remove 'add' buttons and add links
40
$('#gis_editor input.add').each(function(e) {
41
var $button = $(this);
42
$button.addClass('addJs').removeClass('add');
43
var classes = $button.attr('class');
45
'<a class="' + classes + '" name="' + $button.attr('name')
46
+ '" href="#">+ ' + $button.val() + '</a>'
52
* Returns the HTML for a data point.
54
* @param pointNumber point number
55
* @param prefix prefix of the name
56
* @returns the HTML for a data point
58
function addDataPoint(pointNumber, prefix) {
59
return '<br/>' + $.sprintf(PMA_messages['strPointN'], (pointNumber + 1)) + ': '
60
+ '<label for="x">' + PMA_messages['strX'] + '</label>'
61
+ '<input type="text" name="' + prefix + '[' + pointNumber + '][x]" value=""/>'
62
+ '<label for="y">' + PMA_messages['strY'] + '</label>'
63
+ '<input type="text" name="' + prefix + '[' + pointNumber + '][y]" value=""/>';
67
* Initialize the visualization in the GIS data editor.
69
function initGISEditorVisualization() {
70
// Loads either SVG or OSM visualization based on the choice
71
selectVisualization();
72
// Adds necessary styles to the div that coontains the openStreetMap
74
// Loads the SVG element and make a reference to it
76
// Adds controllers for zooming and panning
77
addZoomPanControllers();
82
* Loads JavaScript files and the GIS editor.
84
* @param value current value of the geometry field
85
* @param field field name
86
* @param type geometry type
87
* @param input_name name of the input field
90
function loadJSAndGISEditor(value, field, type, input_name, token) {
91
var head = document.getElementsByTagName('head')[0];
94
// Loads a set of small JS file needed for the GIS editor
95
var smallScripts = [ 'js/jquery/jquery.svg.js',
96
'js/jquery/jquery.mousewheel.js',
97
'js/jquery/jquery.event.drag-2.0.js',
98
'js/tbl_gis_visualization.js' ];
100
for (var i = 0; i < smallScripts.length; i++) {
101
script = document.createElement('script');
102
script.type = 'text/javascript';
103
script.src = smallScripts[i];
104
head.appendChild(script);
107
// OpenLayers.js is BIG and takes time. So asynchronous loading would not work.
108
// Load the JS and do a callback to load the content for the GIS Editor.
109
script = document.createElement('script');
110
script.type = 'text/javascript';
112
script.onreadystatechange = function() {
113
if (this.readyState == 'complete') {
114
loadGISEditor(value, field, type, input_name, token);
117
script.onload = function() {
118
loadGISEditor(value, field, type, input_name, token);
121
script.src = 'js/openlayers/OpenLayers.js';
122
head.appendChild(script);
124
gisEditorLoaded = true;
128
* Loads the GIS editor via AJAX
130
* @param value current value of the geometry field
131
* @param field field name
132
* @param type geometry type
133
* @param input_name name of the input field
136
function loadGISEditor(value, field, type, input_name, token) {
138
var $gis_editor = $("#gis_editor");
139
$.post('gis_data_editor.php', {
143
'input_name' : input_name,
144
'get_gis_editor' : true,
148
if (data.success == true) {
149
$gis_editor.html(data.gis_editor);
150
initGISEditorVisualization();
153
PMA_ajaxShowMessage(data.error, false);
159
* Opens up the dialog for the GIS data editor.
161
function openGISEditor() {
164
var windowWidth = document.documentElement.clientWidth;
165
var windowHeight = document.documentElement.clientHeight;
166
var popupWidth = windowWidth * 0.9;
167
var popupHeight = windowHeight * 0.9;
168
var popupOffsetTop = windowHeight / 2 - popupHeight / 2;
169
var popupOffsetLeft = windowWidth / 2 - popupWidth / 2;
171
var $gis_editor = $("#gis_editor");
172
var $backgrouond = $("#popup_background");
174
$gis_editor.css({"top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
175
$backgrouond.css({"opacity":"0.7"});
177
$gis_editor.append('<div id="gis_data_editor"><img class="ajaxIcon" id="loadingMonitorIcon" src="'
178
+ pmaThemeImage + 'ajax_clock_small.gif" alt=""/></div>'
182
$backgrouond.fadeIn("fast");
183
$gis_editor.fadeIn("fast");
187
* Prepare and insert the GIS data in Well Known Text format
188
* to the input field.
190
function insertDataAndClose() {
191
var $form = $('form#gis_data_editor_form');
192
var input_name = $form.find("input[name='input_name']").val();
194
$.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) {
195
if (data.success == true) {
196
$("input[name='" + input_name + "']").val(data.result);
198
PMA_ajaxShowMessage(data.error, false);
205
* Unbind all event handlers before tearing down a page
207
AJAX.registerTeardown('gis_data_editor.js', function() {
208
$("#gis_editor input[name='gis_data[save]']").die('click');
209
$('#gis_editor').die('submit');
210
$('#gis_editor').find("input[type='text']").die('change');
211
$("#gis_editor select.gis_type").die('change');
212
$('#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor').die('click');
213
$('#gis_editor a.addJs.addPoint').die('click');
214
$('#gis_editor a.addLine.addJs').die('click');
215
$('#gis_editor a.addJs.addPolygon').die('click');
216
$('#gis_editor a.addJs.addGeom').die('click');
219
AJAX.registerOnload('gis_data_editor.js', function() {
221
// Remove the class that is added due to the URL being too long.
222
$('span.open_gis_editor a').removeClass('formLinkSubmit');
225
* Prepares and insert the GIS data to the input field on clicking 'copy'.
227
$("#gis_editor input[name='gis_data[save]']").live('click', function(event) {
228
event.preventDefault();
229
insertDataAndClose();
233
* Prepares and insert the GIS data to the input field on pressing 'enter'.
235
$('#gis_editor').live('submit', function(event) {
236
event.preventDefault();
237
insertDataAndClose();
241
* Trigger asynchronous calls on data change and update the output.
243
$('#gis_editor').find("input[type='text']").live('change', function() {
244
var $form = $('form#gis_data_editor_form');
245
$.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) {
246
if (data.success == true) {
247
$('#gis_data_textarea').val(data.result);
248
$('#placeholder').empty().removeClass('hasSVG').html(data.visualization);
249
$('#openlayersmap').empty();
250
eval(data.openLayers);
251
initGISEditorVisualization();
253
PMA_ajaxShowMessage(data.error, false);
259
* Update the form on change of the GIS type.
261
$("#gis_editor select.gis_type").live('change', function(event) {
262
var $gis_editor = $("#gis_editor");
263
var $form = $('form#gis_data_editor_form');
265
$.post('gis_data_editor.php', $form.serialize() + "&get_gis_editor=true&ajax_request=true", function(data) {
266
if (data.success == true) {
267
$gis_editor.html(data.gis_editor);
268
initGISEditorVisualization();
271
PMA_ajaxShowMessage(data.error, false);
277
* Handles closing of the GIS data editor.
279
$('#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor').live('click', function() {
284
* Handles adding data points
286
$('#gis_editor a.addJs.addPoint').live('click', function() {
288
var name = $a.attr('name');
289
// Eg. name = gis_data[0][MULTIPOINT][add_point] => prefix = gis_data[0][MULTIPOINT]
290
var prefix = name.substr(0, name.length - 11);
291
// Find the number of points
292
var $noOfPointsInput = $("input[name='" + prefix + "[no_of_points]" + "']");
293
var noOfPoints = parseInt($noOfPointsInput.val());
294
// Add the new data point
295
var html = addDataPoint(noOfPoints, prefix);
297
$noOfPointsInput.val(noOfPoints + 1);
301
* Handles adding linestrings and inner rings
303
$('#gis_editor a.addLine.addJs').live('click', function() {
305
var name = $a.attr('name');
307
// Eg. name = gis_data[0][MULTILINESTRING][add_line] => prefix = gis_data[0][MULTILINESTRING]
308
var prefix = name.substr(0, name.length - 10);
309
var type = prefix.slice(prefix.lastIndexOf('[') + 1, prefix.lastIndexOf(']'));
311
// Find the number of lines
312
var $noOfLinesInput = $("input[name='" + prefix + "[no_of_lines]" + "']");
313
var noOfLines = parseInt($noOfLinesInput.val());
315
// Add the new linesting of inner ring based on the type
317
if (type == 'MULTILINESTRING') {
318
html += PMA_messages['strLineString'] + ' ' + (noOfLines + 1) + ':';
321
html += PMA_messages['strInnerRing'] + ' ' + noOfLines + ':';
324
html += '<input type="hidden" name="' + prefix + '[' + noOfLines + '][no_of_points]" value="' + noOfPoints + '"/>';
325
for (var i = 0; i < noOfPoints; i++) {
326
html += addDataPoint(i, (prefix + '[' + noOfLines + ']'));
328
html += '<a class="addPoint addJs" name="' + prefix + '[' + noOfLines + '][add_point]" href="#">+ '
329
+ PMA_messages['strAddPoint'] + '</a><br/>';
332
$noOfLinesInput.val(noOfLines + 1);
336
* Handles adding polygons
338
$('#gis_editor a.addJs.addPolygon').live('click', function() {
340
var name = $a.attr('name');
341
// Eg. name = gis_data[0][MULTIPOLYGON][add_polygon] => prefix = gis_data[0][MULTIPOLYGON]
342
var prefix = name.substr(0, name.length - 13);
343
// Find the number of polygons
344
var $noOfPolygonsInput = $("input[name='" + prefix + "[no_of_polygons]" + "']");
345
var noOfPolygons = parseInt($noOfPolygonsInput.val());
347
// Add the new polygon
348
var html = PMA_messages['strPolygon'] + ' ' + (noOfPolygons + 1) + ':<br/>';
349
html += '<input type="hidden" name="' + prefix + '[' + noOfPolygons + '][no_of_lines]" value="1"/>'
350
+ '<br/>' + PMA_messages['strOuterRing'] + ':'
351
+ '<input type="hidden" name="' + prefix + '[' + noOfPolygons + '][0][no_of_points]" value="4"/>';
352
for (var i = 0; i < 4; i++) {
353
html += addDataPoint(i, (prefix + '[' + noOfPolygons + '][0]'));
355
html += '<a class="addPoint addJs" name="' + prefix + '[' + noOfPolygons + '][0][add_point]" href="#">+ '
356
+ PMA_messages['strAddPoint'] + '</a><br/>'
357
+ '<a class="addLine addJs" name="' + prefix + '[' + noOfPolygons + '][add_line]" href="#">+ '
358
+ PMA_messages['strAddInnerRing'] + '</a><br/><br/>';
361
$noOfPolygonsInput.val(noOfPolygons + 1);
365
* Handles adding geoms
367
$('#gis_editor a.addJs.addGeom').live('click', function() {
369
var prefix = 'gis_data[GEOMETRYCOLLECTION]';
370
// Find the number of geoms
371
var $noOfGeomsInput = $("input[name='" + prefix + "[geom_count]" + "']");
372
var noOfGeoms = parseInt($noOfGeomsInput.val());
374
var html1 = PMA_messages['strGeometry'] + ' ' + (noOfGeoms + 1) + ':<br/>';
375
var $geomType = $("select[name='gis_data[" + (noOfGeoms - 1) + "][gis_type]']").clone();
376
$geomType.attr('name', 'gis_data[' + noOfGeoms + '][gis_type]').val('POINT');
377
var html2 = '<br/>' + PMA_messages['strPoint'] + ' :'
378
+ '<label for="x"> ' + PMA_messages['strX'] + ' </label>'
379
+ '<input type="text" name="gis_data[' + noOfGeoms + '][POINT][x]" value=""/>'
380
+ '<label for="y"> ' + PMA_messages['strY'] + ' </label>'
381
+ '<input type="text" name="gis_data[' + noOfGeoms + '][POINT][y]" value=""/>'
384
$a.before(html1); $geomType.insertBefore($a); $a.before(html2);
385
$noOfGeomsInput.val(noOfGeoms + 1);