~dongpo-deng/sahana-eden/test

« back to all changes in this revision

Viewing changes to static/scripts/gis/mapfish/widgets/geostat/ProportionalSymbol.js

  • Committer: Deng Dongpo
  • Date: 2010-08-01 09:29:44 UTC
  • Revision ID: dongpo@dhcp-21193.iis.sinica.edu.tw-20100801092944-8t9obt4xtl7otesb
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009  Camptocamp
 
3
 *
 
4
 * This file is part of MapFish Client
 
5
 *
 
6
 * MapFish Client is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * MapFish Client is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with MapFish Client.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
/**
 
21
 * @requires core/GeoStat/ProportionalSymbol.js
 
22
 */
 
23
 
 
24
Ext.namespace('mapfish.widgets', 'mapfish.widgets.geostat');
 
25
 
 
26
/**
 
27
 * Class: mapfish.widgets.geostat.ProportionalSymbol
 
28
 * Use this class to create a widget allowing to display proportional
 
29
 * symbols on the map.
 
30
 *
 
31
 * Inherits from:
 
32
 * - {Ext.FormPanel}
 
33
 */
 
34
mapfish.widgets.geostat.ProportionalSymbol = Ext.extend(Ext.FormPanel, {
 
35
 
 
36
    /**
 
37
     * APIProperty: layer
 
38
     * {<OpenLayers.Layer.Vector>} The vector layer containing the features that
 
39
     *      are styled based on statistical values. If none is provided, one will
 
40
     *      be created.
 
41
     */
 
42
    layer: null,
 
43
 
 
44
    /**
 
45
     * APIProperty: format
 
46
     * {<OpenLayers.Format>} The OpenLayers format used to get features from
 
47
     *      the HTTP request response. GeoJSON is used if none is provided.
 
48
     */
 
49
    format: null,
 
50
 
 
51
    /**
 
52
     * APIProperty: url
 
53
     * {String} The URL to the web service. If none is provided, the features
 
54
     *      found in the provided vector layer will be used.
 
55
     */
 
56
    url: null,
 
57
 
 
58
    /**
 
59
     * APIProperty: featureSelection
 
60
     * {Boolean} A boolean value specifying whether feature selection must
 
61
     *      be put in place. If true a popup will be displayed when the
 
62
     *      mouse goes over a feature.
 
63
     */
 
64
    featureSelection: true,
 
65
 
 
66
    /**
 
67
     * APIProperty: nameAttribute
 
68
     * {String} The feature attribute that will be used as the popup title.
 
69
     *      Only applies if featureSelection is true.
 
70
     */
 
71
    nameAttribute: null,
 
72
    
 
73
    /**
 
74
     * APIProperty: indicator
 
75
     * {String} (read-only) The feature attribute currently chosen
 
76
     *     Useful if callbacks are registered on 'featureselected'
 
77
     *     and 'featureunselected' events
 
78
     */
 
79
    indicator: null,
 
80
    
 
81
    /**
 
82
     * APIProperty: indicatorText
 
83
     * {String} (read-only) The raw value of the currently chosen indicator
 
84
     *     (ie. human readable)
 
85
     *     Useful if callbacks are registered on 'featureselected'
 
86
     *     and 'featureunselected' events
 
87
     */
 
88
    indicatorText: null,
 
89
 
 
90
    /**
 
91
     * Property: coreComp
 
92
     * {<mapfish.GeoStat.ProportionalSymbol>} The core component object.
 
93
     */
 
94
    coreComp: null,
 
95
 
 
96
    /**
 
97
     * Property: classificationApplied
 
98
     * {Boolean} true if the classify was applied
 
99
     */
 
100
    classificationApplied: false,
 
101
 
 
102
    /**
 
103
     * Property: ready
 
104
     * {Boolean} true if the widget is ready to accept user commands.
 
105
     */
 
106
    ready: false,
 
107
 
 
108
    /**
 
109
     * Property: border
 
110
     *     Styling border
 
111
     */
 
112
    border: false,
 
113
    
 
114
    /**
 
115
     * APIProperty: loadMask
 
116
     *     An Ext.LoadMask config or true to mask the widget while loading (defaults to false).
 
117
     */
 
118
    loadMask : false,
 
119
 
 
120
    /**
 
121
     * Constructor: mapfish.widgets.geostat.ProportionalSymbol
 
122
     *
 
123
     * Parameters:
 
124
     * config - {Object} Config object.
 
125
     */
 
126
 
 
127
    /**
 
128
     * Method: initComponent
 
129
     *    Inits the component
 
130
     */
 
131
    initComponent : function() {
 
132
        this.items = [{
 
133
            xtype: 'combo',
 
134
            fieldLabel: 'Indicator',
 
135
            name: 'indicator',
 
136
            editable: false,
 
137
            valueField: 'value',
 
138
            displayField: 'text',
 
139
            mode: 'local',
 
140
            emptyText: 'select an indicator',
 
141
            triggerAction: 'all',
 
142
            store: new Ext.data.SimpleStore({
 
143
                fields: ['value', 'text'],
 
144
                data : this.indicators
 
145
            })
 
146
        },{
 
147
            xtype: 'numberfield',
 
148
            fieldLabel:'Min Size',
 
149
            name: 'minSize',
 
150
            width: 30,
 
151
            value: 2,
 
152
            maxValue: 20
 
153
        },{
 
154
            xtype: 'numberfield',
 
155
            fieldLabel:'Max Size',
 
156
            name: 'maxSize',
 
157
            width: 30,
 
158
            value: 20,
 
159
            maxValue: 50
 
160
        }];
 
161
        
 
162
        
 
163
        this.buttons = [{
 
164
            text: 'OK',
 
165
            handler: this.classify,
 
166
            scope: this
 
167
        }];
 
168
        mapfish.widgets.geostat.ProportionalSymbol.superclass.initComponent.apply(this);
 
169
    },
 
170
 
 
171
    /**
 
172
     * Method: requestSuccess
 
173
     *      Calls onReady callback function and mark the widget as ready.
 
174
     *      Called on Ajax request success.
 
175
     */
 
176
    requestSuccess: function(request) {
 
177
        this.ready = true;
 
178
        
 
179
        // if widget is rendered, hide the optional mask
 
180
        if (this.loadMask && this.rendered) {
 
181
            this.loadMask.hide();
 
182
        }
 
183
    },
 
184
 
 
185
    /**
 
186
     * Method: requestFailure
 
187
     *      Displays an error message on the console.
 
188
     *      Called on Ajax request failure.
 
189
     */
 
190
    requestFailure: function(request) {
 
191
        OpenLayers.Console.error('Ajax request failed');
 
192
    },
 
193
        
 
194
    /**
 
195
     * Method: classify
 
196
     *    Reads the features to get the different value for
 
197
     *    the field given for indicator
 
198
     *    Creates a new Distribution and related Classification
 
199
     *    Then creates an new ProportionalSymbols and applies classification
 
200
     */
 
201
    classify: function() {
 
202
        if (!this.ready) {
 
203
            if (exception) {
 
204
                Ext.MessageBox.alert('Error', 'Component init not complete');
 
205
            }
 
206
            return;
 
207
        }
 
208
        this.indicator = this.form.findField('indicator').getValue();
 
209
        this.indicatorText = this.form.findField('indicator').getRawValue();
 
210
        if (!this.indicator) {
 
211
            Ext.MessageBox.alert('Error', 'You must choose an indicator');
 
212
            return;
 
213
        }
 
214
        var minSize = this.form.findField('minSize').getValue();
 
215
        var maxSize = this.form.findField('maxSize').getValue();
 
216
        this.coreComp.updateOptions({
 
217
            'indicator': this.indicator,
 
218
            'minSize': minSize,
 
219
            'maxSize': maxSize
 
220
        });
 
221
        this.coreComp.applyClassification();
 
222
        this.classificationApplied = true;
 
223
    },
 
224
 
 
225
    /**
 
226
     * Method: onRender
 
227
     * Called by EXT when the component is rendered.
 
228
     */
 
229
    onRender: function(ct, position) {
 
230
        mapfish.widgets.geostat.Choropleth.superclass.onRender.apply(
 
231
                this, arguments);
 
232
        
 
233
        if(this.loadMask){
 
234
            this.loadMask = new Ext.LoadMask(this.bwrap,
 
235
                    this.loadMask);
 
236
            this.loadMask.show();
 
237
        }
 
238
        
 
239
        this.coreComp = new mapfish.GeoStat.ProportionalSymbol(this.map, {
 
240
            'layer': this.layer,
 
241
            'format': this.format,
 
242
            'url': this.url,
 
243
            'requestSuccess': this.requestSuccess.createDelegate(this),
 
244
            'requestFailure': this.requestFailure.createDelegate(this),
 
245
            'featureSelection': this.featureSelection,
 
246
            'nameAttribute': this.nameAttribute
 
247
        });
 
248
    }
 
249
});
 
250
Ext.reg('proportionalsymbol', mapfish.widgets.geostat.ProportionalSymbol);