Hi All,

I apologize in advance if this question is already answered in a previous
post. I have looked through many GetFeatureWFS (and proxy.cgi) related posts
and have not found a solution to my problem as of yet - and it doesn't help
that my coding skills have gone stale - so here goes....

I've been fiddling with the Openlayers WFS GetFeature capabilities for a
little while, but have been having a hard time getting any results from it.
At first, Firebug was giving me a lot of errors when I tried to select or
hover over features, but I quickly found out about the need for the
ProxyHost, and have downloaded the proxy.cgi from the Openlayers site and
placed it in my /cgi-bin/ folder. After a lot of work with it, I believe I
finally have that working - it's properly opening when directly referenced
(though It could still be failing for other purposes). 

Now when I try to select features from my map, I'm no longer getting any
'red errors' in Firebug, but nothing is being selected and I'm still seeing
some error messages (though no longer red) pop up in Firebug. The query
appears to be sent to the server, but this is what is coming up as the
response:

Some unexpected error occurred. Error text was: 'CONTENT_LENGTH'

Now, I'm guessing that I have something wrong with either my js or my proxy
(or even possibly my mapfile), but I can't seem to find where the problem
is. Anybody  have any ideas?

As for the environment details:

I'm currently running my website on a Ubuntu 8.04 machine with Apache
version 2.2, and am referencing the newest version of OpenLayers from their
site. I will post the web and proxy code below, but if someone wants to play
in my sandbox, please go right ahead : 
http://www.cemetermaps.ca/Simpletest.html
www.cemeterymaps.ca/Simpletest.html . It only appears to work for Firefox
right now - not IE. That's a completely separate issue that I will tackle
later on .

Any help would be appreciated - please let me know if you have any
clarification questions for me.

Thanks,

Chris


CODE

Website code -- -----------------

         
        <html xmlns="http://www.w3.org/1999/xhtml";>
          <head>
        <link rel="stylesheet"
href="http://openlayers.org/api/theme/default/style.css"; type="text/css" />

            <style type="text/css">
                #map {
                    width: 640px;
                    height: 480px;
                    border: 1px solid black;
                }
                div.olControlScaleLine {
                        color: black;
                        font-family: Arial;
                        font-size: 0.8em;
                        background-color: white;
                        }

            </style>
            <script src="http://openlayers.org/api/OpenLayers.js";></script> <!--
/OpenLayers.js"></script> -->
            <script type="text/javascript">
                <!--
                var map, scaleline, cemlayer, photoLayer, vectorLayer, select,
hover, control;

                function init(){

                OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

                    map = new OpenLayers.Map('map', {maxExtent: new
OpenLayers.Bounds(570745.457020642, 4843274.70626104, 570993.457787,
4843505.93442523), maxResolution: 0.5, units: 'm', projection: "EPSG:32617",
isbaselayer:false, numZoomLevels: 10, tileSize: new OpenLayers.Size(0.005,
0.005)});//new OpenLayers.Map('map'); 156543

                        var bounds = new OpenLayers.Bounds(); //-80.121444 
43.739134 -80.118334
43.741192 
                        bounds.left = 570745.457020642; //-80.121444; //
                        bounds.bottom = 4843274.70626104; //43.739134; //
                        bounds.right = 570993.457787; //-80.118334; //
                        bounds.top = 4843505.93442523; //43.741192; //

                map.setOptions({restrictedExtent: bounds}); //Sets it so you 
can't zoom or
pan off of the map surface
                scaleline = new OpenLayers.Control.ScaleLine({maxWidth: 100}); 
//creates
the scale line

                cemlayer = new OpenLayers.Layer.WMS( "Coningsby Test",
                   
"http://192.168.1.66/cgi-bin/mapserv?map=%2F%2Fhome%2Fchris%2FCemeterySite%2Fmapdata%2Fconingsby_test.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=&REQUEST=GetMap&LAYERS=Cem_Photo,coningsby&STYLES=&SRS=EPSG:32617&FORMAT=image/png";,
{layers: 'Cem_Photo,Coningsby'}, {singleTile: true}, {maxExtent: bounds},
{units: 'm'}, {isBaseLayer: true}); //WORKING - doesn't need the image size
or bounds in the connection string


        select = new OpenLayers.Layer.Vector("Selection", {styleMap: 
                new
OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
            });
            hover = new OpenLayers.Layer.Vector("Hover");
                
            control = new OpenLayers.Control.GetFeature({
               protocol: OpenLayers.Protocol.WFS.fromWMSLayer(cemlayer), 
                box: true,
                hover: true,
                multipleKey: "ctrlKey",
                toggleKey: "altKey"
            });
                //alert("Message1!");

            control.events.register("featureselected", this, function(e) {
                select.addFeatures([e.feature]);
                //alert("Message2!");
            });
           control.events.register("featureunselected", this, function(e) {
                select.removeFeatures([e.feature]);
                //alert("Message3!");
            });
            control.events.register("hoverfeature", this, function(e) {
                hover.addFeatures([e.feature]);
                //alert("Message4!");
            });
            control.events.register("outfeature", this, function(e) {
                hover.removeFeatures([e.feature]);
                //alert("Message5!");
            });

                    //map.addLayer(photoLayer);
                    map.addLayer(cemlayer);
                    map.addLayers([hover, select]);
                    map.addControl(scaleline); //adds the scaleline
                    map.addControl(new OpenLayers.Control.LayerSwitcher());
                    map.addControl(control); //Adds the GetFeature material
                    control.activate();
                    map.zoomToExtent(bounds); //Will zoom to the 'area' of the 
cemetery
when using dd instead of UTM    
                }
                 -->
            </script>
          </head>
          <body onload="init()">
            <div id="map"></div>
            <div id="scaleline"></div>
          </body>

        </html>

------------------------Proxy.cgi Code --------------------------------

#!/usr/bin/env python
        
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', 'www.cemeterymaps.ca', '192.168.1.66']

method = os.environ["REQUEST_METHOD"]

if method == "POST":
        qs = os.environ["REQUEST_METHOD"]
        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] #Gets rid of the http or https
        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"])
                        print y.read()
                        y.close()
                else:
                        print "Content-type: text/plain\n\n"
                        print
                        print y.read()
                        y.close()
        else:
                print "Content-type: text/plain\n\n"
                print
                print "Illegal request."

except Exception, E:
        print "Status: 500 Unexpected Error"
        print "Content-type: text/plain\n\n"
        print
        print "Some unexpected error occurred. Error text was:", E
-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Another-GetFeatureWFS-Possible-Proxy-Issue-CONTENT-LENGTH-tp5024916p5024916.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users

Reply via email to