[OpenLayers-Users] Difficulties with GetFeatureInfo

Eric Lemoine eric.c2c at gmail.com
Tue Jul 8 16:41:21 EDT 2008


Hi. Have you tried using OpenLayers.Format.GML for de-serializing the
response text into feature objects? Eric

2008/7/8, Rick Wayne <fewayne at wisc.edu>:
> Hullo all,
>
> I'm using OpenLayers and GeoServer, and am having some trouble with
> getting XML data out of GetFeatureInfo. If I ask GeoServer for
> INFO_FORMAT of application/vnd.ogc.gml, I get a response back, and it
> has the data I desire. But I cannot access those data as XML. I have
> to get them via responseText and parse that looking for angle brackets
> and the like, which is all very boring, not to say fragile as a dried
> leaf.
>
> Of course, I should be able to make use of the responseXML property,
> but that obstinately persists in being NULL, even when the text
> response is fine. In fact, the text response is perfectly good XML. As
> a big honkin' string.
>
> I'm using GeoServer 1.5.3 and, er, whichever OL version came with
> that. :-)
>
> Below are the relevant calls. If anyone can assuage my ignorance, good
> cheer to them!
>
> TIA,
>
> Rick Wayne
> UW Soil Science
>
>          [...]
> 	map.events.register('click', map, function (e) {
> 		var url =  map.baseLayer.getFullRequestString({
> 			REQUEST: "GetFeatureInfo",
> 			EXCEPTIONS: "application/vnd.ogc.se_xml",
> 			BBOX: map.getExtent().toBBOX(),
> 			X: e.xy.x,
> 			Y: e.xy.y,
> 			INFO_FORMAT: 'application/vnd.ogc.gml',
> 			// INFO_FORMAT: 'text/plain',
> 			QUERY_LAYERS: map.baseLayer.params.LAYERS,
> 			FEATURE_COUNT: 1,
> 			srs: 'EPSG:26916',
> 			styles: '',
> 			layers: 'mmas:civil',
> 			WIDTH: map.size.w,
> 			HEIGHT: map.size.h},
> 			"/geoserver/wms"
> 	  );
> 		OpenLayers.loadURL(url, '', this, zoomToFeature, zoomToFeature);
> 		Event.stop(e);
> 	});
>
> function zoomToFeature(response) {
> 	// lines = response.responseText.split('\n');
> 	var txt;
> 	var tag;
> 	var coord_index;
> 	var rest;
> 	var coord_text;
> 	var coords;
> 	var coord_pairs,ll,ur;
>
> 	txt = response.responseText; // here should be xml =
> response.responseXML;
> 	tag = 'gml:coordinates decimal="." cs="," ts=" ">';
> 	coord_index = txt.indexOf(tag);
> 	rest = txt.substr(coord_index + tag.length);
> 	end_coord_index = rest.indexOf('<');
>          // And so on, too ugly to reveal the rest!
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list