[Users] control which fields are displayed in my Geoext popups
Matt Priour
mpriour at kestrelcomputer.com
Thu Jul 21 16:04:25 CEST 2011
Unless you have some crazy old version of Geoserver, you do NOT need to create a template on the server side. Just make the infoformat parameter “JSON” to get back GeoJSON rather than text/html.
I’ve accomplished what you are trying to do on several projects. Keep in mind that the GeoExt popup inherits from Ext.Window so you should configure the contents just as you would for that.
What I do is:
1. create XTemplates, either in hidden markup or in a separate js file
2. key the templates by the featureType (either as the div id or as a javascript object key)
3. apply the appropriate template for each feature returned
4. create a GeoExt popup with the HTML created in step 3 inserted in the correct place
So your GFI handler would be something like this:
> getfeatureinfo: function(e) {
if(e.features && e.features.length){
var results = {};
//Loop through the different features, apply templates, and store results in a featureType keyed object
Ext.each(e.features,function(feat){
var type = feat.fid.split(‘.’)[0];
if(!results[type]){results[type]=[]}
results[type].push(MyTemplates[type].apply(feat.attributes));
});
var popItems = [];
//Loop through returned featureTypes and create a panel for each one to put into the
//popup’s accordion layout
Ext.iterate(results,function(ftype,vals){
var panel = {
title:ftype,
html:’<div>’+vals.join(‘</div><div>’)+’</div>’,
width:400}
popItems.push(panel)
});
> new GeoExt.Popup({
> title: "Position:
> "+mappanel.map.getLonLatFromPixel(e.xy).transform(epsg900913, epsg4326),
> width: 400,
> autoHeight: true,
> layout: 'accordion',
> bodyStyle: 'background-color:#FFF;,font-size:14px;',
> autoScroll: true,
> maximizable: true,
> map: mappanel.map,
> lonlat: mappanel.map.getLonLatFromPixel(e.xy),
> unpinnable:true,
> anchored: true,
> shadow: true,
items:popItems,
> listeners: {
> close: function() {
> // closing a popup destroys it, but our reference
> is
> truthy
> popup = null;
> }
> }
> }).show();
> }
I wrote this on the fly, so beware of typos and not quite complete logic, but that should at least get you started on the right path
Matt Priour
Kestrel Computer Consulting
From: Hugo
Sent: Thursday, July 21, 2011 6:19 AM
To: Robert Buckley
Cc: users at geoext.org
Subject: Re: [Users] control which fields are displayed in my Geoext popups
Hi Robert,
What you can do in fact is:
- Make a geoserver template that will return your data in JSON format
- Then, process the data as you wish on the client side (this is, using GeoExt)
Below you can find an example of content.ftl that is returning the data in JSON format.
[{
<#assign i = 0 />
<#list type.attributes as attribute>
<#if (i >= 0) && (!attribute.isGeometry)>
"${attribute.name}":
<#list features as feature>
<#assign k = 0 />
<#list feature.attributes as attribute>
<#if (k = i) && (!attribute.isGeometry)>
"${attribute.value}"
</#if>
<#assign k = k+1 />
</#list>
<#if attribute_has_next>
,
</#if>
</#list>
</#if>
<#assign i = i+1 />
</#list>
}]
hope this helps.
Cheers,
Hugo
On Thu, Jul 21, 2011 at 12:15 PM, Robert Buckley <robertdbuckley at yahoo.com> wrote:
Hi,
Standard format... text/html as defined in the Parameter tab in Firebug.
I have read that if the format is changed, then the attributes can be manipulated ie fields can be left out. I haven´t seen any code fór it though.
I have tried with the content.ftl file in the geoserver workspaces, but the results are pretty grim! I would rather do it in javascript so that everything is kept in my app and not spread around different applications.
yours,
Rob
------------------------------------------------------------------------------
Von: "dan at inlet.geol.sc.edu" <dan at inlet.geol.sc.edu>
An: Robert Buckley <robertdbuckley at yahoo.com>
CC: users at geoext.org
Gesendet: Donnerstag, den 21. Juli 2011, 12:24:24 Uhr
Betreff: Re: [Users] control which fields are displayed in my Geoext popups
What is the format of the data coming back from the WMSGetFeatureInfo?
> Hi,
>
> I would like to do the following and after several hours of trying and
> googling
> will have to admit that I haven´t got far.
>
> I want to ...
>
> 1. Restrict the fields displayed in my popup window so that I can control
> which
> fields are displayed. I don´t want to show fid, objectid etc
>
> 2. Ideally I would like to use the accordion layout for when there is more
> than
> one queryable layer, but I can´t find any code to implement this. I have
> seen it
> on Bryan Mcbrides explorer, but apart from that can´t find any
> documentation.
>
> currently I have a popup designed like this...
>
>
> // create the popup
> var featureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
> queryVisible: true,
> highlightOnly: true,
> maxFeatures: 5,
> layers: [layer_wea_wms,EnMap_SG_WEA_f]
> });
>
> featureInfo.events.on({
> getfeatureinfo: function(e) {
> new GeoExt.Popup({
> title: "Position:
> "+mappanel.map.getLonLatFromPixel(e.xy).transform(epsg900913, epsg4326),
> width: 400,
> autoHeight: true,
> layout: 'accordion',
> bodyStyle: 'background-color:#FFF;,font-size:14px;',
> autoScroll: true,
> maximizable: true,
> map: mappanel.map,
> lonlat: mappanel.map.getLonLatFromPixel(e.xy),
> html:'<p style="font-size:10px;">Attributen</p><br>'+e.text,
> unpinnable:true,
> anchored: true,
> shadow: true,
> listeners: {
> close: function() {
> // closing a popup destroys it, but our reference
> is
> truthy
> popup = null;
> }
> }
> }).show();
> }
> });
>
> map.addControl(featureInfo);
> featureInfo.activate();
>
>
>
>
> thanks for any help_______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>
_______________________________________________
Users mailing list
Users at geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users
--
Hugo Martins
LabNT - ISEGI UNL
Campus de Campolide
1070-312 Lisboa
N 38°43'56.84", W 9°9'35.74"
--------------------------------------------------------------------------------
_______________________________________________
Users mailing list
Users at geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110721/f5a95b09/attachment.htm
More information about the Users
mailing list