Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I was advised in a previous post to ask this question again using a small data sample

My base layer is a postgis vector dataset in WGS84

When I click on the map I get the following an error in the nodelist could somebody help part of the error is here

        X and Y incorrectly specified Details:
        org.geoserver.platform.ServiceException: X and Y incorrectly specified at org.geoserver.wms.featureinfo.GetFeatureInfoKvpReader.read(GetFeatureInf
        oKvpReader.java:162) at
        org.geoserver.ows.Dispatcher.parseRequestKVP(Dispatcher.java:1230) at
        org.geoserver.ows.Dispatcher.dispatch(Dispatcher.java:488) at
        org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:231)
        at
        org.springframework.web.servlet.mvc.AbstractController.handleRequest(Abs
        tractController.java:153) ava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) 

My openlayers code is generated from a perl script the code below is the result of right click View Page Source.

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
        <link rel="stylesheet" type="text/css"href="http://localhost:8080/geoserver/openlayers/theme/default/style.css"/>
        <link rel="stylesheet" type="text/css" href="http://localhost:8080/geoserver/www/scale/scalebar-fat.css"/>
        <!-- Basic CSS definitions -->
        <style type="text/css">
            /* General settings */
            body {
                font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
                font-size: small;
            }
            /* Toolbar styles */
            #toolbar {
                position: relative;
                padding-bottom: 0.5em;
                display: none;
            }

            #toolbar ul {
                list-style: none;
                padding: 0;
                margin: 0;
            }

            #toolbar ul li {
                float: left;
                padding-right: 1em;
                padding-bottom: 0.5em;
            }

            #toolbar ul li a {
                font-weight: bold;
                font-size: smaller;
                vertical-align: middle;
                color: black;
                text-decoration: none;
            }

            #toolbar ul li a:hover {
                text-decoration: underline;
            }

            #toolbar ul li * {
                vertical-align: middle;
            }

            /* The map and the location bar */
            #map {
                clear: both;
                position: relative;
                width: 600px;
                height: 600px;
                border: 1px solid black;
            }

            #wrapper {
                width: 512px;
            }

            #location {
                float: right;
            }

            #options {
                position: absolute;
                left: 13px;
                top: 7px;
                z-index: 3000;
            }

            /* Styles used by the default GetFeatureInfo output, added to make IE happy */
            table.featureInfo, table.featureInfo td, table.featureInfo th {
                border: 1px solid #ddd;
                border-collapse: collapse;
                margin: 0;
                padding: 0;
                font-size: 90%;
                padding: .2em .1em;
            }

            table.featureInfo th {
                padding: .2em .2em;
                text-transform: uppercase;
                font-weight: bold;
                background: #eee;
            }

            table.featureInfo td {
                background: #fff;
            }

            table.featureInfo tr.odd td {
                background: #eee;
            }

            table.featureInfo caption {
                text-align: left;
                font-size: 100%;
                font-weight: bold;
                text-transform: uppercase;
                padding: .2em .2em;
            }
     </style>

        </style>
    <script src="http://localhost:8080/geoserver/www/OpenLayers-2.11/OpenLayers.js"> </script>

    <script src="http://localhost:8080/geoserver/www/scale/ScaleBar.js"></script>
    <script type="text/javascript">
        var pureCoverage = false;
        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
            // make OL compute scale according to WMS spec
            OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;

        var map, scalebar;
        function createGeodesicPolygon(origin, radius, sides, rotation, projection) {

          if (projection.getCode() !== "EPSG:4326") {
          origin.transform(projection, new OpenLayers.Projection("EPSG:4326"));
          }
          var latlon = new OpenLayers.LonLat(origin.x, origin.y);

          var angle;
          var new_lonlat, geom_point;
          var points = [];

          for (var i = 0; i < sides; i++) {
          angle = (i * 360 / sides) + rotation;
          new_lonlat = OpenLayers.Util.destinationVincenty(latlon, angle, radius);
          new_lonlat.transform(newOpenLayers.Projection("EPSG:4326"), projection);
          geom_point = new OpenLayers.Geometry.Point(new_lonlat.lon,new_lonlat.lat);
          points.push(geom_point);
          }
          var ring = new OpenLayers.Geometry.LinearRing(points);
          return new OpenLayers.Geometry.Polygon([ring]);
          }

          var map = new OpenLayers.Map({
          div: "map",
          center: new OpenLayers.LonLat(0, 0),
          minResolution: "auto",
          maxResolution: "auto"
          });

        function init(){
        format = 'image/png';
         if(pureCoverage) {
            document.getElementById('filterType').disabled = true;
            document.getElementById('filter').disabled = true;
            document.getElementById('antialiasSelector').disabled = true;
            document.getElementById('updateFilterButton').disabled = true;
            document.getElementById('resetFilterButton').disabled = true;
            document.getElementById('jpeg').selected = true;
            format = "image/jpeg";
        }

            var bounds = new OpenLayers.Bounds(
                    1, 53, 3, 54
                );
                var options = {
                    controls: [],
                    //'PanZoomBar', 'Navigation', 'Scale', 'MousePosition'
                    maxExtent: bounds,
                    maxResolution: 0.00365234375,
                    projection: "EPSG:4326",
                    units: 'degrees'
                };
                map = new OpenLayers.Map('map', options);

                //

            var Base = new OpenLayers.Layer.WMS(
                "Land",
                "http://localhost:8080/geoserver/cite/wms",
                {LAYERS: 'cite:land',
                 format: 'image/png',
                 isBaseLayer: true,
                 srsName: 'EPSG:4326',
                }
            );
            map.addLayers([Base]);

            var L1234 = new OpenLayers.Layer.WMS(
                "1234",
                "http://localhost:8080/geoserver/cite/wms",
                {
                VIEWPARAMS: 'kathy:10654',
                LAYERS: 'cite:Q_Results',
                transparent: 'true',
                isBaseLayer: false
                }
            );


            var vectorLayer = new OpenLayers.Layer.Vector("myPolygonLayer",{
                styleMap: new OpenLayers.StyleMap({
                fillColor: "#33CC00",
                strokeColor: "#000000",
                strokeWidth: 1

                })
            }
            );

            var format = new OpenLayers.Format.WKT({
            'internalProjection': map.baseLayer.projection,
            'externalProjection': new OpenLayers.Projection("EPSG:4326"),
            });

            var polygonFeature= format.read("POLYGON((1.9 53.17,2.4 53.17,2.4 53.49, 1.9 53.49,1.9 53.17))");

            vectorLayer.addFeatures([polygonFeature]);

            map.addLayers([L1234,vectorLayer]);
            // build up all controls


                // build up all controls
              map.addControl(new OpenLayers.Control.PanZoomBar({
                    position: new OpenLayers.Pixel(2, 15)
                }));
                map.addControl(new OpenLayers.Control.Navigation());
                map.addControl(new OpenLayers.Control.Scale($('scale')));

                map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
                map.addControl(new openLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));


               var scalebar = new OpenLayers.Control.ScaleBar({
                div: document.getElementById("scalebar"),
                displaySystem: "metric",
                minWidth: 175,
                maxWidth: 575,
                divisions: 4,
                subdivisions: 1,
                showMinorMeasures: true,
                abbreviateLabel: true,
                singleLine: true
            });
            map.addControl(scalebar);

            map.zoomToExtent(
                new OpenLayers.Bounds(1, 53, 3, 54)
            );

                // support GetFeatureInfo
                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,
                        Viewparams: 'kathy:10654',
                        Layers: 'cite:land,cite:Q_Results',
                        WIDTH: map.size.w,
                        HEIGHT: map.size.h,
                        format: format,
                        styles: 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 = e.xy.x;
                        params.i = e.xy.y;
                    } else {
                        params.version = "1.1.1";
                        params.x = e.xy.x;
                        params.y = 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/cite/wms", params, this, setHTML, setHTML);
                    OpenLayers.Event.stop(e);
                });

        }
        // end init
                // sets the HTML provided into the nodelist element
        function setHTML(response){
            document.getElementById('nodelist').innerHTML = response.responseText;
        };


    </script>
  </head>

  <body onload="init()">
    <h3>OpenLayers PostGis Layers</h3>
    <DIV id=layerswitcher class=olControlLayerSwitcher></DIV>
    <div id="map"></div>

        <div id="wrapper">
        <div id="location">location</div>
        <div id="scale">        </div>
        <div id=scalebar></div>
    </div>
    <div id="nodelist">
    </div>
  </body>

</html>

Update New Error

The above works if suggestions by iant are used however if an additional layer is added and the veiwparams in the GetFeatureInfo are altered to incorporate this new layer an error similar to 3 layers selected but 2 veiwparams occurs when you click on the map.

Please advise

            var L5678= new OpenLayers.Layer.WMS(
                "5678",
                "http://localhost:8080/geoserver/cite/wms",
                {
                VIEWPARAMS: 'kathy:5678',
                LAYERS: 'cite:Q_Results',
                transparent: 'true',
                isBaseLayer: false
                }
            );

Viewparams: 'kathy:10654,5678',
share|improve this question
    
If you improve your acceptance rate people are more likely to help and answer your question. –  CaptDragon Apr 17 '12 at 18:00
    
OOpps Sorry I thought i Had i'll do so now –  Holly Apr 17 '12 at 18:28
    
Wow! 100% acceptance, very good! –  CaptDragon Apr 17 '12 at 19:57
add comment

2 Answers

up vote 1 down vote accepted

Have a look in firebug to see what the actual request that is sent looks like - my suspicion is that your x and y (or i an j) are being sent as reals not integers.

If so a quick fix would be to change:

params.x = e.xy.x;
params.y = e.xy.y;

to

params.x = Math.floor(e.xy.x);
params.y = Math.floor(e.xy.y);
share|improve this answer
    
Looked in firebug wasn't able to discover if X & Y was a real or integer so changed the params as per suggestion anyway and it worked. Thank you! –  Holly Apr 20 '12 at 16:24
    
Please view my update –  Holly Apr 24 '12 at 17:58
add comment

OpenLayers.loadURL is deprecated. It is not neccessary to build GetFeatureInfo request manually, use WMSGetFeatureInfo control. I've wrote post about using WMSGEtFeatureInfo in OpenLayers. Try to modify your script accordingly this post.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.