1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: TipWidgetOL.js 3955 2008-03-31 13:00:49Z ahocevar $
|
4
|
*/
|
5
|
|
6
|
// Ensure this object's dependancies are loaded.
|
7
|
mapbuilder.loadScript(baseDir+"/widget/TipWidgetBase.js");
|
8
|
mapbuilder.loadScript(baseDir+"/util/openlayers/OpenLayers.js");
|
9
|
|
10
|
/**
|
11
|
* Manages MapTips on the map. This widget works with models that
|
12
|
* have a FeatureSelectHandler tool.
|
13
|
* @base TipWidgetBase
|
14
|
* @author Andreas Hocevar andreas.hocevarATgmail.com
|
15
|
* @param widgetNode The tool node from the Config XML file.
|
16
|
* @param model The ButtonBar widget.
|
17
|
*/
|
18
|
function TipWidgetOL(widgetNode, model) {
|
19
|
TipWidgetBase.apply(this, new Array(widgetNode, model));
|
20
|
|
21
|
/**
|
22
|
* This method is triggered when a user clicks on a feature.
|
23
|
* @param objRef reference to this widget
|
24
|
*/
|
25
|
this.onClick = function(objRef) {
|
26
|
var evt = objRef.model.getParam("olFeatureSelect");
|
27
|
var popup = objRef.createPopup(objRef, evt, false);
|
28
|
evt.feature.layer.mbClickPopup = popup;
|
29
|
}
|
30
|
|
31
|
/**
|
32
|
* This method is triggered when the mouse is over a feature.
|
33
|
* @param objRef reference to this widget
|
34
|
*/
|
35
|
this.onMouseover = function(objRef) {
|
36
|
var evt = objRef.model.getParam("olFeatureHover");
|
37
|
// only create popup if there is no visible click popup
|
38
|
if (evt.feature && !evt.feature.layer.mbClickPopup || !evt.feature.layer.mbClickPopup.visible()) {
|
39
|
var popup = objRef.createPopup(objRef, evt, true);
|
40
|
evt.feature.layer.mbHoverPopup = popup;
|
41
|
// if the olFeatureOut event gets lost (eg during drag operation),
|
42
|
// registering this additional event will help to get rid of the
|
43
|
// popup quickly
|
44
|
popup.events.register('mouseover', popup, popup.hide);
|
45
|
}
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* This method is triggered when the mouse moves out of a feature.
|
50
|
* @param objRef reference to this widget
|
51
|
*/
|
52
|
this.onMouseout = function(objRef) {
|
53
|
var feature = objRef.model.getParam("olFeatureOut");
|
54
|
if (feature && feature.layer && feature.layer.mbHoverPopup) {
|
55
|
feature.layer.mbHoverPopup.destroy();
|
56
|
feature.layer.mbHoverPopup = null;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Creates a popup.
|
62
|
* @param objRef reference to this widget
|
63
|
* @param evt OpenLayers.Event that triggered the popup action
|
64
|
* @param hover true if the popup should be styled as a hover popup,
|
65
|
* false if it is a click popup.
|
66
|
* @return reference to the created popup
|
67
|
*/
|
68
|
this.createPopup = function(objRef, evt, hover) {
|
69
|
var feature = evt.feature;
|
70
|
// check if there is a source model linked with this feature
|
71
|
var sourceNode = objRef.model.doc.selectSingleNode("//*[@fid='"+feature.fid+"']");
|
72
|
var sourceModel = null;
|
73
|
if (sourceNode) {
|
74
|
sourceModel = sourceNode.getAttribute('sourceModel');
|
75
|
}
|
76
|
// if so, use the config from the source model
|
77
|
var widgetConfig = null;
|
78
|
if (sourceModel && config.objects[sourceModel].config && config.objects[sourceModel].config[objRef.id]) {
|
79
|
widgetConfig = config.objects[sourceModel].config[objRef.id];
|
80
|
} else {
|
81
|
widgetConfig = objRef.config;
|
82
|
}
|
83
|
widgetConfig.stylesheet.setParameter('fid', feature.fid);
|
84
|
var lonlat = feature.layer.map.getLonLatFromPixel(evt.xy);
|
85
|
var popup = new Mapbuilder.Popup(null, lonlat, new OpenLayers.Size(widgetConfig.width, widgetConfig.height),
|
86
|
new XMLSerializer().serializeToString(widgetConfig.stylesheet.transformNodeToObject(widgetConfig.model.doc)).replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),
|
87
|
null, hover == false);
|
88
|
popup.setOpacity(widgetConfig.opacity);
|
89
|
popup.setBackgroundColor(widgetConfig.backgroundColor);
|
90
|
popup.setBorder(widgetConfig.border);
|
91
|
var quadrant = feature.layer.map.getExtent().determineQuadrant(lonlat);
|
92
|
var lonOffset = quadrant.charAt(1) == 'r' ? -5 : 5;
|
93
|
var latOffset = quadrant.charAt(0) == 't' ? 5 : -5;
|
94
|
popup.anchor = { size: new OpenLayers.Size(0,0), offset: new OpenLayers.Pixel(lonOffset, latOffset)};
|
95
|
|
96
|
feature.layer.map.addPopup(popup, true);
|
97
|
return popup;
|
98
|
}
|
99
|
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Derived from OpenLayers.Popup (svn r6430) and
|
104
|
* OpenLayers.Popup.Anchored (svn r5614), this class preserves the
|
105
|
* functionality of OpenLayers.Popup.Anchored before the new style popups
|
106
|
* of http://trac.openlayers.org/ticket/926 were introduced.
|
107
|
*/
|
108
|
Mapbuilder.Popup = OpenLayers.Class(OpenLayers.Popup.Anchored, {
|
109
|
|
110
|
initialize: function(id, lonlat, size, contentHTML, anchor, closeBox,
|
111
|
closeBoxCallback) {
|
112
|
OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments);
|
113
|
this.contentDiv.style.overflow = "hidden";
|
114
|
},
|
115
|
|
116
|
setSize:function(size) {
|
117
|
if (size != undefined) {
|
118
|
this.size = size;
|
119
|
}
|
120
|
|
121
|
if (this.div != null) {
|
122
|
this.div.style.width = this.size.w + "px";
|
123
|
this.div.style.height = this.size.h + "px";
|
124
|
}
|
125
|
if (this.contentDiv != null){
|
126
|
this.contentDiv.style.width = this.size.w + "px";
|
127
|
this.contentDiv.style.height = this.size.h + "px";
|
128
|
}
|
129
|
|
130
|
if ((this.lonlat) && (this.map)) {
|
131
|
var px = this.map.getLayerPxFromLonLat(this.lonlat);
|
132
|
this.moveTo(px);
|
133
|
}
|
134
|
},
|
135
|
|
136
|
addCloseBox:function(closeBoxCallback) {
|
137
|
// close icon
|
138
|
var closeSize = new OpenLayers.Size(17,17);
|
139
|
var img = config.skinDir + "/openlayers/img/close.gif";
|
140
|
this.closeDiv = OpenLayers.Util.createAlphaImageDiv(
|
141
|
this.id + "_close", null, closeSize, img
|
142
|
);
|
143
|
this.closeDiv.style.right = this.padding + "px";
|
144
|
this.closeDiv.style.top = this.padding + "px";
|
145
|
this.groupDiv.appendChild(this.closeDiv);
|
146
|
|
147
|
var closePopup = closeBoxCallback || function(e) {
|
148
|
this.hide();
|
149
|
OpenLayers.Event.stop(e);
|
150
|
};
|
151
|
OpenLayers.Event.observe(this.closeDiv, "click",
|
152
|
OpenLayers.Function.bindAsEventListener(closePopup, this));
|
153
|
},
|
154
|
|
155
|
CLASS_NAME: "Mapbuilder.Popup"
|
156
|
});
|
157
|
|