[OpenLayers-Users] How can I show a picture a popup (URL for the pic should be read automatically from the attributes)

Max Stephan x.zam at gmx.net
Wed Feb 4 07:24:02 EST 2009


Hey Ivan,

Yes, I checked out this your link. But I don´t have success in transferring
it to my own document. Here is what I got yet:

=> I perform a GetFeatureInfo-Request on
"http://localhost:8080/geoserver/wms" with INFO_FORMAT: 
'application/vnd.ogc.gml'.

=> this is done via
OpenLayers.loadURL("http://localhost:8080/geoserver/wms", params, this,
setHTML, setHTML);

=> my setHTML-function now looks like that:

function setHTML(response){
var g = new OpenLayers.Format.XML();
var features = g.read(response.responseText);
var url = g.getAttributeNS(features.documentElement, 
'http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation');

document.getElementById('nodelist').innerHTML=response.responseText;
document.getElementById('urlOutput').innerHTML=url;}


In this case it puts out the schemalocation in the urlOutput. But that´s not
what I want to achieve. So the question is, how can i get other elements out
of the XML like the ID for example.

For that I have to competely understand what all those methods do which is
not the case yet ;-). For example the read-method: does it read the content
of an XML-File node by node? Or the getAttributeNS-method: What does
features.documentElement (= the node) mean and why am I not able to refer to
another name than 'schemalocation' (when I try url, which is an attribute in
my layer it returns no result).

thanks for your help
Max Stephan



Ivan Grcic-2 wrote:
> 
> Hi, did you check out http://openlayers.org/dev/examples/GMLParser.html
> 
> Function load takes ur xml data (which can be getFeatureInfo), and
> gives it to parseData function, which parses all the features and
> their attributes...its all you need ;)
> And i suggest to make it in JSON format, its much lighter
> 
>         function load() {
>             OpenLayers.loadURL("gml/owls.xml", "", null, parseData);
>         }
> 
>         function parseData(req) {
>           g =  new OpenLayers.Format.GML();
>           html = ""
>           features = g.read(req.responseText);
>           for(var feat in features) {
>             html += "Feature: Geometry: "+ features[feat].geometry+",";
>                 html += "<ul>";
>             for (var j in features[feat].attributes) {
>                 html += "<li>"+j+":"+features[feat].attributes[j]+"</li>";
>             }
>                 html += "</ul>"
>           }
>           document.getElementById('output').innerHTML = html;
>         }
> 
> Cheers
> 
> On Tue, Feb 3, 2009 at 9:09 PM, Max Stephan <x.zam at gmx.net> wrote:
>>
>> Ok, that sounds like an idea.
>>
>> I´ve been reading a bit more about JavaScript-development in general. So
>> I
>> developed the following change in the setHTML-function that allows me to
>> show a picture when the function is executed.
>>
>>>>>
>>
>>
>> function setHTML(response){
>> var img = document.createElement("img");
>> img.setAttribute("src", "qu18_2.jpg");
>> document.getElementById('nodelist').innerHTML=response.responseText;
>> document.getElementById('pic-container').replaceChild(img,document.getElementById('pic-container').lastChild);}
>>
>>
>> This works fine for a predefined pic. But how can I get the specific
>> attribute that contains the URL out of the getFeatureRequest-response. So
>> what I´m searching for is something like "response.getContent[5]"
>> (fictional
>> code ;-)).
>>
>> So, as you see, by now it´s a bit abstract to me what I exactly get back
>> from this getFeatureRequest and how I can get further informations out of
>> it...
>>
>> Thank you for your help Ivan and Till and thanks to everyone else in
>> advance
>> Max Stephan
>>
>>
>>
>> Till Adams wrote:
>>>
>>> Max,
>>>
>>> in general you need to define your output format which comes back from
>>> Geoserver as text or Xml or whatever - then you may parse the backcoming
>>> stuff and put the URL in an html image tag - basically you can see what
>>> to
>>> do regarding the OL featureinfo example::
>>> you must do alter it at the place when you receive the result from your
>>> WMS
>>> back and before you put it this in the result-div in your client -
>>> you'll
>>> have to parse it and rewrite it to html, alternatively you may define a
>>> template for your WMS which gives the results back in Html, so you can
>>> do
>>> sth like:
>>>
>>> <html>
>>> ...
>>>  [URL]
>>> ...
>>>
>>> Where [URL] will be filled by your WMS server - this is mainly the
>>> proceeding I know from UMN mapserver.
>>>
>>> Just some ideas - regards, Till
>>>
>>>
>>> "Max Stephan" <x.zam at gmx.net> schrieb:
>>>> Hey everybody!
>>>>
>>>> I got a shapefile here which I added to my geoserver. I have integrated
>>>> it
>>>> as a layer in an openlayers map container. In the attributes of the
>>>> layer/shapefile is a field which contains an URL to a pic of each
>>>> feature
>>>> (in this case the features are points). Now I want this picture to be
>>>> displayed in a popup (like it can be done in a marker layer). But I
>>>> want
>>> to
>>>> have the URL automatically read from the attributes of the feature I´m
>>>> clicking on. It would be great to see some of the other attributes read
>>> from
>>>> the feature as well. The problem is I don´t know that much about the
>>>> OpenLayers-API. I only know how to write a GetFeatureRequest but this
>>> would
>>>> show me only the attribute table. If it´s too difficult to show a
>>>> picture
>>>> which´s URL is in the attributes it would be even enough if the URL in
>>>> the
>>>> attribute table (the one I get from the GetFeatureRequest) would be
>>>> clickable.
>>>>
>>>> Greets and thanks for your help in advance Max Stephan
>>>>
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at openlayers.org
>>>> http://openlayers.org/mailman/listinfo/users
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/How-can-I-show-a-picture-a-popup-%28URL-for-the-pic-should-be-read-automatically-from-the-attributes%29-tp2262546p2265382.html
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
> 
> 
> 
> -- 
> Ivan Grcic
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/How-can-I-show-a-picture-a-popup-%28URL-for-the-pic-should-be-read-automatically-from-the-attributes%29-tp2262546p2268463.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list