Changeset 189


Ignore:
Timestamp:
Oct 26, 2006, 9:26:12 PM (13 years ago)
Author:
David Sheldon
Message:

Display a list of possible locations if geonames has several results.

Location:
trunk/npemap.org.uk/static/tiles
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/static/tiles/grid.css

    r125 r189  
    2323                        z-index: 10;
    2424    }
    25  
     25
     26    div.geonames {
     27      background-color: white;
     28      border: 1px solid black;
     29      float: right;
     30      position: absolute;
     31    }
     32    div.geonames span.loc {
     33      font-size: 60%;
     34    }
     35   
    2636   span.terms {
    2737                 margin-top: 0px;
  • trunk/npemap.org.uk/static/tiles/map.html

    r176 r189  
    2222
    2323<div id="main_page">
    24 <div id="move" style="float:right">
     24<div id="menu" style="float:right">
    2525         <table border="0">
    2626           <tr>
     
    5757                        <a href="/reportBug.html">problem?</a>
    5858                </div>
    59                 <div>
     59                <div id="geonames-search">
    6060      <form onsubmit="return find()" action="">
    6161      <p><label for="where">Place name:</label><br/>
  • trunk/npemap.org.uk/static/tiles/mapTiles.js

    r187 r189  
    417417
    418418function find() {
    419    request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent($('where').value)  + '&maxRows=1&callback=getLocation&country=GB&fclass=P&style=SHORT';
     419   request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent($('where').value)  + '&callback=getLocation&country=GB&fclass=P&style=SHORT';
    420420  aObj = new JSONscriptRequest(request);
    421421  // Build the script tag
     
    434434  var geonames = jData.geonames;
    435435  if (geonames.length > 0) {
    436     var name = geonames[0];
    437     var ll = new LatLng(name.lat,name.lng);
     436    if (geonames.length == 1) {
     437      var name = geonames[0];
     438      gotoLatLong(name.lat, name.lng, 1);
     439    } else {
     440      var popup = geonamesPopup();
     441      for(var i=0; i<geonames.length; i=i+1) {
     442        appendLink(popup, geonames[i]);
     443      }
     444    }
     445    $('where').value = '';
     446  }
     447  else {
     448    alert("Sorry, can't find that location");
     449  }
     450}
     451
     452function geonamesPopup() {
     453 var popup = document.createElement("div");
     454 popup.className = "geonames";
     455 $("menu").appendChild(popup);
     456 var link = document.createElement("A");
     457 link.onclick = function () { $("menu").removeChild(popup); return false; };
     458 link.href = '#';
     459 link.innerHTML = "close" ;
     460 popup.appendChild(link);
     461 popup.appendChild(document.createElement("BR"));
     462// popup.setXY($("geonames-search").getXY());
     463 return popup;
     464}
     465
     466function appendLink(popup, loc) {
     467 var link = document.createElement("A");
     468 link.onclick = function () { gotoLatLong(loc.lat, loc.lng, 1); $("menu").removeChild(popup); return false; };
     469 link.href = '#';
     470 link.innerHTML = loc.name ;
     471 popup.appendChild(link);
     472 var span = document.createElement("SPAN");
     473 span.className = "loc";
     474 formatLatLong(span, loc.lat, loc.lng);
     475 popup.appendChild(span);
     476 popup.appendChild(document.createElement("BR"));
     477}
     478
     479function formatLatLong(parent, lat, lng) {
     480  var text = " N " + formatDeg(lat) + " " ;
     481  if (lng < 0) { text += "W ";} else { text += "E ";}
     482  text += formatDeg(Math.abs(lng));
     483  parent.appendChild(document.createTextNode(text));
     484}
     485
     486function formatDeg(num) {
     487  var text = (Math.floor(num * 10)/10) + "° ";
     488  return text;
     489}
     490
     491function gotoLatLong(lat, lng, zoom) {
     492    var ll = new LatLng(lat,lng);
    438493    ll.WGS84ToOSGB36();
    439494    var en = ll.toOSRef();
    440495    var easting = Math.round(en.easting/1000);
    441496    var northing = Math.round(en.northing/1000);
    442     gotoLocation(easting, northing, 1);
    443    
    444     $('where').value = '';
    445   }
    446   else {
    447     alert("Sorry, can't find that location");
    448   }
    449 }
    450 
    451 
     497    gotoLocation(easting, northing, zoom);
     498}
     499
     500
Note: See TracChangeset for help on using the changeset viewer.