This repository was archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathWMSSource.js
More file actions
975 lines (875 loc) · 34.6 KB
/
Copy pathWMSSource.js
File metadata and controls
975 lines (875 loc) · 34.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
/**
* Copyright (c) 2008-2011 The Open Planning Project
*
* Published under the GPL license.
* See https://github.com/opengeo/gxp/raw/master/license.txt for the full text
* of the license.
*/
/**
* @requires plugins/LayerSource.js
*/
/**
* The WMSCapabilities and WFSDescribeFeatureType formats parse the document and
* pass the raw data to the WMSCapabilitiesReader/AttributeReader. There,
* records are created from layer data. The rest of the data is lost. It
* makes sense to store this raw data somewhere - either on the OpenLayers
* format or the GeoExt reader. Until there is a better solution, we'll
* override the reader's readRecords method here so that we can have access to
* the raw data later.
*
* The purpose of all of this is to get the service title, feature type and
* namespace later.
* TODO: push this to OpenLayers or GeoExt
*/
(function() {
function keepRaw(data) {
var format = this.meta.format;
if (typeof data === "string" || data.nodeType) {
data = format.read(data);
// cache the data for the single read that readRecord does
var origRead = format.read;
format.read = function() {
format.read = origRead;
return data;
};
}
// here is the new part
this.raw = data;
};
Ext.intercept(GeoExt.data.WMSCapabilitiesReader.prototype, "readRecords", keepRaw);
GeoExt.data.AttributeReader &&
Ext.intercept(GeoExt.data.AttributeReader.prototype, "readRecords", keepRaw);
})();
/** api: (define)
* module = gxp.plugins
* class = WMSSource
*/
/** api: (extends)
* plugins/LayerSource.js
*/
Ext.namespace("gxp.plugins");
/** api: constructor
* .. class:: WMSSource(config)
*
* Plugin for using WMS layers with :class:`gxp.Viewer` instances. The
* plugin issues a GetCapabilities request to create a store of the WMS's
* layers.
*/
/** api: example
* Configuration in the :class:`gxp.Viewer`:
*
* .. code-block:: javascript
*
* defaultSourceType: "gxp_wmssource",
* sources: {
* "opengeo": {
* url: "http://suite.opengeo.org/geoserver/wms"
* }
* }
*
* A typical configuration for a layer from this source (in the ``layers``
* array of the viewer's ``map`` config option would look like this:
*
* .. code-block:: javascript
*
* {
* source: "opengeo",
* name: "world",
* group: "background"
* }
*
*/
gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
/** api: ptype = gxp_wmssource */
ptype: "gxp_wmssource",
/** api: config[url]
* ``String`` WMS service URL for this source
*/
/** api: config[baseParams]
* ``Object`` Base parameters to use on the WMS GetCapabilities
* request.
*/
baseParams: null,
layerBaseParams: null,
/** private: property[format]
* ``OpenLayers.Format`` Optional custom format to use on the
* WMSCapabilitiesStore store instead of the default.
*/
format: null,
/** private: property[describeLayerStore]
* ``GeoExt.data.WMSDescribeLayerStore`` additional store of layer
* descriptions. Will only be available when the source is configured
* with ``describeLayers`` set to true.
*/
describeLayerStore: null,
/** private: property[describedLayers]
*/
describedLayers: null,
/** private: property[schemaCache]
*/
schemaCache: null,
/** api: config[version]
* ``String``
* If specified, the version string will be included in WMS GetCapabilities
* requests. By default, no version is set.
*/
/** api: config[loadingProgress]
* ``Boolean`` if true, loadingProgress property is applied to all the WMSSource layers.
*/
loadingProgress: false,
/** api: config[useCapabilities]
* ``Boolean`` if false, no capabilities request is sent to the server to initialize the store.
*/
useCapabilities: true,
/** api: config[useScaleHints]
* ``String`` Uses WMSCapabilities scaleHints or scaleDenominator
* Values:
* 'udp' Use scalehints and transform the value from udp to denominator
* 'denominator': Use scaleHints or denominator
* default: Doesn't use scaleHints or scaleDenominator
*/
useScaleHints:null,
noCompatibleProjectionError: "Layer is not available in the map projection",
wfsDescribeFeatureTypeError: "Error getting attributes of feature type",
errorTitle: "Error",
/** api: method[createStore]
*
* Creates a store of layer records. Fires "ready" when store is loaded.
*/
createStore: function() {
if(this.useCapabilities) {
return this.createCapabilitiesStore();
}
this.fireEvent("ready", this);
return null;
},
/**
* Get the user's corrensponding authkey if present
* (see MSMLogin.getLoginInformation for more details)
*/
getAuthParam: function(){
var userInfo = this.target.userDetails;
var authkey;
if(userInfo.token) {
authkey = userInfo.token;
}
if(authkey){
this.authParam = userInfo.user.authParam || this.authParam;
}
return authkey;
},
createCapabilitiesStore: function() {
var baseParams = this.baseParams || {
SERVICE: "WMS",
REQUEST: "GetCapabilities"
};
if (this.version) {
baseParams.VERSION = this.version;
}
// /////////////////////////////////////////////////////
// Get the user's corrensponding authkey if present
// (see MSMLogin.getLoginInformation for more details)
// /////////////////////////////////////////////////////
if(this.authParam && this.target.userDetails){
var authkey = this.getAuthParam();
if(authkey){
baseParams[this.authParam] = authkey;
}
}
this.store = new GeoExt.data.WMSCapabilitiesStore({
// Since we want our parameters (e.g. VERSION) to override any in the
// given URL, we need to remove corresponding paramters from the
// provided URL. Simply setting baseParams on the store is also not
// enough because Ext just tacks these parameters on to the URL - so
// we get requests like ?Request=GetCapabilities&REQUEST=GetCapabilities
// (assuming the user provides a URL with a Request parameter in it).
url: this.trimUrl(this.url, baseParams),
baseParams: baseParams,
format: this.format,
autoLoad: true,
sortInfo : {
field : 'title',
direction : 'ASC'
},
listeners: {
load: function() {
// The load event is fired even if a bogus capabilities doc
// is read (http://trac.geoext.org/ticket/295).
// Until this changes, we duck type a bad capabilities
// object and fire failure if found.
if (!this.store.reader.raw || !this.store.reader.raw.service) {
this.fireEvent("failure", this, "Invalid capabilities document.");
} else {
if (!this.title) {
this.title = this.store.reader.raw.service.title;
}
this.fireEvent("ready", this);
}
},
exception: function(proxy, type, action, options, response, arg) {
delete this.store;
var msg;
if (type === "response") {
msg = arg || "Invalid response from server.";
} else {
msg = "Trouble creating layer store from response.";
}
// TODO: decide on signature for failure listeners
this.fireEvent("failure", this, msg, Array.prototype.slice.call(arguments));
},
scope: this
}
});
},
/** private: method[trimUrl]
* :arg url: ``String``
* :arg params: ``Object``
*
* Remove all parameters from the URL's query string that have matching
* keys in the provided object. Keys are compared in a case-insensitive
* way.
*/
trimUrl: function(url, params, respectCase) {
var urlParams = OpenLayers.Util.getParameters(url);
params = OpenLayers.Util.upperCaseObject(params);
var keys = 0;
for (var key in urlParams) {
++keys;
if (key.toUpperCase() in params) {
--keys;
delete urlParams[key];
}
}
return url.split("?").shift() + (keys ?
"?" + OpenLayers.Util.getParameterString(urlParams) :
""
);
},
/** api: method[createLayerRecord]
* :arg config: ``Object`` The application config for this layer.
* :returns: ``GeoExt.data.LayerRecord``
*
* Create a layer record given the config.
*/
createLayerRecord: function(config) {
if(this.useCapabilities) {
return this.createLayerRecordCapabilities(config);
}
var reader = new GeoExt.data.WMSCapabilitiesReader();
var layerConfig = Ext.apply({
formats: ['image/png', 'image/jpeg', 'image/gif']
}, config);
var records = reader.readRecords({
capability: {
request: {
getmap: {
href: this.url
}
},
layers: [layerConfig]
}
});
return this.createLayerRecordFromOriginal(records.records[0], config);
},
createLayerRecordFromOriginal: function(original, config) {
var layer = original.getLayer();
layer.url = layer.url.replace('SERVICE=WMS&', '');
/**
* TODO: The WMSCapabilitiesReader should allow for creation
* of layers in different SRS.
*/
var projection = this.getMapProjection();
var defProp = this.getDefaultProps(original, config);
config = Ext.applyIf(defProp, config);
// If the layer is not available in the map projection, find a
// compatible projection that equals the map projection. This helps
// us in dealing with the different EPSG codes for web mercator.
var layerProjection = this.getProjection(original);
if (layerProjection) {
layer.addOptions({projection: layerProjection});
} else {
Ext.Msg.show({
title: this.errorTitle,
msg: this.noCompatibleProjectionError,
buttons: Ext.Msg.OK,
width: 300,
icon: Ext.MessageBox.ERROR
});
return null;
}
var projCode = projection.getCode();
var nativeExtent = original.get("bbox")[projCode];
//var swapAxis = layer.params.VERSION >= "1.3" && !!layer.yx[projCode];
var swapAxis = layer.params.VERSION >= "1.3" && layer.reverseAxisOrder();
var maxExtent =
(nativeExtent && OpenLayers.Bounds.fromArray(nativeExtent.bbox, swapAxis)) ||
(original.get("llbbox") && OpenLayers.Bounds.fromArray(original.get("llbbox")).transform(new OpenLayers.Projection("EPSG:4326"), projection)) || null;
// ///////////////////////////////////////////////////////////////////////////////////////////
// 'layersCachedExtent' property can be defined for source and/or a single
// layer configuration when we use GeoWebCache integration in GeoServer.
// GeoServer getCapabilities request return only bounds in 4326 and native CRS so, if the
// map CRS is 900913 the transformed bounds is not aligned with the google standard
// gridset defined in GeoServer.
// //////////////////////////////////////////////////////////////////////////////////////////
var maxCachedExtent = config.layersCachedExtent ? OpenLayers.Bounds.fromArray(config.layersCachedExtent) :
this.layersCachedExtent ? OpenLayers.Bounds.fromArray(this.layersCachedExtent) : maxExtent;
if(maxExtent) {
// make sure maxExtent is valid (transfzorm does not succeed for all llbbox)
if (!(1 / maxExtent.getHeight() > 0) || !(1 / maxExtent.getWidth() > 0)) {
// maxExtent has infinite or non-numeric width or height
// in this case, the map maxExtent must be specified in the config
maxExtent = undefined;
}
}
var styles = this.getLayerStyle(config);
// use all params from sources layerBaseParams option
var params = Ext.applyIf({
STYLES: styles || "",
FORMAT: config.format,
TRANSPARENT: config.transparent,
//CQL_FILTER: config.cql_filter,
TIME: config.time,
ELEVATION: config.elevation
}, this.layerBaseParams);
// ///////////////////////////////////////////////////////
// Check for existing 'viewparams' in config and apply
// them into the WMS params of the layer
// ///////////////////////////////////////////////////////
if(config.vendorParams){
params = Ext.applyIf(params, config.vendorParams);
}
// use all params from original
params = Ext.applyIf(params, layer.params);
// /////////////////////////////////////////////////////////
// Checking if the OpenLayers transition should be
// disabled (transitionEffect: null).
//
// (see also
// https://github.com/openlayers/openlayers/blob/master/notes/2.13.md#layergrid-resize-transitions-by-default).
//
// In this case also the zoomMethod must be setted to null
// in Map configuration (see widgets/Viewer.js).
// /////////////////////////////////////////////////////////
var transitionEffect = null;
if(this.target.map.animatedZooming){
if(this.target.map.animatedZooming.transitionEffect == null){
transitionEffect = null;
}else{
transitionEffect = this.target.map.animatedZooming.transitionEffect;
}
}
//
// retrive scale hints and bounds
//
if(this.useScaleHints){
config.useScaleHints = config.useScaleHints || this.useScaleHints
}
var zoomLevelsConf={};
if(config.minScale)zoomLevelsConf.minScale=config.minScale;
if(config.maxScale)zoomLevelsConf.maxScale=config.maxScale;
if(config.minResolution)zoomLevelsConf.minResolution=config.minResolution;
if(config.maxResolution)zoomLevelsConf.maxResolution=config.maxResolution;
if(config.scales)zoomLevelsConf.scales=config.scales;
if(config.resolutions)zoomLevelsConf.resolutions=config.resolutions;
if(config.numZoomLevels)zoomLevelsConf.numZoomLevels=config.numZoomLevels;
if(config.units)zoomLevelsConf.units=config.units;
// if some option is defined in the layer configuration
// this options will override the hints
var skipHint=(config.minScale||config.maxScale||config.minResolution||config.maxResolution||config.scales||config.resolutions||config.numZoomLevels);
if(config.useScaleHints && !skipHint){
var rad2 = Math.pow(2, 0.5);
var ipm = OpenLayers.INCHES_PER_UNIT["m"];
if(layer.maxScale){
var val=(layer.params.VERSION >= "1.3" || config.useScaleHints=='udp')?layer.maxScale:(layer.maxScale/(ipm * OpenLayers.DOTS_PER_INCH ))*rad2;
zoomLevelsConf.maxScale=val;
}
if(layer.minScale){
var val=(layer.params.VERSION >= "1.3" || config.useScaleHints=='udp')?layer.minScale:(layer.minScale/(ipm * OpenLayers.DOTS_PER_INCH ))*rad2;
zoomLevelsConf.minScale=val;
}
}
layer = new OpenLayers.Layer.WMS(
config.title || config.name,
layer.url,
params, Ext.apply({
attribution: ("attribution" in config) ? (config.attribution ? layer.attribution : '') : layer.attribution,
maxExtent: maxCachedExtent,
restrictedExtent: maxExtent,
displayInLayerSwitcher: ("displayInLayerSwitcher" in config) ? config.displayInLayerSwitcher :true,
singleTile: ("tiled" in config) ? !config.tiled : false,
ratio: config.ratio || 1,
visibility: ("visibility" in config) ? config.visibility : true,
opacity: ("opacity" in config) ? config.opacity : 1,
buffer: ("buffer" in config) ? config.buffer : 0,
loadingProgress: config.loadingProgress || this.loadingProgress || false,
dimensions: original.data.dimensions,
projection: layerProjection,
vendorParams: config.vendorParams,
transitionEffect: transitionEffect
},zoomLevelsConf)
);
// data for the new record
var data = Ext.applyIf({
title: config.title,
name: config.name,
group: config.group,
uuid: config.uuid,
gnURL: config.gnURL,
source: config.source,
properties: "gxp_wmslayerpanel",
times: "times" in config ? config.times : null,
elevations: "elevations" in config ? config.elevations : null,
fixed: config.fixed,
selected: "selected" in config ? config.selected : false,
layer: layer
}, original.data);
// add additional fields
var fields = [
{name: "source", type: "string"},
{name: "name", type: "string"},
{name: "group", type: "string"},
{name: "uuid", type: "string"},
{name: "gnURL", type: "string"},
{name: "title", type: "string"},
{name: "properties", type: "string"},
{name: "fixed", type: "boolean"},
{name: "selected", type: "boolean"},
{name: "times", type: "string"},
{name: "elevations", type: "string"}
];
original.fields.each(function(field) {
fields.push(field);
});
var Record = GeoExt.data.LayerRecord.create(fields);
return new Record(data, layer.id);
},
createLayerRecordCapabilities: function(config) {
var record;
var index = this.store.findExact("name", config.name);
if (index > -1) {
var original = this.store.getAt(index);
record = this.createLayerRecordFromOriginal(original, config);
} else {
if (window.console && this.store.getCount() > 0) {
console.warn("Could not create layer record for layer '" + config.name + "'. Check if the layer is found in the WMS GetCapabilities response.");
}
}
return record;
},
/** api: method[getProjection]
* :arg layerRecord: ``GeoExt.data.LayerRecord`` a record from this
* source's store
* :returns: ``OpenLayers.Projection`` A suitable projection for the
* ``layerRecord``. If the layer is available in the map projection,
* the map projection will be returned. Otherwise an equal projection,
* or null if none is available.
*
* Get the projection that the source will use for the layer created in
* ``createLayerRecord``. If the layer is not available in a projection
* that fits the map projection, null will be returned.
*/
getProjection: function(layerRecord) {
var projection = this.getMapProjection();
var compatibleProjection = projection;
var availableSRS = layerRecord.get("srs");
if (!availableSRS[projection.getCode()]) {
compatibleProjection = null;
var p, srs;
for (srs in availableSRS) {
if ((p=new OpenLayers.Projection(srs)).equals(projection)) {
compatibleProjection = p;
break;
}
}
}
return compatibleProjection;
},
/** private: method[switchWmsVersion]
* returns the WMS version alternative to the one passed as parameter
*/
switchWmsVersion: function(wmsVersion) {
var WMS_VERSIONS = {
"1.1.1": "1.3.0",
"1.3.0": "1.1.1"
};
return WMS_VERSIONS[wmsVersion];
},
/** private: method[initDescribeLayerStore]
* creates a WMSDescribeLayer store for layer descriptions of all layers
* created from this source.
*/
initDescribeLayerStore: function() {
var DEFAULT_WMS_VERSION = "1.1.1";
var url;
var version;
var baseParams = {
SERVICE: "WMS",
REQUEST: "DescribeLayer"
};
if (this.useCapabilities === true) {
var describeLayerRequest = this.store.reader.raw.capability.request.describelayer;
var wmsVersion = this.store.reader.raw.version;
if (describeLayerRequest) {
url = describeLayerRequest.href;
version = wmsVersion;
} else {
url = this.url;
version = this.switchWmsVersion(wmsVersion);
}
} else {
url = this.url;
version = this.version;
}
version = version || DEFAULT_WMS_VERSION;
this.describeLayerStore = new GeoExt.data.WMSDescribeLayerStore({
url: url,
baseParams: Ext.apply(baseParams, {
VERSION: version
})
});
},
/** api: method[describeLayer]
* :arg rec: ``GeoExt.data.LayerRecord`` the layer to issue a WMS
* DescribeLayer request for
* :arg callback: ``Function`` Callback function. Will be called with
* an ``Ext.data.Record`` from a ``GeoExt.data.DescribeLayerStore``
* as first argument, or false if the WMS does not support
* DescribeLayer.
* :arg scope: ``Object`` Optional scope for the callback.
*
* Get a DescribeLayer response from this source's WMS.
*/
describeLayer: function(rec, callback, scope) {
if (!this.describeLayerStore) {
this.initDescribeLayerStore();
}
function delayedCallback(arg) {
window.setTimeout(function() {
callback.call(scope, arg);
}, 0);
}
if (!this.describeLayerStore) {
delayedCallback(false);
return;
}
if (!this.describedLayers) {
this.describedLayers = {};
}
if (!this.describeLayerQueue) {
this.describeLayerQueue = [];
}
//If I'm wating for a describe layer request I have to append to the queue new request!
for(lname in this.describedLayers){
if(typeof this.describedLayers[lname]== "function"){
this.describeLayerQueue.push(arguments);
return;//Stop cycle and return
}
}
var layerName = rec.getLayer().params.LAYERS;
var cb = function() {
var recs = Ext.isArray(arguments[1]) ? arguments[1] : arguments[0];
var options = Ext.isObject(arguments[2]) ? arguments[2] : arguments[1];
var rec, name;
for (var i=recs.length-1; i>=0; i--) {
rec = recs[i];
name = rec.get("layerName");
if (name == layerName) {
this.describeLayerStore.un("load", arguments.callee, this);
this.describedLayers[name] = true;
//Check's if we have some describe layer request in queue!
if(this.describeLayerQueue.length>0){
var arg=this.describeLayerQueue.pop();
this.describeLayer(arg[0],arg[1],arg[2]);
}
callback.call(scope, rec);
return;
} else if (typeof this.describedLayers[name] == "function") {
var fn = this.describedLayers[name];
this.describeLayerStore.un("load", fn, this);
fn.apply(this, arguments);
}
}
// something went wrong (e.g. using a WMS version which does not support
// DescribeLayer operation): try again with a different WMS version
// before giving up...
if (arguments.callee.retryCount < 2) {
var otherWmsVersion = this.switchWmsVersion(this.describeLayerStore.baseParams.VERSION);
// override VERSION parameter both in the store's baseParams
// AND in the options object passed to the load method
this.describeLayerStore.setBaseParam('VERSION', otherWmsVersion);
options.params.VERSION = otherWmsVersion;
arguments.callee.retryCount++;
this.describeLayerStore.load(options);
return;
}
//Check's if we have some describe layer request in queue!
if(this.describeLayerQueue.length>0){
var arg=this.describeLayerQueue.pop();
this.describeLayer(arg[0],arg[1],arg[2]);
}
// something went definitively wrong (e.g. GeoServer does not return a valid
// DescribeFeatureType document for group layers)
delete describedLayers[layerName];
callback.call(scope, false);
};
cb.retryCount = 1;
var describedLayers = this.describedLayers;
var index;
if (!describedLayers[layerName]) {
describedLayers[layerName] = cb;
this.describeLayerStore.load({
params: {
LAYERS: layerName
},
add: true,
callback: cb,
scope: this
});
} else if ((index = this.describeLayerStore.findExact("layerName", layerName)) == -1) {
this.describeLayerStore.on("load", cb, this);
} else {
delayedCallback(this.describeLayerStore.getAt(index));
}
},
/** api: method[getSchema]
* :arg rec: ``GeoExt.data.LayerRecord`` the WMS layer to issue a WFS
* DescribeFeatureType request for
* :arg callback: ``Function`` Callback function. Will be called with
* a ``GeoExt.data.AttributeStore`` containing the schema as first
* argument, or false if the WMS does not support DescribeLayer or the
* layer is not associated with a WFS feature type.
* :arg scope: ``Object`` Optional scope for the callback.
*
* Gets the schema for a layer of this source, if the layer is a feature
* layer.
*/
getSchema: function(rec, callback, scope) {
if (!this.schemaCache) {
this.schemaCache = {};
}
this.describeLayer(rec, function(r) {
if (r && r.get("owsType") == "WFS") {
var typeName = r.get("typeName");
var schema = this.schemaCache[typeName];
if (schema) {
if (schema.getCount() == 0) {
schema.on("load", function() {
callback.call(scope, schema);
}, this, {
single: true
});
} else {
callback.call(scope, schema);
}
} else {
schema = new GeoExt.data.AttributeStore({
url: r.get("owsURL"),
baseParams: {
SERVICE: "WFS",
//TODO should get version from WFS GetCapabilities
VERSION: "1.1.0",
REQUEST: "DescribeFeatureType",
TYPENAME: typeName
},
autoLoad: true,
listeners: {
"load": function() {
callback.call(scope, schema);
},
"exception": function(data) {
Ext.MessageBox.show({
title: this.errorTitle,
msg: this.wfsDescribeFeatureTypeError + " " + typeName,
buttons: Ext.Msg.OK,
animEl: 'elId',
icon: Ext.MessageBox.ERROR
});
},
scope: this
}
});
this.schemaCache[typeName] = schema;
}
} else {
callback.call(scope, false);
}
}, this);
},
/** api: method[getConfigForRecord]
* :arg record: :class:`GeoExt.data.LayerRecord`
* :returns: ``Object``
*
* Create a config object that can be used to recreate the given record.
*/
getConfigForRecord: function(record) {
var config = gxp.plugins.WMSSource.superclass.getConfigForRecord.apply(this, arguments);
var layer = record.getLayer();
var params = layer.params;
return Ext.apply(config, {
format: params.FORMAT,
styles: params.STYLES,
transparent: params.TRANSPARENT,
//cql_filter: params.CQL_FILTER,
elevation: params.ELEVATION
});
},
/** api: method[getLayerStyle]
* :config: ``Object`` The application config for this layer.
* :returns: ``String``
*
* Return the loacalized styles parmater if defined or the default styles parmater for the layer.
*/
getLayerStyle: function (config){
var styles = null;
var locCode = GeoExt.Lang.locale;
if(config.stylesAvail instanceof Array){
if(config.stylesAvail.length > 0){
var defaultStyle = config.styles || config.stylesAvail[0].name;
for(var k=0; k<config.stylesAvail.length; k++){
var checkString = defaultStyle;
var langs = ["it","de", "en", "fr"]; // TODO: Fix this using the LanguageSelector tool.
for(var y=0; y<langs.length; y++){
if(checkString.indexOf("_" + langs[y]) != -1){
checkString = checkString.substring(0, checkString.indexOf("_" + langs[y]));
}
}
if(config.stylesAvail[k].name == checkString + "_" + locCode)
styles = config.stylesAvail[k].name;
}
if(!styles){
styles = defaultStyle;
}
}
}else{
if(config.styles){
styles = config.styles;
}
}
return styles;
/*if(config.styles && config.styles.indexOf("_") == -1){
// /////////////////////////////////////////////////////
// If I've defined a style, I have to use it if
// isnt localized (not contains the "_" character)
// /////////////////////////////////////////////////////
styles = config.styles;
}else{
// /////////////////////////////////////////////////////
// If I've not defined a style:
// - I have to get the localized style from
// capabilities.
// If I've defined a localized style:
// - MapStore assume that the localization is
// correctly defined and use this style.
// /////////////////////////////////////////////////////
var locCode = GeoExt.Lang.locale;
if(config.stylesAvail instanceof Array){
if(config.stylesAvail.length > 0){
var defaultStyle = config.styles || config.stylesAvail[0].name;
for(var k=0; k<config.stylesAvail.length; k++){
if(config.stylesAvail[k].name == defaultStyle + "_" + locCode)
styles = config.stylesAvail[k].name;
}
if(!styles){
styles = defaultStyle;
}
}
}
}
return styles;*/
/*if(config.styles){
// //////////////////////////////////////////////////
// If the config.styles contains the
// character "_" the style is already localized
// //////////////////////////////////////////////////
config.styles = config.styles.indexOf("_") == -1 ? config.styles : null;
}
var locCode = GeoExt.Lang.locale;
if(config.stylesAvail instanceof Array){
if(config.stylesAvail.length > 0){
var defaultStyle = config.styles || config.stylesAvail[0].name;
for(var k=0; k<config.stylesAvail.length; k++){
if(config.stylesAvail[k].name == defaultStyle + "_" + locCode)
styles = config.stylesAvail[k].name;
}
if(! styles){
styles = defaultStyle;
}
}
}else{
if(config.styles){
styles = config.styles;
}
}
return styles;*/
},
/** api: method[getDefaultProps]
* :arg record: :class:`GeoExt.data.LayerRecord`
* :returns: ``Object``
*
* Create a config object with the capabilities information that can be used to recreate the given record.
*/
getDefaultProps: function (record, config){
var locCode = GeoExt.Lang.locale;
var defaultProps = {
name: config.name || record.get("name"),
title: config.title || record.get("title")
};
var keywords = record.get("keywords");
var dimensions = record.get("dimensions");
var identifiers = record.get("identifiers") || undefined;
defaultProps.stylesAvail = record.get("styles");
if(dimensions) {
// ////////
// looking for time dimension
// ////////
if (dimensions.time && dimensions.time.values) {
if (dimensions.time.values.length>0) {
var time=new Object();
time.times=dimensions.time.values.join();
defaultProps = Ext.applyIf(defaultProps, time);
}
}
if (dimensions.elevation && dimensions.elevation.values) {
if (dimensions.elevation.values.length>0) {
var elevation=new Object();
elevation.elevations=dimensions.time.values.join();
defaultProps = Ext.applyIf(defaultProps, elevation);
}
}
}
if(keywords.length>0 || !this.isEmptyObject(identifiers)){
var props=new Object();
for(var k=0; k<keywords.length; k++){
var keyword = keywords[k].value || keywords[k];
if(keyword.indexOf("uuid") != -1){
props.uuid = keyword.substring(keyword.indexOf("uuid="));
props.uuid = keyword.split("=")[1];
}
// ///////////////////////////////////////////////////////////////
// Use 'enableLang' set to 'true' in order to not enable i18n
// for a specific layer
// ///////////////////////////////////////////////////////////////
if(keyword.indexOf(locCode+"=") == 0 && config.enableLang != false){
props.title = keyword.split("=")[1];
}
}
for(var identifierKey in identifiers){
if(identifierKey === locCode && identifiers.hasOwnProperty(identifierKey)) {
props.title = identifiers[identifierKey];
}
}
return Ext.applyIf(props, defaultProps);
} else {
return {};
}
},
isEmptyObject: function(obj) {
for(var prop in obj){
if(obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
}
});
Ext.preg(gxp.plugins.WMSSource.prototype.ptype, gxp.plugins.WMSSource);