[mapserver-users] Templates & JOIN object (one to many)

Ted Spradley tspradley at snoogems.com
Tue Jan 12 23:15:51 EST 2010


Ok, I pieced the tidbits of info together.  I thought I would go ahead and
post it all in one place in case anyone else is ever interested.  I don't
know what I would do with out the postings in this list.

The bottom line is that the JOIN object and the LAYER object both require a
template directive.  The
LAYER template functions only to redirect to the JOIN template.  The
redirect is done with a template tag of the format: [join_joinname] (literal
word join followed by underscore then the JOIN object name).
The tags in the JOIN template have the format: [joinname_selectitem].  Here
they are in context.


Ted Spradley wrote:
> 
> 
>     JOIN
>       NAME "building_components"
>       CONNECTION "dbname=cad1 user=user password=password host=localhost
> port=5432"
>       CONNECTIONTYPE ogr
>       TABLE "building_component_areas"
>       FROM "hcad_num"
>       TO "hcad_acct"
>       TYPE ONE-TO-MANY
>       TEMPLATE bldgCompGetFeatureInfo.html
>     END
> 
> 

The JOIN object needs its own template defined.

TEMPLATE bldgCompGetFeatureInfo_join.html

Evidently when the layer is queried the function of the LAYER TEMPLATE
directive is to say 'Hey, process
JOIN "building_components" '.


Ted Spradley wrote:
> 
> /* template bldgCompGetFeatureInfo.html */
>   /* Mapserver Template */
> 
>   
>         building_num =
> building_num.push('[building_components_building_num]');
>         building_component =
> building_component.push('[building_components_building_component]');
>         area = area.push('[building_components_area]');
> 
> 

should be:

/* template bldgCompGetFeatureInfo.html */
  /* Mapserver Template */

  [join_building_components]

and then you need the template for the JOIN object with errors corrected in
the js:

/* template bldgCompGetFeatureInfo_join.html */
  /* Mapserver Template */
  
    building_num.push('[building_components_building_num]');
    building_component.push('[building_components_building_component]');
    area.push('[building_components_area]');
  

Ted Spradley wrote:
> 
> /* template bldgCompGetFeatureInfo_footer.html */
> <!-- Mapserver Template -->
> 
>   /* Write out the table by accessing the arrays */
> 
>   document.write("
>     <table id=\"bldg_comp_areas\">
>       <tr>
>         <th colspan=\"2\">Building Details</th>
>       </tr>
>       <tr>
>         <td>Building Number</td>
>         <td>Building Component</td>
>         <td>Area</td>
>         <td>units</td>
>       </tr>"
>       );
> 
>   for(key in building_num){
>     document.write("<tr><td>" + building_num[key] + "</td><td>" + 
>         building_component[key] + "</td><td>" + area[key] + "</td><td>" +
>         "sq ft");
>         }
> 
>   document.write("
>     </table>
>     <br />
>     ");
> 

should be:

  /* Write out the table by accessing the arrays */

  document.write("<table id='bldg_comp_areas'><tr><th colspan='4'>Building
Details</th></tr><tr><td>Building Number</td><td>Building
Component</td><td>Area</td><td>units</td></tr>");
  
  for(key in building_num){
  document.write("<tr><td>" + building_num[key] + "</td><td>" + 
      building_component[key] + "</td><td>" + area[key] + "</td><td>" +
        "sq ft" + "</td></tr>");
        }
  document.write("</table><br />");

 </script>    

The result is a table listing all of the building components.

Building Details
Building Number	Building Component	Area	units
1	ONE STORY MAS UPR	24	sq ft
1	OPEN MAS PORCH PRI	24	sq ft
1	BASE AREA PRI	1164	sq ft
1	MAS/BRK GARAGE PRI	400	sq ft
1	OPEN MAS PORCH PRI	16	sq ft
1	BASE AREA UPR	1164	sq ft
1	ONE STORY FRAME PRI	60	sq ft
1	ONE STORY MAS UPR	400	sq ft
1	OPEN MAS PORCH PRI	31	sq ft

This will work using GetFeatureInfo in the URL, but if you are accessing
your WMS with OpenLayers, you are already in a javascript, so you need to
use straight html in your templates.

/* template bldgCompGetFeatureInfo_header.html */

<!-- Mapserver Template -->
<!-- No javascript, must be straight html to handle output -->
<table>
  <tr>
    <td colspan="4">Building Details</td>
  </tr>
  <tr>
    <td>Building Number</td>
    <td>Building Component</td>
    <td>Area</td>
    <td>Units</td>
  </tr>

/* template bldgCompGetFeatureInfo.html */
<!-- Mapserver Template -->

  [join_building_components]

/* template bldgCompGetFeatureInfo_join.html */
<!-- Mapserver Template -->
  <tr>
    <td>[building_components_building_num]</td>
    <td>[building_components_building_component]</td>
    <td>[building_components_area]</td>
    <td>sq ft</td>
  </tr>
 
/* template bldgCompGetFeatureInfo_footer.html */
<!-- Mapserver Template -->

</table>

Cheers everybody! Hope it helps someone.


-----
Gracias a todo!
Ted S

MapServer version 5.4.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP
OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=ICONV
SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER
SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=THREADS INPUT=EPPL7
INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE 

Linux/Fedora7
-- 
View this message in context: http://n2.nabble.com/Templates-JOIN-object-one-to-many-tp4293738p4306948.html
Sent from the Mapserver - User mailing list archive at Nabble.com.


More information about the mapserver-users mailing list