[Mapbender-commits] r8974 - in trunk/mapbender: http/plugins lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 2 07:00:01 PDT 2014


Author: hwbllmnn
Date: 2014-07-02 07:00:00 -0700 (Wed, 02 Jul 2014)
New Revision: 8974

Modified:
   trunk/mapbender/http/plugins/mb_digitize_widget.php
   trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
Log:
added selection by box (still interferes with other map functions)


Modified: trunk/mapbender/http/plugins/mb_digitize_widget.php
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_widget.php	2014-07-02 11:54:49 UTC (rev 8973)
+++ trunk/mapbender/http/plugins/mb_digitize_widget.php	2014-07-02 14:00:00 UTC (rev 8974)
@@ -532,7 +532,6 @@
 
     var editObject = function($link, menu) {
         return function(e) {
-
             editDialog.find('*').unbind();
             if($link.hasClass('kmltree-selected')) {
                 editDialog.dialog('close');
@@ -782,6 +781,10 @@
         }
     };
 
+    this.closeEditDialog = function() {
+        editDialog.dialog('close');
+    };
+
     create();
 };
 

Modified: trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
===================================================================
--- trunk/mapbender/lib/mb.ui.displayKmlFeatures.js	2014-07-02 11:54:49 UTC (rev 8973)
+++ trunk/mapbender/lib/mb.ui.displayKmlFeatures.js	2014-07-02 14:00:00 UTC (rev 8974)
@@ -61,7 +61,55 @@
             self.render();
         });
 
+		// go: function () {
+		// 	if (!map) {
+		// 		new Mb_exception(options.id + ": " +
+		// 			options.target + " is not a map!");
+		// 		return;
+		// 	}
+
+		// 	box = new Mapbender.Box({
+		// 		target: options.target
+		// 	});
+		// 	$(map.getDomElement()).css(
+		// 		"cursor", "crosshair"
+		// 	).mousedown(function (e) {
+		// 		box.start(e);
+		// 		return false;
+		// 	}).mouseup(function (e) {
+		// 		box.stop(e, function (extent) {
+		// 			if (typeof extent === "undefined") {
+		// 				return false;
+		// 			}
+		// 			if (extent.constructor === Mapbender.Extent) {
+		// 				var xt = map.calculateExtent(extent);
+		// 				map.setMapRequest();
+		// 			}
+		// 			else if (extent.constructor === Mapbender.Point) {
+		// 				map.setCenter(extent);
+		// 				map.setMapRequest();
+		// 			}
+		// 		});
+		// 		return false;
+		// 	});
+		// },
+		// stop: function () {
+		// 	if (!map) {
+		// 		return;
+		// 	}
+		// 	$(map.getDomElement())
+		// 		.css("cursor", "default")
+		// 		.unbind("mousedown")
+		// 		.unbind("mouseup")
+		// 		.unbind("mousemove");
+		// 	box = null;
+
+
         this.element.bind('click', function(e) {
+            if(self.lastWasBox) {
+                self.lastWasBox = false;
+                return;
+            }
             var map = self.element.mapbender();
             var pos = map.getMousePosition(e);
             var clickPoint =  map.convertPixelToReal(new Point(pos.x,pos.y));
@@ -70,78 +118,41 @@
 
             if(!self.queriedLayer) return;
 
-            var matchedIds = [];
+            var matchedIds = self.findFeatures(pos);
 
-            $.each(self._kmls, function(_, itm) {
-                $.each(itm.data.features, function(k, v) {
-                    if(v.geometry.type.match(/point/i)) {
-                        var pt = Proj4js.transform(self.wgs84, self.targetProj, {x: v.geometry.coordinates[0], y: v.geometry.coordinates[1]});
-                        var minx = pt.x - 20 * res;
-                        var miny = pt.y - 20 * res;
-                        var maxx = minx + 40 * res;
-                        var maxy = miny + 40 * res;
-                        if(minx < clickPoint.x && maxx > clickPoint.x && miny < clickPoint.y && maxy > clickPoint.y) {
-                            matchedIds.push({url: itm.url, id: k});
-                        }
-                    } else {
-                        var box = self.getBbox(v);
-                        if(box[0] < wgspt.x && box[2] > wgspt.x && box[1] < wgspt.y && box[3] > wgspt.y) {
-                            matchedIds.push({url: itm.url, id: k});
-                        }
-                    }
-                });
-            });
-            if(matchedIds.length == 1 && !e.ctrlKey && self.selectedFeatures.length == 0) {
-                $('li[title="' + matchedIds[0].url + '"] li[idx="' + matchedIds[0].id + '"]').click();
-            } else {
-                if(!e.ctrlKey) {
-                    self.selectedFeatures = [];
-                }
-                $.each(matchedIds, function(_, v) {
-                    var contained = false;
-                    $.each(self.selectedFeatures, function(_, sel) {
-                        if(v.url == sel.url && v.id == sel.id) contained = true;
-                    });
-                    if(!contained) {
-                        self.selectedFeatures.push(v);
-                    }
-                });
+            self.updateSelectedFeatures(matchedIds, e.ctrlKey);
+        });
 
-                $('.kmltree-selected').removeClass('kmltree-selected');
-                $.each(self.selectedFeatures, function(_, v) {
-                    $('li[title="' + v.url + '"] li[idx="' + v.id + '"]').addClass('kmltree-selected');
-                });
+        var boxfun;
 
-                if(self.selectedFeatures.length > 1) {
-                    $('#selection-dialog').dialog('destroy').remove();
-                    var dlg = $(self.selectionDialog);
-                    var list = dlg.find('#selected-features-list')
-                    .html('');
-                    $.each(self.selectedFeatures, function(_, v) {
-                        var feat = self._kmls[v.url].data.features[v.id];
-                        var title = feat.properties.name;
-                        list.append('<li><div style="width: 20px; height: 20px; display: inline;" class="style-preview"></div><span>' + title + '</span></li>');
-                        var node = list.find('li div.style-preview').last()[0];
-                        self.renderPreview(feat, node);
-                    });
-                    dlg.dialog({
-                        close: function() {
-                            $('.kmltree-selected').removeClass('kmltree-selected');
-                            $(this).dialog('destroy').remove();
-                        }
-                    });
-                    dlg.find('.digitize-export').bind('click', function() {
-                        var data = {type: 'FeatureCollection', features: []};
-                        $.each(self.selectedFeatures, function(_, v) {
-                            var feat = self._kmls[v.url].data.features[v.id];
-                            data.features.push(feat);
-                            self.exportItem(data);
-                        });
-                        dlg.dialog('close');
-                    });
-                }
-            }
-        });
+        this.element.bind('mousedown', boxfun = function(e) {
+                                           if(!self.queriedLayer) return;
+                                           var box = new Mapbender.Box({
+                                               target: 'mapframe1'
+                                           });
+                                           box.start(e);
+                                           $('#mapframe1').css("cursor", "crosshair")
+                                           .mouseup(function (e) {
+                                               box.stop(e, function (extent) {
+                                                   if (typeof extent === "undefined") {
+                                                       return;
+                                                   }
+
+                                                   var matchedIds = self.findFeatures(extent);
+                                                   self.updateSelectedFeatures(matchedIds, e.ctrlKey);
+                                                   self.lastWasBox = true;
+
+                                                   $('#mapframe1')
+                                                   .css("cursor", "default")
+                                                   .unbind("mousedown")
+                                                   .unbind("mouseup")
+                                                   .unbind("mousemove")
+                                                   .bind('mousedown', boxfun);
+                                               });
+                                               return false;
+                                           });
+                                       });
+
         self.element.bind('kml:loaded',function(event,obj){
             if(o.autoOpen){
                 self.render();
@@ -176,6 +187,154 @@
         }
     },
 
+    findFeatures: function(posOrBox) {
+        var matchedIds = [];
+
+        var self = this;
+        var map = self.element.mapbender();
+        var ispoint;
+        var clickPoint, wgspt, clickBox, min, max;
+        if(posOrBox.x) {
+            clickPoint =  map.convertPixelToReal(new Point(posOrBox.x,posOrBox.y));
+            wgspt = Proj4js.transform(self.targetProj, self.wgs84, {x: clickPoint.x, y: clickPoint.y});
+            ispoint = true;
+        } else {
+            clickBox = posOrBox;
+            min = Proj4js.transform(self.targetProj, self.wgs84, {x: clickBox.minx, y: clickBox.miny});
+            max = Proj4js.transform(self.targetProj, self.wgs84, {x: clickBox.maxx, y: clickBox.maxy});
+            ispoint = false;
+        }
+        var res = map.getScale() / mb_resolution / 100;
+
+        $.each(self._kmls, function(_, itm) {
+            $.each(itm.data.features, function(k, v) {
+                if(ispoint) {
+                    self.matchFeatureToPoint(v, clickPoint, matchedIds, res, itm, wgspt, k);
+                } else {
+                    self.matchFeatureToBox(v, {min: min, max: max}, matchedIds, itm, k);
+                }
+            });
+        });
+
+        return matchedIds;
+    },
+
+    inBox: function(minx, miny, maxx, maxy, x, y) {
+        return minx < x && maxx > x && miny < y && maxy > y;
+    },
+
+    matchFeatureToPoint: function(feat, clickPoint, matchedIds, res, itm, wgspt, idx) {
+        if(feat.geometry.type.match(/point/i)) {
+            var pt = Proj4js.transform(this.wgs84, this.targetProj, {x: feat.geometry.coordinates[0], y: feat.geometry.coordinates[1]});
+            var minx = pt.x - 20 * res;
+            var miny = pt.y - 20 * res;
+            var maxx = minx + 40 * res;
+            var maxy = miny + 40 * res;
+            if(minx < clickPoint.x && maxx > clickPoint.x && miny < clickPoint.y && maxy > clickPoint.y) {
+                matchedIds.push({url: itm.url, id: idx});
+            }
+        } else {
+            var box = this.getBbox(feat);
+            if(this.inBox(box[0], box[1], box[2], box[3], wgspt.x, wgspt.y)) {
+                matchedIds.push({url: itm.url, id: idx});
+            }
+        }
+    },
+
+    matchFeatureToBox: function(feat, wgsbox, matchedIds, itm, idx) {
+        if(feat.geometry.type.match(/point/i)) {
+            if(this.inBox(wgsbox.min.x, wgsbox.min.y, wgsbox.max.x, wgsbox.max.y, feat.geometry.coordinates[0], feat.geometry.coordinates[1])) {
+                matchedIds.push({url: itm.url, id: idx});
+            }
+        } else {
+            var box = this.getBbox(feat);
+            if(this.inBox(box[0], box[1], box[2], box[3], wgsbox.min.x, wgsbox.min.y)
+             || this.inBox(box[0], box[1], box[2], box[3], wgsbox.min.x, wgsbox.max.y)
+             || this.inBox(box[0], box[1], box[2], box[3], wgsbox.max.x, wgsbox.max.y)
+             || this.inBox(box[0], box[1], box[2], box[3], wgsbox.max.x, wgsbox.min.y)) {
+                matchedIds.push({url: itm.url, id: idx});
+                return;
+            }
+            if(wgsbox.min.x > box[0] && wgsbox.max.x < box[2]) {
+                if(wgsbox.min.y > box[1] && wgsbox.max.y < box[3]) {
+                    matchedIds.push({url: itm.url, id: idx});
+                    return;
+                }
+                if(wgsbox.min.y < box[1] && wgsbox.max.y > box[3]) {
+                    matchedIds.push({url: itm.url, id: idx});
+                    return;
+                }
+            }
+            if(wgsbox.min.x < box[0] && wgsbox.max.x > box[2] && wgsbox.min.y > box[1] && wgsbox.max.y < box[3]) {
+                matchedIds.push({url: itm.url, id: idx});
+                return;
+            }
+        }
+    },
+
+    updateSelectedFeatures: function(ids, append) {
+        var self = this;
+
+        if(ids.length == 1 && !append && self.selectedFeatures.length == 0) {
+            $('li[title="' + ids[0].url + '"] li[idx="' + ids[0].id + '"]').click();
+        } else {
+            if(!append) {
+                self.selectedFeatures = [];
+            }
+            $.each(ids, function(_, v) {
+                var contained = false;
+                $.each(self.selectedFeatures, function(_, sel) {
+                    if(v.url == sel.url && v.id == sel.id) contained = true;
+                });
+                if(!contained) {
+                    self.selectedFeatures.push(v);
+                }
+            });
+
+            $('.kmltree-selected').removeClass('kmltree-selected');
+            $.each(self.selectedFeatures, function(_, v) {
+                $('li[title="' + v.url + '"] li[idx="' + v.id + '"]').addClass('kmltree-selected');
+            });
+
+
+            $('#selection-dialog').dialog('destroy').remove();
+
+            if(self.selectedFeatures.length == 0) {
+                Mapbender.modules.digitize_widget.closeEditDialog();
+            }
+
+            if(self.selectedFeatures.length > 1) {
+                Mapbender.modules.digitize_widget.closeEditDialog();
+                var dlg = $(self.selectionDialog);
+                var list = dlg.find('#selected-features-list')
+                .html('');
+                $.each(self.selectedFeatures, function(_, v) {
+                    var feat = self._kmls[v.url].data.features[v.id];
+                    var title = feat.properties.name;
+                    list.append('<li><div style="width: 20px; height: 20px; display: inline;" class="style-preview"></div><span>' + title + '</span></li>');
+                    var node = list.find('li div.style-preview').last()[0];
+                    self.renderPreview(feat, node);
+                });
+                dlg.dialog({
+                    close: function() {
+                        self.selectedFeatures = [];
+                        $('.kmltree-selected').removeClass('kmltree-selected');
+                        $(this).dialog('destroy').remove();
+                    }
+                });
+                dlg.find('.digitize-export').bind('click', function() {
+                    var data = {type: 'FeatureCollection', features: []};
+                    $.each(self.selectedFeatures, function(_, v) {
+                        var feat = self._kmls[v.url].data.features[v.id];
+                        data.features.push(feat);
+                        self.exportItem(data);
+                    });
+                    dlg.dialog('close');
+                });
+            }
+        }
+    },
+
     zoomToFeature: function(url, idx) {
         var map = $('#mapframe1').mapbender();
         var item = this._kmls[url];



More information about the Mapbender_commits mailing list