[OSM-dev] Name finder for the main OSM page?

David Earl david at frankieandshadow.com
Wed Aug 8 12:13:36 BST 2007


On 08/08/2007 11:55, Abigail Brady wrote:
> On 8/8/07, *Tom Hughes* <tom at compton.nu <mailto:tom at compton.nu>> wrote:
> 
>     I've made it so that only the actual name is the link now, which
>     helps to make that stand out from the type prefix and the proximity
>     suffix stuff.
> 
> 
> This is good, except for the niggle that some anonymous objects get 
> returned by the namefinder (try searching for 'post offices near london' 
> as an example).  Possibly link the type in this case?

Indeed, there's nothing to click on and an extraneous space before the 
comma.

You (Tom) might find the following helpful in how I construct the long 
contextual description that you see in PHP. This is from the 'named' 
class, which corresponds very closely with the XML structure you see. 
Note that in describing the compass points, I'm not doing exact 45 
degree segments.I found that it looked odd describing something as 
'east' when it was as quite a long way off the straight line, so I opted 
for 20 degrees either side of the primary compass points and 30 degrees 
either side of the secondary ones.

David


   // --------------------------------------------------
   function assigndescription($placerequested) {
     $prefix = '';
     $s = $this->describeincontext(TRUE) . ' found ';
     if (is_object($this->placenearer) &&
         ! $this->contextcontains($this->placenearer) &&
        $this->placenearer->id != $this->id)
     {
       $s .= $this->placenearer->describedistancefrom() . ' ' .
             $this->placenearer->describeincontext();
       $prefix = ' and ';
     }
     if (is_object($this->place) &&
         ! $this->contextcontains($this->place))
     {
       $s .= $prefix .
             $this->place->describedistancefrom() . ' ' .
             $this->place->describeincontext();
     }

     $this->description = $s;
   }

     // --------------------------------------------------
   function describebasic($resetisin=FALSE) {
     $info = $this->info;
     if ($info == 'airport; airport') { $info = 'airport'; /* until I 
can fix it in the index */}
     $infohtml = htmlspecialchars($info, ENT_QUOTES, 'UTF-8');
     $namehtml = htmlspecialchars($this->name, ENT_QUOTES, 'UTF-8');
     $isinhtml = htmlspecialchars($this->info, ENT_QUOTES, 'UTF-8');
     $isinhtml = htmlspecialchars($this->tidyupisin($resetisin), 
ENT_QUOTES, 'UTF-8');
     return "{$infohtml} 
<strong>{$namehtml}</strong>{$isinhtml}";
   }

   // --------------------------------------------------
   function describedistancefrom() {
     $angle = $this->direction;
     if ($angle <= 20 || $angle >= 340) { $direction = 'west'; }
     else if ($angle <= 70) { $direction = 'south-west'; }
     else if ($angle <= 110) { $direction = 'south'; }
     else if ($angle <= 160) { $direction = 'south-east'; }
     else if ($angle <= 200) { $direction = 'east'; }
     else if ($angle <= 250) { $direction = 'north-east'; }
     else if ($angle <= 290) { $direction = 'north'; }
     else { $direction = 'north-west'; }

     $approxdistance = $this->approxdistance();
     return $approxdistance . ' ' . $direction .
       ($this->distance < 3.0 && $this->name != '' ? ' of middle of' : ' 
of');
   }

   // --------------------------------------------------
   function describeincontext($resetisin=FALSE) {
     $s = $this->describebasic($resetisin);
     $prefix = ' (which is ';
     $andprefix = ' and ';
     if (isset($this->nearesttown1)) {
       $s .= $prefix . $this->nearesttown1->describedistancefrom() . ' ' .
         $this->nearesttown1->describebasic();
       $prefix = $andprefix;
     }
     if (isset($this->nearesttown2)) {
       $s .= $prefix . $this->nearesttown2->describedistancefrom() . ' ' .
         $this->nearesttown2->describebasic();
       $prefix = $andprefix;
     }
     if ($prefix == $andprefix) { $s .= ')'; }
     return $s;
   }

   // --------------------------------------------------
   function contextcontains($place) {
     if (empty($place)) { return FALSE; }
     if (! empty($this->nearesttown1) && $this->nearesttown1->id == 
$place->id) { return TRUE; }
     if (! empty($this->nearesttown2) && $this->nearesttown2->id == 
$place->id) { return TRUE; }
     return FALSE;
   }








More information about the dev mailing list