2

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);
        }
    }
9
  • I specifically said don't double click on the html file - it is running from file://... and not localhost... so it is cross domain and you are back to needing a proxy.
    – Ian Turton
    Dec 6, 2012 at 14:54
  • I apologize, I did see that you said not to double click on it, I just did not fully understand what the reasoning was behind that. I am now running the map on localhost, but unfortunately the WFS points still aren't showing up. I am receiving the following error in firebug: uncaught exception: [Exception... "Component returned failure code: 0x805e0006 [nsIXMLHttpRequest.open]" nsresult: "0x805e0006 (<unknown>)" location: "JS frame :: localhost:8080/geoserver/www/openlayers/OpenLayers.js :: <TOP_LEVEL> :: line 747" data: no]
    – robc89
    Dec 6, 2012 at 15:08
  • did you copy the OpenLayers.js file in to the www folder? and change the reference to it in the html file?
    – Ian Turton
    Dec 6, 2012 at 15:14
  • Yes, GeoServer provides an OpenLayers.js file but it is outdated so I copied in my own and changed the reference in the html file.
    – robc89
    Dec 6, 2012 at 15:30
  • and you put the new version in www/openlayers/OpenLayers.js? Also was it the full version (or might bits be missing?)?
    – Ian Turton
    Dec 6, 2012 at 15:34

3 Answers 3

3

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

1

might want to look into wamp, lamp, or mamp depending on what your OS is. Depending on what OS it is might want to look at services in Windows as well as turning off the firewall.

4
  • I am working on Windows 7.
    – robc89
    Dec 5, 2012 at 20:27
  • in that case make you will need to run geoserver on apache server locally. So make sure the firewall is turned off. Depending on certain circumstances possibly need to go into the etc folder and change the host file or consider using 127.0.0.1 as oppopsed to localhost. Make sure to check services to make sure no network issues occur. Dec 5, 2012 at 20:29
  • Depending on what kind of browser you are using consider looking at the network traffic from the openlayers map and check whether requests are served correctly from geoserver. Make sure the requests are done correctly in openlayers js files based on geoserver's layer preview metadata. Dec 5, 2012 at 20:32
  • I am using Firefox, and I've installed the Firebug plugin because I've seen that a lot of people recommend it. However, I have no idea how to check if the requests are done correctly. Is Firebug the tool I should be using?
    – robc89
    Dec 6, 2012 at 14:47
1

EDIT: Check out iant's answer and go for it.

You run Geoserver by Jetty web server in port 8080, and Apache (with proxy.cgi) on port 80. So far, did you opened your application directly from disk (ie with URL like file:///C:/foo.html), without Web server?

In order to use proxy.cgi, you have to copy your application to Apache html folder () and open it through http URL (ie localhost:80/foo.html). Then, both your application HTML page and proxy executable are on same host and on same port.

I've never used proxy.cgi myself. It is python application, and I'm not sure, if default installation of Apache for Windows includes python support. Maybe you have to install python additionally.

Also, you are using local tiles - how do you access them? If you move your application from file:/// to html:// you can't access files directly on you local disk anymore, and you have to move tiles under web server.

Final idea - check out, maybe it's possible to serve your application by same Jetty web server, that serves Geoserver? Sorry, I don't know answer myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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