Project

General

Profile

1
/*
2
Author:  Patrice G. Cappelaere patATcappelaere.com
3
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
4
$Id$
5
*/
6
 
7

    
8
/**
9
  * Point Feature Factory
10
  * @param widgetNode  The widget's XML object node from the configuration document.
11
  * @param model       The model object that this widget belongs to.
12
  */
13
function FeaturePointFactory(widgetNode, model) {
14
  // initialize from model
15
  this.normalImage = widgetNode.selectSingleNode("mb:normalImage").firstChild.nodeValue; 
16
  this.highlightImage = widgetNode.selectSingleNode("mb:highlightImage").firstChild.nodeValue;
17
}
18

    
19
/**
20
  * Clear all created features
21
  */
22
FeaturePointFactory.prototype.clearPointFeatures = function( ) {
23
  // we need to clear all the div's first
24
  var divs = document.getElementsByTagName("div");
25
  for (var i= divs.length-1; i>= 0; i--) {
26
    var div = divs[i];
27
    if( div.id.indexOf("RSS_Item") > -1 ) {
28
        var img = divs[i].firstChild;
29
        img.onmouseover = null;
30
        img.onmouseout = null;
31
        divs[i].parentNode.removeChild( divs[i] );
32
    }
33
  }
34
}
35

    
36
/**
37
  * Create Point Feature
38
  * 
39
  * @param objRef a pointer to this widget object
40
  * @param geometry array of necessary coordinates for that type of geometry
41
  * @param itemId feature Id
42
  * @param title title of feature
43
  * @param papupStr popup to display on mouseover
44
  */
45
FeaturePointFactory.prototype.createPointFeature = function( objRef, geometry, itemId, title, popupStr ) {
46
  //add in the normalImage
47
  var normalImageDiv = document.createElement("DIV");
48
  normalImageDiv.setAttribute("id",itemId+"_normal");
49
  normalImageDiv.style.position = "absolute";
50
  normalImageDiv.style.visibility = "visible";
51
  normalImageDiv.style.zIndex = 300;
52
          
53
  var newImage = document.createElement("IMG");
54
  newImage.src = config.skinDir+ this.normalImage;
55
  newImage.title = title;
56
 
57
  normalImageDiv.appendChild(newImage);
58
  objRef.node.appendChild( normalImageDiv );
59
 
60
  // install handlers
61
  this.install( newImage, itemId, popupStr );
62
                     
63
  //add in the highlightImage
64
  var highlightImageDiv = document.createElement("DIV");
65
  highlightImageDiv.setAttribute("id",itemId+"_highlight");
66
  highlightImageDiv.style.position = "absolute";
67
  highlightImageDiv.style.visibility = "hidden";
68
  highlightImageDiv.style.zIndex = 301;   //all highlight images are on top of others
69
  var newImage = document.createElement("IMG");
70
  newImage.src = config.skinDir+ this.highlightImage;
71
  newImage.title = title;
72
  highlightImageDiv.appendChild(newImage);
73
  objRef.node.appendChild( highlightImageDiv );
74
  
75
  normalImageDiv.style.left = geometry[0];
76
  normalImageDiv.style.top = geometry[1];
77
  highlightImageDiv.style.left = geometry[0];
78
  highlightImageDiv.style.top = geometry[1];
79
}
80

    
81
/**
82
  * MouseOver Handler
83
  *
84
  * Note: "This" points to the feature
85
  */
86
FeaturePointFactory.prototype.mouseOverHandler = function(ev) {    
87
  // get the enclosing div to get the current position
88
  var normalImageDiv = document.getElementById(this.itemId+"_normal");
89
  var topPx = new String(normalImageDiv.style.top);
90
  var leftPx = new String(normalImageDiv.style.left);
91
  var offx = normalImageDiv.offsetParent.offsetLeft;
92
  var offy = normalImageDiv.offsetParent.offsetTop;
93
  var top = parseInt(topPx.replace("px","")) + 20 + offy;
94
  var left = parseInt(leftPx.replace("px","")) + 20 + offx;
95

    
96
      
97
  // hilite the marker
98
  normalImageDiv.style.visibility = "hidden";
99
  var highlightImageDiv = document.getElementById(this.itemId+"_highlight");
100
  highlightImageDiv.style.visibility = "visible";
101
    
102
  // set the popup text with stylesheet output
103
  var popupStr = this.overlib;
104
  if( popupStr == undefined ) {
105
    popupStr = "Feature under construction.  Stay tuned!";
106
  }
107

    
108
  overlib( popupStr, WIDTH, 50, STICKY, FIXX, left, FIXY, top, CAPTION, 'Caption');
109
  return true;
110
}
111
  
112
/*
113
 * Mouseout handler
114
 */
115
FeaturePointFactory.prototype.mouseOutHandler = function(ev) {
116
  var highlightImageDiv = document.getElementById(this.itemId+"_highlight");
117
  highlightImageDiv.style.visibility = "hidden";
118
  var normalImageDiv = document.getElementById(this.itemId+"_normal");
119
  normalImageDiv.style.visibility = "visible";
120
  return nd();
121
}
122

    
123
/**
124
  * install mouse handlers and params in div element
125
  * 
126
  */
127
FeaturePointFactory.prototype.install = function( feature, itemId, popupStr ) {
128
  feature.itemId = itemId;
129
  feature.overlib = popupStr;
130
      
131
  feature.onmouseover = this.mouseOverHandler; 
132
  feature.onmouseout  = this.mouseOutHandler;
133
}
(2-2/15)