Permalink
Browse files

handle the no way found situation more gracefully

  • Loading branch information...
1 parent e80fdcc commit 55a39b3a699a2b5c6fa675bdf311779dd15433ff @fruminator committed Apr 6, 2011
Showing with 32 additions and 3 deletions.
  1. +23 −2 debug.tmpl.php
  2. +9 −1 osb.inc.php
View
@@ -29,12 +29,33 @@
<input type="submit" name="GO">
</FORM>
+<? if(array_key_exists('error', $osb)) { ?>
+ <p><B>ERROR:
+<?= htmlentities($osb[error]); ?>
+</p></b>
+<? } ?>
<p>
-Closest OSM Way is: <strong><?= $osb[way][name] ?> (<?=$osb[way][osm_id] ?>)</strong> (Normalized: <?=street_norm($osb[way][name]);?>)
+Closest OSM Way is:
+<? if(array_key_exists('way', $osb)) { ?>
+
+<strong><?= $osb[way][name] ?> (<?=$osb[way][osm_id] ?>)</strong> (Normalized: <?=street_norm($osb[way][name]);?>)
+
+<? } else { ?>
+
+NONE FOUND
+
+<? } ?>
</p>
<p>
- Which has <?= count($osb[node_ids]) ?> OSM nodes: (<?= join(",", $osb[node_ids]); ?>)
+ Which has <?= count($osb[node_ids]) ?> OSM nodes:
+
+<? if(array_key_exists('node_ids', $osb)) { ?>
+(<?= join(",", $osb[node_ids]); ?>)
+
+<? } ?>
+
+
</p>
The <?= OSB_MAX_NODES_EXPAND ?> closest nodes are:
View
@@ -55,7 +55,7 @@ function OpenStreetBlock($lat, $lon, $db, $max_nodes_expand = OSB_MAX_NODES_EXPA
$way = $way_query->fetch(PDO::FETCH_ASSOC);
if(!$way) {
- $res['error'] = sprintf("NO WAY FOUND NEAR: %s,%s", $lat, $lon);
+ $res['error'] = sprintf("No Way Found Near (%s,%s)", $lat, $lon);
return $res;
}
@@ -152,6 +152,10 @@ function node_intersection_name($node) {
}
function osb_simple($osb) {
+ if(array_key_exists('error', $osb)) {
+ return sprintf("ERROR: %s", $osb[error]);
+ }
+
return(sprintf("%s %s %s", $osb[way][name]
, count($osb[nodes]) == 1 ? '@' : 'bet.'
, join(" & ", array_map(create_function('$n', 'return node_intersection_name($n);'), $osb[nodes]))
@@ -178,6 +182,10 @@ function osb_json($osb) {
$x[text] = osb_simple($osb);
+ if(array_key_exists('error', $osb)) {
+ $x[error] = $osb[error];
+ }
+
return json_encode($x);
}

0 comments on commit 55a39b3

Please sign in to comment.