[OpenLayers-Commits] r2031 - in sandbox/vector/lib/OpenLayers: . Control
commits at openlayers.org
commits at openlayers.org
Sun Dec 10 22:14:07 EST 2006
Author: camerons
Date: 2006-12-10 22:14:07 -0500 (Sun, 10 Dec 2006)
New Revision: 2031
Modified:
sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js
sandbox/vector/lib/OpenLayers/Feature.js
sandbox/vector/lib/OpenLayers/Geometry.js
Log:
Add a tolerance to queries so that Point queries work. (This tolerance should be removed from non-point queries in future).
Modified: sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js 2006-12-11 00:20:26 UTC (rev 2030)
+++ sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js 2006-12-11 03:14:07 UTC (rev 2031)
@@ -162,6 +162,16 @@
var lonlat = this.map.getLonLatFromLayerPx(evt.xy);
evt.point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
+ // Set tolerance for point layers
+ // Currently tolerence is hard coded to +/- 2
+ // TBD, use the radius from Style for tollerance instead
+ var size=this.map.getSize();
+ var extent=this.map.getExtent();
+ var tolerance=2; // +/- 2 pixels
+ var toleranceLon=(extent.right-extent.left)*tolerance/size.w;
+ var toleranceLat=(extent.top-extent.bottom)*tolerance/size.h;
+ var toleranceLon1,toleranceLat1;
+
// For the top layer, query the SVG/VML feature
if(this.map.layers.length>0){
evt.targetGeometry = this.map.layers[this.map.layers.length-1].renderer.getGeometryFromEvent(evt);
@@ -170,8 +180,17 @@
// Exit loop when a feature is found.
for(var i=this.map.layers.length-1;(!evt.targetGeometry&&(i>=0));i--){
if(this.map.layers[i].getVisibility()&&this.map.layers[i].isVector){
+// TBD: CLASS_TYPE is set to "Feature" instead of "Point". This doesn't seem right.
+// if((this.map.layers[i].features.length>0)&&(this.map.layers[i].features[0].CLASS_NAME=="OpenLayers.Geometry.Point")){
+ toleranceLon1=toleranceLon;
+ toleranceLat1=toleranceLat;
+// }
+// else{
+// toleranceLon1=0;
+// toleranceLat1=0;
+// }
for(var f=0;!evt.targetGeometry&&(f<this.map.layers[i].features.length);f++){
- if(this.map.layers[i].features[f].atPoint(lonlat)){
+ if(this.map.layers[i].features[f].atPoint(lonlat,toleranceLon1,toleranceLat1)){
evt.targetGeometry=this.map.layers[i].features[f].geometry;
}
Modified: sandbox/vector/lib/OpenLayers/Feature.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Feature.js 2006-12-11 00:20:26 UTC (rev 2030)
+++ sandbox/vector/lib/OpenLayers/Feature.js 2006-12-11 03:14:07 UTC (rev 2031)
@@ -218,12 +218,14 @@
/**
* Takes an lonLat point and returns true if the feature is at this location.
* @param {OpenLayers.LonLat} lonlat
+ * @param toleranceLon Optional tolerance in Geometric Coords
+ * @param toleranceLat Optional tolerance in Geographic Coords
* @return Boolean
*/
- atPoint: function(lonlat){
+ atPoint: function(lonlat,toleranceLon,toleranceLat){
var atPoint=false;
if(this.geometry){
- atPoint=this.geometry.atPoint(lonlat);
+ atPoint=this.geometry.atPoint(lonlat,toleranceLon,toleranceLat);
}
return atPoint;
},
Modified: sandbox/vector/lib/OpenLayers/Geometry.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Geometry.js 2006-12-11 00:20:26 UTC (rev 2030)
+++ sandbox/vector/lib/OpenLayers/Geometry.js 2006-12-11 03:14:07 UTC (rev 2031)
@@ -66,18 +66,23 @@
* 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
+ * @param toleranceLon Optional tolerance in Geometric Coords
+ * @param toleranceLat Optional tolerance in Geographic Coords
* @return Boolean
*/
- atPoint: function(lonlat){
+ atPoint: function(lonlat,toleranceLon,toleranceLat){
var atPoint=false;
+ toleranceLon=(toleranceLon)?toleranceLon:0;
+ toleranceLat=(toleranceLat)?toleranceLat:0;
if(this.bounds){
- atPoint=(this.bounds.bottom<=lonlat.lat)
- && (lonlat.lat<=this.bounds.top)
- && (this.bounds.left<=lonlat.lon)
- && (lonlat.lon<=this.bounds.right);
+ atPoint=((this.bounds.bottom-toleranceLat)<=lonlat.lat)
+ && (lonlat.lat<=(this.bounds.top+toleranceLat))
+ && ((this.bounds.left-toleranceLon)<=lonlat.lon)
+ && (lonlat.lon<=(this.bounds.right+toleranceLon));
}
return atPoint;
},
+
CLASS_NAME: "OpenLayers.Geometry"
};
\ No newline at end of file
More information about the Commits
mailing list