1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
Dependancies: Context
|
4
|
$Id: WfsGetFeature.js 3899 2008-03-03 10:33:30Z ahocevar $
|
5
|
*/
|
6
|
|
7
|
// Ensure this object's dependancies are loaded.
|
8
|
mapbuilder.loadScript(baseDir+"/widget/ButtonBase.js");
|
9
|
mapbuilder.loadScript(baseDir+"/util/openlayers/OpenLayers.js");
|
10
|
/**
|
11
|
* Builds then sends a WFS GetFeature GET request based on the WMC
|
12
|
* coordinates and click point.
|
13
|
* @constructor
|
14
|
* @base ButtonBase
|
15
|
* @author Cameron Shorter
|
16
|
* @param widgetNode The XML node in the Config file referencing this object.
|
17
|
* @param model The Context object which this tool is associated with.
|
18
|
*/
|
19
|
function WfsGetFeature(widgetNode, model) {
|
20
|
// Extend ButtonBase
|
21
|
ButtonBase.apply(this, new Array(widgetNode, model));
|
22
|
|
23
|
this.widgetNode = widgetNode;
|
24
|
// id of the transactionResponseModel
|
25
|
this.trm = this.getProperty("mb:transactionResponseModel");
|
26
|
this.httpPayload = new Object({
|
27
|
method: "get",
|
28
|
postData: null
|
29
|
});
|
30
|
this.typeName = this.getProperty('mb:typeName');
|
31
|
this.maxFeatures = this.getProperty('mb:maxFeatures', 1);
|
32
|
this.webServiceUrl= this.getProperty('mb:webServiceUrl');
|
33
|
this.webServiceUrl += this.webServiceUrl.indexOf("?") > -1 ? '&' : '?';
|
34
|
this.webServiceSrs= new OpenLayers.Projection(this.getProperty('mb:webServiceSrs', "EPSG:4326"));
|
35
|
|
36
|
// override default cursor by user
|
37
|
// cursor can be changed by spefying a new cursor in config file
|
38
|
this.cursor = "pointer";
|
39
|
|
40
|
this.createControl = function(objRef) {
|
41
|
var transactionResponseModel = config.objects[objRef.trm];
|
42
|
|
43
|
var Control = OpenLayers.Class( OpenLayers.Control, {
|
44
|
CLASS_NAME: 'mbControl.WfsGetFeature',
|
45
|
type: OpenLayers.Control.TYPE_TOOL, // constant from OpenLayers.Control
|
46
|
tolerance: new Number(objRef.getProperty('mb:tolerance')),
|
47
|
httpPayload: objRef.httpPayload,
|
48
|
maxFeatures: objRef.maxFeatures,
|
49
|
webServiceUrl: objRef.webServiceUrl,
|
50
|
transactionResponseModel: transactionResponseModel,
|
51
|
|
52
|
draw: function() {
|
53
|
this.handler = new OpenLayers.Handler.Box( this,
|
54
|
{done: this.selectBox}, {keyMask: this.keyMask} );
|
55
|
},
|
56
|
|
57
|
selectBox: function (position) {
|
58
|
var bounds, minXY, maxXY;
|
59
|
if (position instanceof OpenLayers.Bounds) {
|
60
|
// it's a box
|
61
|
minXY = this.map.getLonLatFromPixel(
|
62
|
new OpenLayers.Pixel(position.left, position.bottom));
|
63
|
maxXY = this.map.getLonLatFromPixel(
|
64
|
new OpenLayers.Pixel(position.right, position.top));
|
65
|
} else {
|
66
|
// it's a pixel
|
67
|
minXY = this.map.getLonLatFromPixel(
|
68
|
new OpenLayers.Pixel(position.x-this.tolerance, position.y+this.tolerance));
|
69
|
maxXY = this.map.getLonLatFromPixel(
|
70
|
new OpenLayers.Pixel(position.x+this.tolerance, position.y-this.tolerance));
|
71
|
}
|
72
|
|
73
|
bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, maxXY.lon, maxXY.lat);
|
74
|
if (this.map.projection.projCode != this.objRef.webServiceSrs.projCode) {
|
75
|
bounds.transform(this.map.projection, this.objRef.webServiceSrs);
|
76
|
}
|
77
|
|
78
|
var typeName = objRef.typeName;
|
79
|
|
80
|
if (!typeName) {
|
81
|
var queryList=objRef.targetModel.getQueryableLayers();
|
82
|
if (queryList.length==0) {
|
83
|
alert(mbGetMessage("noQueryableLayers"));
|
84
|
return;
|
85
|
}
|
86
|
else {
|
87
|
typeName = "";
|
88
|
for (var i=0; i<queryList.length; ++i) {
|
89
|
var layerNode = queryList[i];
|
90
|
|
91
|
// Get the name of the layer
|
92
|
var layerName = layerNode.selectSingleNode("wmc:Name");
|
93
|
layerName=(layerName)?getNodeValue(layerName):"";
|
94
|
|
95
|
// Get the layerId. Fallback to layerName if non-existent
|
96
|
var layerId = layerNode.getAttribute("id") || layerName;
|
97
|
|
98
|
var hidden = objRef.targetModel.getHidden(layerId);
|
99
|
if (hidden == 0) { //query only visible layers
|
100
|
if (typeName != "") {
|
101
|
typeName += ",";
|
102
|
}
|
103
|
typeName += layerName;
|
104
|
}
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
|
109
|
if (typeName=="") {
|
110
|
alert(mbGetMessage("noQueryableLayersVisible"));
|
111
|
return;
|
112
|
}
|
113
|
|
114
|
// now create request url
|
115
|
this.httpPayload.url = this.webServiceUrl+OpenLayers.Util.getParameterString({
|
116
|
SERVICE: "WFS",
|
117
|
VERSION: "1.0.0",
|
118
|
REQUEST: "GetFeature",
|
119
|
TYPENAME: typeName,
|
120
|
MAXFEATURES: this.maxFeatures,
|
121
|
BBOX: bounds.toBBOX()
|
122
|
});
|
123
|
this.transactionResponseModel.newRequest(this.transactionResponseModel, this.httpPayload);
|
124
|
}
|
125
|
});
|
126
|
return Control;
|
127
|
}
|
128
|
}
|