[Mapbender-commits] r9199 - in trunk/mapbender: http/extensions http/extensions/JSON-Schema-Instantiator http/php http/plugins lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu May 21 05:14:28 PDT 2015


Author: syed
Date: 2015-05-21 05:14:28 -0700 (Thu, 21 May 2015)
New Revision: 9199

Added:
   trunk/mapbender/http/extensions/JSON-Schema-Instantiator/
   trunk/mapbender/http/extensions/JSON-Schema-Instantiator/instantiator.js
Modified:
   trunk/mapbender/http/php/mod_CalculateAreaAndLength.php
   trunk/mapbender/http/plugins/kmlTree.js
   trunk/mapbender/http/plugins/mb_digitize_widget.php
   trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
Log:
add handling for feature-attributes by using json-attributeschema

Added: trunk/mapbender/http/extensions/JSON-Schema-Instantiator/instantiator.js
===================================================================
--- trunk/mapbender/http/extensions/JSON-Schema-Instantiator/instantiator.js	                        (rev 0)
+++ trunk/mapbender/http/extensions/JSON-Schema-Instantiator/instantiator.js	2015-05-21 12:14:28 UTC (rev 9199)
@@ -0,0 +1,98 @@
+'use strict';
+
+// The JSON Object that defines the default values of certain types.
+var typesInstantiator = {
+  'string': '',
+  'number': 0,
+  'integer': 0,
+  'null': null,
+  'boolean': false, // Always stay positive?
+  'object': { }
+};
+
+/**
+ * Checks whether a variable is a primitive.
+ * @param obj - an object.
+ * @returns {boolean}
+ */
+function isPrimitive(obj) {
+  var type = obj.type;
+
+  return typesInstantiator[type] !== undefined;
+}
+
+/**
+ * Instantiate a primitive.
+ * @param val - The object that represents the primitive.
+ * @returns {*}
+ */
+function instantiatePrimitive(val) {
+  var type = val.type;
+
+  // Support for default values in the JSON Schema.
+  if (val.default) {
+    return val.default;
+  }
+
+  return typesInstantiator[type];
+}
+
+/**
+ * The main function.
+ * Calls sub-objects recursively, depth first, using the sub-function 'visit'.
+ * @param schema - The schema to instantiate.
+ * @returns {*}
+ */
+function instantiate(schema) {
+
+  /**
+   * Visits each sub-object using recursion.
+   * If it reaches a primitive, instantiate it.
+   * @param obj - The object that represents the schema.
+   * @param name - The name of the current object.
+   * @param data - The instance data that represents the current object.
+   */
+  function visit(obj, name, data) {
+    if (!obj) {
+      return;
+    }
+
+    var type = obj.type;
+    // We want non-primitives objects (primitive === object w/o properties).
+    if (type === 'object' && obj.properties) {
+      data[name] = { };
+
+      // Visit each property.
+      for (var property in obj.properties) {
+        if (obj.properties.hasOwnProperty(property)) {
+          visit(obj.properties[property], property, data[name]);
+        }
+      }
+    } else if (type === 'array') {
+      data[name] = [];
+      var len = 1;
+      if (obj.minItems) {
+        len = obj.minItems;
+      }
+
+      // Instantiate 'len' items.
+      for (var i = 0; i < len; i++) {
+        visit(obj.items, i, data[name]);
+      }
+
+    } else if (isPrimitive(obj)) {
+      data[name] = instantiatePrimitive(obj);
+    }
+  }
+
+  var data = {};
+  visit(schema, 'kek', data);
+  return data['kek'];
+}
+
+// If we're using Node.js, export the module.
+if (typeof module !== 'undefined') {
+  module.exports = {
+    instantiate: instantiate
+  };
+}

Modified: trunk/mapbender/http/php/mod_CalculateAreaAndLength.php
===================================================================
--- trunk/mapbender/http/php/mod_CalculateAreaAndLength.php	2015-05-18 13:49:18 UTC (rev 9198)
+++ trunk/mapbender/http/php/mod_CalculateAreaAndLength.php	2015-05-21 12:14:28 UTC (rev 9199)
@@ -23,6 +23,7 @@
 $geom_type = $_POST['geom_type'];
 $geom_data = $_POST['wkt_geom'];
 $sql;
+// die('<pre>' . print_r($geom_data, 1) . '</pre>');
 // calculate length of a linetring
 // var_dump($geom_data);die;
 if ($geom_type == 'line') {

Modified: trunk/mapbender/http/plugins/kmlTree.js
===================================================================
--- trunk/mapbender/http/plugins/kmlTree.js	2015-05-18 13:49:18 UTC (rev 9198)
+++ trunk/mapbender/http/plugins/kmlTree.js	2015-05-21 12:14:28 UTC (rev 9199)
@@ -37,845 +37,845 @@
  */
 
 if (typeof window.DOMParser === "undefined") {
-    window.DOMParser = function() {};
+	window.DOMParser = function() {};
 
-    window.DOMParser.prototype.parseFromString = function(str, contentType) {
-        if (typeof ActiveXObject !== 'undefined') {
-            var xmldata = new ActiveXObject('MSXML.DomDocument');
-            xmldata.async = false;
-            xmldata.loadXML(str);
-            return xmldata;
-        } else if (typeof XMLHttpRequest !== 'undefined') {
-            var xmldata = new XMLHttpRequest;
+	window.DOMParser.prototype.parseFromString = function(str, contentType) {
+		if (typeof ActiveXObject !== 'undefined') {
+			var xmldata = new ActiveXObject('MSXML.DomDocument');
+			xmldata.async = false;
+			xmldata.loadXML(str);
+			return xmldata;
+		} else if (typeof XMLHttpRequest !== 'undefined') {
+			var xmldata = new XMLHttpRequest;
 
-            if (!contentType) {
-                contentType = 'application/xml';
-            }
+			if (!contentType) {
+				contentType = 'application/xml';
+			}
 
-            xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + encodeURIComponent(str), false);
+			xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + encodeURIComponent(str), false);
 
-            if (xmldata.overrideMimeType) {
-                xmldata.overrideMimeType(contentType);
-            }
+			if (xmldata.overrideMimeType) {
+				xmldata.overrideMimeType(contentType);
+			}
 
-            xmldata.send(null);
-            return xmldata.responseXML;
-        }
-    };
+			xmldata.send(null);
+			return xmldata.responseXML;
+		}
+	};
 
 }
 
 var $kmlTree = $(this);
 var KmlTree = function(o) {
-    $kmlTree.children().remove();
-    $kmlTree.addClass('kmlTree');
-    var $KMLfolder = $('<li class="open kml"><ul></ul></li>');
-    $kmlTree.append($KMLfolder);
+	$kmlTree.children().remove();
+	$kmlTree.addClass('kmlTree');
+	var $KMLfolder = $('<li class="open kml"><ul></ul></li>');
+	$kmlTree.append($KMLfolder);
 
-    $addButton = $('<button class="add" name="addkml" value="addkml"></button>');
+	$addButton = $('<button class="add" name="addkml" value="addkml"></button>');
 
-    var selectButton = $('<img id="toggle-select-features" src="../img/osgeo_graphics/geosilk/cursor.png"></img>');
+	var selectButton = $('<img id="toggle-select-features" src="../img/osgeo_graphics/geosilk/cursor.png"></img>');
 
-    $addButton.click(function() {
-        if ($('#mySpatialData').dialog('isOpen') === true) {
+	$addButton.click(function() {
+		if ($('#mySpatialData').dialog('isOpen') === true) {
 
 
-            return;
+			return;
 
-        } else {
-            var dlg = $('<div id="mySpatialData"></div>').dialog({
-                "title": "My spatial data",
-                width: 720,
-                height: 420,
-                close: function() {
-                    $('#kml-load-tabs').tabs('destroy');
-                    $(this).html('').dialog('destroy');
-                    // $('#mySpatialData').dialog('destroy');
-                    $('#mySpatialData').remove();
-                }
-            });
-            var dlgcontent = '<div id="kml-load-tabs">' + '<ul><li><a class="icon icon-wmc" href="#kml-from-wmc">Stored data</a></li>' + '<li><a class="icon icon-local" href="#kml-from-upload">Upload</a></li>' + '<li><a class="icon icon-remote" href="#kml-from-url">External source</a></li>' + '<li><a class="icon icon-new" href="#kml-new">New</a></li></ul>' + '<div id="kml-from-wmc">wmc</div>' + '<div id="kml-from-upload">' + '<iframe name="kml-upload-target" style="width: 0; height: 0; border: 0px;"></iframe>' + '<form action="../php/uploadKml.php" method="post" enctype="multipart/form-data" target="kml-upload-target">' + '<input type="file" name="kml"></input>' + '<input type="submit" class="upload" value="Upload"></input><br>' + 'You can upload local KML, GPX and geoJSON files here. The filename should' + ' have the typical file extension (.kml, .gpx or .geojson) and the size' + ' is limited to 250kb of data.' + '</div>' + '</form>' + '<div id="kml-from-url">URL: <input class="kml
 url" /><button class="add" name="add" value="add"></button><br>' + 'You can give an url to a datafile which is located somewhere in the www. ' + 'Only KML, geoJSON and GPX files are supported. The files will be validated before they' + ' are loaded into the mapviewer.' + '</div>' + '<div id="kml-new">' + '<label>Title: <input type="text" name="kml-new-title"></input></label>' + '<button class="add-kml"></button>' + '</div>' + '</div>';
-            $('#kml-load-tabs').remove();
-            $(dlg).append(dlgcontent);
-            $.ajax({
-                type: 'get',
-                url: '../php/mb_list_wmc_local_data.php',
-                success: function(data) {
-                    var origData = $.extend(true, {}, data);
-                    $.each(data, function(_, v) {
-                        v[2] = new Date(v[2] * 1000);
-                        if (v[3]) {
-                            v[3] = '<img src="' + v[3] + '"></img>';
-                        }
-                        if (v[4]) {
-                            v[4] = '<img class="publishIcon" src="../img/osgeo_graphics/check.png"></img><img class="exportImage" src="../img/osgeo_graphics/geosilk/link22.png"></img>';
-                        } else {
-                            v[4] = '<img class="publishIcon" src="../img/button_digitize/geomRemove.png"></img>';
-                        }
-                        v[5] = Math.round(v[5] / 1024) + 'kb';
-                    });
+		} else {
+			var dlg = $('<div id="mySpatialData"></div>').dialog({
+				"title": "My spatial data",
+				width: 720,
+				height: 420,
+				close: function() {
+					$('#kml-load-tabs').tabs('destroy');
+					$(this).html('').dialog('destroy');
+					// $('#mySpatialData').dialog('destroy');
+					$('#mySpatialData').remove();
+				}
+			});
+			var dlgcontent = '<div id="kml-load-tabs">' + '<ul><li><a class="icon icon-wmc" href="#kml-from-wmc">Stored data</a></li>' + '<li><a class="icon icon-local" href="#kml-from-upload">Upload</a></li>' + '<li><a class="icon icon-remote" href="#kml-from-url">External source</a></li>' + '<li><a class="icon icon-new" href="#kml-new">New</a></li></ul>' + '<div id="kml-from-wmc">wmc</div>' + '<div id="kml-from-upload">' + '<iframe name="kml-upload-target" style="width: 0; height: 0; border: 0px;"></iframe>' + '<form action="../php/uploadKml.php" method="post" enctype="multipart/form-data" target="kml-upload-target">' + '<input type="file" name="kml"></input>' + '<input type="submit" class="upload" value="Upload"></input><br>' + 'You can upload local KML, GPX and geoJSON files here. The filename should' + ' have the typical file extension (.kml, .gpx or .geojson) and the size' + ' is limited to 250kb of data.' + '</div>' + '</form>' + '<div id="kml-from-url">URL: <input class="kmlurl" /><b
 utton class="add" name="add" value="add"></button><br>' + 'You can give an url to a datafile which is located somewhere in the www. ' + 'Only KML, geoJSON and GPX files are supported. The files will be validated before they' + ' are loaded into the mapviewer.' + '</div>' + '<div id="kml-new">' + '<label>Title: <input type="text" name="kml-new-title"></input></label>' + '<button class="add-kml"></button>' + '</div>' + '</div>';
+			$('#kml-load-tabs').remove();
+			$(dlg).append(dlgcontent);
+			$.ajax({
+				type: 'get',
+				url: '../php/mb_list_wmc_local_data.php',
+				success: function(data) {
+					var origData = $.extend(true, {}, data);
+					$.each(data, function(_, v) {
+						v[2] = new Date(v[2] * 1000);
+						if (v[3]) {
+							v[3] = '<img src="' + v[3] + '"></img>';
+						}
+						if (v[4]) {
+							v[4] = '<img class="publishIcon" src="../img/osgeo_graphics/check.png"></img><img class="exportImage" src="../img/osgeo_graphics/geosilk/link22.png"></img>';
+						} else {
+							v[4] = '<img class="publishIcon" src="../img/button_digitize/geomRemove.png"></img>';
+						}
+						v[5] = Math.round(v[5] / 1024) + 'kb';
+					});
 
-                    // add dialog for ópen links
-                    $('#kml-from-wmc').html('<table class="display"></table>').find('table').dataTable({
-                            aaData: data,
-                            aoColumns: [{
-                                sTitle: 'ID'
-                            }, {
-                                sTitle: 'Title'
-                            }, {
-                                sTitle: 'last change'
-                            }, {
-                                sTitle: 'License'
-                            }, {
-                                sTitle: 'public'
-                            }, {
-                                sTitle: 'size'
-                            }, {
-                                sTitle: 'owner'
-                            }]
-                        })
-                        .find('tr').bind('dblclick', function() {
-                            var id = $($(this).find('td')[0]).text();
-                            $.ajax({
-                                type: 'post',
-                                url: '../php/mb_load_local_data.php',
-                                data: {
-                                    id: id
-                                },
-                                success: function(data) {
-                                    var kml = $('#mapframe1').data('kml');
-                                    $.each(data, function(url, json) {
-                                        kml.addLayer(url, json.data);
-                                    });
-                                    $(dlg).dialog('destroy');
-                                }
-                            });
-                        }).end()
-                        .find('.exportImage').bind('click', function(event) { // add click event to the link image
-                            // stop event propagation beacause the following bind has to catch the click events on the 'tr'
-                            event.stopPropagation();
-                            if ($('#dataExportDialog').dialog('isOpen') === true) {
+					// add dialog for ópen links
+					$('#kml-from-wmc').html('<table class="display"></table>').find('table').dataTable({
+							aaData: data,
+							aoColumns: [{
+								sTitle: 'ID'
+							}, {
+								sTitle: 'Title'
+							}, {
+								sTitle: 'last change'
+							}, {
+								sTitle: 'License'
+							}, {
+								sTitle: 'public'
+							}, {
+								sTitle: 'size'
+							}, {
+								sTitle: 'owner'
+							}]
+						})
+						.find('tr').bind('dblclick', function() {
+							var id = $($(this).find('td')[0]).text();
+							$.ajax({
+								type: 'post',
+								url: '../php/mb_load_local_data.php',
+								data: {
+									id: id
+								},
+								success: function(data) {
+									var kml = $('#mapframe1').data('kml');
+									$.each(data, function(url, json) {
+										kml.addLayer(url, json.data);
+									});
+									$(dlg).dialog('destroy');
+								}
+							});
+						}).end()
+						.find('.exportImage').bind('click', function(event) { // add click event to the link image
+							// stop event propagation beacause the following bind has to catch the click events on the 'tr'
+							event.stopPropagation();
+							if ($('#dataExportDialog').dialog('isOpen') === true) {
 
-                                $('#dataExportDialog').dialog('close');
-                                $('#dataExportDialog').remove();
-                                $(this).trigger('click');
+								$('#dataExportDialog').dialog('close');
+								$('#dataExportDialog').remove();
+								$(this).trigger('click');
 
-                            } else {
-                                var title = $(this).parent().siblings().eq(1).html();
-                                var wmc_serial_id = $(this).parent().siblings().eq(0).html();
-                                var outputFormat;
+							} else {
+								var title = $(this).parent().siblings().eq(1).html();
+								var wmc_serial_id = $(this).parent().siblings().eq(0).html();
+								var outputFormat;
 
-                                var dataExportDlg = $('<div id="dataExportDialog"></div>').dialog({
-                                    title: "Export my data " + title,
-                                    width: 250,
-                                    height: 212,
-                                    position: {
-                                        my: "center",
-                                        at: "top",
-                                        of: window
-                                    },
-                                    close: function() {
+								var dataExportDlg = $('<div id="dataExportDialog"></div>').dialog({
+									title: "Export my data " + title,
+									width: 250,
+									height: 212,
+									position: {
+										my: "center",
+										at: "top",
+										of: window
+									},
+									close: function() {
 
-                                        $('#dataExportDialog').dialog('destroy');
-                                        $('#dataExportDialog').remove();
-                                    }
-                                });
-                                // var exportHtmlsdfdsf = '<div id="exportHtml">' + '<form>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label><br><br>' +
-                                //     '<img src="../img/osgeo_graphics/geosilk/link22.png"/>' + '<label class="export-format-gpx">GPX</label>' + '<label class="export-format-geojson">geoJSON</label><br></br>' +
-                                //     '<a download="myfeatures.kml" href="#" class="digitize-image digitize-export" style="float: left;"></a>' + '</form>' + '</div>';
-                                var exportHtml = '<div id="exportHtml"><table><tbody>' +
-                                    '<tr><td>KML:</td><td><label class="export-format-kml exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink kml" wmcId="' + wmc_serial_id + '"outputFormat="kml"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
-                                    '<tr><td>GPX:</td><td><label class="export-format-gpx exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink gpx" wmcId="' + wmc_serial_id + '"outputFormat="gpx"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
-                                    '<tr><td>GeoJson:</td><td><label class="export-format-geojson exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink geojson" wmcId="' + wmc_serial_id + '"outputFormat="geojson"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
-                                    '</tbody></table></div><iframe id="export-DataCollection" style="border:0;height:0; width:0;"></iframe>';
-                                // append the context
-                                $(dataExportDlg).append(exportHtml);
-                                //export the data
-                                $('.exportDatasetIcon').bind('click', function(event) {
+										$('#dataExportDialog').dialog('destroy');
+										$('#dataExportDialog').remove();
+									}
+								});
+								// var exportHtmlsdfdsf = '<div id="exportHtml">' + '<form>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label><br><br>' +
+								//     '<img src="../img/osgeo_graphics/geosilk/link22.png"/>' + '<label class="export-format-gpx">GPX</label>' + '<label class="export-format-geojson">geoJSON</label><br></br>' +
+								//     '<a download="myfeatures.kml" href="#" class="digitize-image digitize-export" style="float: left;"></a>' + '</form>' + '</div>';
+								var exportHtml = '<div id="exportHtml"><table><tbody>' +
+									'<tr><td>KML:</td><td><label class="export-format-kml exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink kml" wmcId="' + wmc_serial_id + '"outputFormat="kml"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
+									'<tr><td>GPX:</td><td><label class="export-format-gpx exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink gpx" wmcId="' + wmc_serial_id + '"outputFormat="gpx"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
+									'<tr><td>GeoJson:</td><td><label class="export-format-geojson exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink geojson" wmcId="' + wmc_serial_id + '"outputFormat="geojson"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
+									'</tbody></table></div><iframe id="export-DataCollection" style="border:0;height:0; width:0;"></iframe>';
+								// append the context
+								$(dataExportDlg).append(exportHtml);
+								//export the data
+								$('.exportDatasetIcon').bind('click', function(event) {
 
-                                    var exportClass = $(this).attr('class').toString().split(' ')[0];
-                                    //getting the outputformat
-                                    switch (exportClass) {
-                                        case 'export-format-kml':
+									var exportClass = $(this).attr('class').toString().split(' ')[0];
+									//getting the outputformat
+									switch (exportClass) {
+										case 'export-format-kml':
 
-                                            outputFormat = 'kml';
-                                            break;
-                                        case 'export-format-gpx':
+											outputFormat = 'kml';
+											break;
+										case 'export-format-gpx':
 
-                                            outputFormat = 'gpx';
-                                            break;
-                                        case 'export-format-geojson':
+											outputFormat = 'gpx';
+											break;
+										case 'export-format-geojson':
 
-                                            outputFormat = 'geojson';
-                                            break;
-                                    }
-                                    $('#export-DataCollection').attr("src", "../php/mod_GetPublishedData.php?wmc_id=" + wmc_serial_id + "&outputFormat=" + outputFormat);
+											outputFormat = 'geojson';
+											break;
+									}
+									$('#export-DataCollection').attr("src", "../php/mod_GetPublishedData.php?wmc_id=" + wmc_serial_id + "&outputFormat=" + outputFormat);
 
 
-                                });
+								});
 
-                                $('.exportDataLink').bind('click', function(event) {
-                                    var format = $(this).attr('outputFormat');
-                                    var exportDataLinkDlg = $('<div id="exportDataLinkDlg"></div>').dialog({
-                                        "title": "Link to your Dataset",
-                                        width: 350,
-                                        height: 80,
-                                        close: function() {
-                                            $('#exportDataLinkDlg').dialog('destroy');
-                                            $('#exportDataLinkDlg').remove();
+								$('.exportDataLink').bind('click', function(event) {
+									var format = $(this).attr('outputFormat');
+									var exportDataLinkDlg = $('<div id="exportDataLinkDlg"></div>').dialog({
+										"title": "Link to your Dataset",
+										width: 350,
+										height: 80,
+										close: function() {
+											$('#exportDataLinkDlg').dialog('destroy');
+											$('#exportDataLinkDlg').remove();
 
-                                        }
-                                    });
+										}
+									});
 
-                                    var exportDataLinkContent = '<div><label for="exportLinkInput">Link: </label><input id="exportLinkInput" size="35" type="text" value="http://' + window.location.hostname + '/mapbender/php/mod_GetPublishedData.php?wmc_id=' + wmc_serial_id + '&outputFormat=' + format + '"></div>';
-                                    $(exportDataLinkDlg).append(exportDataLinkContent);
-                                });
-                            }
-                        })
-                        .end()
-                        .find('.publishIcon').bind('click', function() {
-                            // var id = $($(this).find('td')[0]).text();
-                            var id = $(this).parent().parent().children(':first').html();
-                            var d;
-                            $.each(origData, function(_, val) {
-                                if (val[0] == id) {
-                                    d = val;
-                                }
-                            });
-                            var dlg = '<div title="Options ' + d[1] + '">' +
-                                '<ul class="kmltree-metadata-list">' + '<li class="kmltree-metadata-delete"><img style="vertical-align: middle;" src="../img/button_digitize/geomRemove.png"></img>Delete datacollection</li>';
+									var exportDataLinkContent = '<div><label for="exportLinkInput">Link: </label><input id="exportLinkInput" size="35" type="text" value="http://' + window.location.hostname + '/mapbender/php/mod_GetPublishedData.php?wmc_id=' + wmc_serial_id + '&outputFormat=' + format + '"></div>';
+									$(exportDataLinkDlg).append(exportDataLinkContent);
+								});
+							}
+						})
+						.end()
+						.find('.publishIcon').bind('click', function() {
+							// var id = $($(this).find('td')[0]).text();
+							var id = $(this).parent().parent().children(':first').html();
+							var d;
+							$.each(origData, function(_, val) {
+								if (val[0] == id) {
+									d = val;
+								}
+							});
+							var dlg = '<div title="Options ' + d[1] + '">' +
+								'<ul class="kmltree-metadata-list">' + '<li class="kmltree-metadata-delete"><img style="vertical-align: middle;" src="../img/button_digitize/geomRemove.png"></img>Delete datacollection</li>';
 
-                            if (d[4]) {
-                                dlg += '<li class="kmltree-metadata-unpublish"><img style="vertical-align: middle;" src="../img/gnome/emblem-unreadable.png"></img>Withdraw publication</li>';
-                            } else {
-                                dlg += '<li class="kmltree-metadata-publish"><img style="vertical-align: middle;" src="../img/gnome/share.png"></img>Publish datacollection</li>';
-                            }
+							if (d[4]) {
+								dlg += '<li class="kmltree-metadata-unpublish"><img style="vertical-align: middle;" src="../img/gnome/emblem-unreadable.png"></img>Withdraw publication</li>';
+							} else {
+								dlg += '<li class="kmltree-metadata-publish"><img style="vertical-align: middle;" src="../img/gnome/share.png"></img>Publish datacollection</li>';
+							}
 
-                            dlg += '</ul></div>';
+							dlg += '</ul></div>';
 
-                            dlg = $(dlg).appendTo('body');
+							dlg = $(dlg).appendTo('body');
 
-                            $(dlg).dialog({
-                                create: function() {
-                                    $(dlg).find('li.kmltree-metadata-delete').bind('click', function() {
-                                        if (confirm('Really delete spatial data set?')) {
-                                            $(dlg).dialog('destroy');
-                                            $.ajax({
-                                                type: 'post',
-                                                url: '../php/mb_delete_local_data.php',
-                                                data: {
-                                                    id: id
-                                                },
-                                                success: function(data) {
-                                                    if (arguments[1] == 'success') {
+							$(dlg).dialog({
+								create: function() {
+									$(dlg).find('li.kmltree-metadata-delete').bind('click', function() {
+										if (confirm('Really delete spatial data set?')) {
+											$(dlg).dialog('destroy');
+											$.ajax({
+												type: 'post',
+												url: '../php/mb_delete_local_data.php',
+												data: {
+													id: id
+												},
+												success: function(data) {
+													if (arguments[1] == 'success') {
 
-                                                        alert('Deleting local data was succesfull');
-                                                        $('#mySpatialData').dialog('destroy');
-                                                        $('#mySpatialData').remove();
-                                                        $($addButton).trigger('click');
-                                                    } else {
-                                                        alert('Problem when deleting local data');
+														alert('Deleting local data was succesfull');
+														$('#mySpatialData').dialog('destroy');
+														$('#mySpatialData').remove();
+														$($addButton).trigger('click');
+													} else {
+														alert('Problem when deleting local data');
 
-                                                    }
+													}
 
-                                                }
-                                            });
-                                        }
-                                    });
+												}
+											});
+										}
+									});
 
-                                    $(dlg).find('li.kmltree-metadata-unpublish').bind('click', function() {
-                                        if (confirm('Really unpublish spatial data set?')) {
-                                            $(dlg).dialog('destroy');
-                                            $.ajax({
-                                                url: '../php/mb_unpublish_wmc.php',
-                                                type: 'POST',
-                                                data: {
-                                                    wmc_serial_id: id
-                                                },
+									$(dlg).find('li.kmltree-metadata-unpublish').bind('click', function() {
+										if (confirm('Really unpublish spatial data set?')) {
+											$(dlg).dialog('destroy');
+											$.ajax({
+												url: '../php/mb_unpublish_wmc.php',
+												type: 'POST',
+												data: {
+													wmc_serial_id: id
+												},
 
-                                                success: function(data) {
+												success: function(data) {
 
-                                                    $('#mySpatialData').dialog('destroy');
-                                                    $('#mySpatialData').remove();
-                                                    $($addButton).trigger('click');
+													$('#mySpatialData').dialog('destroy');
+													$('#mySpatialData').remove();
+													$($addButton).trigger('click');
 
 
 
-                                                }
+												}
 
 
-                                            });
+											});
 
 
 
-                                        }
-                                    });
+										}
+									});
 
-                                    $(dlg).find('li.kmltree-metadata-publish').bind('click', function() {
+									$(dlg).find('li.kmltree-metadata-publish').bind('click', function() {
 
-                                        // check if the user is public(guest-user) or not
-                                        var isPublic;
-                                        $.ajax({
-                                            url: '../php/mb_checkGuest.php',
-                                            type: 'POST',
-                                            success: function(data) {
-                                                isPublic = data;
-                                                if (isPublic == 1){
+										// check if the user is public(guest-user) or not
+										var isPublic;
+										$.ajax({
+											url: '../php/mb_checkGuest.php',
+											type: 'POST',
+											success: function(data) {
+												isPublic = data;
+												if (isPublic == 1){
 
-                        							alert('To publicate a WMC is not allowed for the Guest-User!'+
-                        							      'If you want to use this function, please create an account.');
-                        							return false;
-                                                }
-                                                var publishDialog;
-                                                $(dlg).dialog('destroy');
-                                                if ($('#wmcPublishConfirm').dialog('isOpen') === true) {
+													alert('To publicate a WMC is not allowed for the Guest-User!'+
+														  'If you want to use this function, please create an account.');
+													return false;
+												}
+												var publishDialog;
+												$(dlg).dialog('destroy');
+												if ($('#wmcPublishConfirm').dialog('isOpen') === true) {
 
 
-                                                    return;
+													return;
 
-                                                } else {
+												} else {
 
-                                                    publishDialog = $('<div id="wmcPublishConfirm"></div>').dialog({
-                                                        title: "Publish datacollection " + d[1],
-                                                        width: 373,
-                                                        height: 'auto',
-                                                        position: {
-                                                            my: "center",
-                                                            at: "top",
-                                                            of: window
-                                                        },
-                                                        close: function() {
-                                                            // $('#kml-load-tabs').tabs('destroy');
-                                                            // $(this).html('').dialog('destroy');
-                                                            $('#wmcPublishConfirm').dialog('destroy');
-                                                            $('#wmcPublishConfirm').remove();
-                                                        }
-                                                    });
+													publishDialog = $('<div id="wmcPublishConfirm"></div>').dialog({
+														title: "Publish datacollection " + d[1],
+														width: 373,
+														height: 'auto',
+														position: {
+															my: "center",
+															at: "top",
+															of: window
+														},
+														close: function() {
+															// $('#kml-load-tabs').tabs('destroy');
+															// $(this).html('').dialog('destroy');
+															$('#wmcPublishConfirm').dialog('destroy');
+															$('#wmcPublishConfirm').remove();
+														}
+													});
 
-                                                    var publishDlgContent = "<div style='font-size:16px;text-align:justify'>If you want to publish a datacolletcion, you first have to choose a license" +
-                                                        " under which you want to distribute your data. Actually only OpenData compatible" +
-                                                        " licences are supported in this application. Please read the licenses carefully before" +
-                                                        " you activate this option. All of your data will be available for each person in the web" +
-                                                        " in different formats and may be redistributed freely without any copyright. </div>" +
-                                                        "<table style='margin-top:7px' ><tr><th id = 'publishDenied'><img src='../img/button_digitize/geomRemove.png'></img>  No, I dont't want to publish</th>" +
-                                                        "<th style='width:16%;visibility:hidden'>empty</th>" +
-                                                        "<th id = 'publishConfirmed'><img src='../img/osgeo_graphics/check.png'></img>  Yes, I know what I am doing </th></tr></table>";
+													var publishDlgContent = "<div style='font-size:16px;text-align:justify'>If you want to publish a datacolletcion, you first have to choose a license" +
+														" under which you want to distribute your data. Actually only OpenData compatible" +
+														" licences are supported in this application. Please read the licenses carefully before" +
+														" you activate this option. All of your data will be available for each person in the web" +
+														" in different formats and may be redistributed freely without any copyright. </div>" +
+														"<table style='margin-top:7px' ><tr><th id = 'publishDenied'><img src='../img/button_digitize/geomRemove.png'></img>  No, I dont't want to publish</th>" +
+														"<th style='width:16%;visibility:hidden'>empty</th>" +
+														"<th id = 'publishConfirmed'><img src='../img/osgeo_graphics/check.png'></img>  Yes, I know what I am doing </th></tr></table>";
 
-                                                    $(publishDialog).append(publishDlgContent);
+													$(publishDialog).append(publishDlgContent);
 
 
-                                                }
+												}
 
 
 
 
 
 
-                                                $(publishDialog).find('#publishConfirmed').bind('click', function() {
-                                                    $(publishDialog).dialog('close');
-                                                    var chooseLicenseDialog = $('<div id="chooseLicenseDialog"></div>').dialog({
-                                                        title: "Choose OpenData license for datacollection " + d[1],
-                                                        width: 720,
-                                                        height: 150,
-                                                        position: {
-                                                            my: "center",
-                                                            at: "top",
-                                                            of: window
-                                                        },
-                                                        close: function() {
+												$(publishDialog).find('#publishConfirmed').bind('click', function() {
+													$(publishDialog).dialog('close');
+													var chooseLicenseDialog = $('<div id="chooseLicenseDialog"></div>').dialog({
+														title: "Choose OpenData license for datacollection " + d[1],
+														width: 720,
+														height: 150,
+														position: {
+															my: "center",
+															at: "top",
+															of: window
+														},
+														close: function() {
 
-                                                            $('#chooseLicenseDialog').dialog('destroy');
-                                                            $('#chooseLicenseDialog').remove();
-                                                        }
-                                                    });
+															$('#chooseLicenseDialog').dialog('destroy');
+															$('#chooseLicenseDialog').remove();
+														}
+													});
 
-                                                    var chooseLicenseDlgCont = "<div><table id='licenseTbl'style='border-collapse: collapse'>" +
-                                                        "<tr><th>Lizenz</th>" +
-                                                        "<th>Logo</th><th>Beschreibung</th><th>Opendata</th></tr>" +
-                                                        "<tr><td><select id='licenseChooser name='license'>" +
-                                                        "</select></td>" +
-                                                        "<td id='licenseImg'></td>" +
-                                                        "<td id='licenseDescription'></td>" +
-                                                        "<td id='licenseOpen' nowrap></td></tr>" +
-                                                        "<tr id='submitLicense' ><td style='border:none;cursor:pointer; nowrap'><img src='../img/osgeo_graphics/check.png' style='margin-top:10px'/> <span>Publish data</span></td></tr>" +
-                                                        "</table></div>";
+													var chooseLicenseDlgCont = "<div><table id='licenseTbl'style='border-collapse: collapse'>" +
+														"<tr><th>Lizenz</th>" +
+														"<th>Logo</th><th>Beschreibung</th><th>Opendata</th></tr>" +
+														"<tr><td><select id='licenseChooser name='license'>" +
+														"</select></td>" +
+														"<td id='licenseImg'></td>" +
+														"<td id='licenseDescription'></td>" +
+														"<td id='licenseOpen' nowrap></td></tr>" +
+														"<tr id='submitLicense' ><td style='border:none;cursor:pointer; nowrap'><img src='../img/osgeo_graphics/check.png' style='margin-top:10px'/> <span>Publish data</span></td></tr>" +
+														"</table></div>";
 
-                                                    //  add options for the select box
-                                                    $(chooseLicenseDialog).append(chooseLicenseDlgCont);
+													//  add options for the select box
+													$(chooseLicenseDialog).append(chooseLicenseDlgCont);
 
-                                                    $.ajax({
-                                                        url: '../php/mb_publish_wmc.php',
-                                                        type: 'POST',
-                                                        data: {
-                                                            wmc_serial_id: id,
-                                                            mode: 'getAllLicencesMode',
-                                                            license: 'empty',
-                                                            openData_only: options.openData_only,
-                                                        },
+													$.ajax({
+														url: '../php/mb_publish_wmc.php',
+														type: 'POST',
+														data: {
+															wmc_serial_id: id,
+															mode: 'getAllLicencesMode',
+															license: 'empty',
+															openData_only: options.openData_only,
+														},
 
-                                                        success: function(data) {
+														success: function(data) {
 
-                                                            for (var i = 0; i < data.length; i++) {
+															for (var i = 0; i < data.length; i++) {
 
-                                                                $('#licenseTbl select').append("<option>" + data[i].name + "</option>");
-                                                            }
+																$('#licenseTbl select').append("<option>" + data[i].name + "</option>");
+															}
 
-                                                        }
+														}
 
-                                                    });
+													});
 
 
-                                                    $.ajax({
-                                                        url: '../php/mb_publish_wmc.php',
-                                                        type: 'POST',
-                                                        data: {
-                                                            wmc_serial_id: id,
-                                                            mode: 'getLicenseMode',
-                                                            license: 'cc-by'
-                                                        },
+													$.ajax({
+														url: '../php/mb_publish_wmc.php',
+														type: 'POST',
+														data: {
+															wmc_serial_id: id,
+															mode: 'getLicenseMode',
+															license: 'cc-by'
+														},
 
-                                                        success: function(data) {
+														success: function(data) {
 
-                                                            $('#licenseImg').html('<img src="' + data.symbollink + '" />');
-                                                            $('#licenseDescription').html('<a href="' + data.description + '" />' + data.description + '</a>');
-                                                            if (data.isopen == 1) {
+															$('#licenseImg').html('<img src="' + data.symbollink + '" />');
+															$('#licenseDescription').html('<a href="' + data.description + '" />' + data.description + '</a>');
+															if (data.isopen == 1) {
 
-                                                                $('#licenseOpen').html('<img src="../img/od_80x15_blue.png" />');
-                                                            } else {
+																$('#licenseOpen').html('<img src="../img/od_80x15_blue.png" />');
+															} else {
 
-                                                                $('#licenseOpen').html('<span>No OpenData</span>');
-                                                            }
+																$('#licenseOpen').html('<span>No OpenData</span>');
+															}
 
-                                                        }
+														}
 
-                                                    });
+													});
 
 
-                                                    $('#licenseTbl select').bind('change', function(event) {
-                                                        $('#licenseImg').html('');
-                                                        $('#licenseDescription').html('');
+													$('#licenseTbl select').bind('change', function(event) {
+														$('#licenseImg').html('');
+														$('#licenseDescription').html('');
 
-                                                        $.ajax({
-                                                            url: '../php/mb_publish_wmc.php',
-                                                            type: 'POST',
-                                                            data: {
-                                                                wmc_serial_id: id,
-                                                                mode: 'getLicenseMode',
-                                                                license: $('#licenseTbl select').val()
-                                                            },
+														$.ajax({
+															url: '../php/mb_publish_wmc.php',
+															type: 'POST',
+															data: {
+																wmc_serial_id: id,
+																mode: 'getLicenseMode',
+																license: $('#licenseTbl select').val()
+															},
 
-                                                            success: function(data) {
+															success: function(data) {
 
-                                                                $('#licenseImg').html('<img src="' + data.symbollink + '" />');
-                                                                $('#licenseDescription').html('<a href="' + data.description + '" />' + data.description + '</a>');
-                                                                if (data.isopen == 1) {
+																$('#licenseImg').html('<img src="' + data.symbollink + '" />');
+																$('#licenseDescription').html('<a href="' + data.description + '" />' + data.description + '</a>');
+																if (data.isopen == 1) {
 
-                                                                    $('#licenseOpen').html('<img src="../img/od_80x15_blue.png" />');
+																	$('#licenseOpen').html('<img src="../img/od_80x15_blue.png" />');
 
-                                                                } else {
+																} else {
 
-                                                                    $('#licenseOpen').html('<span>No OpenData</span>');
-                                                                }
+																	$('#licenseOpen').html('<span>No OpenData</span>');
+																}
 
-                                                            }
+															}
 
-                                                        });
-                                                    });
+														});
+													});
 
-                                                    $('#submitLicense').bind('click', function(event) {
-                                                        //save the license from the choosed wmc
+													$('#submitLicense').bind('click', function(event) {
+														//save the license from the choosed wmc
 
-                                                        $.ajax({
-                                                            url: '../php/mb_publish_wmc.php',
-                                                            type: 'POST',
-                                                            data: {
-                                                                wmc_serial_id: id,
-                                                                mode: 'saveLicenseMode',
-                                                                license: $('#licenseTbl select').val()
-                                                            },
+														$.ajax({
+															url: '../php/mb_publish_wmc.php',
+															type: 'POST',
+															data: {
+																wmc_serial_id: id,
+																mode: 'saveLicenseMode',
+																license: $('#licenseTbl select').val()
+															},
 
-                                                            success: function(data) {
+															success: function(data) {
 
-                                                                $('#chooseLicenseDialog').dialog('destroy');
-                                                                $('#chooseLicenseDialog').remove();
-                                                                $('#mySpatialData').dialog('destroy');
-                                                                $('#mySpatialData').remove();
-                                                                $($addButton).trigger('click');
+																$('#chooseLicenseDialog').dialog('destroy');
+																$('#chooseLicenseDialog').remove();
+																$('#mySpatialData').dialog('destroy');
+																$('#mySpatialData').remove();
+																$($addButton).trigger('click');
 
 
 
 
-                                                            }
+															}
 
-                                                        });
-                                                    });
+														});
+													});
 
-                                                });
+												});
 
-                                                $(publishDialog).find('#publishDenied').bind('click', function() {
-                                                    $(publishDialog).dialog('close');
+												$(publishDialog).find('#publishDenied').bind('click', function() {
+													$(publishDialog).dialog('close');
 
 
-                                                });
-                                            }
-                                        });
+												});
+											}
+										});
 
 
 
 
-                                    });
+									});
 
-                                }
-                            });
-                        });
-                    // .bind('dblclick', function() {
-                    //     var id = $($(this).find('td')[0]).text();
-                    //     $.ajax({
-                    //         type: 'post',
-                    //         url: '../php/mb_load_local_data.php',
-                    //         data: {
-                    //             id: id
-                    //         },
-                    //         success: function(data) {
-                    //             var kml = $('#mapframe1').data('kml');
-                    //             $.each(data, function(url, json) {
-                    //                 kml.addLayer(url, json.data);
-                    //             });
-                    //             $(dlg).dialog('destroy');
-                    //         }
-                    //     });
-                    // });
-                }
-            });
-            $('#kml-load-tabs').tabs();
-            $('#kml-load-tabs').find('button.add').bind('click', function() {
-                $('#mapframe1').kml({ //TODO: what is happening?
-                    url: $('#kml-load-tabs').find('.kmlurl').val()
-                });
-                // $(dlg).dialog('destroy');
-            });
-            $('#kml-load-tabs').find('button.add-kml').bind('click', function() {
-                var kml = $('#mapframe1').data('kml');
-                var title = $('#kml-load-tabs input[name="kml-new-title"]').val();
-                var version = 'v1'
-                if (title == '') {
-                    return;
-                }
-                kml.addLayer(title, {
-                    uuid: UUID.genV4().toString(),
-                    created: new Date().toISOString(),
-                    title: title,
-                    updated: new Date().toISOString(),
-                    version: version,
-                    type: 'FeatureCollection',
-                    features: []
-                });
-                $(dlg).dialog('destroy');
-            });
-            var ifr = $('iframe[name="kml-upload-target"]')[0];
-            var onloadfun = function() {
-                ifr.onload = null;
-                var txt = $(this).contents().find('pre').text(); // result von uploadKML.php
-                var data;
-                try {
-                    data = JSON.parse(txt);
+								}
+							});
+						});
+					// .bind('dblclick', function() {
+					//     var id = $($(this).find('td')[0]).text();
+					//     $.ajax({
+					//         type: 'post',
+					//         url: '../php/mb_load_local_data.php',
+					//         data: {
+					//             id: id
+					//         },
+					//         success: function(data) {
+					//             var kml = $('#mapframe1').data('kml');
+					//             $.each(data, function(url, json) {
+					//                 kml.addLayer(url, json.data);
+					//             });
+					//             $(dlg).dialog('destroy');
+					//         }
+					//     });
+					// });
+				}
+			});
+			$('#kml-load-tabs').tabs();
+			$('#kml-load-tabs').find('button.add').bind('click', function() {
+				$('#mapframe1').kml({ //TODO: what is happening?
+					url: $('#kml-load-tabs').find('.kmlurl').val()
+				});
+				// $(dlg).dialog('destroy');
+			});
+			$('#kml-load-tabs').find('button.add-kml').bind('click', function() {
+				var kml = $('#mapframe1').data('kml');
+				var title = $('#kml-load-tabs input[name="kml-new-title"]').val();
+				var version = 'v1'
+				if (title == '') {
+					return;
+				}
+				kml.addLayer(title, {
+					uuid: UUID.genV4().toString(),
+					created: new Date().toISOString(),
+					title: title,
+					updated: new Date().toISOString(),
+					version: version,
+					type: 'FeatureCollection',
+					features: []
+				});
+				$(dlg).dialog('destroy');
+			});
+			var ifr = $('iframe[name="kml-upload-target"]')[0];
+			var onloadfun = function() {
+				ifr.onload = null;
+				var txt = $(this).contents().find('pre').text(); // result von uploadKML.php
+				var data;
+				try {
+					data = JSON.parse(txt);
 
-                } catch (e) {
+				} catch (e) {
 
-                    var xml = new DOMParser().parseFromString(txt, 'application/xml');
-                    data = toGeoJSON.gpx(xml);
-                }
-                var kml = $('#mapframe1').data('kml');
-                var name;
-                // check the features for properties
-                data = setFeatureAttr(data);
+					var xml = new DOMParser().parseFromString(txt, 'application/xml');
+					data = toGeoJSON.gpx(xml);
+				}
+				var kml = $('#mapframe1').data('kml');
+				var name;
+				// check the features for properties
+				data = setFeatureAttr(data);
 
-                if (data.hasOwnProperty('title')) {
+				if (data.hasOwnProperty('title')) {
 
-                    name = data['title'];
-                    kml.addLayer(name, data);
-                } else {
+					name = data['title'];
+					kml.addLayer(name, data);
+				} else {
 
-                    name = $('#kml-from-upload input[type="file"]').val();
+					name = $('#kml-from-upload input[type="file"]').val();
 
-                    // test.replace(/\\/g,"/").split("/")
-                    if (name.replace(/\\/g, "/").split("/")) {
-                        // name = name.match(/[\\]([^\\]+)/g);
-                        name = name.replace(/\\/g, "/").split("/");
-                    }
-                    name = name[name.length - 1];
-                    kml.addLayer(name, data);
-                }
+					// test.replace(/\\/g,"/").split("/")
+					if (name.replace(/\\/g, "/").split("/")) {
+						// name = name.match(/[\\]([^\\]+)/g);
+						name = name.replace(/\\/g, "/").split("/");
+					}
+					name = name[name.length - 1];
+					kml.addLayer(name, data);
+				}
 
-                $(dlg).dialog('destroy');
-            };
-            $('#kml-from-upload form').bind('submit', function() {
-                ifr.onload = onloadfun;
-            });
+				$(dlg).dialog('destroy');
+			};
+			$('#kml-from-upload form').bind('submit', function() {
+				ifr.onload = onloadfun;
+			});
 
-        }
-    });
-    $KMLfolder.find('ul').before(selectButton);
-    $KMLfolder.find("ul").before($addButton);
+		}
+	});
+	$KMLfolder.find('ul').before(selectButton);
+	$KMLfolder.find("ul").before($addButton);
 
-    var btn = new Mapbender.Button({
-        domElement: selectButton[0],
-        over: '../img/osgeo_graphics/geosilk/cursor_selected.png',
-        on: '../img/osgeo_graphics/geosilk/cursor_selected.png',
-        off: '../img/osgeo_graphics/geosilk/cursor.png',
-        name: 'toggle-select-features',
-        go: function() {
-            var kml = $('#mapframe1').data('kml');
-            kml.setQueriedLayer(true);
-        },
-        stop: function() {
-            var kml = $('#mapframe1').data('kml');
-            kml.setQueriedLayer(false);
-        }
-    });
+	var btn = new Mapbender.Button({
+		domElement: selectButton[0],
+		over: '../img/osgeo_graphics/geosilk/cursor_selected.png',
+		on: '../img/osgeo_graphics/geosilk/cursor_selected.png',
+		off: '../img/osgeo_graphics/geosilk/cursor.png',
+		name: 'toggle-select-features',
+		go: function() {
+			var kml = $('#mapframe1').data('kml');
+			kml.setQueriedLayer(true);
+		},
+		stop: function() {
+			var kml = $('#mapframe1').data('kml');
+			kml.setQueriedLayer(false);
+		}
+	});
 
-    o.$target.bind('kml:loaded', function(e, obj) {
-        var checked = obj.display ? 'checked="checked"' : '';
-        title = obj.url;
-        if (obj.refreshing) {
-            $KMLfolder.find('ul li[title="' + title + '"]').remove();
-        }
-        abbrevTitle = title.length < 20 ? title : title.substr(0, 17) + "...";
-        $kmlEntry = $('<li title="' + title + '" class="open"><button class="digitize-menu-arrow"></button><button class="toggle" name="toggle" value="toggle" ></button> <input type="checkbox"' + checked + '/><a href="#">' + abbrevTitle + '</a></li>');
-        $KMLfolder.children("ul").append($kmlEntry);
+	o.$target.bind('kml:loaded', function(e, obj) {
+		var checked = obj.display ? 'checked="checked"' : '';
+		title = obj.url;
+		if (obj.refreshing) {
+			$KMLfolder.find('ul li[title="' + title + '"]').remove();
+		}
+		abbrevTitle = title.length < 20 ? title : title.substr(0, 17) + "...";
+		$kmlEntry = $('<li title="' + title + '" class="open"><button class="digitize-menu-arrow"></button><button class="toggle" name="toggle" value="toggle" ></button> <input type="checkbox"' + checked + '/><a href="#">' + abbrevTitle + '</a></li>');
+		$KMLfolder.children("ul").append($kmlEntry);
 
-        $kmlEntry.find("a").bind("click", (function(url) {
-            return function() {
-                $('#mapframe1').data('kml').zoomToLayer(url);
-            };
-        })(obj.url));
+		$kmlEntry.find("a").bind("click", (function(url) {
+			return function() {
+				$('#mapframe1').data('kml').zoomToLayer(url);
+			};
+		})(obj.url));
+		//@TODO: add default icon for points,polygons and linestrings on import
+		$featureList = $("<ul />");
+		$kmlEntry.append($featureList);
+		var pointCount = 1;
+		var polygonCount = 1;
+		var linestringCount = 1;
+		for (var i = obj.data.features.length - 1; i >= 0; --i) { //FIXME: for feature without the "type: FeatureCollection ",change functionallity: if (obj.data.type == "Feature") ...
+			var multi = obj.data.features[i].geometry.type.match(/^Multi/i);
+			var toggle = '';
+			if (multi) {
+				toggle = '<button class="toggle" name="toggle" value="toggle"></button>';
+			}
 
-        $featureList = $("<ul />");
-        $kmlEntry.append($featureList);
-        var pointCount = 1;
-        var polygonCount = 1;
-        var linestringCount = 1;
-        for (var i = obj.data.features.length - 1; i >= 0; --i) { //FIXME: for feature without the "type: FeatureCollection ",change functionallity: if (obj.data.type == "Feature") ...
-            var multi = obj.data.features[i].geometry.type.match(/^Multi/i);
-            var toggle = '';
-            if (multi) {
-                toggle = '<button class="toggle" name="toggle" value="toggle"></button>';
-            }
+			if (obj.data.features[i].properties.name) {
 
-            if (obj.data.features[i].properties.name) {
+				title = obj.data.features[i].properties.name;
 
-                title = obj.data.features[i].properties.name;
+			} else if (obj.data.features[i].properties.title) {
 
-            } else if (obj.data.features[i].properties.title) {
+				title = obj.data.features[i].properties.title;
+			} else {
 
-                title = obj.data.features[i].properties.title;
-            } else {
+				switch (obj.data.features[i].geometry.type){
 
-            	switch (obj.data.features[i].geometry.type){
+					case 'Point':
+						title = 'point_'+pointCount;
+						pointCount += 1;
+						break;
+					case 'Polygon':
+						title = 'polygon_'+polygonCount;
+						polygonCount += 1;
+						break;
+					case 'LineString':
+						title = 'linestring_'+linestringCount;
+						linestringCount += 1;
+						break;
+				}
+				// title = 'Title undefined';
 
-            		case 'Point':
-                		title = 'point_'+pointCount;
-                		pointCount += 1;
-                		break;
-            		case 'Polygon':
-            			title = 'polygon_'+polygonCount;
-                		polygonCount += 1;
-            			break;
-            		case 'LineString':
-            			title = 'linestring_'+linestringCount;
-                		linestringCount += 1;
-            			break;
-            	}
-                // title = 'Title undefined';
+			}
+			// title = obj.data.features[i].properties.name;
 
-            }
-            // title = obj.data.features[i].properties.name;
 
+			abbrevTitle = title.length < 20 ? title : title.substr(0, 17) + "...";
+			var displ = obj.data.features[i].display === true || obj.data.features[i].display === undefined;
+			$feature = $('<li idx="' + i + '" title="' + title + '"><button class="digitize-menu-arrow"></button>' + toggle + '<input type="checkbox" ' + (displ ? 'checked="checked"' : '') + '/><div class="style-preview" style="width: 20px; height: 20px; display: inline;"></div><a href="#" >' + abbrevTitle + '</a></li>');
+			$featureList.append($feature);
 
-            abbrevTitle = title.length < 20 ? title : title.substr(0, 17) + "...";
-            var displ = obj.data.features[i].display === true || obj.data.features[i].display === undefined;
-            $feature = $('<li idx="' + i + '" title="' + title + '"><button class="digitize-menu-arrow"></button>' + toggle + '<input type="checkbox" ' + (displ ? 'checked="checked"' : '') + '/><div class="style-preview" style="width: 20px; height: 20px; display: inline;"></div><a href="#" >' + abbrevTitle + '</a></li>');
-            $featureList.append($feature);
+			var preview = $feature.find('.style-preview').get(0);
+			$('#mapframe1').data('kml').renderPreview(obj.data.features[i], preview, 20);
 
-            var preview = $feature.find('.style-preview').get(0);
-            $('#mapframe1').data('kml').renderPreview(obj.data.features[i], preview, 20);
+			title = obj.data.features[i].properties.name;
 
-            title = obj.data.features[i].properties.name;
+			$feature.bind('mouseout', (function(jsonFeature) {
+				return function() {
+					var map = o.$target.mapbender();
+					var g = new GeometryArray();
+					g.importGeoJSON(jsonFeature, false);
+					var feature = g.get(0);
 
-            $feature.bind('mouseout', (function(jsonFeature) {
-                return function() {
-                    var map = o.$target.mapbender();
-                    var g = new GeometryArray();
-                    g.importGeoJSON(jsonFeature, false);
-                    var feature = g.get(0);
+					if (feature.geomType != "point") {
+						var me = $kmlTree.mapbender();
+						me.resultHighlight.clean();
+						me.resultHighlight.paint();
+					}
+				}
+			})(obj.data.features[i]));
+			$feature.bind('mouseover', (function(jsonFeature) {
+				return function() {
+					var map = o.$target.mapbender();
+					var g = new GeometryArray();
+					g.importGeoJSON(jsonFeature, false);
+					var feature = g.get(0);
 
-                    if (feature.geomType != "point") {
-                        var me = $kmlTree.mapbender();
-                        me.resultHighlight.clean();
-                        me.resultHighlight.paint();
-                    }
-                }
-            })(obj.data.features[i]));
-            $feature.bind('mouseover', (function(jsonFeature) {
-                return function() {
-                    var map = o.$target.mapbender();
-                    var g = new GeometryArray();
-                    g.importGeoJSON(jsonFeature, false);
-                    var feature = g.get(0);
+					if (feature.geomType != "point") {
+						var me = $kmlTree.mapbender();
+						feature = feature.getBBox4();
+						me.resultHighlight = new Highlight(
+							[o.target],
+							"KmlTreeHighlight", {
+								"position": "absolute",
+								"top": "0px",
+								"left": "0px",
+								"z-index": 100
+							},
+							2);
 
-                    if (feature.geomType != "point") {
-                        var me = $kmlTree.mapbender();
-                        feature = feature.getBBox4();
-                        me.resultHighlight = new Highlight(
-                            [o.target],
-                            "KmlTreeHighlight", {
-                                "position": "absolute",
-                                "top": "0px",
-                                "left": "0px",
-                                "z-index": 100
-                            },
-                            2);
+						me.resultHighlight.add(feature, "#00ff00");
+						me.resultHighlight.paint();
+					} else if (feature.geomType == "point") {
 
-                        me.resultHighlight.add(feature, "#00ff00");
-                        me.resultHighlight.paint();
-                    } else if (feature.geomType == "point") {
+					}
 
-                    }
+				};
+			})(obj.data.features[i]));
+		}
 
-                };
-            })(obj.data.features[i]));
-        }
+		$('button.digitize-layer', $kmlEntry).bind('click', function() {
+			var active = $(this).toggleClass('active').hasClass('active');
+			if (active) {
+				$(this).parent().siblings().find('button.digitize-layer').removeClass('active');
+			}
+		});
 
-        $('button.digitize-layer', $kmlEntry).bind('click', function() {
-            var active = $(this).toggleClass('active').hasClass('active');
-            if (active) {
-                $(this).parent().siblings().find('button.digitize-layer').removeClass('active');
-            }
-        });
+		$('#kmlTree > li > ul').sortable({
+			update: function() {
+				var kml = $('#mapframe1').data('kml');
+				var urls = [];
+				$(this).children('li[title]').each(function(k, v) {
+					urls.push($(this).attr('title'));
+				});
+				kml.setOrder(urls);
+			}
+		});
 
-        $('#kmlTree > li > ul').sortable({
-            update: function() {
-                var kml = $('#mapframe1').data('kml');
-                var urls = [];
-                $(this).children('li[title]').each(function(k, v) {
-                    urls.push($(this).attr('title'));
-                });
-                kml.setOrder(urls);
-            }
-        });
+		$('#kmlTree > li > ul > li > ul').sortable({
+			update: function(evt, data) {
+				var kml = $('#mapframe1').data('kml');
+				var url = $(this).parent().attr('title');
+				var ids = [];
+				var i = $(this).children().length;;
+				$.each($(this).children(), function(k, v) {
+					ids.push($(v).attr('idx'));
+					$(v).attr('idx', --i);
+				});
+				kml.reorderFeatures(url, ids.reverse());
+			}
+		});
 
-        $('#kmlTree > li > ul > li > ul').sortable({
-            update: function(evt, data) {
-                var kml = $('#mapframe1').data('kml');
-                var url = $(this).parent().attr('title');
-                var ids = [];
-                var i = $(this).children().length;;
-                $.each($(this).children(), function(k, v) {
-                    ids.push($(v).attr('idx'));
-                    $(v).attr('idx', --i);
-                });
-                kml.reorderFeatures(url, ids.reverse());
-            }
-        });
+		$('input[type="checkbox"]', $kmlEntry).bind('click', function() {
+			var idx = $(this).parent().attr('idx');
 
-        $('input[type="checkbox"]', $kmlEntry).bind('click', function() {
-            var idx = $(this).parent().attr('idx');
+			if (idx === undefined) {
+				if ($(this).attr('checked')) {
+					o.$target.kml('show', obj.url);
+				} else {
+					o.$target.kml('hide', obj.url);
+				}
+			} else {
+				var kml = $('#mapframe1').data('kml');
+				if ($(this).attr('checked')) {
+					kml.showFeature(obj.url, idx);
+				} else {
+					kml.hideFeature(obj.url, idx);
+				}
+			}
+		});
 
-            if (idx === undefined) {
-                if ($(this).attr('checked')) {
-                    o.$target.kml('show', obj.url);
-                } else {
-                    o.$target.kml('hide', obj.url);
-                }
-            } else {
-                var kml = $('#mapframe1').data('kml');
-                if ($(this).attr('checked')) {
-                    kml.showFeature(obj.url, idx);
-                } else {
-                    kml.hideFeature(obj.url, idx);
-                }
-            }
-        });
+		$("button.toggle", $kmlEntry).bind('click', function() {
+			if ($(this).parent().hasClass("open")) {
+				$(this).parent().removeClass("open");
+				$(this).parent().addClass("closed");
+			} else {
+				$(this).parent().removeClass("closed");
+				$(this).parent().addClass("open");
+			}
 
-        $("button.toggle", $kmlEntry).bind('click', function() {
-            if ($(this).parent().hasClass("open")) {
-                $(this).parent().removeClass("open");
-                $(this).parent().addClass("closed");
-            } else {
-                $(this).parent().removeClass("closed");
-                $(this).parent().addClass("open");
-            }
+			// IE8 workaround to make style previews visible...
+			$(this).parent().find('ul.ui-sortable li .rvml').removeClass('rvml').addClass('rvml');
+		});
 
-            // IE8 workaround to make style previews visible...
-            $(this).parent().find('ul.ui-sortable li .rvml').removeClass('rvml').addClass('rvml');
-        });
+		$('#tabs_kmlTree').bind('click', function() {
+			window.setTimeout(function() {
+				// IE8 workaround to make style previews visible...
+				$('#kmlTree').find('ul.ui-sortable li .rvml').removeClass('rvml').addClass('rvml');
+			}, 1000);
+		});
 
-        $('#tabs_kmlTree').bind('click', function() {
-            window.setTimeout(function() {
-                // IE8 workaround to make style previews visible...
-                $('#kmlTree').find('ul.ui-sortable li .rvml').removeClass('rvml').addClass('rvml');
-            }, 1000);
-        });
+	});
 
-    });
+	var setFeatureAttr = function(data) {
+		var simpleStyleDefaults = {
 
-    var setFeatureAttr = function(data) {
-        var simpleStyleDefaults = {
+			"title": "",
+			"description": "",
+			"marker-size": "medium",
+			"marker-symbol": "",
+			"marker-color": "7e7e7e",
+			"stroke": "#555555",
+			"stroke-opacity": 1.0,
+			"stroke-width": 2,
+			"fill": "#555555",
+			"fill-opacity": 0.5
+		};
 
-            "title": "",
-            "description": "",
-            "marker-size": "medium",
-            "marker-symbol": "",
-            "marker-color": "7e7e7e",
-            "stroke": "#555555",
-            "stroke-opacity": 1.0,
-            "stroke-width": 2,
-            "fill": "#555555",
-            "fill-opacity": 0.5
-        };
+		if (data.type == 'Feature') {
 
-        if (data.type == 'Feature') {
+			if (Object.getOwnPropertyNames(data.properties).length === 0 || data.properties === null) {
 
-            if (Object.getOwnPropertyNames(data.properties).length === 0 || data.properties === null) {
+				data.properties = simplyStyleDefaults;
 
-                data.properties = simplyStyleDefaults;
+			} else {
 
-            } else {
+				$.each(simpleStyleDefaults, function(index, val) {
 
-                $.each(simpleStyleDefaults, function(index, val) {
+					if (!data.properties.hasOwnProperty(index)) {
 
-                    if (!data.properties.hasOwnProperty(index)) {
+						data.properties[index] = value;
+					}
 
-                        data.properties[index] = value;
-                    }
+				});
 
-                });
+			}
 
-            }
+		} else if (data.type == 'FeatureCollection') {
+			// get all features in the featureCollection and set the default properties if they are not set
+			$.each(data.features, function(index, val) {
 
-        } else if (data.type == 'FeatureCollection') {
-            // get all features in the featureCollection and set the default properties if they are not set
-            $.each(data.features, function(index, val) {
+				$.each(simpleStyleDefaults, function(prop, propVal) {
 
-                $.each(simpleStyleDefaults, function(prop, propVal) {
+					if (!val.properties.hasOwnProperty(prop)) {
 
-                    if (!val.properties.hasOwnProperty(prop)) {
+						//TODO: get index in this scope
+						data.features[index].properties[prop] = propVal;
+					}
 
-                        //TODO: get index in this scope
-                        data.features[index].properties[prop] = propVal;
-                    }
+				});
+			});
 
-                });
-            });
+		}
 
-        }
+		return data;
 
-        return data;
 
-
-    };
+	};
 };
 
 Mapbender.events.init.register(function() {
-    $kmlTree.mapbender(new KmlTree(options));
+	$kmlTree.mapbender(new KmlTree(options));
 });

Modified: trunk/mapbender/http/plugins/mb_digitize_widget.php
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_widget.php	2015-05-18 13:49:18 UTC (rev 9198)
+++ trunk/mapbender/http/plugins/mb_digitize_widget.php	2015-05-21 12:14:28 UTC (rev 9199)
@@ -52,6 +52,8 @@
  * > VALUES('<app_id>', 'digitize_widget', 'polygonStrokeWidthDefault', '1', '' ,'var');
  * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type)
  * > VALUES('<app_id>', 'digitize_widget', 'polygonStrokeWidthSnapped', '3', '' ,'var');
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type)
+ * > VALUES('<app_id>', 'digitize_widget', 'featureAttributeCategories', 'test', '' ,'var');
  *
  * Help:
  * http://www.mapbender.org/Digitize_widget
@@ -560,9 +562,9 @@
         });
         menu.children('li:has(.digitize-pencil)').bind('click', editObject($link, menu));
         menu.children('li:has(.digitize-export)').bind('click', function() {
-            var kml = $('#mapframe1').data('kml');
-            var url = $link.parent().parent().attr('title');
-            var idx = $link.attr('idx');
+            var kml  = $('#mapframe1').data('kml');
+            var url  = $link.parent().parent().attr('title');
+            var idx  = $link.attr('idx');
             var data = kml._kmls[url];
             exportItem(data.data.features[idx]);
             menu.menu('destroy').remove();
@@ -594,10 +596,20 @@
 
             if ($(this).hasClass('editFeatureCollection')) {
                     // kml = $('#mapframe1').data('kml');
-                    var oldCollectionName = feature['@context'].title;
+                    var oldCollectionName;
+                    if (feature.hasOwnProperty('@context')) {
+
+                        oldCollectionName = feature['@context'].title;
+
+                    } else{
+
+                        oldCollectionName = feature.title;
+
+                    }
                     var featureCollAttrDlg = $('<div id="featureCollAttrDlg"></div>').dialog({
                         title: "<?php echo _mb("Featurecollection attributes");?> ",// of "+ url,
-                        width: 400,
+                        // title: "<?php echo _mb("Featurecollection attributes");?> ",// of "+ url,
+                        width: 500,
                         // height: 212,
                         position: {
                             my: "center",
@@ -618,44 +630,48 @@
                                                     "<div class='digitize-image digitize-add'></div>"+
                                                     "<div class='digitize-image digitize-save'></div>";
                     $('#featureCollAttrDlg').append(featureCollectionContent);
-                    $.each(feature['@context'], function(index, val) {
+                    $.each(feature, function(index, val) {
                         if (index == 'uuid' || index == 'created' || index == 'updated') {
 
                             $('#featureCollTbl').append("<tr><td>"+index+"</td><td><input style='width:230px;' type='text' name='"+index+"' value='"+val+"' disabled /></td></tr>");
 
                         }else{
 
+                            if ( index == "features" || index == "type" ) {
+
+                                return;
+                            };
                             $('#featureCollTbl').append("<tr><td>"+index+"</td><td><input  style='width:230px;' type='text' name='"+index+"' value='"+val+"'/></td></tr>");
 
                         }
                     });
                     featureCollAttrDlg.find('.digitize-save').bind('click', function() {
-                    featureCollAttrDlg.find('table input').each(function() {
-                        var k = $(this).attr('name');
-                        var v = $(this).val();
-                        if(k) {
-                            feature['@context'][k] = v;
-                        }
-                    });
-                    feature['@context'].updated = new Date().toISOString();
-                    // save the changed feature in a new object
-                    if ( $('#mapframe1').data('kml')._kmls[oldCollectionName].url != $('#mapframe1').data('kml')._kmls[oldCollectionName].data['@context'].title ) {
+                        featureCollAttrDlg.find('table input').each(function() {
+                            var k = $(this).attr('name');
+                            var v = $(this).val();
+                            if(k) {
+                                feature[k] = v;
+                            }
+                        });
+                        feature.updated = new Date().toISOString();
+                        // save the changed feature in a new object
+                        if ( $('#mapframe1').data('kml')._kmls[oldCollectionName].url != $('#mapframe1').data('kml')._kmls[oldCollectionName].data.title ) {
 
-                        $('#mapframe1').data('kml')._kmls[feature['@context'].title] = $('#mapframe1').data('kml')._kmls[oldCollectionName];
-                        $('#mapframe1').data('kml')._kmls[feature['@context'].title].url = $('#mapframe1').data('kml')._kmls[feature['@context'].title].data['@context'].title;
-                        kml.remove(url);
-                        $("#kmlTree>li>ul>li[title='"+url+"']").remove();
-                        url =  $('#mapframe1').data('kml')._kmls[feature['@context'].title].url;
-                        featureCollAttrDlg.dialog('close');
-                        editDialog.dialog('close');
-                        kml.refresh(url);
-                    } else {
+                            $('#mapframe1').data('kml')._kmls[feature.title] = $('#mapframe1').data('kml')._kmls[oldCollectionName];
+                            $('#mapframe1').data('kml')._kmls[feature.title].url = $('#mapframe1').data('kml')._kmls[feature.title].data.title;
+                            kml.remove(url);
+                            $("#kmlTree>li>ul>li[title='"+url+"']").remove();
+                            url =  $('#mapframe1').data('kml')._kmls[feature.title].url;
+                            featureCollAttrDlg.dialog('close');
+                            editDialog.dialog('close');
+                            kml.refresh(url);
+                        } else {
 
-                        featureCollAttrDlg.dialog('close');
-                        editDialog.dialog('close');
-                        kml.refresh(url);
+                            featureCollAttrDlg.dialog('close');
+                            editDialog.dialog('close');
+                            kml.refresh(url);
 
-                    }
+                        }
                 // var preview = attributesDialog.find('.digitize-preview').html('').get(0);
                 // kml.renderPreview(feature, preview);
                 });
@@ -675,83 +691,56 @@
 
 
             }else{
-                //TODO: add variables for each html element -->> usability and easier to read the source-code
+                // instantiate the geometry objects from the defined schema in config
+                var featureCategoriesSchemaInstance = instantiate( options.featureCategoriesSchema );
+                // declarate the variables for later use
+                var schemaInstance;
+                var geomType;
+                //  differentiate between the geometry-type
+                switch(feature.geometry.type){
+                    case "Point":
+                        schemaInstance = instantiate( options.pointAttributesSchema );
+                        geomType = "Point"
+                        break;
+                    case "Polygon":
+                        schemaInstance = instantiate( options.polygonAttributesSchema );
+                        geomType = "Polygon"
+                        break;
+                    case "Polyline":
+                        schemaInstance = instantiate( options.polylineAttributesSchema );
+                        geomType = "Polyline"
+                        break;
+                }
                 attributesDialog.dialog('open');
                 attributesDialog.find('*').unbind();
                 attributesDialog.html(tableEditAttributesHtml);
-
+                // create an object with the given categories from the categorySchema
+                var categories = {};
+                $.each(featureCategoriesSchemaInstance.categories, function(index, val) {
+                    categories[index] = '<h3 style="text-align:center;"><?php echo _mb("'+val+'");?></h3><div><table class="ftr-data-tbl '+val+' ">';
+                });
+                // create div-element for the geometry properties
                 var geometryDiv = $('<div class= "geometry-div"></div>');
-                // create for each section [#4] one table in a div and put it in html of .attrAccordion
-                var nonEditableRows = '<h3 style="text-align:center;"><?php echo _mb("Fix-Data");?></h3><div><table class="ftr-data-tbl fix-data">';//</table></div>';
-                // var nonEditableRows = '<tr><th>Fix-Data</th></tr>';
-                var editableRows = '<h3 style="text-align:center;"><?php echo _mb("Editable-Data");?></h3><div><table class="ftr-data-tbl edit-data">';//</table></div>';
-                // var editableRows = '<tr><th>Editable-Data</th></tr>';
-                var customRows = '<h3 style="text-align:center;"><?php echo _mb("Custom-Data");?></h3><div><table class="ftr-data-tbl custom-data">';//</table></div>';
-                // var customRows = '<tr><th>Custom-Data</th></tr>';
-                var styleRows = '<h3 style="text-align:center;"><?php echo _mb("Style-Data");?></h3><div><table class="ftr-data-tbl style-data">';//</table></div>';
-                // var divider = "<tr><th>divider</th></tr>";
-
-                //console.log(feature.properties);
-
+                // map each property to one of the given categories
                 $.each(feature.properties, function(k, v) {
-                    console.log(k, v);
-
-                    if(k.match(/Mapbender:/)) return;
-                    if ( k == "uuid" || k == "created" || k == "updated" || k == "version" ) {
-
-                        nonEditableRows += '<tr><td>' + k + '</td><td><input disabled type="text" name="' + k + '" value="' + v + '"></input></td></tr>';
-
-                    }else if(k == "title" || k == "name" || k == "description"){
-
-                        editableRows += '<tr><td>' + k + '</td><td><input type="text" name="' + k + '" value="' + v + '"></input></td></tr>';
-
-                    } else if( k.match('marker') != null || k == 'stroke' || k == 'stroke-opacity' || k == 'stroke-width' || k == 'fill' || k == 'fill-opacity' ){
-
-                        styleRows += '<tr><td>' + k + '</td><td><input type="text" name="' + k + '" value="' + v + '"></input></td></tr>';
-
-                    } else if( k == "area" || k == "boundary-length" || k == "track-length"){
-				switch(k) {
-				    case "area":
-				        header = "<?php echo _mb("Area [m²]");?>";
-				        break;
-				    case "boundary-length":
-				        header = "<?php echo _mb("Boundary length [m]");?>";
-				        break;
-				    case "track-length":
-				        header = "<?php echo _mb("Length [m]");?>";
-				        break;
-				} 
-                            	geometryDiv.append('<div><p class = " geometry-p "name="' + k + '">'+ header +' : ' + v + '</p></div>');
-
-                    } else{
-
-                        customRows += '<tr><td>' + k + '</td><td><input type="text" name="' + k + '" value="' + v + '"></input></td><td><img class="removeCustomFeatAttr" src="../img/button_digitize/geomRemove.png" title="<?php echo _mb("Remove attribute");?>"></td></tr>';
-
-                    }
+                    mapFeature( k, v, categories, schemaInstance, geomType, geometryDiv);
                 });
-                //close the table tags
-                nonEditableRows += '</table></div>';
-                editableRows += '</table></div>';
-                styleRows += '</table></div>';
-                customRows += '</table></div>';
-
-                var icons = {
-                    header: "ui-icon-circle-arrow-e",
-                    activeHeader: "ui-icon-circle-arrow-s"
-                };
-
-                $('.attrAccordion').append(nonEditableRows)
-                .append(editableRows)
-                .append(styleRows)
-                .append(customRows).accordion({
+                // append the before created html-elements to the accordion-menu
+                $.each(featureCategoriesSchemaInstance.categories, function(index, val) {
+                    categories[index] += '</table></div>';
+                    $('.attrAccordion').append(categories[index]);
+                });
+                // instantiate the accordion
+                $('.attrAccordion').accordion({
                     collapsible: false
                 });
-
+                // prepend the geometryDiv to the attribute dialog
                 attributesDialog.prepend(geometryDiv);
 
                 attributesDialog.find('.digitize-add').bind('click', function() {
+                    console.log( "click" );
                     var newRow = $('<tr><td><input style="width:81px" type="text"></input></td><td><input style="width:100px" type="text"></input></td></tr>');
-                    attributesDialog.find('.ftr-data-tbl.custom-data').append(newRow);
+                    attributesDialog.find('.ftr-data-tbl.Custom-Data').append(newRow);
                     newRow.find('input').first().bind('change', function() {
                         newRow.find('input').last().attr('name', $(this).val());
                     });
@@ -760,7 +749,7 @@
                 var $link = $('li[title="' + url + '"] > ul > li');
 
                 attributesDialog.find('.digitize-style').bind('click', editStyle($link, null));
-                attributesDialog.find('.digitize-save').bind('click', function() {
+                attributesDialog.find('.digitize-save').bind('click', function() { //@TODO: save update to the matching feature collection
                     attributesDialog.find('table input').each(function() {
                         var k = $(this).attr('name');
                         var v = $(this).val();
@@ -770,9 +759,9 @@
                     });
                     feature.properties.updated = new Date().toISOString();
                     //get parent and change updated
-                    if($('#mapframe1').data('kml')._kmls[url].data.hasOwnProperty('@context')){
+                    if($('#mapframe1').data('kml')._kmls[url].data.hasOwnProperty('updated')){
 
-                    	$('#mapframe1').data('kml')._kmls[url].data['@context'].updated = new Date().toISOString();
+                    	$('#mapframe1').data('kml')._kmls[url].data.updated = new Date().toISOString();
                     }
 
                     attributesDialog.dialog('close');
@@ -835,7 +824,6 @@
                     editDialog.dialog('close');
                 }
             });
-
             status = 'edit-' + feature.geometry.type.toLowerCase();
             if(status === 'edit-linestring') {
                 // TODO consolidate this
@@ -1003,6 +991,7 @@
         var multi = new MultiGeometry(geomType);
         multi.add(geom);
 
+
         if(status === 'edit-point') {
             editedFeature.geometry.coordinates = [pts[0].pos.x, pts[0].pos.y];
         } else if(status === 'edit-line') {
@@ -1016,7 +1005,18 @@
                 editedFeature.geometry.coordinates[0].push([v.pos.x, v.pos.y]);
             });
         }
+        // cloning the geoms to calculate the area or length
+        var modifiedGeom = $.extend(true, {}, geom);
+        var modifiedData = new MultiGeometry(geomType);
 
+        if (geomType == 'polygon') {
+            modifiedGeom.addPoint(geom.list[0]); // add first point as last point
+            modifiedData.add(modifiedGeom);
+
+        } else {
+
+            modifiedData.add(modifiedGeom);
+        }
         if (status != 'edit-point') {
 
             // calculate current area (polygon) or length(linestring)
@@ -1026,7 +1026,7 @@
                 dataType: 'json',
                 data: {
                     geom_type: geomType,
-                    wkt_geom: multi.toText()
+                    wkt_geom: modifiedData.toText()
                 },
                 success: function(data) {
 
@@ -1128,6 +1128,54 @@
     };
 
     create();
+
+    /**
+     * mapFeature appends every property to a category
+     * @param  {[type]} propertyKey   [description]
+     * @param  {[type]} propertyValue [description]
+     * @param  {[type]} categories    [description]
+     * @param  {[type]} mappingSchema [description]
+     * @return {[type]}               [description]
+     */
+    var mapFeature = function( propertyKey, propertyValue, categories, mappingSchema, geomType, geometryDiv){
+
+        if ( propertyKey != "area" && propertyKey != "boundary-length" && propertyKey != "track-length" ) {
+            // check if property exists in mappingSchema otherwise put it in custom-data
+            if (mappingSchema[geomType].hasOwnProperty(propertyKey)) {
+                // first need to know the matching category
+                var featureCategory = mappingSchema[geomType][propertyKey]["category"];
+                // if property is part of Fix-Data, disable the input
+                if (featureCategory == "Fix-Data") {
+
+                    categories[featureCategory] += '<tr><td>' + propertyKey + '</td><td><input disabled type="text" name="' + propertyKey + '" value="' + propertyValue + '"></input></td></tr>';
+                // else allow to edit the input
+                } else {
+
+                    categories[featureCategory] += '<tr><td>' + propertyKey + '</td><td><input type="text" name="' + propertyKey + '" value="' + propertyValue + '"></input></td></tr>';
+                }
+            } else {
+                // put property in custom-data because it doesn't belong to any category
+                categories["Custom-Data"] += '<tr><td>' + propertyKey + '</td><td><input type="text" name="' + propertyKey + '" value="' + propertyValue + '"></input></td></tr>';
+
+            }
+        } else {
+            var header;
+            // differentiate between the geometry-properties
+            switch(propertyKey) {
+                case "area":
+                    header = "<?php echo _mb("Area [m²]");?>";
+                    break;
+                case "boundary-length":
+                    header = "<?php echo _mb("Boundary length [m]");?>";
+                    break;
+                case "track-length":
+                    header = "<?php echo _mb("Length [m]");?>";
+                    break;
+            }
+
+            geometryDiv.append('<div><p class = " geometry-p "name="' + propertyKey + '">'+ header +' : ' + propertyValue + '</p></div>');
+        }
+    }
 };
 
 $digitize.mapbender(new DigitizeApi(options));

Modified: trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
===================================================================
--- trunk/mapbender/lib/mb.ui.displayKmlFeatures.js	2015-05-18 13:49:18 UTC (rev 9198)
+++ trunk/mapbender/lib/mb.ui.displayKmlFeatures.js	2015-05-21 12:14:28 UTC (rev 9199)
@@ -449,14 +449,13 @@
 
             if (geom.geomType == 'polygon') {
 
-                modifiedGeom.addPoint(geom.list[0]);
+                modifiedGeom.addPoint(geom.list[0]); // add first point as last point
                 modifiedData.add(modifiedGeom);
 
             } else {
 
                 modifiedData.add(modifiedGeom);
             }
-
             // calculate current area (polygon) or length(linestring)
             $.ajax({
                 url: '../php/mod_CalculateAreaAndLength.php',
@@ -464,7 +463,7 @@
                 dataType: 'json',
                 data: {
                     geom_type: modifiedData.geomType,
-                    wkt_geom: modifiedData.toText()
+                    wkt_geom: modifiedData.toText(),
                 },
                 success: function(data) {
 
@@ -480,20 +479,17 @@
 
                 },
                 complete: function() {
-                    if (icon == "false" || icon === false) {
-                        multi.e.setElement("iconOffsetX", -10);
-                        multi.e.setElement("iconOffsetY", -34);
-                        multi.e.setElement("icon", "../img/marker/red.png");
-                    }
-                        multi.e.setElement("marker-size", 34); // default value 'medium, small, large' is not allowed from canvas
-                        multi.e.setElement("marker-symbol", "");
-                        multi.e.setElement("marker-color", "#7e7e7e");
-                        multi.e.setElement("stroke", "#555555");
-                        multi.e.setElement("stroke-opacity", 1.0);
-                        multi.e.setElement("stroke-width", 2);
+
+                    multi.e.setElement("stroke", "#555555"); //@TODO: get the attributes from the config! Don't hardcode it!
+                    multi.e.setElement("stroke-opacity", 1.0);
+                    multi.e.setElement("stroke-width", 2);
+                    if (geom.geomType == 'polygon') {
+
                         multi.e.setElement("fill", "#555555");
                         multi.e.setElement("fill-opacity", 0.5);
 
+                    }
+
                     var feat = JSON.parse(multi.toString());
                     itm.data.features.push(feat);
 
@@ -518,21 +514,14 @@
                     multi.e.setElement($(this).attr('name'), $(this).val());
                 }
             });
-
             if (icon == "false" || icon === false) {
                 multi.e.setElement("iconOffsetX", -10);
                 multi.e.setElement("iconOffsetY", -34);
-                multi.e.setElement("icon", "../img/marker/red.png");
-
+                // multi.e.setElement("icon", "marker");
             }
-                multi.e.setElement("marker-size", 34); // default value 'medium, small, large' is not allowed from canvas
-                multi.e.setElement("marker-symbol", "");
-                multi.e.setElement("marker-color", "#7e7e7e");
-                multi.e.setElement("stroke", "#555555");
-                multi.e.setElement("stroke-opacity", 1.0);
-                multi.e.setElement("stroke-width", 2);
-                multi.e.setElement("fill", "#555555");
-                multi.e.setElement("fill-opacity", 0.5);
+            multi.e.setElement("marker-size", 34); // default value 'medium, small, large' is not allowed from canvas
+            multi.e.setElement("marker-symbol", "marker");
+            multi.e.setElement("marker-color", "#7e7e7e");
 
             var feat = JSON.parse(multi.toString());
             itm.data.features.push(feat);



More information about the Mapbender_commits mailing list