[GIS] Proxy Issues for WFS and GeoServer – Running on Local Machine

geoserverPROXYwfs

I see that a number of similar questions have been asked, but I cannot find the answer to mine so I will be as specific as I can.

I am trying to create an OpenLayers map that can run without an internet connection. I have created my own OpenStreetMap tiles and am storing them locally on my hard drive. I have also downloaded local copies of the OpenLayers.js and OpenStreetMap.js files, etc. The basic map functionality is all working.

I am now trying to plot a number of latitude/longitude points on the map. These points are stored in a PostGIS database, and I have loaded them into a layer in GeoServer. I am attempting to create a WFS layer in my OpenLayers map that will plot the data from the GeoServer layer, but as of right now the points are just not showing up on the map. I understand from previous questions that I probably have to deal with Access-Control-Allow-Origin. I have installed Apache Server, downloaded and modified the proxy.cgi file to allow 'localhost' and 'localhost:8080', and placed the proxy.cgi file in the cgi-bin directory. My question is:

Do I need to use Apache Server if I am trying to run this all locally? I have not yet been able to get this to work and I imagine it is because I don't know what I am doing with Apache.

I appreciate any suggestions you may have.

Thanks,

-Rob

EDIT *

Thanks for the suggestions!

iant, I have successfully moved everything into the GeoServer www directory, and I can open my map by double-clicking on the .html file. Strangely enough, I get a 404 NOT_FOUND error when I try to use a url like the one you posted.

Unfortunately, my WFS layer still won't show up. In GeoServer, I have the following settings:
– Workspace Name: MyWorkspace
– Workspace URI: myworkspaceuri
– Layer Name: testpoints
– Native SRS: EPSG:4326

I am including my code below:

// Start position for the map (hardcoded here for simplicity)
    var lat=42.3583;
    var lon=-71.0603;
    var zoom=10;

    var map; //complex object of type OpenLayers.Map

    //Initialise the 'map' object
    function init() {

        // allow testing of specific renderers via "?renderer=Canvas", etc
        var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
        renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;

        map = new OpenLayers.Map ("map", {
            controls:[
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.ScaleLine({geodesic: true}),
                new OpenLayers.Control.Permalink('permalink'),
                new OpenLayers.Control.MousePosition(),                    
                new OpenLayers.Control.Attribution()],

            maxExtent: new OpenLayers.Bounds(-8182919, 5035362.5, -7784059.5, 5304535),
            maxResolution: 700,
            numZoomLevels: 18,
            units: 'm',
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326"),

            layers: [new OpenLayers.Layer.OSM(
                        "Local Tiles", 
                        "openlayers/tiles/${z}/${x}/${y}.png", 
                        {numZoomLevels: 18, 
                        alpha: true, 
                        isBaseLayer: true,
                        //tileOptions: {crossOriginKeyword: null}
                        }
                    ),

                    new OpenLayers.Layer.Vector("Points", {
                        strategies: [new OpenLayers.Strategy.BBOX()],
                        protocol: new OpenLayers.Protocol.WFS({
                            version: "1.1.0",
                            url: "localhost:8080/geoserver/wfs",
                            srsName: "EPSG:4326",
                            featureNS: "localhost:8080/workspaceuri",
                            featurePrefix: "MyWorkspace",
                            featureType: "testpoints"
                        }),
                        renderers: renderer 
                    })

                ]


        } );


            var switcherControl = new OpenLayers.Control.LayerSwitcher();
            map.addControl(switcherControl);
            switcherControl.maximizeControl();

        if( ! map.getCenter() ){
            var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            map.setCenter (lonLat, zoom);
        }
    }

Best Answer

Place your html files (and OpenLayers.js etc) in the www directory of your GeoServer data directory. You will not then need a proxy as your map page and WFS data will be coming from the same machine and port.

For what you are doing there is no need to run Apache.

The only other problem you may see is if you just double click on the html file in explorer to open it instead of typing http:// localhost :8080/geoserver/web/mypage.html (without the spaces) into the browser