[OpenLayers-Users] How to use WMSGetFeatureInfo to get features andadd it to map?

Robert Sanson SansonR at asurequality.com
Wed Apr 7 23:00:18 EDT 2010


Once you have parsed out the response from your WMS GetFeatureInfo request, you can use the result to send a WFS GetFeature request.
 
Here is a GetFeature request which uses a farmid= variable to send a where filter condition:
 
var othptsurl = "http://wfsserver/cgi-bin/agbwfs.exe?farmid="+farmid+"&request=getfeature&typename=otherpoints&service=wfs&version=1.0.0&BBOX=773500,4555450,2602100,6384050 ( 'http://wfsserver/cgi-bin/agbwfs.exe?farmid="+farmid+"&request=getfeature&typename=otherpoints&service=wfs&version=1.0.0&BBOX=773500,4555450,2602100,6384050' )";
OpenLayers.loadURL(othptsurl, '', this, othptsreturn);
 
And here is turning the response into a Vector layer:
 
var gml_format = new OpenLayers.Format.GML();
function othptsreturn(response) {
                var oFeatures = gml_format.read(response.responseText); 
                var othptsl = new OpenLayers.Layer.Vector("Other Points",
                    {isBaseLayer: false,
                    styleMap: othStyles, 
                    extractAttributes: true });
                othptsl.addFeatures(oFeatures);
                map.addLayer(othptsl);
}
regards,
 
Robert S 

>>> <ahwangyuwei at sina.com> 8/04/2010 1:50 p.m. >>>
 I'm using WMSGetFeatureInfo to get Featureinfo.
How can I get Feature from the WMSGetFeatureInfo 's response?
And add them to map?
I am imitating the Control OpenLayers.Control.WMSGetFeatureInfo ( http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Control/WMSGetFeatureInfo-js.html#OpenLayers.Control.WMSGetFeatureInfo )'s bahavior.
It's available?

 map.events.register('click', map, function (e) {
                    document.getElementById('nodelist').innerHTML = "Loading... please wait...";
                    var params = {
                        REQUEST: "GetFeatureInfo",
                        EXCEPTIONS: "application/vnd.ogc.se_xml",
                        BBOX: map.getExtent().toBBOX(),
                        X: e.xy.x,
                        Y: e.xy.y,
                        INFO_FORMAT: 'text/html',
                        QUERY_LAYERS: map.layers[0].params.LAYERS,
                        FEATURE_COUNT: 50,
                        Layers: 'CHN',
                        Styles: '',
                        Srs: 'EPSG:4326',
                        WIDTH: map.size.w,
                        HEIGHT: map.size.h,
                        format: format};
                    updateFeatureInfoFilters(params);
                    OpenLayers.loadURL("http://159.226.13.203:8080/geoserver/wms", params, this, setHTML, setHTMLx);
                    OpenLayers.Event.stop(e);
                });
            }
 var parseformat= new OpenLayers.Format.WMSGetFeatureInfo();
function setHTML(response){
       document.getElementById('nodelist').innerHTML = response.responseText;
                
             var doc = response.responseXML;
            if(!doc || !doc.documentElement) {
               doc = response.responseText;
             }
           
            var features = parseformat.read(doc);
            highlightLayer.addFeatures(features);

            
            };




Click here ( https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg== ) to report this email as spam.


This message has been scanned for malware by SurfControl plc. www.surfcontrol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100408/b1fd085a/attachment.html


More information about the Users mailing list