Project

General

Profile

« Previous | Next » 

Revision 2671

Added by harris about 19 years ago

Fixed the mapbuilder getfeatureinfo function and modified the config. Now the metacat url addresses are available from the rendering.

View differences:

src/spatial/rendering/mapbuilder/lib/widget/GetFeatureInfo.js
1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
Dependancies: Context
4
$Id$
5
*/
6

  
7
// Ensure this object's dependancies are loaded.
8
mapbuilder.loadScript(baseDir+"/tool/ButtonBase.js");
9

  
10
/**
11
 * Implements WMS GetFeatureInfo functionality, popping up a query result
12
 * window when user clicks on map.
13
 * @constructor
14
 * @base ButtonBase
15
 * @author Nedjo
16
 * @constructor
17
 * @param toolNode The XML node in the Config file referencing this object.
18
 * @param model The widget object which this tool is associated with.
19
 */
20
function GetFeatureInfo(toolNode, model) {
21
  // Extend ButtonBase
22
  var base = new ButtonBase(this, toolNode, model);
23

  
24
  /** Xsl to build a GetFeatureInfo URL */
25
  this.xsl=new XslProcessor(baseDir+"/tool/GetFeatureInfo.xsl");
26
  
27
  /** Determine whether Query result is returned as HTML or GML */
28
  // TBD This should be stored in the Config file.
29
  //this.infoFormat="application/vnd.ogc.gml";
30
  this.infoFormat="text/html";
31

  
32
  /**
33
   * Open window with query info.
34
   * This function is called when user clicks map with Query tool.
35
   * @param objRef      Pointer to this GetFeatureInfo object.
36
   * @param targetNode  The node for the enclosing HTML tag for this widget.
37
   */
38

  
39
  this.doAction = function(objRef,targetNode) {
40
    if (objRef.enabled) {
41
      var selectedLayer=objRef.context.getParam("selectedLayer");
42
      if (selectedLayer==null) {
43
        alert("Query layer not selected, select a queryable layer in the Legend.");
44
      }
45
      else {
46
 //       objRef.xsl.setParameter("FORMAT", "text/html");
47
        objRef.xsl.setParameter("queryLayer", selectedLayer);
48
        objRef.xsl.setParameter("xCoord", targetNode.evpl[0]);
49
        objRef.xsl.setParameter("yCoord", targetNode.evpl[1]);
50
        objRef.xsl.setParameter("infoFormat", objRef.infoFormat);
51
        objRef.xsl.setParameter("featureCount", "1");
52

  
53
        urlNode=objRef.xsl.transformNodeToObject(objRef.context.doc);
54
        //alert(urlNode);
55
        url=urlNode.documentElement.firstChild.nodeValue;
56
        alert("GetFeatureInfo .. : \n url="+url);
57

  
58
        if (objRef.infoFormat=="text/html"){
59
          window.open(url,'queryWin','height=200,width=300,scrollbars=yes');
60
        }
61
      }
62
    }
63
  }
64

  
65
  /**
66
   * Register for mouseUp events.
67
   * @param objRef  Pointer to this object.
68
   */
69
  this.setMouseListener = function(objRef) {
70
    if (objRef.mouseHandler) {
71
      objRef.mouseHandler.model.addListener('mouseup',objRef.doAction,objRef);
72
    }
73
    objRef.context=objRef.widgetNode.selectSingleNode("mb:context");
74
    if (objRef.context){
75
      objRef.context=eval("config.objects."+objRef.context.firstChild.nodeValue);
76
    }
77
  }
78
  config.addListener( "loadModel", this.setMouseListener, this );
79
}
0 80

  
src/spatial/rendering/mapbuilder/lib/tool/GetFeatureInfo.xsl
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<!--
4
Description: parses an OGC context document to generate a GetFeatureInfo url
5
Author:      Nedjo
6
Licence:     LGPL as specified in http://www.gnu.org/copyleft/lesser.html .
7

  
8
$Id$
9
$Name$
10
-->
11
<xsl:stylesheet version="1.0" xmlns:wmc="http://www.opengis.net/context" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink">
12
  <xsl:output method="xml"/>
13
  <xsl:strip-space elements="*"/>
14

  
15
  <!-- parameters to be passed into the XSL -->
16
  <!-- The name of the WMS GetFeatureInfo layer -->
17
  <xsl:param name="queryLayer">highways</xsl:param>
18
  <xsl:param name="xCoord">1</xsl:param>
19
  <xsl:param name="yCoord">1</xsl:param>
20
  <xsl:param name="infoFormat">text/html</xsl:param>
21
  <xsl:param name="featureCount">1</xsl:param>
22

  
23
  <!-- Global variables -->
24
  <xsl:variable name="bbox">
25
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@minx"/>,<xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@miny"/>,<xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@maxx"/>,<xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@maxy"/>
26
  </xsl:variable>
27
  <xsl:variable name="width">
28
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:Window/@width"/>
29
  </xsl:variable>
30
  <xsl:variable name="height">
31
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:Window/@height"/>
32
  </xsl:variable>
33
  <xsl:variable name="srs" select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@SRS"/>
34

  
35
  <!-- Root template -->
36
  <xsl:template match="/">
37
    <url>
38
      <xsl:apply-templates select="wmc:ViewContext/wmc:LayerList"/>
39
      <error>URL not calculated for layer=<xsl:value-of select="$queryLayer"/></error>
40
    </url>
41
  </xsl:template>
42

  
43
  <!-- Layer template -->
44
  <xsl:template match="wmc:Layer">
45
    <xsl:if test="contains($queryLayer,wmc:Name)">
46
      <!-- Layer variables -->
47
      <xsl:variable name="version">
48
        <xsl:value-of select="wmc:Server/@version"/>    
49
      </xsl:variable>
50
      <xsl:variable name="baseUrl">
51
        <xsl:value-of select="wmc:Server/wmc:OnlineResource/@xlink:href"/>    
52
      </xsl:variable>
53
      <xsl:variable name="firstJoin">
54
        <xsl:choose>
55
          <xsl:when test="substring($baseUrl,string-length($baseUrl))='?'"></xsl:when>
56
          <xsl:when test="contains($baseUrl, '?')">&amp;</xsl:when> 
57
          <xsl:otherwise>?</xsl:otherwise>
58
        </xsl:choose>
59
      </xsl:variable>
60

  
61
      <!-- Print the URL -->
62
      <xsl:value-of select="$baseUrl"/><xsl:value-of select="$firstJoin"/>VERSION=<xsl:value-of select="$version"/>&amp;REQUEST=GetFeatureInfo&amp;SRS=<xsl:value-of select="$srs"/>&amp;BBOX=<xsl:value-of select="$bbox"/>&amp;WIDTH=<xsl:value-of select="$width"/>&amp;HEIGHT=<xsl:value-of select="$height"/>&amp;LAYERS=<xsl:value-of select="$queryLayer"/>&amp;FORMAT=<xsl:value-of select="$infoFormat"/>&amp;FEATURE_COUNT=<xsl:value-of select="$featureCount"/>&amp;QUERY_LAYERS=<xsl:value-of select="$queryLayer"/>&amp;X=<xsl:value-of select="$xCoord"/>&amp;Y=<xsl:value-of select="$yCoord"/>
63
    </xsl:if>
64
  </xsl:template>
65
</xsl:stylesheet>
0 66

  
src/spatial/rendering/mapbuilder/metacat.xml
18 18
      <Name>topp:metacat_testdata</Name>
19 19
      <Title>Metacat</Title>
20 20
      <SRS>EPSG:4326</SRS>
21
      <FormatList><Format current="1">image/png</Format></FormatList>
21
      <FormatList>
22
        <Format current="1">image/png</Format>
23
      </FormatList>
22 24
    </Layer>
23 25
  </LayerList>
24 26
</ViewContext>

Also available in: Unified diff