[Mapbender-commits] r8855 - in trunk/mapbender/http: plugins widgets

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue May 13 06:32:35 PDT 2014


Author: hwbllmnn
Date: 2014-05-13 06:32:35 -0700 (Tue, 13 May 2014)
New Revision: 8855

Modified:
   trunk/mapbender/http/plugins/mb_digitize_widget.php
   trunk/mapbender/http/widgets/w_digitize.js
Log:
highlight vertices of edited features


Modified: trunk/mapbender/http/plugins/mb_digitize_widget.php
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_widget.php	2014-05-13 12:10:33 UTC (rev 8854)
+++ trunk/mapbender/http/plugins/mb_digitize_widget.php	2014-05-13 13:32:35 UTC (rev 8855)
@@ -140,6 +140,7 @@
         inProgress = false,
         title = o.title,
         digitizingFor = '',
+        editedFeature = null,
         status = 'none';
 
     var create = function() {
@@ -218,47 +219,7 @@
             kml.zoomToFeature(url, $link.attr('idx'));
             menu.menu('destroy').remove();
         });
-        menu.children('li:has(.digitize-pencil)').bind('click', function() {
-            $link.addClass('kmltree-selected').siblings().removeClass('kmltree-selected');
-            var idx = $link.attr('idx');
-            var kml = $('#mapframe1').data('kml');
-            var url = $link.parent().parent().attr('title');
-            var feature = kml._kmls[url].data.features[idx];
-            editDialog.find('span').text(feature.properties.title);
-            editDialog.dialog('open');
-            editDialog.find('.digitize-attributes').bind('click', function() {
-                attributesDialog.dialog('open');
-                var rows = '';
-                $.each(feature.properties, function(k, v) {
-                    if(k.match(/Mapbender:/)) return;
-                    rows += '<tr><td>' + k + '</td><td><input type="text" name="' + k + '" value="' + v + '"></input></td></tr>';
-                });
-                attributesDialog.find('table').html(rows);
-                attributesDialog.find('.digitize-add').bind('click', function() {
-                    var newRow = $('<tr><td><input type="text"></input></td><td><input type="text"></input></td></tr>');
-                    attributesDialog.find('table').append(newRow);
-                    newRow.find('input').first().bind('change', function() {
-                        newRow.find('input').last().attr('name', $(this).val());
-                    });
-                });
-                attributesDialog.find('.digitize-save').bind('click', function() {
-                    attributesDialog.find('table input').each(function() {
-                        var k = $(this).attr('name');
-                        var v = $(this).val();
-                        if(k) {
-                            feature.properties[k] = v;
-                        }
-                    });
-                    attributesDialog.dialog('close');
-                    editDialog.dialog('close');
-                    kml.refresh(url);
-                });
-            });
-            editDialog.find('.digitize-pencil').bind('click', function() {
-                $(this).next().toggleClass('digitize-hidden');
-            });
-            menu.menu('destroy').remove();
-        });
+        menu.children('li:has(.digitize-pencil)').bind('click', editObject($link, menu));
         menu.children('li:has(.digitize-remove)').bind('click', function() {
             var kml = $('#mapframe1').data('kml');
             var url = $link.parent().parent().attr('title');
@@ -276,6 +237,60 @@
         return false;
     };
 
+    var editAttributes = function(feature, kml, url) {
+        return function() {
+            attributesDialog.dialog('open');
+            var rows = '';
+            $.each(feature.properties, function(k, v) {
+                if(k.match(/Mapbender:/)) return;
+                rows += '<tr><td>' + k + '</td><td><input type="text" name="' + k + '" value="' + v + '"></input></td></tr>';
+            });
+            attributesDialog.find('table').html(rows);
+            attributesDialog.find('.digitize-add').bind('click', function() {
+                var newRow = $('<tr><td><input type="text"></input></td><td><input type="text"></input></td></tr>');
+                attributesDialog.find('table').append(newRow);
+                newRow.find('input').first().bind('change', function() {
+                    newRow.find('input').last().attr('name', $(this).val());
+                });
+            });
+            attributesDialog.find('.digitize-save').bind('click', function() {
+                attributesDialog.find('table input').each(function() {
+                    var k = $(this).attr('name');
+                    var v = $(this).val();
+                    if(k) {
+                        feature.properties[k] = v;
+                    }
+                });
+                attributesDialog.dialog('close');
+                editDialog.dialog('close');
+                kml.refresh(url);
+            });
+        };
+    };
+
+    var editObject = function($link, menu) {
+        return function() {
+            $link.addClass('kmltree-selected').siblings().removeClass('kmltree-selected');
+            var idx = $link.attr('idx');
+            var kml = $('#mapframe1').data('kml');
+            var url = $link.parent().parent().attr('title');
+            var feature = kml._kmls[url].data.features[idx];
+            editDialog.find('span').text(feature.properties.title);
+            editDialog.dialog('open');
+            editDialog.find('.digitize-attributes').bind('click', editAttributes(feature, kml, url));
+            editDialog.find('.digitize-pencil').bind('click', function() {
+                $(this).next().toggleClass('digitize-hidden');
+            });
+
+            status = 'edit-point';
+            digitizingFor = url;
+            editedFeature = feature;
+            that.activate();
+
+            menu.menu('destroy').remove();
+        };
+    };
+
     var contextmenuLayer = function() {
         var $link = $(this);
         var menu = $(folderMenu);
@@ -371,13 +386,23 @@
     };
 
     this.activate = function () {
-        if (o.$target.size() > 0) {
-            o.type = status.match(/new-(.+)/)[1];
-            o.$target
-                .mb_digitize(o)
-//				.bind("mb_digitizepointadded", newPoint)
-                .bind("mb_digitizelastpointadded", finishDigitize)
-                .bind("mb_digitizereinitialize", reinitializeDigitize);
+        var mode = status.match(/(new|edit)-.+/)[1];
+
+        if(mode === 'new') {
+            if (o.$target.size() > 0) {
+                o.type = status.match(/new-(.+)/)[1];
+                o.$target
+                    .mb_digitize(o)
+                    .bind("mb_digitizelastpointadded", finishDigitize)
+                    .bind("mb_digitizereinitialize", reinitializeDigitize);
+            }
+        } else {
+            if(o.$target.size() > 0) {
+                o.type = status.match(/edit-(.+)/)[1];
+                o.editedFeature = editedFeature;
+                o.$target
+                .mb_digitize(o);
+            }
         }
         if (!inProgress) {
             inProgress = true;

Modified: trunk/mapbender/http/widgets/w_digitize.js
===================================================================
--- trunk/mapbender/http/widgets/w_digitize.js	2014-05-13 12:10:33 UTC (rev 8854)
+++ trunk/mapbender/http/widgets/w_digitize.js	2014-05-13 13:32:35 UTC (rev 8855)
@@ -15,7 +15,8 @@
         pointStrokeDefault: "#FC3",
         pointStrokeSnapped: "#F30",
         pointStrokeWidthDefault: 2,
-        type: null
+        type: null,
+        editedFeature: null
     },
     _digitizePoints: [],
     _map: undefined,
@@ -393,18 +394,34 @@
         this._digitizePoints = [];
         this._canvas.clear();
 
-        // if(this.options.type === 'point') {
-        //     this.element
-        //         .bind("click", $.proxy(this, "_addPoint"))
-        //         .css("cursor", "crosshair");
-        // } else {
+        if(this.options.editedFeature) {
+            this._digitizePoints = this.coordinatesToDigitizePoints(this.options.editedFeature.geometry.coordinates);
+            this._redraw();
+        } else {
             this.element
                 .bind("click", $.proxy(this, "_addPoint"))
                 .bind("mousemove", $.proxy(this, "_digitize"))
                 .css("cursor", "crosshair");
-        // }
+        }
     },
 
+    coordinatesToDigitizePoints: function(coords) {
+        var map = $('#mapframe1').mapbender();
+        if($.isArray(coords[0])) {
+            var pts = [];
+            $.each(coords, function(_, v) {
+                var pos = {x: v[0], y: v[1]};
+                var mousePos = map.convertRealToPixel(pos);
+                pts.push({pos: pos, mousePos: mousePos});
+            });
+            return pts;
+        } else {
+            var pos = {x: coords[0], y: coords[1]};
+            var mousePos = map.convertRealToPixel(pos);
+            return [{pos: pos, mousePos: mousePos}];
+        }
+    },
+
     _create: function () {
         this._digitizePoints = [];
 



More information about the Mapbender_commits mailing list