Hi all, I'm trying to serve a WFS layer from mapserver using openlayers. I have it working in IE7, but Firefox doesn't show the WFS layer. Now, as I understand it from other threads on this mailing list, the issue might be that I need to set up a Proxy to allow Firefox to show the WFS features. (I'm not entirely sure though, since all the layers are served/requested from the same localhost server.....?). I am no expert at server configuration, but I followed some advice from http://trac.openlayers.org/wiki/FrequentlyAskedQuestions#ProxyHost the FAQ .
When I visit http://localhost/cgi-bin/proxy.cgi http://localhost/cgi-bin/proxy.cgi , I get the openlayers site, like I'm supposed to. The WFS layer still doesn't show up in Firefox though, so maybe something is wrong with my javascript. I added the openlayers init script below. I used Firebug to log to the console. The GET request seems to work, (line 193 in openlayers.js), but I get an error: "parentnode is undefined" in line 199 of openalyers.js. It's a line with the following code: OpenLayers.Ajax.Responders.dispatch('onException',this,exception);}});OpenLayers.Ajax.Request.Events=['Uninitialized','Loading','Loaded','Interactive','Complete'];OpenLayers.Ajax.getElementsByTagNameNS=function(parentnode,nsuri,nsprefix,tagname){var elem=null;if(parentnode.getElementsByTagNameNS){elem=parentnode.getElementsByTagNameNS(nsuri,tagname);}else{elem=parentnode.getElementsByTagName(nsprefix+':'+tagname);} I don't understand the error or know a solution for it. I also tried the suggestions on http://www.imladris.com/Scripts/PythonForWindows.html this site about Python on windows . This didn't result in anything useful though. When I rename the proxy.cgi to proxy.py and add the required text to httpd.conf, I get even more errors than before. (See below for the additions I made to the httpd.conf file and the Proxy.cgi. What to do? Should the proxy be the solution to my problem? Or don't I need one and is the problem coming from elsewhere? The error I het in Firebug is the same with or without the proxy, so I think something else might be going on (or I'm not calling the proxy script correctly in the javascript.) I hope someone may be able to help me out. Please let me know if more information about my setup and code is needed. Any help will be appreciated! Best regards, Martijn Senden. The javascript of my init() function __________________________________________ function init(){ OpenLayers.ProxyHost="/cgi-bin/proxy.cgi/?url="; //Create a new OpenLayers mapwindow with associated controls var map = new OpenLayers.Map('map', { projection: "EPSG:28992", maxResolution: 1328.125, numZoomLevels: 14, maxExtent : new OpenLayers.Bounds(-23500,289000,316500,629000), restrictedExtent: new OpenLayers.Bounds(80000,442000,88000,452000), units : "meters", controls: [ new OpenLayers.Control.ZoomToMaxExtent(), new OpenLayers.Control.PanZoomBar({zoomWorldIcon: true}), new OpenLayers.Control.LayerSwitcher({'ascending':false}), //new OpenLayers.Control.MousePosition(), new OpenLayers.Control.MouseDefaults(), new OpenLayers.Control.KeyboardDefaults() ] }); // Add Spoortunnel Delft Mapserver .map-files layer = new OpenLayers.Layer.MapServer( "Topografie", "/geoviewerbin/mapserv.exe", {map: "c:/OSGeo4W/apps/geoviewer/maps/spoortunnel.map", layers: "Topografie"} ); map.addLayer(layer); // layer = new OpenLayers.Layer.MapServer( "Spoortunnel", // "/geoviewerbin/mapserv.exe", {map: "c:/OSGeo4W/apps/geoviewer/maps/spoortunnel.map", layers: "Spoortunnel"}, // {isBaseLayer: false, opacity: 0.6} ); // map.addLayer(layer); wfs = new OpenLayers.Layer.WFS( "Contour spoortunnel", "http://localhost/geoviewerbin/mapserv.exe?map=c:/OSGeo4W/apps/geoviewer/maps/spoortunnel.map", {typename: 'SpoortunnelWFS'}, { typename: "SpoortunnelWFS", featureNS: "http://localhost/geoviewer", extractAttributes: true } ); //wfs.styleMap = new OpenLayers.StyleMap({strokeColor: "#00ffff"}); map.addLayer(wfs); //Add a scalebar to the map scalebar = new OpenLayers.Control.ScaleBar(); map.addControl(scalebar); //Set extents of initial mapview var geoviewerExtent=new Array(); geoviewerExtent[0] = 83600; // x-min geoviewerExtent[1] = 446000; // y-min geoviewerExtent[2] = 84600; // x-max geoviewerExtent[3] = 448200; // y-max ZoomToSetExtent(geoviewerExtent[0],geoviewerExtent[1],geoviewerExtent[2],geoviewerExtent[3],map); // Add a permanent link to the current view //map.addControl(new OpenLayers.Control.Permalink() ); } function ZoomToSetExtent(Xmin,Ymin,Xmax,Ymax,geoviewermap){ // Set mapview extents to input parameters var extentRatio = (Xmax-Xmin)/(Ymax-Ymin); var geoviewerSize = geoviewermap.getSize(); var sizeRatio = geoviewerSize.w/geoviewerSize.h; if (sizeRatio >= extentRatio) { var geoviewerResolution = (Ymax-Ymin)/geoviewerSize.h; var minX = ((Xmin+Xmax)/2)-(geoviewerResolution*geoviewerSize.w/2); var minY = Ymin; var maxX = ((Xmin+Xmax)/2)+(geoviewerResolution*geoviewerSize.w/2); var maxY = Ymax; } else { var geoviewerResolution = (Xmax-Xmin)/geoviewerSize.w; var minX = Xmin; var minY = ((Ymin+Ymax)/2)-(geoviewerResolution*geoviewerSize.h/2); var maxX = Xmax; var maxY = ((Ymin+Ymax)/2)+(geoviewerResolution*geoviewerSize.h/2); }; // Zoom to set extent geoviewermap.zoomToExtent(new OpenLayers.Bounds(minX,minY,maxX,maxY)); } __________________________________________ The changes/additions I made in the httpd.conf file: __________________________________________ # Added by Martijn Senden - to handle python scripts as cgi scripts AddHandler cgi-script .py # Added by Martijn Senden - to ignore the 'shebang lines' of cgi-scripts # (see http://www.imladris.com/Scripts/PythonForWindows.html) ScriptInterpreterSource registry # Added by Martijn Senden - when 'shebang lines' of cgi-scripts are ignored, # the -u switch is ignored as well. It is used to run python in the 'unbuffered' # mode. Trying to run python cgi scripts in the (default) buffered mode will # either result in a complete lack of return value from your cgi script # (manifesting as a blank html page) or a "premature end of script headers" # error. The lines below put python into the unbuffered mode. PassEnv PYTHONPATH SetEnv PYTHONUNBUFFERED 1 # Settings for access to the geoviewer folder <Directory "C:\OSGeo4W/apps/geoviewer/htdocs"> AllowOverride None Options Indexes FollowSymLinks Multiviews ExecCGI Order allow,deny Allow from all </Directory> The Proxy.cgi I currently have: __________________________________________ #!C:/OSGeo4W/bin/python.exe -u """This is a blind proxy that we use to get around browser restrictions that prevent the Javascript from loading pages not on the same server as the Javascript. This has several problems: it's less efficient, it might break some sites, and it's a security risk because people can use this proxy to browse the web and possibly do bad stuff with it. It only loads pages via http and https, but it can load any content type. It supports GET and POST requests.""" import urllib2 import cgi import sys, os # Designed to prevent Open Proxy type stuff. allowedHosts = ['www.openlayers.org', 'openlayers.org', 'labs.metacarta.com', 'world.freemap.in', 'prototype.openmnnd.org', 'geo.openplans.org', 'sigma.openplans.org', 'demo.opengeo.org', 'www.openstreetmap.org', 'sample.avencia.com', 'localhost'] method = os.environ["REQUEST_METHOD"] if method == "POST": qs = os.environ["QUERY_STRING"] d = cgi.parse_qs(qs) if d.has_key("url"): url = d["url"][0] else: url = "http://www.openlayers.org" else: fs = cgi.FieldStorage() url = fs.getvalue('url', "http://www.openlayers.org") try: host = url.split("/")[2] if allowedHosts and not host in allowedHosts: print "Status: 502 Bad Gateway" print "Content-Type: text/plain" print print "This proxy does not allow you to access that location (%s)." % (host,) print print os.environ elif url.startswith("http://") or url.startswith("https://"): if method == "POST": length = int(os.environ["CONTENT_LENGTH"]) headers = {"Content-Type": os.environ["CONTENT_TYPE"]} body = sys.stdin.read(length) r = urllib2.Request(url, body, headers) y = urllib2.urlopen(r) else: y = urllib2.urlopen(url) # print content type header i = y.info() if i.has_key("Content-Type"): print "Content-Type: %s" % (i["Content-Type"]) else: print "Content-Type: text/plain" print print y.read() y.close() else: print "Content-Type: text/plain" print print "Illegal request." except Exception, E: print "Status: 500 Unexpected Error" print "Content-Type: text/plain" print print "Some unexpected error occurred. Error text was:", E -- View this message in context: http://n2.nabble.com/WFS-layer-visible-in-IE6-and-IE7%2C-but-not-in-Firefox.-Tried-to-set-up-proxy.-No-succes-yet.-tp3113693p3113693.html Sent from the OpenLayers Users mailing list archive at Nabble.com. _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
