Changeset 5776


Ignore:
Timestamp:
29/09/09 11:16:40 (10 years ago)
Author:
pnorton
Message:

Created the outline control object.

Changed the event model slightly so that there is just one event manager for all the top level objects.

Made the wcs download code into an object and fixed it.

Location:
cowsclient/trunk/cowsclient
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • cowsclient/trunk/cowsclient/public/js/boundsControl.js

    r5759 r5776  
    1616WMSC.BoundsControl.prototype =  
    1717{ 
    18     EVENT_TYPES: ['changeWMS', 'clearSelection', 'TEXT_SELECTION_CHANGED'], 
     18    EVENT_TYPES: ['clearSelection', 'TEXT_SELECTION_CHANGED'], 
    1919     
    2020    GLOBAL_BOUNDS: new OpenLayers.Bounds(-180.0, -90.0, 180.0, 90.0), 
     
    5151     *    is not set, a default markup is used 
    5252     */ 
    53     initialize: function (domainDivID, initialBounds, controlMarkup)  
     53    initialize: function (domainDivID, initialBounds, eventsManager, controlMarkup )  
    5454    { 
    5555          
     
    6161            this.controlMarkup = controlMarkup; 
    6262        } 
    63         this.events = new OpenLayers.Events(this, this.selectionForm, 
    64                         this.EVENT_TYPES); 
     63        this.eventsManager = eventsManager; 
     64         
    6565        this.wmsParams = {}; 
    6666 
     
    7878            this.setSelection(this.GLOBAL_BOUNDS); 
    7979        } 
     80         
     81        this.eventsManager.register('MAP_SELECTION_CHANGED', this, this._onMapSelectionChanged); 
    8082    }, 
    8183 
     
    8688    destroy: function ()  
    8789    { 
    88         this.events.destroy(); 
    8990    }, 
    9091 
     
    9899         
    99100        if (this._supressTextChangeEvent === false) { 
    100             this.events.triggerEvent('TEXT_SELECTION_CHANGED', {selection: selection}); 
     101            this.eventsManager.triggerEvent('TEXT_SELECTION_CHANGED', {selection: selection}); 
    101102        } 
    102103         
     
    156157    _clearSelection: function ()  
    157158    { 
    158         this.events.triggerEvent('clearSelection'); 
     159        this.eventsManager.triggerEvent('clearSelection'); 
    159160    }, 
    160161     
     
    247248     
    248249    /** 
    249      * Need to listen for dragging of the selection box on the map itself 
    250      */ 
    251     addMapSelectionChanged: function (events) { 
    252         events.register('MAP_SELECTION_CHANGED', this, this._onMapSelectionChanged);         
    253     }, 
    254      
    255     /** 
    256250     * When the selection on the map has changed update the bounds controls. 
    257251     *  
  • cowsclient/trunk/cowsclient/public/js/figureBuilder.js

    r5743 r5776  
    22/*globals WMSC: false, document: false, Utils: false, alert: false*/ 
    33 
    4 var FigureBuilder = function (formId, buttonId, initialBounds) { 
     4var FigureBuilder = function (formId, buttonId, initialBounds, eventsManager) { 
    55        this._form = document.getElementById(formId); 
    66        this._button = document.getElementById(buttonId); 
     
    1313         
    1414        this._currentSelection = initialBounds; 
     15         
     16        this.eventsManager = eventsManager; 
     17        eventsManager.register("LAYER_ORDER_CHANGED", this, this.onLayerOrderChanged); 
     18        eventsManager.register('MAP_SELECTION_CHANGED', this, this.onChangeSelection); 
    1519}; 
    1620 
    1721FigureBuilder.prototype = { 
    18          
    19         /** 
    20          * The figure builder needs to know what the current layers are, this could 
    21          * be done by holding a reference to the LayerList object or listening to the 
    22          * LAYER_ORDER_CHANGED event. 
    23          */ 
    24         addLayerOrderChangedHandlers: function (events) { 
    25         events.register("LAYER_ORDER_CHANGED", this, this.onLayerOrderChanged); 
    26         }, 
    27  
    28         addMapSelectionChangedHandlers: function (events) { 
    29                 events.register('MAP_SELECTION_CHANGED', this, this.onChangeSelection); 
    30         }, 
    31          
     22                 
    3223        /** 
    3324         * When the layer order changes update the current layers 
  • cowsclient/trunk/cowsclient/public/js/layerControl.js

    r5744 r5776  
    1515 
    1616WMSC.VisAppLayers.prototype = { 
    17     EVENT_TYPES: ['changeWMS', 'changeSelection', "NEW_LAYER"], 
     17    EVENT_TYPES: ["NEW_LAYER"], 
    1818 
    1919    // The id of an element in which to render the layer selection tree 
    2020    treeDiv: null, 
     21     
    2122    // The id of an element in which to render the field selection list 
    2223    layerDiv: null, 
     
    3435     *     NB, this control must include a method, updateDomainDiv(OpenLayers.Bounds) 
    3536     */ 
    36     initialize: function (treeDiv, layerDiv, wmcRetriever, newEndpointInputId, addNewEndpointBtnId, defaultOptionsList)  
     37    initialize: function (treeDiv, layerDiv, wmcRetriever, newEndpointInputId, addNewEndpointBtnId, defaultOptionsList, eventsManager)  
    3738    { 
    3839        WMSC.log("Initialising Control"); 
     
    4647        this.addNewEndpointBtn.onclick = this.onNewEndpointClick.bindAsEventListener(this); 
    4748         
    48         this.events = new OpenLayers.Events(this, $(this.treeDiv), 
    49                         this.EVENT_TYPES); 
     49        this.eventsManager = eventsManager; 
    5050 
    5151        this._selectedTreeNode = null; 
     
    5454        this.tree = new YAHOO.widget.TreeView(this.treeDiv); 
    5555         
    56         // the label click event doesn't occurr if the selected node is clicked on 
     56        // the label click event doesn't occur if the selected node is clicked on 
    5757        // because someone might want to add multiple copies of one layer  
    58         // (to compare different dimesnions maybe) using the simple clickEvent which is always called 
     58        // (to compare different dimensions maybe) using the simple clickEvent which is always called 
    5959        //this.tree.subscribe('labelClick', this._selectTreeNode.bindAsEventListener(this)); 
    6060        this.tree.subscribe('clickEvent', this._onTreeClick.bindAsEventListener(this)); 
     
    7979        this.defaultSetter = new LayerDefaultSetter(globalDefaultParams, defaultOptionsList); 
    8080         
    81          
    8281        this.layersToSelect = {}; 
    8382         
     
    9190    destroy: function ()  
    9291    { 
    93         this.events.destroy(); 
    9492        this.tree.unsubscribe(); 
    9593    }, 
     
    402400        var newLayer = this.makeNewLayer(node.data.wmcEndpoint, node.data.layer); 
    403401         
    404         this.events.triggerEvent("NEW_LAYER", {layer: newLayer}); 
     402        this.eventsManager.triggerEvent("NEW_LAYER", {layer: newLayer}); 
    405403         
    406404        return; 
  • cowsclient/trunk/cowsclient/public/js/layerDimensions.js

    r5724 r5776  
    1111 * @constructor 
    1212 */ 
    13 var LayerDimensions = function (layerDimensionsFormId) { 
     13var LayerDimensions = function (layerDimensionsFormId, eventsManager) { 
    1414    this._form = document.getElementById(layerDimensionsFormId); 
    15     this.events = new OpenLayers.Events(this, null, this.EVENTS_RAISED); 
     15    this.eventsManager = eventsManager; 
    1616    this._handlerLookup  = null; 
     17     
     18    this.eventsManager.register('CURRENT_WMCLAYER_CHANGED', this, this._onCurrentLayerChanged); 
     19     
    1720}; 
    1821 
     
    2124    EVENTS_RAISED: ['LAYER_DIMENSION_CHANGED'], 
    2225     
    23     /** 
    24      * Adds the handler for the CURRENT_LAYER_CHANGED event 
    25      */ 
    26     addCurrentWMCLayerChangedHandlers: function (events) { 
    27         events.register('CURRENT_WMCLAYER_CHANGED', this, this._onCurrentLayerChanged); 
    28     }, 
    2926     
    3027    _onCurrentLayerChanged: function (e) { 
     
    9188        var param = target.id.substr(7); 
    9289 
    93         this.events.triggerEvent("LAYER_DIMENSION_CHANGED", {param: param, 
    94                                                             value: target.value}); 
     90        this.eventsManager.triggerEvent("LAYER_DIMENSION_CHANGED",  
     91                {param: param, value: target.value}); 
    9592    }, 
    9693 
  • cowsclient/trunk/cowsclient/public/js/layerDisplayOptions.js

    r5721 r5776  
    2626 * @constructor 
    2727 */ 
    28 var LayerDisplayOpts = function (layerDisplayOptionsFormId, hideDisplayOptions) { 
     28var LayerDisplayOpts = function (layerDisplayOptionsFormId, hideDisplayOptions, eventsManager) { 
    2929     
    3030    this._form = document.getElementById(layerDisplayOptionsFormId); 
    31     this.events = new OpenLayers.Events(this, null, this.EVENTS_RAISED); 
     31    this.eventsManager = eventsManager; 
    3232    this.displayOptsRetriever = new DisplayOptionsRetriever(); 
    3333    this.hideDisplayOptions = hideDisplayOptions; 
     
    3535    this.currentOLLayer = null; 
    3636    this._handlerLookup = null; 
     37     
     38    this.eventsManager.register("LAYER_STYLE_CHANGED", this, this._onLayerStyleChanged); 
     39    this.eventsManager.register('CURRENT_WMCLAYER_CHANGED', this, this._onCurrentLayerChanged); 
    3740}; 
    3841 
    3942LayerDisplayOpts.prototype = { 
    4043    EVENTS_RAISED: ['LAYER_DISPLAY_CHANGED'], 
    41          
    42     /** 
    43      * Adds the handler for the LAYER_STYLE_CHANGED event 
    44      */ 
    45     addStyleChangedEvent: function (events) { 
    46         events.register("LAYER_STYLE_CHANGED", this, this._onLayerStyleChanged); 
    47     }, 
    48  
    49     /** 
    50      * Adds the handler for the CURRENT_LAYER_CHANGED event 
    51      */ 
    52     addCurrentWMCLayerChangedHandlers: function (events) { 
    53         events.register('CURRENT_WMCLAYER_CHANGED', this, this._onCurrentLayerChanged); 
    54     }, 
    5544 
    5645    _onSelectionChange: function (e) { 
     
    6453        } 
    6554         
    66         this.events.triggerEvent('LAYER_DISPLAY_CHANGED',  
     55        this.eventsManager.triggerEvent('LAYER_DISPLAY_CHANGED',  
    6756            { 
    6857                param: param,  
  • cowsclient/trunk/cowsclient/public/js/layerInformation.js

    r5720 r5776  
    2222 * @constructor 
    2323 */ 
    24 var LayerInfo = function (layerInfoFormId) { 
     24var LayerInfo = function (layerInfoFormId, eventsManager) { 
    2525     
    2626    this._form = document.getElementById(layerInfoFormId); 
    27     this.events = new OpenLayers.Events(this, null, this.EVENTS_RAISED); 
     27    this.eventsManager = eventsManager; 
    2828    this.displayOptsRetriever = new DisplayOptionsRetriever(); 
    2929    this.currentWMCLayer = null; 
     
    3737     
    3838    this._currentSelection =  new OpenLayers.Bounds(-180, -90, 180, 90); 
     39     
     40    this.eventsManager.register('CURRENT_WMCLAYER_CHANGED', this, this._onCurrentLayerChanged); 
    3941}; 
    4042 
    4143LayerInfo.prototype = { 
    4244    EVENTS_RAISED: ['LAYER_STYLE_CHANGED'], 
    43      
    44     /** 
    45      * Adds the handler for the CURRENT_LAYER_CHANGED event 
    46      */ 
    47     addCurrentWMCLayerChangedHandlers: function (events) { 
    48         events.register('CURRENT_WMCLAYER_CHANGED', this, this._onCurrentLayerChanged); 
    49     }, 
    50  
    51      
     45         
    5246    _onStyleChange: function (e) { 
    5347        var target = e.target || e.srcElement; 
    5448         
    55         this.events.triggerEvent('LAYER_STYLE_CHANGED',  
     49        this.eventsManager.triggerEvent('LAYER_STYLE_CHANGED',  
    5650            {  
    5751                param: 'styles', 
  • cowsclient/trunk/cowsclient/public/js/layerList.js

    r5743 r5776  
    2626         *    LAYER_ORDER_CHANGED is raised when the order of the layers is changed 
    2727         */ 
    28     EVENTS_RAISED: ['SELECTED_LAYER_CHANGED', 'LAYER_ORDER_CHANGED'], 
     28    EVENTS_RAISED: ['SELECTED_LAYER_CHANGED', 'LAYER_ORDER_CHANGED', 'LAYER_REMOVED'], 
    2929 
    3030    MAX_LAYERS: 10, 
     
    4343     * @param dragListId - ID of the ul that is being used for the drag list 
    4444     */ 
    45     initialize: function (dragListId) { 
     45    initialize: function (dragListId, eventsManager) { 
    4646                this._dragList = document.getElementById(dragListId); 
     47                this.eventsManager = eventsManager; 
    4748                 
    4849                // remove any initial children 
     
    5253                 
    5354            this._layers = []; 
    54             this.events = new OpenLayers.Events(this, this._dragList, this.EVENTS_RAISED); 
    5555             
    5656            this.target = new YAHOO.util.DDTarget(dragListId); 
    5757            this.removeLayerBtn = document.getElementById('btn_remove_selected_layer'); 
    5858            Utils.addHTMLEventListener(this.removeLayerBtn, 'click', this._onRemoveClick, this); 
     59             
     60            this.eventsManager.register("NEW_OUTLINE", this, this.onNewLayer); 
     61            this.eventsManager.register("NEW_LAYER", this, this.onNewLayer); 
    5962        }, 
    6063     
     
    9396         */ 
    9497        _onRemoveClick: function (event, target) { 
    95                 if (this.getSelectedLayer() !== null) { 
     98              
     99            var selectedLayer = this.getSelectedLayer(); 
     100                if (selectedLayer !== null) { 
     101                    var id = selectedLayer.id; 
    96102                        this._removeSelectedItem(); 
    97103                         
     
    101107                        } 
    102108                         
     109                        this._triggerLayerRemoved(id); 
    103110                        this._triggerLayerOrderChange(); 
    104111                        this._triggerSelectedLayerChange();     //selected layer should now be null 
     
    254261                return items; 
    255262        }, 
    256          
    257         /** 
    258          * Adds the onNewLayer handler tot he NEW_LAYER event. 
    259          */ 
    260     addSelectorHandlers: function (events) { 
    261             events.register("NEW_LAYER", this, this.onNewLayer); 
    262     }, 
    263263 
    264264    /** 
     
    271271        } 
    272272        else { 
    273             this._addLayer(e.layer); 
     273            //check if this layer has already been added 
     274            var duplicateId = false; 
     275            for (var i = 0; i < this._layers.length; i++)  { 
     276                if (this._layers[i].id === e.layer.id) { 
     277                    duplicateId = true; 
     278                } 
     279            } 
     280             
     281            if (duplicateId) { 
     282                alert("Layer with id = " + e.layer.id + " already in the list"); 
     283            } 
     284            else { 
     285                this._addLayer(e.layer); 
     286            } 
    274287        } 
    275288         
     
    294307     */ 
    295308    _triggerLayerOrderChange: function () { 
    296         this.events.triggerEvent("LAYER_ORDER_CHANGED", {layers: this._getOrderedLayers()});     
     309        this.eventsManager.triggerEvent("LAYER_ORDER_CHANGED", {layers: this._getOrderedLayers()});      
    297310    }, 
    298311     
     
    302315     */ 
    303316    _triggerSelectedLayerChange: function () { 
    304         this.events.triggerEvent("SELECTED_LAYER_CHANGED", {layer: this.getSelectedLayer()}); 
     317        this.eventsManager.triggerEvent("SELECTED_LAYER_CHANGED", {layer: this.getSelectedLayer()}); 
     318    }, 
     319     
     320    _triggerLayerRemoved: function (id) { 
     321        this.eventsManager.triggerEvent("LAYER_REMOVED", {layer_id: id}); 
    305322    }, 
    306323 
     
    355372 
    356373        destroy: function () { 
    357         this.events.destroy(); 
    358374        this.target.unreg(); 
    359375        this._removeAllItems(); 
  • cowsclient/trunk/cowsclient/public/js/layerParameters.js

    r5754 r5776  
    1717 * @constructor 
    1818 */ 
    19 var LayerParameters = function (propertiesDivId, selectionFormId, wmcRetriever, hideDisplayOptions) { 
     19var LayerParameters = function (propertiesDivId, selectionFormId, wmcRetriever,  
     20                                hideDisplayOptions, eventsManager) { 
    2021     
    21      
    22     this.layerDisplay = new LayerDisplayOpts(selectionFormId, hideDisplayOptions); 
    23     this.layerInfo = new LayerInfo('layer_info_form'); 
    24     this.layerDims = new LayerDimensions('WMSC_dimForm'); 
     22    this.globalEventsManager = eventsManager; 
    2523     
    2624    this.propertiesDiv = document.getElementById(propertiesDivId); 
     
    2927    this.currentWMCLayer = null; 
    3028    this.wmcRetriever = wmcRetriever; 
    31          
    32     this.events = new OpenLayers.Events(this, null, this.EVENTS_RAISED); 
    3329     
    34     this.layerDisplay.addCurrentWMCLayerChangedHandlers(this.events); 
    35     this.layerInfo.addCurrentWMCLayerChangedHandlers(this.events); 
    36     this.layerDims.addCurrentWMCLayerChangedHandlers(this.events); 
     30    // trying to keep the contained controls isolated from the global events 
     31    this.internalEvents = new OpenLayers.Events(this, null, this.INTERNAL_EVENTS_RAISED); 
     32 
     33    this.layerInfo = new LayerInfo('layer_info_form', this.internalEvents); 
     34    this.layerDims = new LayerDimensions('WMSC_dimForm', this.internalEvents); 
    3735     
    3836    // monitor all the parameter changes 
    39     this.layerDisplay.events.register('LAYER_DISPLAY_CHANGED', this, this.onParamChange); 
    40     this.layerInfo.events.register('LAYER_STYLE_CHANGED', this, this.onParamChange); 
    41     this.layerDims.events.register('LAYER_DIMENSION_CHANGED', this, this.onParamChange); 
     37    this.internalEvents.register('LAYER_DISPLAY_CHANGED', this, this.onParamChange); 
     38    this.internalEvents.register('LAYER_STYLE_CHANGED', this, this.onParamChange); 
     39    this.internalEvents.register('LAYER_DIMENSION_CHANGED', this, this.onParamChange); 
    4240     
    43     // also need to let the display options know if the style has changed. 
    44     this.layerDisplay.addStyleChangedEvent(this.layerInfo.events); 
     41    this.layerDisplay = new LayerDisplayOpts(selectionFormId, hideDisplayOptions, this.internalEvents); 
     42        
     43    this.globalEventsManager.register("SELECTED_LAYER_CHANGED", this, this.onSelectedLayerChanged); 
     44     
    4545    WMSC.log("layer parameters created"); 
    4646}; 
    4747 
    4848LayerParameters.prototype = { 
     49         
     50    EVENTS_RAISED: ['LAYER_PROPERTY_CHANGED', 'CURRENT_WMCLAYER_CHANGED'], 
    4951     
    50     EVENTS_RAISED: ['LAYER_PROPERTY_CHANGED', 'CURRENT_WMCLAYER_CHANGED'], 
     52    INTERNAL_EVENTS_RAISED: ['LAYER_PROPERTY_CHANGED', 'CURRENT_WMCLAYER_CHANGED', 
     53                             'LAYER_DISPLAY_CHANGED','LAYER_STYLE_CHANGED','LAYER_DIMENSION_CHANGED'], 
    5154     
    5255    onParamChange: function (e) { 
     
    5760        } 
    5861 
    59         this.events.triggerEvent("LAYER_PROPERTY_CHANGED", {layer: this.currentOLLayer, 
    60                                                          wmcLayer: this.currentWMCLayer}); 
     62        this.globalEventsManager.triggerEvent("LAYER_PROPERTY_CHANGED",  
     63                {layer: this.currentOLLayer, wmcLayer: this.currentWMCLayer});         
     64         
     65        this.internalEvents.triggerEvent("LAYER_PROPERTY_CHANGED",  
     66                {layer: this.currentOLLayer, wmcLayer: this.currentWMCLayer}); 
    6167         
    6268    },     
    6369     
    64     /** 
    65      * registers the @see #onSelectedLayerChanged method to the SELECTED_LAYER_CHANGED 
    66      * event. 
    67      */ 
    68     addLayerListHandlers: function (events) { 
    69         events.register("SELECTED_LAYER_CHANGED", this, this.onSelectedLayerChanged); 
    70     }, 
    71  
    7270    /** 
    7371     * Handles the SELECTED_LAYER_CHANGED event, when the layer is changed the current 
     
    8280         
    8381        if (e.layer === null) { 
    84             this.events.triggerEvent('CURRENT_WMCLAYER_CHANGED', {wmc: null, 
    85                                                                   olLayer: null, 
    86                                                                   wmcLayer: null}); 
     82            var eventArgs = {wmc: null, olLayer: null, wmcLayer: null}; 
     83            this.globalEventsManager.triggerEvent('CURRENT_WMCLAYER_CHANGED', eventArgs); 
     84            this.internalEvents.triggerEvent('CURRENT_WMCLAYER_CHANGED', eventArgs);             
     85             
    8786        } else { 
    8887            this.updateControls(); 
     
    124123         
    125124        this.currentWMCLayer = wmcLayer; 
    126         this.events.triggerEvent('CURRENT_WMCLAYER_CHANGED', {wmc: wmc, 
    127                                                               olLayer: this.currentOLLayer, 
    128                                                               wmcLayer: this.currentWMCLayer}); 
     125         
     126        var eventArgs = { 
     127            wmc: wmc, 
     128            olLayer: this.currentOLLayer, 
     129            wmcLayer: this.currentWMCLayer 
     130        } 
     131         
     132        this.globalEventsManager.triggerEvent('CURRENT_WMCLAYER_CHANGED', eventArgs); 
     133        this.internalEvents.triggerEvent('CURRENT_WMCLAYER_CHANGED', eventArgs); 
     134               
    129135    }, 
    130136     
     
    160166         
    161167        return wmcLayer; 
     168    }, 
     169     
     170 
     171    destroy: function () { 
     172        this.internalEvents.destroy(); 
     173        this._removeAllItems(); 
    162174    } 
    163175}; 
  • cowsclient/trunk/cowsclient/public/js/legendContainer.js

    r5719 r5776  
    66LegendContainer.prototype = { 
    77                 
    8         initialize: function (legendDivId) { 
     8        initialize: function (legendDivId, eventsManager) { 
    99                this.legendDiv = document.getElementById(legendDivId); 
    1010                this._retriever = new AjaxRetriever(); 
     11                this.eventsManager = eventsManager; 
     12                 
     13                this.eventsManager.register("LAYER_PROPERTY_CHANGED", this, this.onLayerPropertyChanged); 
     14                this.eventsManager.register("CURRENT_WMCLAYER_CHANGED", this, this.onLayerChanged);              
    1115        }, 
    12  
    13         /** 
    14          * add the handler for the layerParemeters events, LAYER_PROPERTY_CHANGED and CURRENT_WMCLAYER_CHANGED 
    15          */ 
    16     addLayerParametersHandlers: function (events) { 
    17         events.register("LAYER_PROPERTY_CHANGED", this, this.onLayerPropertyChanged); 
    18         events.register("CURRENT_WMCLAYER_CHANGED", this, this.onLayerChanged); 
    19          
    20     }, 
    2116 
    2217    /** 
  • cowsclient/trunk/cowsclient/public/js/mapControl.js

    r5772 r5776  
    2929     */ 
    3030    initialize: function (div, numZoomLevels, mapWidth, showCoast,  
    31                          baseLayerURL, baseLayerParams, initialBounds)  
     31                         baseLayerURL, baseLayerParams, initialBounds, 
     32                         eventsManager)  
    3233    { 
    3334        this.figureCounter = 1; 
    3435        this.showCoast = showCoast; 
    3536 
    36         this.events = new OpenLayers.Events(this, div, this.EVENT_TYPES);         
     37        this.eventsManager = eventsManager;         
    3738         
    3839        // NB, can't override both numZoomLevels and minResolution with 
     
    121122        this._divId = div; 
    122123         
     124        this.eventsManager.register('TEXT_SELECTION_CHANGED', this, this.updateSelectionBox); 
     125        this.eventsManager.register('clearSelection', this, this.resetMapCoords); 
     126        this.eventsManager.register("LAYER_ORDER_CHANGED", this, this.onLayerOrderChanged); 
     127        this.map.events.register('moveend', this, this.updateBoundsControl); 
     128        this.map.events.register('zoomend', this, this.updateBoundsBoundsControl);         
    123129    }, 
    124130     
     
    128134    }, 
    129135     
    130      
    131       /** 
    132       * Specify a dimension control to use with the map 
    133       * @param dimControl - a suitable dimension control 
    134       * - this must include an attribute, wmsParams and a method 
    135       * getSelection retuning an OpenLayers.Bounds object 
    136       */ 
    137     addBoundsControl: function (control) 
    138     { 
    139         this.boundsControl = control; 
    140         this.boundsControl.events.register('TEXT_SELECTION_CHANGED', this, this.updateSelectionBox); 
    141         this.boundsControl.events.register('changeWMS', this, this.updateVisLayer); 
    142         this.boundsControl.events.register('clearSelection', this, this.resetMapCoords); 
    143       
    144         this.map.events.register('moveend', this, this.updateBoundsControl); 
    145         this.map.events.register('zoomend', this, this.updateBoundsBoundsControl); 
    146     },     
    147      
    148136    updateBoundsBoundsControl: function (events) { 
    149137        WMSC.log("map zoomed -- this.map resolution = " + this.map.resolution + " zoom=" + this.map.zoom + " maxExtent: b=" + this.map.maxExtent.bottom + " l=" + this.map.maxExtent.left + " t=" + this.map.maxExtent.top + " r=" + this.map.maxExtent.right); 
    150     }, 
    151  
    152     addLayersHandlers: function (events) { 
    153         events.register("LAYER_ORDER_CHANGED", this, this.onLayerOrderChanged); 
    154138    }, 
    155139 
     
    372356    updateBoundsControl: function ()  
    373357    { 
    374 //        alert("UpdateBoundsControl"); 
    375358        var b = this.subselControl.getActiveBounds(); 
    376359 
    377360        WMSC.log("triggering MAP_SELECTION_CHANGED, selection = " + b); 
    378         this.events.triggerEvent('MAP_SELECTION_CHANGED', {selection: b}); 
    379          
    380 //        // Switch to higerres coasts if needed 
    381 //        var coastLayer = 'coastline_01'; 
    382 //        if (this.map.getZoom() > 5) 
    383 //            coastLayer = 'coastline_02'; 
    384 //     
    385 //        if (this.showCoast && this.coastLayer.params.LAYERS != coastLayer)  
    386 //        { 
    387 //            this._initCoast(coastLayer); 
    388 //        } 
     361        this.eventsManager.triggerEvent('MAP_SELECTION_CHANGED', {selection: b}); 
    389362    }, 
    390363 
  • cowsclient/trunk/cowsclient/public/js/wcs.js

    r5626 r5776  
    1 //Create a WCS download button 
    2 function createDownloadButton(div) { 
    3     var button=document.createElement('input'); 
    4     button.type='submit'; 
    5     button.id='wcsdownload'; 
    6     button.value='Download Data'; 
    7     button.onclick= function() { 
    8         setupWCSrequest(); 
     1 
     2WCSDownloadControl = function (downloadDivId, initailBounds, eventsManager) { 
     3     
     4    this.eventsManager = eventsManager; 
     5    this.downloadDiv = document.getElementById(downloadDivId); 
     6    this.currentBounds = initailBounds; 
     7    this.currentLayer = null; 
     8     
     9    this.downloadButton = this.createDownloadButton() 
     10     
     11    Utils.addHTMLEventListener(this.downloadButton, 'click', this.setupWCSrequest, this); 
     12     
     13    this.downloadDiv.appendChild(this.downloadButton);     
     14     
     15    this.eventsManager.register('MAP_SELECTION_CHANGED', this, this._onMapSelectionChanged); 
     16    this.eventsManager.register('SELECTED_LAYER_CHANGED', this, this._onSelectedLayerChanged); 
     17}; 
     18 
     19WCSDownloadControl.prototype = { 
     20         
     21    //Create a WCS download button 
     22    createDownloadButton: function () { 
     23        var button=document.createElement('input'); 
     24        button.type='submit'; 
     25        button.id='wcsdownload'; 
     26        button.value='Download Data'; 
     27        return button 
     28    }, 
     29     
     30    _onMapSelectionChanged: function (e) { 
     31        this.currentBounds = e.selection;   
     32    }, 
     33     
     34    _onSelectedLayerChanged: function (e) { 
     35        this.currentLayer = e.layer; 
     36    }, 
     37     
     38    // call WCS with current map parameters (bbox, layer, crs, dimensions etc) 
     39    setupWCSrequest: function () { 
     40         
     41        if (this.currentLayer === null) { 
     42            alert("No layer currently selected."); 
     43            return 
     44        } 
     45         
     46        //gets the information from the gui needed to make a WCS request. e.g. selected bounding box and other dimensions 
     47        //this implemenation assumes wcs endpoint mirrors wcs endpoint - could get this from webmapcontext dataurl instead?? 
     48        //note, in future this could be expanded to use OWSLib and provide a WCS client interface        
     49        // get the topmost layer 
     50        // NB, there are initially three layers - for the subselection box, coastline and base map 
     51         
     52        var wmsurl = this.currentLayer.getFullRequestString(); 
     53        var urlparts = wmsurl.split('?'); 
     54        var wcsEndpoint=urlparts[0].replace('wms', 'wcs') +'?'; 
     55        var coords=document.getElementById('coordsForm'); 
     56            
     57        var bboxStr = this.currentBounds.left + ',' + this.currentBounds.bottom + ',' + this.currentBounds.right + ',' + this.currentBounds.top; 
     58         
     59        var dims = layerParameters.layerDims.getSelectedDimensions(); 
     60        this.makeWCSrequest(wcsEndpoint, this.currentLayer.params.LAYERS, bboxStr, dims); 
     61    }, 
     62     
     63     
     64    makeWCSrequest: function (wcsEndpoint, coverageid, bbox, dims) { 
     65        // makes the request to the WCS server 
     66         
     67        var params={'request':'GetCoverage', 'service':'WCS', 'version':'1.0.0','crs':'EPSG:4326','format':'cf-netcdf'}  //to store the wcs parameters 
     68         
     69        //add coverage, bbox and dimension parameters 
     70        params['coverage']=coverageid 
     71        params['bbox']=bbox 
     72        for (var dim_id in dims) { 
     73            params[dim_id]=dims[dim_id]; 
     74        }        
     75         
     76        //build url string 
     77        var wcsurl=wcsEndpoint; 
     78        for (param in params) { 
     79            wcsurl = wcsurl + param + '=' + params[param] + '&'; 
     80        } 
     81        WMSC.log('Making wcs request to ' + wcsurl) 
     82        window.open(wcsurl, 'download');  
     83        return false; 
    984    } 
    10     div.appendChild(button); 
    11 } 
     85     
     86}; 
    1287 
    1388 
    14 // call WCS with current map parameters (bbox, layer, crs, dimensions etc) 
    15 function setupWCSrequest() { 
    16         //gets the information from the gui needed to make a WCS request. e.g. selected bounding box and other dimensions 
    17         //this implemenation assumes wcs endpoint mirrors wcs endpoint - could get this from webmapcontext dataurl instead?? 
    18         //note, in future this could be expanded to use OWSLib and provide a WCS client interface        
    19         // get the topmost layer 
    20         // NB, there are initially three layers - for the subselection box, coastline and base map 
    21          
    22         //var layerNo = app.map.layers.length; 
    23         //var topLayer = app.map.layers[layerNo - 3]; 
    24         var topLayer = layerList.getSelectedLayer(); 
    25          
    26         var wmsurl = topLayer.getFullRequestString(); 
    27         var urlparts = wmsurl.split('?'); 
    28         var wcsEndpoint=urlparts[0].replace('wms', 'wcs') +'?'; 
    29         var coords=document.getElementById('coordsForm'); 
    30         var bbox =coords['bboxW'].value + ',' + coords['bboxS'].value + ',' + coords['bboxE'].value + ',' + coords['bboxN'].value; 
    31          
    32         var dims = layerParameters.layerDims.getSelectedDimensions(); 
    33         makeWCSrequest(wcsEndpoint, topLayer.params.LAYERS, bbox, dims); 
    34 } 
    3589 
    3690 
    37 function makeWCSrequest(wcsEndpoint, coverageid, bbox, dims) { 
    38         // makes the request to the WCS server 
    39          
    40         var params={'request':'GetCoverage', 'service':'WCS', 'version':'1.0.0','crs':'EPSG:4326','format':'cf-netcdf'}  //to store the wcs parameters 
    4191 
    42         //add coverage, bbox and dimension parameters 
    43         params['coverage']=coverageid 
    44         params['bbox']=bbox 
    45         for (var dim_id in dims) { 
    46                 params[dim_id]=dims[dim_id]; 
    47         }        
    48                  
    49         //build url string 
    50         var wcsurl=wcsEndpoint; 
    51         for (param in params) { 
    52                 wcsurl = wcsurl + param + '=' + params[param] + '&'; 
    53         } 
    54         WMSC.log('Making wcs request to ' + wcsurl) 
    55         window.open(wcsurl, 'download');  
    56         return false; 
    57 } 
    58  
  • cowsclient/trunk/cowsclient/public/layout/control.css

    r5772 r5776  
    44 
    55#datasets_column { 
    6     width:35%; 
     6    width:40%; 
    77} 
    88 
     
    1212 
    1313#properties_column { 
    14     width:45%; 
     14    width:40%; 
    1515} 
    1616 
  • cowsclient/trunk/cowsclient/templates/wmsviz.html

    r5772 r5776  
    2828 
    2929<!-- BEGIN: Yahoo Interface Library --> 
    30 <link type="text/css" rel="stylesheet" 
    31     href="$g.server/js/yui_2.7.0b/treeview/assets/skins/sam/treeview.css"/>  
    3230      
    3331<!-- Dependency source files -->   
    3432<script type="text/javascript" src ="$g.server/js/yui_2.7.0b/yahoo/yahoo.js" ></script>  
    3533<script type="text/javascript" src="$g.server/js/yui_2.7.0b/event/event.js"></script> 
     34<script type="text/javascript" src="$g.server/js/yui_2.7.0b/dom/dom.js" ></script> 
    3635   
    37 <!-- TreeView source file -->   
    38 <script type="text/javascript" src="$g.server/js/yui_2.7.0b/dom/dom.js" ></script> 
    39  
    40 <!-- TreeView Menu Style --> 
    41   
     36<link rel="stylesheet" type="text/css" href="$g.server/js/yui_2.7.0b/fonts/fonts.css" /> 
     37 
     38<!-- TreeView imports -->   
     39<link type="text/css" rel="stylesheet" href="$g.server/js/yui_2.7.0b/treeview/assets/skins/sam/treeview.css"/>  
    4240<link rel="stylesheet" type="text/css" href="$g.server/js/yui_old_treeview_style/treeview-menu.css"/>  
    43  
    44  
    45 <link rel="stylesheet" type="text/css" href="$g.server/js/yui_2.7.0b/fonts/fonts.css" /> 
     41<script type="text/javascript" src="$g.server/js/yui_2.7.0b/treeview/treeview.js" ></script>  
    4642 
    4743<!-- needed for the drag and drop list --> 
     
    4945<script type="text/javascript" src="$g.server/js/yui_2.7.0b/dragdrop/dragdrop.js" ></script> 
    5046 
    51  
    5247<link type="text/css" rel="stylesheet" href="$g.server/layout/drag_drop_style.css"/> 
    5348<script type="text/javascript" src = "$g.server/js/dragAndDrop.js" ></script>  
    5449 
    55  
    5650<!-- YUI imports for autocomplete --> 
    57  
    5851<link rel="stylesheet" type="text/css" href="$g.server/js/yui_2.7.0b/button/assets/skins/sam/button.css" /> 
    59  
    6052<link rel="stylesheet" type="text/css" href="$g.server/js/yui_2.7.0b/autocomplete/assets/skins/sam/autocomplete.css" /> 
    61  
    6253<script type="text/javascript" src="$g.server/js/yui_2.7.0b/animation/animation.js"></script> 
    6354<script type="text/javascript" src="$g.server/js/yui_2.7.0b/element/element.js"></script> 
     
    6556<script type="text/javascript" src="$g.server/js/yui_2.7.0b/datasource/datasource.js"></script> 
    6657<script type="text/javascript" src="$g.server/js/yui_2.7.0b/autocomplete/autocomplete.js"></script> 
    67      
    6858<!-- End of autocomplete imports --> 
    69  
    70 <script type="text/javascript" src="$g.server/js/yui_2.7.0b/treeview/treeview.js" ></script>  
     59     
    7160 
    7261<!-- END: Yahoo Interface Library --> 
     
    7968<script type="text/javascript" src="$g.server/js/wmsc.js"></script> 
    8069<script type="text/javascript" src="$g.server/js/prototype.js"></script> 
    81 <script type="text/javascript" src="$g.server/js/OpenLayers.js" /> 
     70<script type="text/javascript" src="$g.server/js/openlayers/lib/OpenLayers.js" /> 
    8271<script type="text/javascript" src="$g.server/js/LoadingPanel.js"></script> 
    8372 
     
    116105 
    117106<script type="text/javascript" src="$g.server/js/layerDefaultSetter.js"></script> 
     107<script type="text/javascript" src="$g.server/js/outlineControl.js"></script> 
    118108 
    119109<!-- END: WMSC library --> 
     
    132122var defaultOptions = ${jsonParseIfNotEmpty(c.defaultOptions)}; 
    133123 
     124var eventsManager = null; 
     125 
    134126<?python 
    135127from pylons import session  
     
    149141 
    150142        var initialBounds = new OpenLayers.Bounds(-180,-90,180,90); 
    151          
    152         layerList = new LayerList('layer_list');         
    153     layerParameters = new LayerParameters('layer_properties', 'selection_form', wmcRetriever, hideDisplayOptions); 
    154      
    155     var legendContainer = new LegendContainer('legend'); 
    156  
    157     var figBuilder = new FigureBuilder('figureForm','make_figure_btn', initialBounds); 
    158  
    159     var boundsControl = new WMSC.BoundsControl('dims', initialBounds); 
    160      
    161     var coordControl = null; 
    162     var layerControl = new WMSC.VisAppLayers('layerTree', 'layerLeaves',wmcRetriever, 'new_endpoint', 'add_new_endpoint', defaultOptions);   
    163  
    164     figBuilder.addLayerOrderChangedHandlers(layerList.events);     
    165      
    166     layerList.addSelectorHandlers(layerControl.events); 
    167     layerParameters.addLayerListHandlers(layerList.events); 
    168     legendContainer.addLayerParametersHandlers(layerParameters.events); 
    169      
    170     app = new WMSC.VisApp('map', 10, 640, true, baseLayerData.url, baseLayerData.params, initialBounds); 
    171  
    172     boundsControl.addMapSelectionChanged(app.events) 
    173     figBuilder.addMapSelectionChangedHandlers(app.events); 
    174     layerParameters.layerInfo.addMapSelectionChangedHandlers(app.events); 
    175      
    176     app.addLayersHandlers(layerList.events); 
    177  
    178     app.addBoundsControl(boundsControl); 
    179  
    180     if (document.getElementById('wcsdownload') == null) { 
    181         createDownloadButton(document.getElementById('wcsdownloadDiv'));     
    182     } 
    183      
     143 
     144    var allEvents = []; 
     145 
     146    allEvents = allEvents.concat(LayerList.prototype.EVENTS_RAISED, 
     147                                 LayerParameters.prototype.EVENTS_RAISED, 
     148                                 WMSC.VisAppLayers.prototype.EVENT_TYPES, 
     149                                 WMSC.VisApp.prototype.EVENT_TYPES, 
     150                                 WMSC.BoundsControl.prototype.EVENT_TYPES, 
     151                                 OutlineControl.prototype.EVENT_TYPES); 
     152 
     153    eventsManager =  new OpenLayers.Events(null, null,  allEvents); 
     154 
     155    WMSC.log(allEvents); 
     156              
     157        layerList = new LayerList('layer_list', eventsManager);  
     158    layerParameters = new LayerParameters('layer_properties', 'selection_form', wmcRetriever, hideDisplayOptions, eventsManager); 
     159     
     160    var legendContainer = new LegendContainer('legend', eventsManager); 
     161    var downloadControl = new WCSDownloadControl('wcsdownloadDiv', initialBounds, eventsManager); 
     162    var figBuilder = new FigureBuilder('figureForm','make_figure_btn', initialBounds, eventsManager); 
     163    var outlineControl = new OutlineControl('add_outline', baseLayerData.url, baseLayerData.params, eventsManager); 
     164    var boundsControl = new WMSC.BoundsControl('dims', initialBounds, eventsManager); 
     165    var layerControl = new WMSC.VisAppLayers('layerTree', 'layerLeaves',wmcRetriever, 'new_endpoint', 'add_new_endpoint', defaultOptions, eventsManager);   
     166    app = new WMSC.VisApp('map', 10, 640, true, baseLayerData.url, baseLayerData.params, initialBounds, eventsManager); 
     167 
    184168    var initialEndpoints = JSON.parse(initialSetupJSON); 
    185169 
    186     var baseLayer = new OpenLayers.Layer.WMS( 
    187           'Outline', 
    188           baseLayerData.url,  
    189           baseLayerData.params, 
    190           {isBaseLayer:false, buffer:3}); 
    191  
    192     // must set these parameters or the map wil not draw 
    193     baseLayer.params.CRS = 'CRS:84'; 
    194     baseLayer.params.FORMAT = 'image/png'; 
    195     baseLayer.params.VERSION = '1.3.0'; 
    196     baseLayer.params.TRANSPARENT = 'true'; 
    197     // can't use the default id as there is already an element with that 
    198     // id on the page. 
    199     baseLayer.id = "outline_0";  
    200              
    201      
    202     layerList._addLayer(baseLayer); 
    203  
    204      
     170 
     171    outlineControl.addNewOutline(); 
     172         
    205173    for (var i=0;i&lt;initialEndpoints.length;i++) { 
    206174        var endpoint = initialEndpoints[i]; 
     
    227195    if (layerList !== null) { 
    228196        layerList.destroy(); 
     197    } 
     198 
     199    if (eventsManager !== null) { 
     200        eventsManager.destroy(); 
    229201    } 
    230202} 
     
    366338                                 No datasets loaded. 
    367339                        </div> 
     340                <input type="button" id="add_outline" value="Add Outline Layer"/> 
    368341                        </td> 
    369342                        <td class="controlPanel"> 
Note: See TracChangeset for help on using the changeset viewer.