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
|
//>>built
define(
"dojox/geo/openlayers/WidgetFeature", ["dojo/_base/kernel", "dojo/_base/declare", "dojo/_base/html", "dojo/_base/lang", "dojox/geo/openlayers/Feature"],
function(dojo, declare, html, lang, Feature){
/*=====
var Feature = dojox.geo.openlayers.Feature;
=====*/
return declare("dojox.geo.openlayers.WidgetFeature", Feature, {
// summary:
// Wraps a Dojo widget, provide geolocalisation of the widget and interface
// to Layer class.
// description:
// This class allows to add a widget in a `dojox.geo.openlayers.Layer`.
// Parameters are passed to the constructor. These parameters describe the widget
// and provide geo-localisation of this widget.
// parameters can be:
// * _createWidget_: Function for widget creation. Must return a `dijit._Widget`.
// * _dojoType_: The class of a widget to create;
// * _dijitId_: The digitId of an existing widget.
// * _widget_: An already created widget.
// * _width_: The width of the widget.
// * _height_: The height of the widget.
// * _longitude_: The longitude, in decimal degrees where to place the widget.
// * _latitude_: The latitude, in decimal degrees where to place the widget.
// You must define a least one widget retrieval parameter and the geo-localization parameters.
_widget : null,
_bbox : null,
constructor : function(params){
// summary:
// Constructs a new `dojox.geo.openlayers.WidgetFeature`
// params: Object
// The parameters describing the widget.
this._params = params;
},
setParameters : function(params){
// summary:
// Sets the parameters describing the widget.
// params: Object
// The parameters describing the widget.
this._params = params;
},
getParameters : function(){
// summary:
// Retreives the parameters describing the widget.
// returns: Object
// The parameters describing the widget.
return this._params;
},
_getWidget : function(){
// summary:
// Creates, if necessary the widget and returns it;
// tags:
// private
var params = this._params;
if ((this._widget == null) && (params != null)) {
var w = null;
if (typeof (params.createWidget) == "function") {
w = params.createWidget.call(this);
} else if (params.dojoType) {
dojo["require"](params.dojoType);
var c = lang.getObject(params.dojoType);
w = new c(params);
} else if (params.dijitId) {
w = dijit.byId(params.dijitId);
} else if (params.widget) {
w = params.widget;
}
if (w != null) {
this._widget = w;
if (typeof (w.startup) == "function")
w.startup();
var n = w.domNode;
if (n != null)
html.style(n, {
position : "absolute"
});
}
this._widget = w;
}
return this._widget;
},
_getWidgetWidth : function(){
// summary:
// gets the widget width
// tags:
// private
var p = this._params;
if (p.width)
return p.width;
var w = this._getWidget();
if (w)
return html.style(w.domNode, "width");
return 10;
},
_getWidgetHeight : function(){
// summary:
// gets the widget height
// tags:
// private
var p = this._params;
if (p.height)
return p.height;
var w = this._getWidget();
if (w)
return html.style(w.domNode, "height");
return 10;
},
render : function(){
// summary:
// renders the widget.
// descrption:
// Places the widget accordingly to longitude and latitude defined in parameters.
// This function is called when the center of the maps or zoom factor changes.
var layer = this.getLayer();
var widget = this._getWidget();
if (widget == null)
return;
var params = this._params;
var lon = params.longitude;
var lat = params.latitude;
var from = this.getCoordinateSystem();
var map = layer.getDojoMap();
var p = map.transformXY(lon, lat, from);
var a = this._getLocalXY(p);
var width = this._getWidgetWidth();
var height = this._getWidgetHeight();
var x = a[0] - width / 2;
var y = a[1] - height / 2;
var dom = widget.domNode;
var pa = layer.olLayer.div;
if (dom.parentNode != pa) {
if (dom.parentNode)
dom.parentNode.removeChild(dom);
pa.appendChild(dom);
}
this._updateWidgetPosition({
x : x,
y : y,
width : width,
height : height
});
},
_updateWidgetPosition : function(box){
// summary:
// Places the widget with the computed x and y values
// tags:
// private
// var box = this._params;
var w = this._widget;
var dom = w.domNode;
html.style(dom, {
position : "absolute",
left : box.x + "px",
top : box.y + "px",
width : box.width + "px",
height : box.height + "px"
});
if (w.srcNodeRef) {
html.style(w.srcNodeRef, {
position : "absolute",
left : box.x + "px",
top : box.y + "px",
width : box.width + "px",
height : box.height + "px"
});
}
if (lang.isFunction(w.resize))
w.resize({
w : box.width,
h : box.height
});
},
remove : function(){
// summary:
// removes this feature.
// description:
// Remove this feature by disconnecting the widget from the dom.
var w = this.getWidget();
if (!w)
return;
var dom = w.domNode;
if (dom.parentNode)
dom.parentNode.removeChild(dom);
}
});
});
|