Project

General

Profile

1
/*
2
Author:       Cameron Shorter cameronATshorter.net
3
License:      LGPL as per: http://www.gnu.org/copyleft/lesser.html
4

    
5
$Id$
6
*/
7

    
8
// Ensure this object's dependancies are loaded.
9
mapbuilder.loadScript(baseDir+"/model/Proj.js");
10
mapbuilder.loadScript(baseDir+"/widget/MapContainerBase.js");
11

    
12
/**
13
 * Render GML point geometery into HTML.  This is a MapContainer widget.
14
 * Other Geometries could be handled if there was some way to get a point 
15
 * out of it (e.g. polygon centroid).
16
 * This widget places an image at the specified point on the map.
17
 * It also places a highlight image at the same spot and registers a 
18
 * hihglightFeature event on the model, where the featureId is set as the model param.
19
 * Models using this widget must implement getFeatureNodes(), 
20
 * @constructor
21
 * @base MapContainerBase
22
 * @param widgetNode  The widget's XML object node from the configuration document.
23
 * @param model       The model object that this widget belongs to.
24
 */
25
function GmlPointRenderer(widgetNode, model) {
26
  WidgetBase.apply(this,new Array(widgetNode, model));
27
  MapContainerBase.apply(this,new Array(widgetNode, model));
28

    
29
  this.normalImage = widgetNode.selectSingleNode("mb:normalImage").firstChild.nodeValue; 
30
  this.highlightImage = widgetNode.selectSingleNode("mb:highlightImage").firstChild.nodeValue; 
31

    
32
  this.model.addListener("refresh",this.paint, this); 
33

    
34
  /** highlights the selected feature by switching to the highlight image
35
    * @param objRef a pointer to this widget object
36
    */
37
  this.highlight = function(objRef, featureId) {
38
    var normalImageDiv = document.getElementById(featureId+"_normal");
39
    normalImageDiv.style.visibility = "hidden";
40
    var highlightImageDiv = document.getElementById(featureId+"_highlight");
41
    highlightImageDiv.style.visibility = "visible";
42
  }
43
  this.model.addListener("highlightFeature",this.highlight, this);
44

    
45
  /** highlights the selected feature by switching to the highlight image
46
    * @param objRef a pointer to this widget object
47
    */
48
  this.dehighlight = function(objRef, featureId) {
49
    var normalImageDiv = document.getElementById(featureId+"_normal");
50
    normalImageDiv.style.visibility = "visible";
51
    var highlightImageDiv = document.getElementById(featureId+"_highlight");
52
    highlightImageDiv.style.visibility = "hidden";
53
  }
54
  
55
  /** Clears all the divs
56
    *
57
    */
58
  this.clearFeatures = function() {
59
  
60
    var features = this.model.getFeatureNodes();
61
    for (var i=0; i<features.length; ++i) {
62
        var feature = features[i];
63
        var itemId = this.model.getFeatureId(feature);   //or feature id's for feature collections?
64
        var normalImageDiv = document.getElementById(itemId+"_normal");
65
        var highlightImageDiv = document.getElementById(itemId+"_highlight");
66
        
67
        if( normalImageDiv )
68
          this.node.removeChild( normalImageDiv );
69
          
70
        if( highlightImageDiv)
71
          this.node.removeChild( highlightImageDiv );
72
    }
73
    
74
  }
75
  
76
  this.model.addListener("dehighlightFeature",this.dehighlight, this);
77

    
78
}
79

    
80
 
81
  
82
  /** draw the points by putting the image at the point
83
    * @param objRef a pointer to this widget object
84
    */
85
  GmlPointRenderer.prototype.paint = function(objRef) {
86
   
87
    if (objRef.model.doc && objRef.node && objRef.containerModel.doc ) {
88
      var containerProj = new Proj(objRef.containerModel.getSRS());
89
      
90
      // Does not work for some reason
91
      objRef.clearFeatures();
92
      
93
      var features = objRef.model.getFeatureNodes();
94
      for (var i=0; i<features.length; ++i) {
95
        var feature = features[i];
96
        var title = objRef.model.getFeatureName(feature);
97
        var itemId = objRef.model.getFeatureId(feature);   //or feature id's for feature collections?
98
        var point = objRef.model.getFeaturePoint(feature);
99
        point = containerProj.Forward(point);
100
        point = objRef.containerModel.extent.getPL(point);
101

    
102
        var normalImageDiv = document.getElementById(itemId+"_normal");
103
        var highlightImageDiv = document.getElementById(itemId+"_highlight");
104
        if (!normalImageDiv) {
105
          //add in the normalImage
106
          normalImageDiv = document.createElement("DIV");
107
          normalImageDiv.setAttribute("id",itemId+"_normal");
108
          normalImageDiv.style.position = "absolute";
109
          normalImageDiv.style.visibility = "visible";
110
          normalImageDiv.style.zIndex = 300;
111
          var newImage = document.createElement("IMG");
112
          newImage.src = config.skinDir+objRef.normalImage;
113
          newImage.title = title;
114
          normalImageDiv.appendChild(newImage);
115
          objRef.node.appendChild( normalImageDiv );
116

    
117
          //add in the highlightImage
118
          highlightImageDiv = document.createElement("DIV");
119
          highlightImageDiv.setAttribute("id",itemId+"_highlight");
120
          highlightImageDiv.style.position = "absolute";
121
          highlightImageDiv.style.visibility = "hidden";
122
          highlightImageDiv.style.zIndex = 301;   //all highlight images are on top of others
123
          var newImage = document.createElement("IMG");
124
          newImage.src = config.skinDir+objRef.highlightImage;
125
          newImage.title = title;
126
          highlightImageDiv.appendChild(newImage);
127
          objRef.node.appendChild( highlightImageDiv );
128
        }
129

    
130
        normalImageDiv.style.left = point[0];
131
        normalImageDiv.style.top = point[1];
132
        highlightImageDiv.style.left = point[0];
133
        highlightImageDiv.style.top = point[1];
134
      }
135
    }
136
  }
137

    
138
 
(44-44/145)