1 | <!DOCTYPE html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
---|
5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/> |
---|
6 | <meta name="apple-mobile-web-app-capable" content="yes"/> |
---|
7 | <link rel="stylesheet" href="../theme/default/style.css" type="text/css"/> |
---|
8 | <link rel="stylesheet" href="style.css" type="text/css"/> |
---|
9 | <title>OpenLS: Geocoding Example</title> |
---|
10 | <script type="text/javascript" src="../lib/OpenLayers.js"></script> |
---|
11 | <script type="text/javascript"> |
---|
12 | var map, layer; |
---|
13 | |
---|
14 | function init() { |
---|
15 | OpenLayers.ProxyHost = "proxy.cgi?url="; |
---|
16 | map = new OpenLayers.Map('map', { |
---|
17 | controls: [ |
---|
18 | new OpenLayers.Control.PanZoom(), |
---|
19 | new OpenLayers.Control.Permalink(), |
---|
20 | new OpenLayers.Control.Navigation() |
---|
21 | ] |
---|
22 | }); |
---|
23 | layer = new OpenLayers.Layer.OSM("OpenStreetMap", null, { |
---|
24 | transitionEffect: 'resize' |
---|
25 | }); |
---|
26 | map.addLayers([layer]); |
---|
27 | map.zoomToMaxExtent(); |
---|
28 | } |
---|
29 | function submitform() { |
---|
30 | var queryString = document.forms[0].query.value; |
---|
31 | OpenLayers.Request.POST({ |
---|
32 | url: "http://www.openrouteservice.org/php/OpenLSLUS_Geocode.php", |
---|
33 | scope: this, |
---|
34 | failure: this.requestFailure, |
---|
35 | success: this.requestSuccess, |
---|
36 | headers: {"Content-Type": "application/x-www-form-urlencoded"}, |
---|
37 | data: "FreeFormAdress=" + encodeURIComponent(queryString) + "&MaxResponse=1" |
---|
38 | }); |
---|
39 | } |
---|
40 | function requestSuccess(response) { |
---|
41 | var format = new OpenLayers.Format.XLS(); |
---|
42 | var output = format.read(response.responseXML); |
---|
43 | if (output.responseLists[0]) { |
---|
44 | var geometry = output.responseLists[0].features[0].geometry; |
---|
45 | var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform( |
---|
46 | new OpenLayers.Projection("EPSG:4326"), |
---|
47 | map.getProjectionObject() |
---|
48 | ); |
---|
49 | map.setCenter(foundPosition, 16); |
---|
50 | } else { |
---|
51 | alert("Sorry, no address found"); |
---|
52 | } |
---|
53 | } |
---|
54 | function requestFailure(response) { |
---|
55 | alert("An error occurred while communicating with the OpenLS service. Please try again."); |
---|
56 | } |
---|
57 | |
---|
58 | </script> |
---|
59 | </head> |
---|
60 | <body onload="init()"> |
---|
61 | <h1 id="title">OpenLS Geocoding Example</h1> |
---|
62 | |
---|
63 | <div id="tags"> |
---|
64 | OpenLS, XLS, Geocoding |
---|
65 | </div> |
---|
66 | |
---|
67 | <p id="shortdesc"> |
---|
68 | Show how to use an OpenLS service. |
---|
69 | </p> |
---|
70 | |
---|
71 | <form name="input" action="javascript: submitform();" method="post"> |
---|
72 | <label for="query">Search for address:</label> <input type="text" id="query" size=50 name="query" |
---|
73 | value="Rue des Berges 37 Payerne"/> |
---|
74 | <input type="submit" value="Submit"/> |
---|
75 | </form> |
---|
76 | |
---|
77 | <br> |
---|
78 | |
---|
79 | <div id="map" class="smallmap"></div> |
---|
80 | |
---|
81 | |
---|
82 | <div id="docs"> |
---|
83 | <p> |
---|
84 | Geocoding example using the http://www.openrouteservice.org/ OpenLS service. Recenter to the first item of the results. |
---|
85 | </p> |
---|
86 | </div> |
---|
87 | </body> |
---|
88 | </html> |
---|