Changeset 131


Ignore:
Timestamp:
Oct 22, 2006, 10:49:03 AM (13 years ago)
Author:
David Sheldon
Message:

Form to zoom to a town name. Uses geonames.

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

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/static/index.html

    r123 r131  
    88<script src="tiles/dom.js"></script>
    99<script src="tiles/event.js"></script>
     10<script src="tiles/jsr_class.js"></script>
     11<script src="tiles/jscoord-1.1.1.js"></script>
    1012<div id="body">
    1113<h1>New Popular Mapping<sup>beta</sup></h1>
     
    4244<a href="#" id="link">
    4345<img src="thumbnail.jpg" style="border: none" />
    44 </a> </div>
     46</a>
     47
     48<form onsubmit="return find()">
     49<p><label for="where">Place Name</label>
     50<input id="where" name="where" /></p>
     51<p><input type="submit" name="Zoom To" /></p>
     52</form>
     53</div>
    4554
    4655<script type="text/javascript">
    4756var xOffset = 62;
     57
     58function find() {
     59   request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent(document.getElementById('where').value)  + '&maxRows=1&callback=getLocation&country=GB&fclass=P&style=SHORT';
     60  aObj = new JSONscriptRequest(request);
     61  // Build the script tag
     62  aObj.buildScriptTag();
     63  // Execute (add) the script tag
     64  aObj.addScriptTag();
     65  return false;
     66}
     67
     68// this function will be called by our JSON callback
     69function getLocation(jData) {
     70  if (jData == null) {
     71    // There was a problem parsing search results
     72    return;
     73  }
     74
     75  var geonames = jData.geonames;
     76  if (geonames.length > 0) {
     77    var name = geonames[0];
     78    var ll = new LatLng(name.lat,name.lng);
     79    ll.WGS84ToOSGB36();
     80    var en = ll.toOSRef();
     81    var easting = Math.round(en.easting/1000);
     82    var northing = Math.round(en.northing/1000);
     83    window.location = "tiles/map.html#" + easting + "," + northing + ",1";
     84  }
     85  else {
     86    alert("Sorry, can't find that location");
     87  }
     88}
     89
     90
    4891
    4992function click(e) {
Note: See TracChangeset for help on using the changeset viewer.