From acb003453f2644b8e8bd2263791f80e397de25b4 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 26 Aug 2008 14:27:36 +0000 Subject: [PATCH] Update calculateInRange: Only turn layers off if they have some scale-related properties set directly in their creation options. By default, layers will be "always on", with an overridable "alwaysInRange" parameter. To maintain the old behavior, set: OpenLayers.Layer.prototype.alwaysInRange = false; r=euzuro (Closes #987) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7863 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer.js | 61 +++++++++++++++++++++++++++++++++++++---- tests/Layer.html | 17 ++++++++++-- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index fb2b4e130a..e1a9049076 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -37,6 +37,23 @@ OpenLayers.Layer = OpenLayers.Class({ */ opacity: null, + /** + * APIProperty: alwaysInRange + * {Boolean} If a layer's display should not be scale-based, this should + * be set to true. This will cause the layer, as an overlay, to always + * be 'active', by always returning true from the calculateInRange() + * function. + * + * If not explicitly specified for a layer, its value will be + * determined on startup in initResolutions() based on whether or not + * any scale-specific properties have been set as options on the + * layer. If no scale-specific options have been set on the layer, we + * assume that it should always be in range. + * + * See #987 for more info. + */ + alwaysInRange: null, + /** * Constant: EVENT_TYPES * {Array(String)} Supported application event types. Register a listener @@ -615,14 +632,20 @@ OpenLayers.Layer = OpenLayers.Class({ * * Returns: * {Boolean} The layer is displayable at the current map's current - * resolution. + * resolution. Note that if 'alwaysInRange' is true for the layer, + * this function will always return true. */ calculateInRange: function() { var inRange = false; - if (this.map) { - var resolution = this.map.getResolution(); - inRange = ( (resolution >= this.minResolution) && - (resolution <= this.maxResolution) ); + + if (this.alwaysInRange) { + inRange = true; + } else { + if (this.map) { + var resolution = this.map.getResolution(); + inRange = ( (resolution >= this.minResolution) && + (resolution <= this.maxResolution) ); + } } return inRange; }, @@ -677,6 +700,15 @@ OpenLayers.Layer = OpenLayers.Class({ 'numZoomLevels', 'maxZoomLevel' ); + //these are the properties which do *not* imply that user wishes + // this layer to be scale-dependant + var notScaleProps = ['projection', 'units']; + + //should the layer be scale-dependant? default is false -- this will + // only be set true if we find that the user has specified a property + // from the 'props' array that is not in 'notScaleProps' + var useInRange = false; + // First we create a new object where we will store all of the // resolution-related properties that we find in either the layer's // 'options' array or from the map. @@ -684,9 +716,28 @@ OpenLayers.Layer = OpenLayers.Class({ var confProps = {}; for(var i=0, len=props.length; i