This is a static archive of our old OSM Help Site. Please post any new questions and answers at community.openstreetmap.org.

OpenLSLUS_Geocode zoom problem

0

Referring to this question, did you put the correct link to the python directory in proxy.cgi? I've used python download from FWTools in my Windows environment. I've copied proxy.cgi to the apache\cgi-bin directory, and changed the first line from

'#!/usr/bin/env python

into:

'#!C:\Gis\apps\FWTools\python\python.exe -u

(without the ' before the # character, but this html can't get this right)

I have a different question concerning the searchservice. My proxy.cgi script is working correctly. Using the standard script openls.html zooms in on the right address. When using the code in my own openlayers.html script, zooming-in doesn't function. The returned code is exactly the same response code as the original script in openls.html. The difference is that i'm using a different projection (see part of the code below)

      function submitform() {
          var queryString = document.forms[0].query.value;
          OpenLayers.Request.POST({
              url: "http://www.openrouteservice.org/php/OpenLSLUS_Geocode.php",
              scope: this,
              failure: this.requestFailure,
              success: this.requestSuccess,
              headers: {"Content-Type": "application/x-www-form-urlencoded"},
              data: "FreeFormAdress=" + encodeURIComponent(queryString) + "&MaxResponse=1"
          });
      }
    function requestSuccess(response) {
        var format = new OpenLayers.Format.XLS();
        var output = format.read(response.responseXML);
        if (output.responseLists[0]) {
            var geometry = output.responseLists[0].features[0].geometry;
            var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform(
                    new OpenLayers.Projection("EPSG:28992"),
                    map.getProjectionObject()
                    );
            map.setCenter(foundPosition, 16);
        } else {
            alert("Sorry, no address found");
        }
    }

      function requestFailure(response) {
          alert("no");
      }

The returned code is not in EPSG:28992, but in EPSG:4326:

<gml:pos srsName="EPSG:4326">5.04314283258114 52.3064485837094</gml:pos>

I assume that the different projection is the reason that zooming isn't working. How can I get this search-zoom-action working? Thanks in advance for any response.

asked 29 Jan '12, 22:12

ar_osmap's gravatar image

ar_osmap
11112
accept rate: 0%

edited 31 Jan '13, 17:52

SimonPoole's gravatar image

SimonPoole ♦
44.7k13326701


2 Answers:

1

answered 31 Jan '12, 11:56

pascal_n's gravatar image

pascal_n
18635
accept rate: 14%

Hi Pascal,

Thanks for your response. Unfortunately, it hasn't helped me out. I added:

<script src="../lib/OpenLayers/proj4js-combined.js"></script>
<script src="../lib/OpenLayers/EPSG28992.js"></script>

and changed:

    function requestSuccess(response) {
        var format = new OpenLayers.Format.XLS();
        var output = format.read(response.responseXML);
        if (output.responseLists[0]) {
            var geometry = output.responseLists[0].features[0].geometry;
            var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform(
                    new OpenLayers.Projection("EPSG:28992"),
                    map.getProjectionObject()
                    );
            map.setCenter(
        new OpenLayers.LonLat(131500,479800) // Center of the map
        .transform(
        new OpenLayers.Projection("EPSG:28992"), // transform from new RD
        new OpenLayers.Projection("EPSG:4326") // to default projectie
                    ),
            6); // Zoom level
        } else
        {
            alert("Sorry, no address found");
        }
    }

      function requestFailure(response) {
          alert("no luck");
      }

With the original code, without the above .transform addition but zoomlevel changed to 6 the page zooms in to the center coordinate of the map when using the search function.

With the additions above, te page zooms in to 131500,479800 (EPSG:28992, RD-New), but the coordinates (OpenLayers.Control.MousePosition) are shown in EPSG:4326

I'm new with Openlayers, it would be very nice if I could get this address search function working.

Would it be helpful to post (part of) the openlayers.html page?

(31 Jan '12, 20:56) ar_osmap
1

The Geocoder will always return coordinates in EPSG:4326. So if you need the coordinate in your system ("EPSG:28992"), this should help you:

var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform( new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:28992") );

If you have further issues, maybe it could be useful if you post your complete html-page here.

(31 Jan '12, 23:31) pascal_n

Hi Pascal, Thanks a lot, address search is almost perfect now. The only thing is that the found location is about 100 m south of the correct location, after changing +lon in EPSG28992.js, found location is perfect. Another thing is that coordinates (OpenLayers.Control.MousePosition) are shown in EPSG:4326-coordinates instead of EPSG:28992. I can live with that. Yet another thing, when I use the right-arrow cursor in the address search field, the map moves in right direction. This doesn't happen in example openls.html.

I have a question about tilecache to improve performance, but I'll ask that in another forum.

Posting my html-file here doesn't show in the preview, so I forget about that.

Thanks again!

(01 Feb '12, 09:35) ar_osmap

1

"Another thing is that coordinates (OpenLayers.Control.MousePosition) are shown in EPSG:4326-coordinates instead of EPSG:28992"

A displayProjection: new OpenLayers.Projection("EPSG:28992") or new OpenLayers.Control.MousePosition({"numDigits": 2, displayProjection: new OpenLayers.Projection("EPSG:28992")}) should solve your problem.

"Yet another thing, when I use the right-arrow cursor in the address search field, the map moves in right direction."

You should check your OpenLayers.controls which you addd to your map. Did you add new OpenLayers.Control.KeyboardDefaults()? Maybe try to remove this ...

answered 03 Feb '12, 08:45

pascal_n's gravatar image

pascal_n
18635
accept rate: 14%

Hi Pascal, These two things are resolved to! Thanks alot! Arjen

(03 Feb '12, 10:45) ar_osmap