0

I'm tying to develop a WMS GetFeatureInfo query using GeoExt, OpenLayers and GeoServer and I want a hyperlink to be displayed on the popup window in a specific column. I have created the service but the link is returned as plain text.

I want to modify the content of the GeoExt window's content in order to convert that field to hyperlink. I read several answers in similar questions like: OpenLayers - URL hyperlink in GetFeatureInfo table?

I succeed to convert the WMS GetFeatureInfo response to a hyperlink in GeoServer 'layer preview' template but when I use the same layer in my GeoExt app the content is plain text. Also I read a way to convert GeoExt popup content in the following thread: http://www.geoext.org/pipermail/users/2011-July/002412.html

But I feel that the solution in my case is much simpler. My code:

 var gfiControl = new OpenLayers.Control.WMSGetFeatureInfo({
            // autoActivate: true,
             drillDown: true,
             infoFormat: "application/vnd.ogc.gml",
             maxFeatures: 3,
             eventListeners: {
                "getfeatureinfo": function(e) {
                 var items = [];
                 Ext.each(e.features, function(feature) {
                    items.push({
                       xtype: "propertygrid",
                       title: feature.fid,
                       source: feature.attributes
                  });
             });
             if (items.length > 0) {
                Ext.create('GeoExt.window.Popup', {
                   title: "Feature Info",
                   width: 350,
                   height: 320,
                   layout: "accordion",
                   map: mapPanel,
                   location: e.xy,
                   items: items
                  }).show();
                 }
               }
             }
          });

Any suggestions?

UPDATE

I created a content.ftl template in my GeoServer and the direct response from GeoServer works fine. After the @nmtoken's helpful comments and more searching, I realized that the main issue is that my GeoExt code cannot parse the html response from GeoServer. My GeoExt code now looks like that:

var gfiControl = new OpenLayers.Control.WMSGetFeatureInfo({
            // autoActivate: true,
             drillDown: true,
             infoFormat: "text/html",
             maxFeatures: 3,
             eventListeners: {
                "getfeatureinfo": function(e) {
                 var items = [];
                 Ext.each(e.features, function(feature) {
                    items.push({
                       xtype: "propertygrid",
                       title: feature.fid,
                       source: feature.attributes
                  });
             });
             if (items.length > 0) {
                Ext.create('GeoExt.window.Popup', {
                  title: "Feature Info",
                   width: 350,
                   height: 320,
                   layout: "accordion",
                   map: mapPanel,
                   location: e.xy,
                   items: items
                  }).show();
                 }
               }
             }
          });

But while the ajax response has a status = 200, the popup window doesn't open. When I copy and paste the query that is sent to the server to my browser, the response is successful just like in GeoServer's 'layer preview' page. It seems like GeoExt cannot parse the response as infoFormat = text/html but only in infoFormat= "application/vnd.ogc.gml". How can I fix this ?

  • I'm developing a WMS GetFeatureInfo service not quite sure what you mean, GetFeatureInfo is not a service, it's an operation of a WMS service and goes in tandem with a GetMap operation. – nmtoken Dec 16 '17 at 17:50
  • To add the url of the request to the response, I would look at editing the GeoServer template used to create the response. – nmtoken Dec 16 '17 at 17:52
  • @nmtoken thanks for the response. I have created a GeoServer template adding a content.ftl file in GEOSERVER_DATA_DIR/workspaces/<workspace>/<datastore>/<featuretype>. It works fine when the response is directly from GeoServer (as GeoServer's "layer preview" page). But when I use the same layer in my GeoExt app the result is plain text and not a hyperlink. – Gpetr Dec 16 '17 at 18:05
  • You'll need to specify the info_format parameter as text/html – nmtoken Dec 16 '17 at 19:09
  • Do you mean to change infoFormat: "application/vnd.ogc.gml" ? Because I changed it but the result was the same. – Gpetr Dec 16 '17 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.