문제

I am trying extract a single value using getfeatureinfo. i have used the exact code given by GeoServer.

                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(),
                    SERVICE: "WMS",
                    INFO_FORMAT: 'text/html',
                    QUERY_LAYERS: map.layers[0].params.LAYERS,
                    FEATURE_COUNT: 50,
                    Layers: 'Wind Speed',
                    WIDTH: map.size.w,
                    HEIGHT: map.size.h,
                    format: format,
                    s tyles: map.layers[0].params.STYLES,
                        srs: map.layers[0].params.SRS};

                    // handle the wms 1.3 vs wms 1.1 madness
                if(map.layers[0].params.VERSION == "1.3.0") {
                    params.version = "1.3.0";
                    params.j = parseInt(e.xy.x);
                    params.i = parseInt(e.xy.y);
                } else {
                    params.version = "1.1.1";
                    params.x = parseInt(e.xy.x);
                    params.y = parseInt(e.xy.y);
                }

                // merge filters
                if(map.layers[0].params.CQL_FILTER != null) {
                    params.cql_filter = map.layers[0].params.CQL_FILTER;
                } 
                if(map.layers[0].params.FILTER != null) {
                    params.filter = map.layers[0].params.FILTER;
                }
                if(map.layers[0].params.FEATUREID) {
                    params.featureid = map.layers[0].params.FEATUREID;

                }

               OpenLayers.loadURL("http://localhost:8080/geoserver/GIS/wms", params, this, setHTML, setHTML);

                OpenLayers.Event.stop(e);
            });

        }

        // sets the HTML provided into the nodelist element
        function setHTML(response){

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

        };

Now I want to retrieve a single value from response. I tried parsing. Changing COntent.ftl. But Still the code returned is in HTML Format. When I try to use response.responseXML it returns Null. It would be helpful if anybody could provide any input. Its frustating as it gives the feeling it is straightforward but still I am on it since last three days.

Thanks, Astha

도움이 되었습니까?

해결책

You can try to parse the data as JSON first in your setHTML function and then look for the attribute you need.

var data = JSON.parse(response.responseText);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top