[OpenLayers-Commits] r2004 - in sandbox/vector/lib/OpenLayers/Control: EditingMode EditingTool

commits at openlayers.org commits at openlayers.org
Mon Dec 4 13:24:43 EST 2006


Author: pgiraud
Date: 2006-12-04 13:24:43 -0500 (Mon, 04 Dec 2006)
New Revision: 2004

Modified:
   sandbox/vector/lib/OpenLayers/Control/EditingMode/PointSnapping.js
   sandbox/vector/lib/OpenLayers/Control/EditingTool/MovePathPoint.js
Log:
composite geometries support in MovePathPoint tool

Modified: sandbox/vector/lib/OpenLayers/Control/EditingMode/PointSnapping.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Control/EditingMode/PointSnapping.js	2006-12-04 18:18:35 UTC (rev 2003)
+++ sandbox/vector/lib/OpenLayers/Control/EditingMode/PointSnapping.js	2006-12-04 18:24:43 UTC (rev 2004)
@@ -52,6 +52,10 @@
                     break;
                 }
             }
+        } else if (targetGeometry && targetGeometry.components) {
+            for (var i = 0; i < targetGeometry.components.length; i++) {
+                snappingPoint = this.calculatePoint(mouseCoordinates, targetGeometry.components[i], currentGeometry, layer);
+            }
         } else {
             layer.renderer.eraseGeometry(this.tmpPoint);
         }

Modified: sandbox/vector/lib/OpenLayers/Control/EditingTool/MovePathPoint.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Control/EditingTool/MovePathPoint.js	2006-12-04 18:18:35 UTC (rev 2003)
+++ sandbox/vector/lib/OpenLayers/Control/EditingTool/MovePathPoint.js	2006-12-04 18:24:43 UTC (rev 2004)
@@ -64,67 +64,14 @@
         
         // Set mouse position
         var lonlat = this.map.getLonLatFromLayerPx(evt.xy);
-        var mouseCoordinates =  new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
+        var mouseCoordinates =  new OpenLayers.LonLat(lonlat.lon, lonlat.lat);
         
-        
-        if(evt.targetGeometry && evt.targetGeometry.path) {
-            for(var i = 0; i < evt.targetGeometry.path.length; i++) {
-                
-                var tmpPoint = evt.targetGeometry.path[i];
-                
-                // Calculate screen pixel from segment points and mouseCoordinates
-                var pixel = this.layer.map.getPixelFromLonLat(tmpPoint);
-                var mousePixel = this.layer.map.getPixelFromLonLat(mouseCoordinates);
-             
-                // Compare first segment point pixel to mouse pixel with a tolerance
-                if (Math.abs(mousePixel.x - pixel.x) < this.tolerance && Math.abs(mousePixel.y - pixel.y) < this.tolerance) {
-                    var point = tmpPoint;
-                    break;
-                }
+        if (evt.targetGeometry && evt.targetGeometry.components) {
+            for (var i = 0; i < evt.targetGeometry.components.length; i++) {
+                this._handleSelection(evt.targetGeometry.components[i], mouseCoordinates);
             }
-             
-            // Point Selection            
-            if (point) {
-                // Multiple point Selection
-                // only works now if user keeps the shift key down
-                if (this.shiftDown){
-                    
-                    // Verify if the point is selected
-                    if (OpenLayers.Util.indexOf(this.selection, point) < 0){
-                        this.selection.push(point);
-                        this.layer.renderer.drawGeometry(point, this.layer.style);
-                    
-                    // UnSelect the point
-                    } else {
-                        this.selection = OpenLayers.Util.removeItem(this.selection, point);
-                        this.layer.renderer.eraseGeometry(point);
-                    }
-                    
-                // Reset the point selection
-                } else {
-                    for(var i = 0; i < this.selection.length; i++) {
-                    	this.layer.renderer.eraseGeometry(this.selection[i]);
-                    }
-                    this.selection = [point];
-                    this.layer.renderer.drawGeometry(point, this.layer.style);
-                }
-            } else {
-                for(var i=0; i<this.selection.length; i++) {
-                	this.layer.renderer.eraseGeometry(this.selection[i], this.layer.style);
-                }
-                this.layer.selection = [];
-            }
-            
-            // Geometry Selection
-            if (this.shiftDown){
-                if (OpenLayers.Util.indexOf(this.layer.selection, evt.targetGeometry.feature) < 0){
-                    this.layer.selection.push(evt.targetGeometry.feature);
-                } else {
-                    //this.layer.selection = OpenLayers.Util.removeItem(this.layer.selection, evt.targetGeometry.feature);
-                }
-            } else {
-               this.layer.selection = evt.targetGeometry.feature?[evt.targetGeometry.feature]:[];
-            }
+        } else if (evt.targetGeometry && evt.targetGeometry.path) {
+            this._handleSelection(evt.targetGeometry, mouseCoordinates);
         } else {
             // user clicked out of a geometry
             for(var i=0; i<this.selection.length; i++) {
@@ -142,6 +89,76 @@
         this.lastPositionReference =  new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
         
     },
+    
+    /**
+     * private method
+     * handles the selection for tool and layer
+     * 
+     * @param {OpenLayers.Geometry} geometry
+     * @param {OpenLayers.LonLat} mouseCoordinates
+     */
+    _handleSelection: function(geometry, mouseCoordinates) {
+        
+        for(var i = 0; i < geometry.path.length; i++) {
+            
+            var tmpPoint = geometry.path[i];
+            
+            // Calculate screen pixel from segment points and mouseCoordinates
+            var pixel = this.layer.map.getPixelFromLonLat(tmpPoint);
+            var mousePixel = this.layer.map.getPixelFromLonLat(mouseCoordinates);
+         
+            // Compare first segment point pixel to mouse pixel with a tolerance
+            if (Math.abs(mousePixel.x - pixel.x) < this.tolerance && Math.abs(mousePixel.y - pixel.y) < this.tolerance) {
+                var point = tmpPoint;
+                break;
+            }
+        }
+         
+        // Point Selection            
+        if (point) {
+            // Multiple point Selection
+            // only works now if user keeps the shift key down
+            if (this.shiftDown){
+                
+                // Verify if the point is selected
+                if (OpenLayers.Util.indexOf(this.selection, point) < 0){
+                    this.selection.push(point);
+                    this.layer.renderer.drawGeometry(point, this.layer.style);
+                
+                // UnSelect the point
+                } else {
+                    this.selection = OpenLayers.Util.removeItem(this.selection, point);
+                    this.layer.renderer.eraseGeometry(point);
+                }
+                
+            // Reset the point selection
+            } else {
+                for(var i = 0; i < this.selection.length; i++) {
+                    this.layer.renderer.eraseGeometry(this.selection[i]);
+                }
+                this.selection = [point];
+                this.layer.renderer.drawGeometry(point, this.layer.style);
+            }
+        } else {
+            for(var i = 0; i < this.selection.length; i++) {
+                this.layer.renderer.eraseGeometry(this.selection[i], this.layer.style);
+            }
+            this.layer.selection = [];
+        }
+        
+        // Geometry Selection
+        if (this.shiftDown){
+            if (OpenLayers.Util.indexOf(this.layer.selection, geometry.feature) < 0){
+                this.layer.selection.push(geometry.feature);
+            } else {
+                //this.layer.selection = OpenLayers.Util.removeItem(this.layer.selection, geometry.feature);
+            }
+        } else {
+            console.log(geometry);
+           this.layer.selection = geometry.feature?[geometry.feature]:[];
+        }
+        
+    },
 
     /**
      * @param {Event} evt
@@ -161,11 +178,14 @@
             var lonlat = this.map.getLonLatFromLayerPx(evt.xy);
             this.lastPositionReference =  new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
             
+            
             for(var i=0; i<this.selection.length; i++) {
         	    this.selection[i].setX(this.selection[i].x + xTranslation);
                 this.selection[i].setY(this.selection[i].y + yTranslation);
                 this.layer.renderer.drawGeometry(this.selection[i], this.layer.style);   
         	}
+
+console.log(this.layer.selection.length);
         	
         	// redraw the modified Geometries
         	for(var i = 0; i < this.layer.selection.length; i++) {



More information about the Commits mailing list