Changeset 374


Ignore:
Timestamp:
Nov 19, 2006, 12:06:16 PM (13 years ago)
Author:
David Sheldon
Message:

use the same code on the front page for the searching as we use on the main page.

Location:
trunk/npemap.org.uk/static
Files:
1 added
4 edited

Legend:

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

    r312 r374  
    129129  padding-bottom: 0.2em;
    130130}
     131#geonames_results_window {
     132  font-size: 60%;
     133  line-height: 100%;
     134  background-color: white;
     135  border: 1px solid black;
     136  width: 150px;
     137                z-index: 10;
     138  display: none;
     139padding: 0 0 0 0;
     140margin-bottom: 5px;
     141
     142}
     143
     144#geonames_results_window .close {
     145bordeR: 1px solid black;
     146border-width: 0  0 1px 1px;
     147padding: 2px;
     148}
     149
     150#geonames_results {
     151margin: 5px 2px 6px 2px
     152}
     153.close {
     154 font-family: sans-serif;
     155 float: right;
     156}
     157.close a {
     158text-decoration: none;
     159}
  • trunk/npemap.org.uk/static/index.html

    r352 r374  
    77<script src="tiles/jsr_class.js" type="text/javascript"></script>
    88<script src="tiles/jscoord-1.1.1.js" type="text/javascript"></script>
     9<script src="tiles/prototype.js" type="text/javascript"></script>
     10<script src="find.js" type="text/javascript"></script>
    911
    1012<div id="body">
     
    6466document.write(' <label for="where">Place:</label><input id="where" name="where" /> <input type="submit" name="Zoom To" value="Go" />');
    6567</script>
     68
    6669</p>
     70
     71<div id="geonames_results_window">
     72  <div class="close"><a href="javascript:hideGeonamesPopup()" title="close">X</a></div>
     73  <div id="geonames_results"></div>
     74</div>
     75
    6776</form>
    6877      <span class="terms">Functionality by <a href="http://www.geonames.org/">Geonames</a>.</span>
     
    7483var xOffset = 62;
    7584
    76 function find() {
    77    request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent(document.getElementById('where').value)  + '&maxRows=1&callback=getLocation&country=GB&fclass=P&style=SHORT';
    78   aObj = new JSONscriptRequest(request);
    79   // Build the script tag
    80   aObj.buildScriptTag();
    81   // Execute (add) the script tag
    82   aObj.addScriptTag();
    83   return false;
     85function gotoLocation(easting, northing, zoom) {
     86    location.href = urlFor(easting, northing, zoom);
    8487}
    85 
    86 // this function will be called by our JSON callback
    87 function getLocation(jData) {
    88   if (jData == null) {
    89     // There was a problem parsing search results
    90     return;
    91   }
    92 
    93   var geonames = jData.geonames;
    94   if (geonames.length > 0) {
    95     var name = geonames[0];
    96     var ll = new LatLng(name.lat,name.lng);
    97     ll.WGS84ToOSGB36();
    98     var en = ll.toOSRef();
    99     var easting = Math.round(en.easting/1000);
    100     var northing = Math.round(en.northing/1000);
    101     location.href = urlFor(easting, northing, 1);
    102   }
    103   else {
    104     alert("Sorry, can't find that location");
    105   }
    106 }
    107 
    10888
    10989
  • trunk/npemap.org.uk/static/tiles/map.html

    r369 r374  
    1414<script src="prototype.js" type="text/javascript"></script>
    1515<!-- Our functions -->
     16<script src="../find.js" type="text/javascript"></script>
    1617<script src="mapTiles.js" type="text/javascript"></script>
    1718<script type="text/javascript">
  • trunk/npemap.org.uk/static/tiles/mapTiles.js

    r373 r374  
    509509}
    510510
    511 function postcodeLoc(jData) {
    512   if (jData == null) {
    513     // There was a problem parsing search results
    514     return;
    515   }
    516   gotoLocation(Math.round(jData.e/1000), Math.round(jData.n/1000), 1);
    517 
    518 }
    519 
    520 function find() {
    521   var where = $('where').value;
    522   if (where.length > 0) {
    523     if (where.toUpperCase().match(/^([A-Z]+\d+[A-Z]?)\s*(\d[A-Z][A-Z])?$/)) {
    524       request = "/cgi/geocoder.fcgi?postcode=" + encodeURIComponent(where) + "&callback=postcodeLoc&format=js";
    525      
    526     } else {
    527       request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent(where)  + '&callback=getLocation&country=GB&fclass=P&fclass=T&style=SHORT';
    528     }
    529     aObj = new JSONscriptRequest(request);
    530     // Build the script tag
    531     aObj.buildScriptTag();
    532     // Execute (add) the script tag
    533     aObj.addScriptTag();
    534   }
    535   return false;
    536 }
    537 // this function will be called by our JSON callback
    538 function getLocation(jData) {
    539   if (jData == null) {
    540     // There was a problem parsing search results
    541     return;
    542   }
    543 
    544   var geonames = jData.geonames;
    545   if (geonames.length > 0) {
    546     if (geonames.length == 1) {
    547       var name = geonames[0];
    548       gotoLatLong(name.lat, name.lng, 1);
    549     } else {
    550       var popup = showGeonamesPopup();
    551       for(var i=0; i<geonames.length; i=i+1) {
    552         appendLink($('geonames_results'), geonames[i]);
    553       }
    554     }
    555     $('where').value = '';
    556   }
    557   else {
    558     alert("Sorry, can't find that location");
    559   }
    560 }
    561 
    562 function hideGeonamesPopup() {
    563  var popup = $('geonames_results_window');
    564  popup.style.display = 'none';
    565 }
    566 
    567 function showGeonamesPopup() {
    568  var popup = $('geonames_results_window');
    569  popup.style.display = 'block';
    570  $('geonames_results').innerHTML = '';
    571  
    572 }
    573 
    574 function appendLink(popup, loc) {
    575  var link = document.createElement("A");
    576  link.onclick = function () { gotoLatLong(loc.lat, loc.lng, 1); hideGeonamesPopup(); return false; };
    577  link.href = '#';
    578  link.innerHTML = loc.name ;
    579  popup.appendChild(link);
    580  var span = document.createElement("SPAN");
    581  span.className = "loc";
    582  formatLatLong(span, loc.lat, loc.lng);
    583  popup.appendChild(span);
    584  popup.appendChild(document.createElement("BR"));
    585 }
    586 
    587 function formatLatLong(parent, lat, lng) {
    588   var text = " N " + formatDeg(lat) + " " ;
    589   if (lng < 0) { text += "W ";} else { text += "E ";}
    590   text += formatDeg(Math.abs(lng));
    591   parent.appendChild(document.createTextNode(text));
    592 }
    593 
    594 function formatDeg(num) {
    595   var text = (Math.floor(num * 10)/10) + "\u00B0 ";
    596   return text;
    597 }
    598 
    599 function gotoLatLong(lat, lng, zoom) {
    600     var ll = new LatLng(lat,lng);
    601     ll.WGS84ToOSGB36();
    602     var en = ll.toOSRef();
    603     var easting = Math.round(en.easting/1000);
    604     var northing = Math.round(en.northing/1000);
    605     gotoLocation(easting, northing, zoom);
    606 }
    607 
    608511function showReportForm() {
    609512  $('report_form').style.display = 'block';
Note: See TracChangeset for help on using the changeset viewer.