Control resolution at which snapping is considered with minResolution and maxResolution per target. r=elemoine (closes #3007).

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11016 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2011-01-06 21:41:25 +00:00
parent 8dd58e484a
commit 8c258e9901
2 changed files with 88 additions and 5 deletions

View File

@@ -165,6 +165,14 @@ OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, {
* filter - {OpenLayers.Filter} Optional filter to evaluate to determine if
* feature is eligible for snapping. If filter evaluates to true for a
* target feature a vertex may be snapped to the feature.
* minResolution - {Number} If a minResolution is provided, snapping to this
* target will only be considered if the map resolution is greater than
* or equal to this value (the minResolution is inclusive). Default is
* no minimum resolution limit.
* maxResolution - {Number} If a maxResolution is provided, snapping to this
* target will only be considered if the map resolution is strictly
* less than this value (the maxResolution is exclusive). Default is
* no maximum resolution limit.
*/
initialize: function(options) {
// concatenate events specific to measure with those from the base
@@ -436,10 +444,21 @@ OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, {
* Returns null if candidate is not eligible for snapping.
*/
testTarget: function(target, loc) {
var resolution = this.layer.map.getResolution();
if ("minResolution" in target) {
if (resolution < target.minResolution) {
return null;
}
}
if ("maxResolution" in target) {
if (resolution >= target.maxResolution) {
return null;
}
}
var tolerance = {
node: this.getGeoTolerance(target.nodeTolerance),
vertex: this.getGeoTolerance(target.vertexTolerance),
edge: this.getGeoTolerance(target.edgeTolerance)
node: this.getGeoTolerance(target.nodeTolerance, resolution),
vertex: this.getGeoTolerance(target.vertexTolerance, resolution),
edge: this.getGeoTolerance(target.edgeTolerance, resolution)
};
// this could be cached if we don't support setting tolerance values directly
var maxTolerance = Math.max(
@@ -512,12 +531,12 @@ OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, {
*
* Parameters:
* tolerance - {Number} A tolerance value in pixels.
* resolution - {Number} Map resolution.
*
* Returns:
* {Number} A tolerance value in map units.
*/
getGeoTolerance: function(tolerance) {
var resolution = this.layer.map.getResolution();
getGeoTolerance: function(tolerance, resolution) {
if(resolution !== this.resolution) {
this.resolution = resolution;
this.geoToleranceCache = {};