2
* Copyright (C) 2007-2008 Camptocamp
4
* This file is part of MapFish Client
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.
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.
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/>.
21
* @requires core/GeoStat/Choropleth.js
22
* @requires core/Color.js
25
Ext.namespace('mapfish.widgets', 'mapfish.widgets.geostat');
28
* Class: mapfish.widgets.geostat.Choropleth
29
* Use this class to create a widget allowing to display choropleths
36
mapfish.widgets.geostat.Choropleth = Ext.extend(Ext.FormPanel, {
40
* {<OpenLayers.Layer.Vector>} The vector layer containing the features that
41
* are styled based on statistical values. If none is provided, one will
48
* {<OpenLayers.Format>} The OpenLayers format used to get features from
49
* the HTTP request response. GeoJSON is used if none is provided.
55
* {String} The URL to the web service. If none is provided, the features
56
* found in the provided vector layer will be used.
61
* APIProperty: featureSelection
62
* {Boolean} A boolean value specifying whether feature selection must
63
* be put in place. If true a popup will be displayed when the
64
* mouse goes over a feature.
66
featureSelection: true,
69
* APIProperty: nameAttribute
70
* {String} The feature attribute that will be used as the popup title.
71
* Only applies if featureSelection is true.
76
* APIProperty: indicator
77
* {String} (read-only) The feature attribute currently chosen
78
* Useful if callbacks are registered on 'featureselected'
79
* and 'featureunselected' events
84
* APIProperty: indicatorText
85
* {String} (read-only) The raw value of the currently chosen indicator
86
* (ie. human readable)
87
* Useful if callbacks are registered on 'featureselected'
88
* and 'featureunselected' events
94
* {<mapfish.GeoStat.ProportionalSymbol>} The core component object.
99
* Property: classificationApplied
100
* {Boolean} true if the classify was applied
102
classificationApplied: false,
106
* {Boolean} true if the widget is ready to accept user commands.
117
* APIProperty: loadMask
118
* An Ext.LoadMask config or true to mask the widget while loading (defaults to false).
123
* APIProperty: labelGenerator
124
* Generator for bin labels
126
labelGenerator: null,
129
* Constructor: mapfish.widgets.geostat.Choropleth
132
* config - {Object} Config object.
136
* Method: initComponent
137
* Inits the component
140
selectedLevel : false,
146
initComponent : function() {
150
indicatorStore = new Ext.data.JsonStore({
151
url: 'http://localhost:8180/dhis-webservice/getAllIndicators.service?format=jsonmin',
152
//baseParams: { format: 'jsonmin' },
154
fields: ['id', 'name']//,
158
periodTypeStore = new Ext.data.JsonStore({
159
url: 'http://localhost:8180/dhis-webservice/getAllPeriodTypes.service',
160
baseParams: { format: 'json' },
162
fields: ['id', 'name'],
166
periodStore = new Ext.data.JsonStore({
167
url: 'http://localhost:8180/dhis-webservice/getPeriodsByPeriodType.service',
168
baseParams: { periodTypeId: '9', format: 'json' },
170
fields: ['id', 'startDate'],
174
levelStore = new Ext.data.JsonStore({
175
url: 'http://localhost:8180/dhis-webservice/getOrganisationUnitLevels.service',
176
baseParams: { format: 'json' },
177
root: 'organisationUnitLevels',
178
fields: ['level', 'name'],
195
fieldLabel: 'Indicator',
199
displayField: 'name',
201
forceSelection: true,
202
triggerAction: 'all',
203
emptyText: 'Select indicator',
205
store: indicatorStore
210
fieldLabel: 'Period type',
214
displayField: 'name',
216
forceSelection: true,
217
triggerAction: 'all',
218
emptyText: 'Select period type',
220
store: periodTypeStore,
225
var ptid = Ext.getCmp('periodtype_cb').getValue();
226
periodStore.baseParams = { periodTypeId: ptid, format: 'json' };
227
periodStore.reload();
237
fieldLabel: 'Period',
241
displayField: 'startDate',
243
forceSelection: true,
244
triggerAction: 'all',
245
emptyText: 'Select period',
257
displayField: 'name',
259
forceSelection: true,
260
triggerAction: 'all',
261
emptyText: 'Select level',
267
this.selectedLevel = this.form.findField('level_cb').getValue();
268
this.newUrl = shapefiles[this.form.findField('level_cb').getValue()];
269
this.classify(false);
284
fieldLabel: 'Indicator',
288
displayField: 'text',
290
emptyText: 'Select an indicator',
291
triggerAction: 'all',
292
store: new Ext.data.SimpleStore({
293
fields: ['value', 'text'],
294
data : this.indicators
302
fieldLabel: 'Method',
304
hiddenName: 'method',
307
displayField: 'text',
309
emptyText: 'Select a method',
310
triggerAction: 'all',
311
store: new Ext.data.SimpleStore({
312
fields: ['value', 'text'],
313
data : [['CLASSIFY_BY_EQUAL_INTERVALS', 'Equal Intervals'],
314
['CLASSIFY_BY_QUANTILS', 'Quantils']]
319
fieldLabel: 'Classes',
323
displayField: 'value',
326
triggerAction: 'all',
327
store: new Ext.data.SimpleStore({
329
data: [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]
341
fn: function() {this.classify(false)},
356
handler: function() {
364
mapfish.widgets.geostat.Choropleth.superclass.initComponent.apply(this);
367
setUrl: function(url, isDrillDown) {
370
this.isDrillDown = isDrillDown;
371
this.coreComp.setUrl(this.url);
375
* Method: requestSuccess
376
* Calls onReady callback function and mark the widget as ready.
377
* Called on Ajax request success.
379
requestSuccess: function(request) {
381
this.classify(false);
383
// if widget is rendered, hide the optional mask
384
if (this.loadMask && this.rendered) {
385
this.loadMask.hide();
390
* Method: requestFailure
391
* Displays an error message on the console.
392
* Called on Ajax request failure.
394
requestFailure: function(request) {
395
OpenLayers.Console.error('Ajax request failed');
400
* Retrieves the colors from form elements
403
* {Array(<mapfish.Color>)} an array of two colors (start, end)
405
getColors: function() {
406
var colorA = new mapfish.ColorRgb();
407
colorA.setFromHex(this.form.findField('colorA').getValue());
408
var colorB = new mapfish.ColorRgb();
409
colorB.setFromHex(this.form.findField('colorB').getValue());
410
return [colorA, colorB];
417
* exception - {Boolean} If true show a message box to user if either
418
* the widget isn't ready, or no indicator is specified, or no
419
* method is specified.
421
classify: function(exception, wfs) {
423
// alert("classify");
427
Ext.MessageBox.alert('Error', 'Component init not complete');
433
var url = this.newUrl;
435
this.setUrl(url, false);
440
if (!this.form.findField('indicator_cb').getValue() ||
441
!this.form.findField('periodtype_cb').getValue() ||
442
!this.form.findField('period_cb').getValue() ||
443
!this.form.findField('level_cb').getValue()) {
445
Ext.MessageBox.alert('Error', 'You must choose indicator, period and level');
453
this.indicator = 'value';
454
this.indicatorText = 'Indicator';
455
options.indicator = this.indicator;
458
options.method = this.form.findField('method').getValue();
459
if (!options.method) {
461
Ext.MessageBox.alert('Error', 'You must choose a method');
467
options.method = mapfish.GeoStat.Distribution[options.method];
468
options.numClasses = this.form.findField('numClasses').getValue();
469
options.colors = this.getColors();
471
this.coreComp.updateOptions(options);
472
this.coreComp.applyClassification();
473
this.classificationApplied = true;
475
if (this.isDrillDown) {
477
this.isDrillDown = false;
479
if (this.selectedLevel <= shapefiles.length){
480
this.selectedLevel += 1;
483
this.form.findField('level_cb').setValue(this.selectedLevel);
491
* Called by EXT when the component is rendered.
493
onRender: function(ct, position) {
494
mapfish.widgets.geostat.Choropleth.superclass.onRender.apply(this, arguments);
496
this.loadMask = new Ext.LoadMask(this.bwrap,
498
this.loadMask.show();
503
'format': this.format,
505
'requestSuccess': this.requestSuccess.createDelegate(this),
506
'requestFailure': this.requestFailure.createDelegate(this),
507
'featureSelection': this.featureSelection,
508
'nameAttribute': this.nameAttribute,
509
'legendDiv': this.legendDiv,
510
'labelGenerator': this.labelGenerator
513
this.coreComp = new mapfish.GeoStat.Choropleth(this.map, coreOptions);
516
Ext.reg('choropleth', mapfish.widgets.geostat.Choropleth);