All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.geojsf.WMS.js Maven / Gradle / Ivy

/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */


/**
 * @requires OpenLayers/BaseTypes.js
 * @requires OpenLayers/BaseTypes/Class.js
 * @requires OpenLayers/BaseTypes/Date.js
 * @requires OpenLayers/TimeAgent.js
 */

/**
 * Class: OpenLayers.TimeAgent.WMS
 * Class to display and animate WMS layers across time.
 * This class is created by {OpenLayers.Control.TimeManager} instances
 *
 * Inherits From:
 *  - 
 */
OpenLayers.TimeAgent.WMS = OpenLayers.Class(OpenLayers.TimeAgent, {
    /**
     * APIProperty: intervalMode
     * {String} If a wms layer has distinct valid time intervals,
     *     then this property will control if and how the animation time is
     *     translated into a valid time instance for the layer
     *     Must be one of:
     *     "lastValid" - continue to display it using the last valid time within
     *         the overall control time range
     *     "nearest" - (Default) use the nearest valid time within the overall
     *         control time range.
     *     "exact" - only display the layer when there's an exact match (to the
     *         grainularity of the step unit) in the control time and an interval
     */
    intervalMode : 'nearest',

    /**
     * Constructor: OpenLayers.Control.TimeManager.WMS
     * Create a new time manager control for temporal WMS layers.
     *
     * Parameters:
     * options - {Object} Optional object whose properties will be set on the
     *     control.
     */
    initialize : function(options) {
        OpenLayers.TimeAgent.prototype.initialize.call(this, options);
        //add layer loadend listeners
        if(this.layers) {
            for(var i = 0, len = this.layers.length; i < len; i++) {
                this.layers[i].events.on({
                    'loadend' : this.onLayerLoadEnd,
                    'loadstart' : this.onLayerLoadStart,
                    scope : this
                });
            }
        }
    },

    addLayer : function(layer) {
        layer.events.on({
            'loadend' : this.onLayerLoadEnd,
            'loadstart' : this.onLayerLoadStart,
            scope : this
        });
        OpenLayers.TimeAgent.prototype.addLayer.call(this, layer);
    },

    removeLayer : function(layer) {
        layer.events.un({
            'loadend' : this.onLayerLoadEnd,
            'loadstart' : this.onLayerLoadStart,
            scope : this
        });
        OpenLayers.TimeAgent.prototype.removeLayer.call(this, layer);
    },

    destroy : function() {
        for(var i = this.layers.length - 1; i > -1; i--) {
            this.removeLayer(this.layers[i]);
        }
        OpenLayers.TimeAgent.prototype.destroy.call(this);
    },

    onTick : function(evt) {
        this.currentTime = evt.currentTime || this.timeManager.currentTime;
        OpenLayers.TimeAgent.prototype.onTick.call(this);
        //console.debug('CurrentTime:' + this.currentTime.toString());
        var inrange = this.currentTime <= this.range[1] && this.currentTime >= this.range[0];
        //this is an inrange flag for all the entire value range of layers managed by
        //this dimension agent and not a specific layer
        if(inrange) {
            var validLayers = OpenLayers.Array.filter(this.layers, function(lyr) {
                return lyr.visibility && lyr.inTemporalRange;
            });
            this.loadQueue = validLayers.length;
            
            this.canTick = !this.loadQueue;
            //console.debug('WMS Agent QueueCount:' + this.loadQueue);
            
            for(var i=0;i time - intervals[testResults.after]) {
                wmstime = intervals[testResults.after];
            }
            else {
                wmstime = intervals[testResults.before];
            }
            isotime = OpenLayers.Date.toISOString(wmstime);
        }
        else {
            //format time in ISO:8601 format
            isotime = OpenLayers.Date.toISOString(time);
        }
        layer.mergeNewParams({
            time : isotime
        });
    },

    /**
     *
     * @param {Object} testDate
     * @param {Array[{Date}]} dates - MUST be a sorted date array
     */
    findNearestTimes : function(testDate, dates) {
        var retObj = {
            exact : -1,
            before : -1,
            after : -1
        };
        //first check that this time is in the array
        for(var i = 0, len = dates.length; i < len; i++) {
            if(testDate.getTime() == dates[i].getTime()) {
                retObj.exact = i;
                break;
            }
            else {
                var diff = testDate - dates[i];
                if(diff < 0) {
                    retObj.after = i;
                    if(retObj.before == -1) {
                        retObj.before = 0;
                    }
                    break;
                }
                else {
                    retObj.before = i;
                }
            }
        }
        return retObj;
    },

    onLayerLoadEnd : function() {
        this.loadQueue--;
        //console.debug('QueueCount:' + this.loadQueue);
        if(this.loadQueue <= 0) {
            this.canTick = true;
            //console.debug('canTick:TRUE');
        }
    },

    CLASS_NAME : 'OpenLayers.TimeAgent.WMS'
});




© 2015 - 2025 Weber Informatics LLC | Privacy Policy