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
mapbuilder.loadScript(baseDir+"/widget/Popup.js");
12
mapbuilder.loadScript(baseDir+"/widget/FeatureFactory.js");
13

    
14
// Resource: http://www.bazon.net/mishoo/articles.epl?art_id=824
15

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

    
30
function GmlPointRenderer(widgetNode, model) {
31

    
32
  //this.normalImage = widgetNode.selectSingleNode("mb:normalImage").firstChild.nodeValue; 
33
  	//this.highlightImage = widgetNode.selectSingleNode("mb:highlightImage").firstChild.nodeValue;
34
  this.popup = new Popup( widgetNode, model );
35
  this.featureFactory = new FeatureFactory(widgetNode, model);
36
  
37
  /**
38
    * Clear all markers
39
    */
40
  this.clearWidget = function(objRef) {
41
    // call feature factory since we do not know the implementation
42
    this.featureFactory.clearFeatures();
43
  }
44
  
45
  /** draw the points by putting the image at the point
46
    * @param objRef a pointer to this widget object
47
    */
48
  this.paint = function(objRef) {
49
    
50
    // cleanup first
51
    objRef.clearWidget(objRef );
52
       	
53
    if (objRef.model.doc && objRef.node) {
54
      var containerProj = new Proj(objRef.containerModel.getSRS());
55
      var features = objRef.model.getFeatureNodes();
56
      for (var i=0; i<features.length; ++i) {
57
        var feature = features[i];
58
        var title = objRef.model.getFeatureName(feature);
59
        var itemId = objRef.model.getFeatureId(feature);   //or feature id's for feature collections?
60
        var point = objRef.model.getFeaturePoint(feature);
61
        
62
        if( (point[0] == 0) && (point[1] == 0 )) {
63
        		return;
64
        	}
65
        	
66
        point = containerProj.Forward(point);
67
        point = objRef.containerModel.extent.getPL(point);
68

    
69
        // get the popup info from stylesheet
70
        var popupStr = objRef.popup.transform( objRef.popup, feature );
71
        
72
        // create a point feature
73
        objRef.featureFactory.createFeature( objRef, 'POINT', point, itemId, title, popupStr );
74
      }
75
    }
76
  }
77
    
78
  this.stylesheet = new XslProcessor(baseDir+"/widget/Null.xsl");
79
  var base = new MapContainerBase(this,widgetNode,model);
80
 
81
  /** highlights the selected feature by switching to the highlight image
82
    * @param objRef a pointer to this widget object
83
    */
84
  this.highlight = function(objRef, featureId) {
85
    var normalImageDiv = document.getElementById(featureId+"_normal");
86
    normalImageDiv.style.visibility = "hidden";
87
    var highlightImageDiv = document.getElementById(featureId+"_highlight");
88
    highlightImageDiv.style.visibility = "visible";
89
  }
90
  this.model.addListener("highlightFeature",this.highlight, this);
91

    
92
  /** highlights the selected feature by switching to the highlight image
93
    * @param objRef a pointer to this widget object
94
    */
95
  this.dehighlight = function(objRef, featureId) {
96
    var normalImageDiv = document.getElementById(featureId+"_normal");
97
    normalImageDiv.style.visibility = "visible";
98
    var highlightImageDiv = document.getElementById(featureId+"_highlight");
99
    highlightImageDiv.style.visibility = "hidden";
100
  }
101
  this.model.addListener("dehighlightFeature",this.dehighlight, this);
102

    
103
}
104

    
(5-5/15)