[OpenLayers-Commits] r2020 - in sandbox/vector/lib/OpenLayers: . Control Geometry Parser

commits at openlayers.org commits at openlayers.org
Wed Dec 6 22:47:43 EST 2006


Author: camerons
Date: 2006-12-06 22:47:42 -0500 (Wed, 06 Dec 2006)
New Revision: 2020

Modified:
   sandbox/vector/lib/OpenLayers/BaseTypes.js
   sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js
   sandbox/vector/lib/OpenLayers/Feature.js
   sandbox/vector/lib/OpenLayers/Geometry.js
   sandbox/vector/lib/OpenLayers/Geometry/Aggregate.js
   sandbox/vector/lib/OpenLayers/Parser/GML.js
Log:
#434 Now querying multiple layers works based on querying layers below the top using BoundingBox queries. Still need to address point queries, and aggregate geometries.

Modified: sandbox/vector/lib/OpenLayers/BaseTypes.js
===================================================================
--- sandbox/vector/lib/OpenLayers/BaseTypes.js	2006-12-07 01:07:31 UTC (rev 2019)
+++ sandbox/vector/lib/OpenLayers/BaseTypes.js	2006-12-07 03:47:42 UTC (rev 2020)
@@ -487,8 +487,8 @@
                 this.right=(right>this.right)?right:this.right;
                 this.top=(top>this.top)?top:this.top;
             }else{
-              this.right=(left<this.left)?left:this.left;
-              this.top=(bottom<this.bottom)?bottom:this.bottom;
+              this.right=(left>this.right)?left:this.right;
+              this.top=(bottom>this.top)?bottom:this.top;
             }
         }
     },

Modified: sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js	2006-12-07 01:07:31 UTC (rev 2019)
+++ sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js	2006-12-07 03:47:42 UTC (rev 2020)
@@ -27,13 +27,31 @@
     },
     
     /**
+     * Register for mousedown events
+     */
+    turnOn: function() {
+
+        this.setLayer();
+        
+        this.defaultMouseDown = this.defaultMouseDown.bindAsEventListener(this);
+        this.map.events.register( "mousedown", this, this.defaultMouseDown);
+    },
+
+    /**
+     *
+     */
+    turnOff: function() {
+        this.map.events.unregister( "mousedown", this, this.defaultMouseDown);
+    },
+    
+    /**
      * Render an array of attributes into a popup.
      * @param attributes Attributes array to render
      */
     setContent: function(attributes) {
-		// Clear previous popup
-		this.div.innerHTML="";
-		
+        // Clear previous popup
+        this.div.innerHTML="";
+        
         //configure main div
         this.div.style.position = "absolute";
         this.div.style.top = "30px";
@@ -49,14 +67,14 @@
         this.div.style.backgroundColor = "transparent";
 
         this.innerDiv = document.createElement("div");
-		this.innerDiv.innerHTML="<b>Attribute List</b><br/>"
+        this.innerDiv.innerHTML="<b>Attribute List</b><br/>"
         this.innerDiv.id = "layersDiv";
         this.innerDiv.style.paddingTop = "2px";
         this.innerDiv.style.paddingLeft = "2px";
         this.innerDiv.style.paddingBottom = "2px";
         this.innerDiv.style.paddingRight = "2px";
         this.innerDiv.style.backgroundColor = this.activeColor;
-		this.div.appendChild(this.innerDiv);    
+        this.div.appendChild(this.innerDiv);    
 
         Rico.Corner.round(this.div, {corners: "tl bl",
                                       bgColor: "transparent",
@@ -64,7 +82,7 @@
                                       blend: false});
 
         Rico.Corner.changeOpacity(this.innerDiv, 0.75);
-		
+        
         attribs=attributes.getAttributes();
         for (var i = 0; i < attribs.length; i++) {
             var attributeDiv = document.createElement("div");
@@ -84,7 +102,7 @@
 
             this.innerDiv.appendChild(attributeDiv);
         }
-		
+        
         // minimize button div
         var imgLocation = OpenLayers.Util.getImagesLocation();
         var img = imgLocation + 'layer-switcher-minimize.png';
@@ -104,7 +122,7 @@
                       this.minimizeControl.bindAsEventListener(this));
         this.div.appendChild(this.minimizeDiv);
 
-		// Stop MouseEvents from propogating through this popup
+        // Stop MouseEvents from propogating through this popup
         OpenLayers.Event.observe(this.div, "mouseup", this.ignoreEvent);
         OpenLayers.Event.observe(this.div, "mousedown", this.ignoreEvent);
         OpenLayers.Event.observe(this.div, "click", this.ignoreEvent);
@@ -129,6 +147,52 @@
         }
     },
 
+    /**
+     * Add the Geometry that has been selected to the Event.
+     * The top geometry layer is selected first, this is done using
+     * SVG/VML feature selection and is accurate. If a feature is not
+     * found, features in layers below are progressively queried using
+     * the BoundingBox of the feature. (Ie, it is not very accurate).
+     * See http://trac.openlayers.org/ticket/434 for more info.
+     *
+     * @param {Event} evt
+     */
+    setEventContext: function(evt) {
+        // calculate the mouse position
+        var lonlat = this.map.getLonLatFromLayerPx(evt.xy);
+        evt.point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
+
+        // For the top layer, query the SVG/VML feature
+        if(map.layers.length>0){
+            evt.targetGeometry = map.layers[map.layers.length-1].renderer.getGeometryFromEvent(evt);
+        }
+        // For remaining layers, query features based on feature bounds.
+        // Exit loop when a feature is found.
+        for(var i=map.layers.length-1;(!evt.targetGeometry&&(i>=0));i--){
+            if(map.layers[i].getVisibility()&&map.layers[i].isVector){
+                for(var f=0;!evt.targetGeometry&&(f<map.layers[i].features.length);f++){
+                    if(map.layers[i].features[f].atPoint(lonlat)){
+                        evt.targetGeometry=map.layers[i].features[f].geometry;
+                    }
+                    
+                }
+            }
+        }
+        
+        // reset evt.point if modes are activated.
+        if (this.editingModes) {
+            for (var i = 0; i < this.editingModes.length; i++) {
+                var snappingCoordinates = 
+                    this.editingModes[i].calculatePoint(evt.point, evt.targetGeometry, this.geometry, this.layer);
+
+                if (snappingCoordinates) {
+                    evt.point = snappingCoordinates;                    
+                    break;
+                }
+            }
+        }
+    },
+
     /** Hide all the contents of the control, shrink the size, 
      *   add the maximize icon
      * 

Modified: sandbox/vector/lib/OpenLayers/Feature.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Feature.js	2006-12-07 01:07:31 UTC (rev 2019)
+++ sandbox/vector/lib/OpenLayers/Feature.js	2006-12-07 03:47:42 UTC (rev 2020)
@@ -59,7 +59,7 @@
      */
     initialize: function(layer, geometry, data) {
         this.layer = layer;
-		this.setGeometry(geometry);
+        this.setGeometry(geometry);
         this.data = (data != null) ? data : new Object();
         this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 
         this.state = null;
@@ -168,11 +168,11 @@
      * @param {OpenLayers.Geometry} geometry to set
      */
     setGeometry: function(geometry) {
-		if(geometry){
-	        this.geometry = geometry;
-	        this.geometry.feature = this;
-	        this._setGeometryFeatureReference(this.geometry, this);
-		}
+        if(geometry){
+            this.geometry = geometry;
+            this.geometry.feature = this;
+            this._setGeometryFeatureReference(this.geometry, this);
+        }
     },
     
     /**
@@ -216,6 +216,19 @@
 //    },
 
     /**
+     * Takes an lonLat point and returns true if the feature is at this location.
+     * @param {OpenLayers.LonLat} lonlat
+     * @return Boolean
+     */
+    atPoint: function(lonlat){
+        var atPoint=false;
+        if(this.geometry){
+            atPoint=this.geometry.atPoint(lonlat);
+        }
+        return atPoint;
+    },
+
+    /**
      * Set geometry style
      *
      * @param {OpenLayers.Style} attributes to remove, can be an array

Modified: sandbox/vector/lib/OpenLayers/Geometry/Aggregate.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Geometry/Aggregate.js	2006-12-07 01:07:31 UTC (rev 2019)
+++ sandbox/vector/lib/OpenLayers/Geometry/Aggregate.js	2006-12-07 03:47:42 UTC (rev 2020)
@@ -45,5 +45,31 @@
         }
     },
 
+//	/**
+//	 * Takes an lonLat point and returns true if the feature is at this location.
+//	 * @param {OpenLayers.LonLat} lonlat
+//	 * @return Boolean
+//	 */
+//	atPoint: function(lonlat){
+//		var atPoint=false;
+//		var bounds;
+//		if(this.components){
+//			for(var i=0;!atPoint&&(i<this.components.length);i++){
+//				atPoint=this.components[i].atPoint(lonlat);
+//			}
+//		}else{
+//			// The following code is probably not required as
+//			// agregate geometries will always have components. Right?
+//			// Cameron Shorter.
+//			if(this.bounds){
+//				atPoint=(this.bounds.bottom<=lonlat.lat)
+//				    && (lonlat.lat<=this.bounds.top)
+//					&& (this.bounds.left<=lonlat.lon)
+//					&& (lonlat.lon<=this.bounds.right);
+//			}
+//		}
+//		return atPoint;
+//	},
+
     CLASS_NAME: "OpenLayers.Geometry.Aggregate"
 });

Modified: sandbox/vector/lib/OpenLayers/Geometry.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Geometry.js	2006-12-07 01:07:31 UTC (rev 2019)
+++ sandbox/vector/lib/OpenLayers/Geometry.js	2006-12-07 03:47:42 UTC (rev 2020)
@@ -13,14 +13,14 @@
         
     /** @type OpenLayers.Bounds */
     bounds: null,
-	
-	/** 
-	 * Cross reference back to the feature that owns this geometry so
-	 * that that the feature can be identified after the geometry has been
-	 * selected by a mouse click.
-	 * @type OpenLayers.Feature */
-	feature: null,
     
+    /** 
+     * Cross reference back to the feature that owns this geometry so
+     * that that the feature can be identified after the geometry has been
+     * selected by a mouse click.
+     * @type OpenLayers.Feature */
+    feature: null,
+    
     /**
      * @constructor
      *
@@ -29,38 +29,55 @@
     initialize: function() {
         this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+ "_");
     },
-	
-	/**
-	 * Set the bounds for this Geometry.
-	 * @param {OpenLayers.Bounds} bounds
-	 */
-	setBounds: function(bounds){
-		this.bounds=bounds;
-	},
-	
-	/**
-	 * Extend the existing bounds to include the new bounds. If existing
-	 * bounds=null, then set a new Bounds.
-	 * @param {Object} bounds
-	 */
-	extendBounds: function(bounds){
-		if(!this.bounds){
-			this.setBounds(bounds);
-		}else{
-			this.bounds.extendBounds(bounds);
-		}
-	},
-	
-	/**
-	 * Get the bounds for this Geometry. The bounds will be null if not it has
-	 * not been set.
-	 * Once the bounds is set, it is not calculated again, this makes queries
-	 * faster.
-	 * @return {OpenLayers.Bounds}
-	 */
-	getBounds: function(){
-		return this.bounds;
-	},
     
+    /**
+     * Set the bounds for this Geometry.
+     * @param {OpenLayers.Bounds} bounds
+     */
+    setBounds: function(bounds){
+        this.bounds=bounds;
+    },
+    
+    /**
+     * Extend the existing bounds to include the new bounds. If existing
+     * bounds=null, then set a new Bounds.
+     * @param {Object} bounds
+     */
+    extendBounds: function(bounds){
+        if(!this.bounds){
+            this.setBounds(bounds);
+        }else{
+            this.bounds.extendBounds(bounds);
+        }
+    },
+    
+    /**
+     * Get the bounds for this Geometry. The bounds will be null if not it has
+     * not been set.
+     * Once the bounds is set, it is not calculated again, this makes queries
+     * faster.
+     * @return {OpenLayers.Bounds}
+     */
+    getBounds: function(){
+        return this.bounds;
+    },
+    
+    /**
+     * Takes an lonLat point and returns true if the geometry is at this location.
+     * This is only an approximation based on the bounds of the geometry.
+     * @param {OpenLayers.LonLat} lonlat
+     * @return Boolean
+     */
+    atPoint: function(lonlat){
+        var atPoint=false;
+        if(this.bounds){
+            atPoint=(this.bounds.bottom<=lonlat.lat)
+                && (lonlat.lat<=this.bounds.top)
+                && (this.bounds.left<=lonlat.lon)
+                && (lonlat.lon<=this.bounds.right);
+        }
+        return atPoint;
+    },
+
     CLASS_NAME: "OpenLayers.Geometry"
 };
\ No newline at end of file

Modified: sandbox/vector/lib/OpenLayers/Parser/GML.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Parser/GML.js	2006-12-07 01:07:31 UTC (rev 2019)
+++ sandbox/vector/lib/OpenLayers/Parser/GML.js	2006-12-07 03:47:42 UTC (rev 2020)
@@ -94,7 +94,7 @@
             for (var i = 0; i < polygons.length; i++) {
                 polygon = this.parsePolygonNode(polygons[i],geom);
                 geom.addComponents(polygon);
-				geom.extendBounds(polygon.getBounds());
+                geom.extendBounds(polygon.getBounds());
             }
         }
         // match MultiLineString
@@ -183,16 +183,16 @@
         
         var rings = [];
         var p;
-		var polyBounds;
+        var polyBounds;
         for (var i = 0; i < linearRings.length; i++) {
             p = this.parseCoords(linearRings[i]);
-			ring1=new OpenLayers.Geometry.LinearRing(p.points);
-			ring1.extendBounds(p.bounds);
-			if(polyBounds){
-				polyBounds.extend(p.bounds);
-			}else{
-				polyBounds=p.bounds;
-			}
+            ring1=new OpenLayers.Geometry.LinearRing(p.points);
+            ring1.extendBounds(p.bounds);
+            if(polyBounds){
+                polyBounds.extend(p.bounds);
+            }else{
+                polyBounds=p.bounds;
+            }
             rings.push(ring1);
         }
         
@@ -246,12 +246,12 @@
                 x=parseFloat(nums[i]);
                 y=parseFloat(nums[i+1]);
                 p.points.push(new OpenLayers.Geometry.Point(x,y));
-				
-				if(!p.bounds){
-					p.bounds=new OpenLayers.Bounds(x,y,x,y);
-				}else{
-					p.bounds.extendBounds(x,y);
-				}
+                
+                if(!p.bounds){
+                    p.bounds=new OpenLayers.Bounds(x,y,x,y);
+                }else{
+                    p.bounds.extendBounds(x,y);
+                }
             }
         }
         return p;



More information about the Commits mailing list