Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

update & test Nominatim class

  • Loading branch information...
commit ba2d23127d2d1594b45c4499f0a2c8ab49fe730f 1 parent 66ebb4f
Ken Guest authored
73 Services/OpenStreetMap/Nominatim.php
@@ -39,7 +39,7 @@ class Services_OpenStreetMap_Nominatim
39 39 /**
40 40 * __construct
41 41 *
42   - * @param Services_OpenStreetMap_Transport $transport
  42 + * @param Services_OpenStreetMap_Transport $transport Transport instance.
43 43 *
44 44 * @return Services_OpenStreetMap_Nominatim
45 45 */
@@ -48,7 +48,14 @@ public function __construct($transport)
48 48 $this->setTransport($transport);
49 49 }
50 50
51   - private function buildQuery($place)
  51 + /**
  52 + * Build query portion for request.
  53 + *
  54 + * @param string $place Name of location/place to search for
  55 + *
  56 + * @return string
  57 + */
  58 + private function _buildQuery($place)
52 59 {
53 60 $format = $this->format;
54 61 $limit = $this->limit;
@@ -90,7 +97,7 @@ public function search($place, $limit = null)
90 97 }
91 98
92 99 $format = $this->format;
93   - $query = $this->buildQuery($place);
  100 + $query = $this->_buildQuery($place);
94 101 $url = $this->server . 'search?' . $query;
95 102
96 103 $response = $this->getTransport()->getResponse($url);
@@ -101,13 +108,15 @@ public function search($place, $limit = null)
101 108 } elseif ( $format == 'json' ) {
102 109 $places = json_decode($response->getBody());
103 110 return $places;
  111 + } elseif ($format == 'html') {
  112 + return $response->getBody();
104 113 }
105 114 }
106 115
107 116 /**
108 117 * setFormat
109 118 *
110   - * @param string $format Set format for data to be received in (json, xml)
  119 + * @param string $format Set format for data to be received in (html, json, xml)
111 120 *
112 121 * @return Services_OpenStreetMap_Nominatim
113 122 * @throws Services_OpenStreetMap_RuntimeException If the specified format
@@ -116,6 +125,7 @@ public function search($place, $limit = null)
116 125 public function setFormat($format)
117 126 {
118 127 switch($format) {
  128 + case 'html':
119 129 case 'json':
120 130 case 'xml':
121 131 $this->format = $format;
@@ -129,6 +139,16 @@ public function setFormat($format)
129 139 }
130 140
131 141 /**
  142 + * get which format is set for this instance (xml, json, html)
  143 + *
  144 + * @return string
  145 + */
  146 + public function getFormat()
  147 + {
  148 + return $this->format;
  149 + }
  150 +
  151 + /**
132 152 * setLimit
133 153 *
134 154 * @param integer $limit Maximum number of entries to retrieve
@@ -148,6 +168,16 @@ public function setLimit($limit)
148 168 }
149 169
150 170 /**
  171 + * get Limit
  172 + *
  173 + * @return integer
  174 + */
  175 + public function getLimit()
  176 + {
  177 + return $this->limit;
  178 + }
  179 +
  180 + /**
151 181 * set Transport object.
152 182 *
153 183 * @param Services_OpenStreetMap_Transport $transport transport object
@@ -170,19 +200,52 @@ public function getTransport()
170 200 return $this->transport;
171 201 }
172 202
  203 + /**
  204 + * Set which server to connect to.
  205 + *
  206 + * Possible values are 'nominatim', 'mapquest' and any other valid
  207 + * endpoint specified as an URL.
  208 + *
  209 + * @param string $server Server URL or shorthand (nominatim / mapquest)
  210 + *
  211 + * @return Services_OpenStreetMap_Nominatim
  212 + */
173 213 public function setServer($server)
174 214 {
175 215 switch($server) {
176 216 case 'nominatim':
177 217 $this->server = 'http://nominatim.openstreetmap.org/';
  218 + return $this;
178 219 break;
179 220 case 'mapquest':
180 221 $this->server = 'http://open.mapquestapi.com/nominatim/v1/';
  222 + return $this;
181 223 break;
182 224 default:
183   - $this->server = $server;
  225 + $parsed = parse_url($server);
  226 + if (isset($parsed['scheme'])
  227 + && isset($parsed['host'])
  228 + && isset($parsed['path'])
  229 + ) {
  230 + $this->server = $server;
  231 + } else {
  232 + throw new Services_OpenStreetMap_RuntimeException(
  233 + 'Server endpoint invalid'
  234 + );
  235 + }
  236 + return $this;
184 237 }
185 238 }
  239 +
  240 + /**
  241 + * Retrieve server endpoint.
  242 + *
  243 + * @return string
  244 + */
  245 + public function getServer()
  246 + {
  247 + return $this->server;
  248 + }
186 249 }
187 250
188 251 ?>
2  tests/AllTests.php
@@ -25,6 +25,7 @@
25 25
26 26 require_once 'ChangesetTest.php';
27 27 require_once 'ConfigTest.php';
  28 +require_once 'NominatimTest.php';
28 29 require_once 'NodeTest.php';
29 30 require_once 'OSMTest.php';
30 31 require_once 'RelationTest.php';
@@ -68,6 +69,7 @@ public static function suite()
68 69 $suite->addTestSuite('ConfigTest');
69 70 $suite->addTestSuite('OSMTest');
70 71 $suite->addTestSuite('NodeTest');
  72 + $suite->addTestSuite('NominatimTest');
71 73 $suite->addTestSuite('RelationTest');
72 74 $suite->addTestSuite('UserTest');
73 75 $suite->addTestSuite('WayTest');
221 tests/NominatimTest.php
... ... @@ -0,0 +1,221 @@
  1 +<?php
  2 +/**
  3 + * Unit testing for Services_OpenStreetMap_Nominatim class.
  4 + *
  5 + * PHP Version 5
  6 + *
  7 + * @category Services
  8 + * @package Services_OpenStreetMap
  9 + * @subpackage UnitTesting
  10 + * @author Ken Guest <kguest@php.net>
  11 + * @license BSD http://www.opensource.org/licenses/bsd-license.php
  12 + * @version Release: @package_version@
  13 + * @link NominatimTest.php
  14 + */
  15 +
  16 +$version = '@package_version@';
  17 +if (strstr($version, 'package_version')) {
  18 + set_include_path(dirname(dirname(__FILE__)) . ':' . get_include_path());
  19 +}
  20 +
  21 +require_once 'Services/OpenStreetMap.php';
  22 +
  23 +require_once 'HTTP/Request2.php';
  24 +require_once 'HTTP/Request2/Adapter/Mock.php';
  25 +require_once 'PHPUnit/Framework/TestCase.php';
  26 +
  27 +
  28 +/**
  29 + * Test Services_OpenStreetMap_Config functionality and how it's used
  30 + * throughout the Services_OpenStreetMap package.
  31 + *
  32 + * @category Services
  33 + * @package Services_OpenStreetMap
  34 + * @subpackage UnitTesting
  35 + * @author Ken Guest <kguest@php.net>
  36 + * @license BSD http://www.opensource.org/licenses/bsd-license.php
  37 + * @link ConfigTest.php
  38 + */
  39 +class NominatimTest extends PHPUnit_Framework_TestCase
  40 +{
  41 +
  42 + /**
  43 + * test the getCoordsOfPlace method.
  44 + *
  45 + * @return void
  46 + */
  47 + public function testGetCoordsOfPlace()
  48 + {
  49 + $mock = new HTTP_Request2_Adapter_Mock();
  50 + $mock->addResponse(
  51 + fopen(__DIR__ . '/responses/nominatim_search_limerick.xml', 'rb')
  52 + );
  53 +
  54 + $osm = new Services_OpenStreetMap(array('adapter' => $mock));
  55 + $this->AssertEquals(
  56 + $osm->getCoordsOfPlace('Limerick, Ireland'),
  57 + array('lat'=> '52.6612577', 'lon'=> '-8.6302084')
  58 + );
  59 + }
  60 +
  61 + /**
  62 + * An exception should be thrown if the place of interest can not be
  63 + * found.
  64 + *
  65 + * @expectedException Services_OpenStreetMap_Exception
  66 + * @expectedExceptionMessage Could not get coords for Neeenaaa, Ireland
  67 + *
  68 + * @return void
  69 + */
  70 + public function testGetCoordsOfNonExistentPlace()
  71 + {
  72 + $mock = new HTTP_Request2_Adapter_Mock();
  73 + $mock->addResponse(
  74 + fopen(
  75 + __DIR__ . '/responses/nominatim_search_neeenaaa.xml',
  76 + 'rb'
  77 + )
  78 + );
  79 +
  80 + $osm = new Services_OpenStreetMap(array('adapter' => $mock));
  81 + $osm->getCoordsOfPlace('Neeenaaa, Ireland');
  82 + }
  83 +
  84 + public function testSetFormatHtml()
  85 + {
  86 + $osm = new Services_OpenStreetMap();
  87 + $transport = $osm->getTransport();
  88 + $nominatim = new Services_OpenStreetMap_Nominatim($transport);
  89 + $nominatim->setFormat('html');
  90 + $this->assertEquals($nominatim->getFormat(), 'html');
  91 + }
  92 +
  93 + public function testSetFormatJson()
  94 + {
  95 + $osm = new Services_OpenStreetMap();
  96 + $transport = $osm->getTransport();
  97 + $nominatim = new Services_OpenStreetMap_Nominatim($transport);
  98 + $nominatim->setFormat('json');
  99 + $this->assertEquals($nominatim->getFormat(), 'json');
  100 + }
  101 +
  102 + public function testSetFormatXml()
  103 + {
  104 + $osm = new Services_OpenStreetMap();
  105 + $transport = $osm->getTransport();
  106 + $nominatim = new Services_OpenStreetMap_Nominatim($transport);
  107 + $nominatim->setFormat('xml');
  108 + $this->assertEquals($nominatim->getFormat(), 'xml');
  109 + }
  110 +
  111 + /**
  112 + * Check that an exception is thrown when attempting to set format to an
  113 + * unrecognised value.
  114 + *
  115 + * @expectedException Services_OpenStreetMap_RuntimeException
  116 + * @expectedExceptionMessage Unrecognised format (xhtml)
  117 + *
  118 + * @return void
  119 + */
  120 + public function testInvalidFormat()
  121 + {
  122 + $osm = new Services_OpenStreetMap();
  123 + $transport = $osm->getTransport();
  124 + $nominatim = new Services_OpenStreetMap_Nominatim($transport);
  125 + $nominatim->setFormat('xhtml');
  126 + }
  127 +
  128 +
  129 + public function testSetLimit()
  130 + {
  131 + $osm = new Services_OpenStreetMap();
  132 + $transport = $osm->getTransport();
  133 + $nominatim = new Services_OpenStreetMap_Nominatim($transport);
  134 + $nominatim->setLimit(1);
  135 + $this->assertEquals($nominatim->getLimit(), 1);
  136 + }
  137 +
  138 + /**
  139 + * Check that an exception is thrown when attempting to set limit to an
  140 + * unrecognised value.
  141 + *
  142 + * @expectedException Services_OpenStreetMap_RuntimeException
  143 + * @expectedExceptionMessage Limit must be a numeric value
  144 + *
  145 + * @return void
  146 + */
  147 + public function testSetInvalidLimit()
  148 + {
  149 + $osm = new Services_OpenStreetMap();
  150 + $transport = $osm->getTransport();
  151 + $nominatim = new Services_OpenStreetMap_Nominatim($transport);
  152 + $nominatim->setLimit('one');
  153 + }
  154 +
  155 + public function testJsonSearch()
  156 + {
  157 + $mock = new HTTP_Request2_Adapter_Mock();
  158 + $mock->addResponse(fopen(__DIR__ . '/responses/search.json', 'rb'));
  159 +
  160 + $osm = new Services_OpenStreetMap(array('adapter' => $mock));
  161 +
  162 + $nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
  163 + $nominatim->setFormat('json');
  164 + $place = $nominatim->search('Limerick, Ireland', 1);
  165 + $this->assertEquals($place[0]->class, 'place');
  166 + $this->assertEquals($place[0]->type, 'city');
  167 + $this->assertEquals($place[0]->osm_type, 'node');
  168 + }
  169 +
  170 + public function testHtmlSearch()
  171 + {
  172 + $mock = new HTTP_Request2_Adapter_Mock();
  173 + $mock->addResponse(fopen(__DIR__ . '/responses/search.html', 'rb'));
  174 +
  175 + $osm = new Services_OpenStreetMap(array('adapter' => $mock));
  176 + $nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
  177 + $nominatim->setFormat('html');
  178 + $place = $nominatim->search('Limerick, Ireland', 1);
  179 + $this->assertNotNull($place);
  180 + }
  181 +
  182 + public function testSetServer()
  183 + {
  184 + $osm = new Services_OpenStreetMap();
  185 + $nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
  186 +
  187 + $this->assertEquals(
  188 + $nominatim->getServer(),
  189 + 'http://nominatim.openstreetmap.org/'
  190 + );
  191 + $this->assertEquals(
  192 + $nominatim->setServer('mapquest')->getServer(),
  193 + 'http://open.mapquestapi.com/nominatim/v1/'
  194 + );
  195 + $this->assertEquals(
  196 + $nominatim->setServer('nominatim')->getServer(),
  197 + 'http://nominatim.openstreetmap.org/'
  198 + );
  199 + $this->assertEquals(
  200 + $nominatim->setServer('http://nominatim.example.com/')->getServer(),
  201 + 'http://nominatim.example.com/'
  202 + );
  203 + }
  204 +
  205 + /**
  206 + * Check that an exception is thrown when attempting to set limit to an
  207 + * unrecognised value.
  208 + *
  209 + * @expectedException Services_OpenStreetMap_RuntimeException
  210 + * @expectedExceptionMessage Server endpoint invalid
  211 + *
  212 + * @return void
  213 + */
  214 + public function testSetInvalidServerURL()
  215 + {
  216 + $osm = new Services_OpenStreetMap();
  217 + $nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
  218 + $nominatim->setServer('invalid');
  219 + }
  220 +}
  221 +?>
387 tests/responses/search.html
... ... @@ -0,0 +1,387 @@
  1 +HTTP/1.1 200 OK
  2 +Content-Type: text/html; charset=UTF-8
  3 +
  4 +<html>
  5 +<head>
  6 + <title>OpenStreetMap Nominatim: Search</title>
  7 +
  8 + <base href="http://nominatim.openstreetmap.org/" />
  9 + <link href="nominatim.xml" rel="search" title="Nominatim Search" type="application/opensearchdescription+xml" />
  10 +
  11 + <script src="js/OpenLayers.js"></script>
  12 + <script src="js/tiles.js"></script>
  13 + <script src="js/prototype-1.6.0.3.js"></script>
  14 +
  15 + <style>
  16 +* {-moz-box-sizing: border-box;}
  17 +body {
  18 + margin:0px;
  19 + padding:0px;
  20 + overflow: hidden;
  21 + background:#ffffff;
  22 + height: 100%;
  23 + font: normal 12px/15px arial,sans-serif;
  24 +}
  25 +#seachheader {
  26 + position:absolute;
  27 + z-index:5;
  28 + top:0px;
  29 + left:0px;
  30 + width:100%;
  31 + height:38px;
  32 + background:#F0F7FF;
  33 + border-bottom: 2px solid #75ADFF;
  34 +}
  35 +#q {
  36 + width:300px;
  37 +}
  38 +#seachheaderfade1, #seachheaderfade2, #seachheaderfade3, #seachheaderfade4{
  39 + position:absolute;
  40 + z-index:4;
  41 + top:0px;
  42 + left:0px;
  43 + width:100%;
  44 + opacity: 0.15;
  45 + filter: alpha(opacity = 15);
  46 + background:#000000;
  47 + border: 1px solid #000000;
  48 +}
  49 +#seachheaderfade1{
  50 + height:39px;
  51 +}
  52 +#seachheaderfade2{
  53 + height:40px;
  54 +}
  55 +#seachheaderfade3{
  56 + height:41px;
  57 +}
  58 +#seachheaderfade4{
  59 + height:42px;
  60 +}
  61 +#searchresultsfade1, #searchresultsfade2, #searchresultsfade3, #searchresultsfade4 {
  62 + position:absolute;
  63 + z-index:2;
  64 + top:0px;
  65 + left:200px;
  66 + height: 100%;
  67 + opacity: 0.2;
  68 + filter: alpha(opacity = 20);
  69 + background:#ffffff;
  70 + border: 1px solid #ffffff;
  71 +}
  72 +#searchresultsfade1{
  73 + width:1px;
  74 +}
  75 +#searchresultsfade2{
  76 + width:2px;
  77 +}
  78 +#searchresultsfade3{
  79 + width:3px;
  80 +}
  81 +#searchresultsfade4{
  82 + width:4px;
  83 +}
  84 +
  85 +#searchresults{
  86 + position:absolute;
  87 + z-index:3;
  88 + top:41px;
  89 + width:200px;
  90 + height: 100%;
  91 + background:#ffffff;
  92 + border: 1px solid #ffffff;
  93 + overflow: auto;
  94 +}
  95 +#map{
  96 + position:absolute;
  97 + z-index:1;
  98 + top:38px;
  99 + left:200px;
  100 + width:100%;
  101 + height:100%;
  102 + background:#eee;
  103 +}
  104 +#report{
  105 + position:absolute;
  106 + z-index:2;
  107 + top:38px;
  108 + left:200px;
  109 + width:100%;
  110 + height:100%;
  111 + background:#eee;
  112 + font: normal 12px/15px arial,sans-serif;
  113 + padding:20px;
  114 +}
  115 +#report table {
  116 + margin-left:20px;
  117 +}
  118 +#report th {
  119 + vertical-align:top;
  120 + text-align:left;
  121 +}
  122 +#report td.button {
  123 + text-align:right;
  124 +}
  125 +.result {
  126 + margin:5px;
  127 + margin-bottom:0px;
  128 + padding:2px;
  129 + padding-left:4px;
  130 + padding-right:4px;
  131 + border-radius: 5px;
  132 + -moz-border-radius: 5px;
  133 + -webkit-border-radius: 5px;
  134 + background:#F0F7FF;
  135 + border: 2px solid #D7E7FF;
  136 + font: normal 12px/15px arial,sans-serif;
  137 + cursor:pointer;
  138 +}
  139 +.result img{
  140 + float:right;
  141 +}
  142 +.result .latlon{
  143 + display: none;
  144 +}
  145 +.result .place_id{
  146 + display: none;
  147 +}
  148 +.result .type{
  149 + color: #999;
  150 + text-align:center;
  151 + font: normal 9px/10px arial,sans-serif;
  152 + padding-top:4px;
  153 +}
  154 +.result .details, .result .details a{
  155 + color: #999;
  156 + text-align:center;
  157 + font: normal 9px/10px arial,sans-serif;
  158 + padding-top:4px;
  159 +}
  160 +.noresults{
  161 + color: #000;
  162 + text-align:center;
  163 + font: normal 12px arial,sans-serif;
  164 + padding-top:4px;
  165 +}
  166 +.more{
  167 + color: #ccc;
  168 + text-align:center;
  169 + padding-top:4px;
  170 +}
  171 +.disclaimer{
  172 + color: #ccc;
  173 + text-align:center;
  174 + font: normal 9px/10px arial,sans-serif;
  175 + padding-top:4px;
  176 +}
  177 +form{
  178 + margin:0px;
  179 + padding:0px;
  180 +}
  181 + </style>
  182 +
  183 + <script type="text/javascript">
  184 +
  185 + var map;
  186 +
  187 + function handleResize()
  188 + {
  189 + if ($('searchresults'))
  190 + {
  191 + $('map').style.width = (document.documentElement.clientWidth > 0?document.documentElement.clientWidth:document.documentElement.offsetWidth) - 200;
  192 + $('report').style.width = (document.documentElement.clientWidth > 0?document.documentElement.clientWidth:document.documentElement.offsetWidth) - 200;
  193 + }
  194 + else
  195 + {
  196 + $('map').style.width = (document.documentElement.clientWidth > 0?document.documentElement.clientWidth:document.documentElement.offsetWidth) - 0;
  197 + $('map').style.left = 0;
  198 + }
  199 +
  200 + if ($('map')) $('map').style.height = (document.documentElement.clientHeight > 0?document.documentElement.clientHeight:document.documentElement.offsetHeight) - 38;
  201 + if ($('searchresults')) $('searchresults').style.height = (document.documentElement.clientHeight > 0?document.documentElement.clientHeight:document.documentElement.offsetHeight) - 38;
  202 + if ($('report')) $('report').style.height = (document.documentElement.clientHeight > 0?document.documentElement.clientHeight:document.documentElement.offsetHeight) - 38;
  203 + }
  204 + window.onresize = handleResize;
  205 +
  206 + function panToLatLon(lat,lon) {
  207 + var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
  208 + map.panTo(lonLat, 2);
  209 + }
  210 +
  211 + function panToLatLonZoom(lat,lon, zoom) {
  212 + var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
  213 + if (zoom != map.getZoom())
  214 + map.setCenter(lonLat, zoom);
  215 + else
  216 + map.panTo(lonLat, 10);
  217 + }
  218 +
  219 + function panToLatLonBoundingBox(lat,lon,minlat,maxlat,minlon,maxlon,points) {
  220 + var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326");
  221 + var proj_map = map.getProjectionObject();
  222 + map.zoomToExtent(new OpenLayers.Bounds(minlon,minlat,maxlon,maxlat).transform(proj_EPSG4326, proj_map));
  223 +
  224 + var pointList = [];
  225 + var style = {
  226 + strokeColor: "#75ADFF",
  227 + fillColor: "#F0F7FF",
  228 + strokeWidth: 2,
  229 + strokeOpacity: 0.75,
  230 + fillOpacity: 0.75
  231 + };
  232 + var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326");
  233 + var proj_map = map.getProjectionObject();
  234 + if (points)
  235 + {
  236 + points.each(function(p){
  237 + pointList.push(new OpenLayers.Geometry.Point(p[0],p[1]));
  238 + });
  239 + var linearRing = new OpenLayers.Geometry.LinearRing(pointList).transform(proj_EPSG4326, proj_map);;
  240 + var polygonFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([linearRing]),null,style);
  241 + vectorLayer.destroyFeatures();
  242 + vectorLayer.addFeatures([polygonFeature]);
  243 + }
  244 + else
  245 + {
  246 + var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
  247 + var point = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat);
  248 + var pointFeature = new OpenLayers.Feature.Vector(point,null,style);
  249 + vectorLayer.destroyFeatures();
  250 + vectorLayer.addFeatures([pointFeature]);
  251 + }
  252 + }
  253 +
  254 + function round(v,n)
  255 + {
  256 + n = Math.pow(10,n);
  257 + return Math.round(v*n)/n;
  258 + }
  259 + function floor(v,n)
  260 + {
  261 + n = Math.pow(10,n);
  262 + return Math.floor(v*n)/n;
  263 + }
  264 + function ceil(v,n)
  265 + {
  266 + n = Math.pow(10,n);
  267 + return Math.ceil(v*n)/n;
  268 + }
  269 +
  270 + function mapEventMove() {
  271 + var proj = new OpenLayers.Projection("EPSG:4326");
  272 + var bounds = map.getExtent();
  273 + bounds = bounds.transform(map.getProjectionObject(), proj);
  274 + $('viewbox').value = floor(bounds.left,2)+','+ceil(bounds.top,2)+','+ceil(bounds.right,2)+','+floor(bounds.bottom,2);
  275 + }
  276 +
  277 + function init() {
  278 + handleResize();
  279 + map = new OpenLayers.Map ("map", {
  280 + controls:[
  281 + new OpenLayers.Control.Navigation(),
  282 + new OpenLayers.Control.PanZoomBar(),
  283 + new OpenLayers.Control.MouseDefaults(),
  284 + new OpenLayers.Control.MousePosition(),
  285 + new OpenLayers.Control.Attribution()],
  286 + maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
  287 + maxResolution: 156543.0399,
  288 + numZoomLevels: 19,
  289 + units: 'm',
  290 + projection: new OpenLayers.Projection("EPSG:900913"),
  291 + displayProjection: new OpenLayers.Projection("EPSG:4326"),
  292 + eventListeners: {
  293 + "moveend": mapEventMove
  294 + }
  295 + } );
  296 + map.addLayer(new OpenLayers.Layer.OSM.Mapnik("Default"));
  297 +
  298 + var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
  299 + layer_style.fillOpacity = 0.2;
  300 + layer_style.graphicOpacity = 1;
  301 + vectorLayer = new OpenLayers.Layer.Vector("Points", {style: layer_style});
  302 + map.addLayer(vectorLayer);
  303 +
  304 +// var lonLat = new OpenLayers.LonLat(-8.6302084, 52.6612577).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
  305 +// map.setCenter (lonLat, 2);
  306 + }
  307 +
  308 + function setfocus(field_id) {
  309 + $(field_id).focus()
  310 + }
  311 +
  312 + </script>
  313 +</head>
  314 +
  315 +<body onload="setfocus('q');">
  316 +
  317 + <div id="seachheaderfade1"></div><div id="seachheaderfade2"></div><div id="seachheaderfade3"></div><div id="seachheaderfade4"></div>
  318 +
  319 + <div id="seachheader">
  320 + <form accept-charset="UTF-8" action="http://nominatim.openstreetmap.org/search.php" method="get">
  321 + <table border="0" width="100%">
  322 + <tr>
  323 + <td valign="center" style="width:30px;"><img src="images/logo.gif"></td>
  324 + <td valign="center" style="width:400px;"><input id="q" name="q" value="Limerick, Ireland" style="width:270px;"><input type="text" id="viewbox" style="width:130px;" name="viewbox"></td>
  325 + <td style="width:80px;"><input type="submit" value="Search"></td>
  326 + <td style="width:100px;"><input type="checkbox" value="1" name="polygon" > Highlight</td>
  327 +<td style="text-align:right;">Data: 2012/04/08</td>
  328 +<td style="text-align:right;">
  329 +<a href="http://wiki.openstreetmap.org/wiki/Nominatim" target="_blank">Documentation</a> | <a href="http://wiki.openstreetmap.org/wiki/Nominatim/FAQ"
  330 +target="_blank">FAQ</a></td>
  331 +
  332 + <td style="text-align:right;"><input type="button" value="Report Problem With Results" onclick="$('report').style.visibility=($('report').style.visibility=='hidden'?'visible':'hidden')"></td>
  333 + </tr>
  334 + </table>
  335 + </form>
  336 + </div>
  337 +
  338 + <div id="searchresultsfade1"></div><div id="searchresultsfade2"></div><div id="searchresultsfade3"></div><div id="searchresultsfade4"></div>
  339 + <div id="searchresults">
  340 +<div class="result" onClick='panToLatLonBoundingBox(52.6612577, -8.6302084, 52.651254882813, 52.67125869751, -8.6402089691162, -8.6202080154419, "");'><img src="http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"> <span class="name">Limerick, County Limerick, Munster, Ireland, Europe</span> <span class="latlon">52.661,52.661</span> <span class="place_id">4353410</span> <span class="type">(City)</span> <span class="details">(<a href="details.php?place_id=4353410">details</a>)</span></div><div class="more"><a href="http://nominatim.openstreetmap.org/search?format=html&exclude_place_ids=4353410&accept-language=&q=Limerick%2C+Ireland">Search for more results</a></div> <div class="disclaimer">Addresses and postcodes are approximate
  341 + <input type="button" value="Report Problem" onclick="$('report').style.visibility=($('report').style.visibility=='hidden'?'visible':'hidden')">
  342 + </div>
  343 + </div>
  344 +
  345 + <div id="map"></div>
  346 + <div id="report" style="visibility:hidden;"><div style="width:600px;margin:auto;margin-top:60px;">
  347 + <h2>Report a problem</h2>
  348 + <p>Before reporting problems please read the <a href="http://wiki.openstreetmap.org/wiki/Nominatim">user documentation</a> and <a
  349 +href="http://wiki.openstreetmap.org/wiki/Nominatim/FAQ">FAQ</a>. If your problem relates to the address of a particular search result please use the 'details' link
  350 +to check how the address was generated before reporting a problem.</p>
  351 + <p>Please use <a href="http://trac.openstreetmap.org/newticket?component=nominatim">trac.openstreetmap.org</a> to report problems
  352 +making sure to set
  353 +the component to 'nominatim'. You can search for existing bug reports <a href="http://trac.openstreetmap.org/query?status=new&status=assigned&status=reopened&component=nominatim&order=priority">here</a>.</p>
  354 + <p>Please ensure that you include a full description of the problem, including the search query that you used, the problem with the result and, if
  355 +the problem relates to missing data, the osm id of the item that is missing. Problems that contain enough detail are likely to get looked at before ones that
  356 +require significant research!</p>
  357 + </div>
  358 +
  359 +<!--
  360 + <p>Please use this form to report problems with the search results. Of particular interest are items missing, but please also use this form to
  361 +report any other problems.</p>
  362 + <p>If your problem relates to the address of a particular search result please use the 'details' link to check how the address was generated before
  363 +reporting a problem.</p>
  364 + <p>If you are reporting a missing result please (if possible) include the OSM ID of the item you where expecting (i.e. node 422162)</p>
  365 + <form method="post">
  366 + <table>
  367 + <tr><th>Your Query:</th><td><input type="hidden" name="report:query" value="Limerick, Ireland" style="width:500px;">Limerick, Ireland</td></tr>
  368 + <tr><th>Your Email Address(opt):</th><td><input type="text" name="report:email" value="" style="width:500px;"></td></tr>
  369 + <tr><th>Description of Problem:</th><td><textarea name="report:description" style="width:500px;height:200px;"></textarea></td></tr>
  370 + <tr><td colspan="2" class="button"><input type="button" value="Cancel" onclick="$('report').style.visibility='hidden'"><input type="submit" value="Report"></td></tr>
  371 + </table>
  372 + </form>
  373 + <h2>Known Problems</h2>
  374 + <ul>
  375 + <li>Countries where missed out of the index</li>
  376 + <li>Area Polygons relate to the search area - not the address area which would make more sense</li>
  377 + </ul>
  378 +-->
  379 + </div>
  380 +
  381 + <script type="text/javascript">
  382 +init();
  383 +panToLatLonBoundingBox(52.6612577, -8.6302084, 52.651254882813, 52.67125869751, -8.6402089691162, -8.6202080154419, "");
  384 +</script>
  385 +</body>
  386 +
  387 +</html>
13 tests/responses/search.json
... ... @@ -0,0 +1,13 @@
  1 +HTTP/1.1 200 OK
  2 +Date: Mon, 09 Apr 2012 18:38:13 GMT
  3 +Server: Apache/2.2.14 (Ubuntu)
  4 +Content-Location: search.php
  5 +Vary: negotiate
  6 +TCN: choice
  7 +X-Powered-By: PHP/5.3.2-1ubuntu4.14
  8 +Access-Control-Allow-Origin: *
  9 +Content-Length: 464
  10 +Connection: close
  11 +Content-Type: application/json; charset=UTF-8
  12 +
  13 +[{"place_id":"4353410","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"428339453","boundingbox":["52.651254882813","52.67125869751","-8.6402089691162","-8.6202080154419"],"lat":"52.6612577","lon":"-8.6302084","display_name":"Limerick, County Limerick, Munster, Ireland, Europe","class":"place","type":"city","icon":"http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"}]

0 comments on commit ba2d231

Please sign in to comment.
Something went wrong with that request. Please try again.