Reputation: 13
I want to implement a fast and simple way to extract information from a single polygon within a large set of polygons stored in a wms-layer. I thought about doing it with getGetFeatureInfoUrl, but the problem is that I only get back the url itself.
I have to follow the link in order to get the information of the feature. As soon as I follow the link everything is in there, and by everything I mean every single attribute that is associated with the feature. However, I want to save only one attribute of that request.
Any ideas on how to do that?
Upvotes: 1
Views: 218
Reputation: 506
Assuming that I understood what you mean: I happened to have solved an issue like that a couple of days ago:
It's quite simple actually. First, I just assume that you have already written the part with the getGetFeatureInfoUrl. I recommend to have the result of your getGetFeatureInfoUrl as a json. it might work with other formats too, but I haven't tried.
Everything else is just a matter of minutes:
So this is a javascript-function that you feed the url you got from getGetFeatureInfoUrl
function httpGet(theUrl)
{ var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
Now you just copy the result of that function to a variable
var content = httpGet(theUrl);
And then you search the content-string for that one attribute you want to save.
In my case it was at the end of that string, don't know how it's done in your case. But it might end up looking pretty much like this.
var specific_attribute = content.substr(content.length-10);
specific_attribute = specific_attribute.substr(0,5);
And voila, you saved that one attribute you need to a variable.
Hope, that helped.
Upvotes: 1