[OpenLayers-Commits] r7510 - in sandbox/topp/almanac: examples lib lib/OpenLayers/Control
commits at openlayers.org
commits at openlayers.org
Tue Jul 15 16:04:17 EDT 2008
Author: sbenthall
Date: 2008-07-15 16:04:17 -0400 (Tue, 15 Jul 2008)
New Revision: 7510
Added:
sandbox/topp/almanac/examples/yahoogeocoder.html
sandbox/topp/almanac/lib/OpenLayers/Control/YahooGeocoder.js
Modified:
sandbox/topp/almanac/lib/OpenLayers.js
Log:
work towards a Yahoo geocoding control (with example)
Added: sandbox/topp/almanac/examples/yahoogeocoder.html
===================================================================
--- sandbox/topp/almanac/examples/yahoogeocoder.html (rev 0)
+++ sandbox/topp/almanac/examples/yahoogeocoder.html 2008-07-15 20:04:17 UTC (rev 7510)
@@ -0,0 +1,57 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>OpenLayers Example</title>
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+ <link rel="stylesheet" href="style.css" type="text/css" />
+ <script src="../lib/OpenLayers.js"></script>
+ <script type="text/javascript">
+ // making this a global variable so that it is accessible for
+ // debugging/inspecting in Firebug
+ var map = null;
+
+ appid = "pggycKLV34H4zJIYhznYx8MSJVU8JDKq1NITZjt1yL5iWPSlju6FegSo1uiwBE4M0bzgndu1Dvu0";
+ OpenLayers.ProxyHost="/cgi-bin/proxy.cgi?url=";
+
+ var yahoo;
+
+ function init(){
+
+
+ map = new OpenLayers.Map('map');
+
+ var ol_wms = new OpenLayers.Layer.WMS(
+ "OpenLayers WMS",
+ "http://labs.metacarta.com/wms/vmap0",
+ {layers: 'basic'}
+ );
+
+ map.addLayers([ol_wms]);
+
+ yahoo = new OpenLayers.Control.YahooGeocoder(appid, OpenLayers.ProxyHost)
+
+ map.addControl(yahoo);
+ map.zoomToMaxExtent();
+ }
+
+ function locate(){
+ address = document.getElementById("location").value;
+
+ yahoo.getLocation(address);
+ }
+ </script>
+ </head>
+ <body onload="init()">
+ <h1 id="title">OpenLayers Example</h1>
+ <div id="tags"></div>
+ <p id="shortdesc">
+ Demonstrate a simple map with an overlay that includes layer switching controls.
+ </p>
+ <div id="map" class="smallmap"></div>
+
+ <form>
+ <input type="text" id="location"></input>
+ <input type="button" value="Submit" onclick="locate()"></input>
+ </form>
+ <div id="docs"></div>
+ </body>
+</html>
\ No newline at end of file
Added: sandbox/topp/almanac/lib/OpenLayers/Control/YahooGeocoder.js
===================================================================
--- sandbox/topp/almanac/lib/OpenLayers/Control/YahooGeocoder.js (rev 0)
+++ sandbox/topp/almanac/lib/OpenLayers/Control/YahooGeocoder.js 2008-07-15 20:04:17 UTC (rev 7510)
@@ -0,0 +1,128 @@
+/**
+ * Class: OpenLayers.Control.Geocoder
+ * A wrapper around Yahoo's REST geocoding API.
+ */
+OpenLayers.Control.YahooGeocoder = OpenLayers.Class(OpenLayers.Control, {
+
+ /**
+ * Property: yahooUrl
+ * The URL of Yahoo's geocoding service
+ */
+ yahooUrl : "http://local.yahooapis.com/MapsService/V1/geocode",
+
+ /**
+ * Property: appid
+ * {String} The Yahoo application ID.
+ * See here: http://developer.yahoo.com/faq/index.html#appid
+ */
+ appid: null,
+
+ /**
+ * proxy: proxy
+ * {String} The URL of the proxy.
+ */
+
+ proxy: null,
+
+ /**
+ * Property: clientProj
+ * {<OpenLayers.Projection>} The spatial reference for the client (the map).
+ */
+ clientProj: null,
+
+ /**
+ * Property: serverProj
+ * {<OpenLayers.Projection>} The spatial reference for the geocoding service.
+ */
+ serverProj: null,
+
+ /**
+ * Constructor: OpenLayers.Control.YahooGeocoder
+ *
+ * Parameters:
+ * options - {Object} An optional object with properties to be set on the
+ * control.
+ */
+ initialize: function(appid, options) {
+ this.appid = appid;
+ this.proxy = "";
+
+ this.serverProj = new OpenLayers.Projection("EPSG:4326");
+
+ OpenLayers.Control.prototype.initialize.apply(this, [options]);
+ },
+
+ /**
+ * APIMethod: destroy
+ * Clean up the control
+ */
+ destroy: function() {
+ OpenLayers.Control.prototype.destroy.apply(this, arguments);
+ },
+
+ /**
+ * Method: setMap
+ * Handle whatever needs to be done when control is added to map.
+ *
+ * Parameters:
+ * map - {<OpenLayers.Map>}
+ */
+ setMap: function(map) {
+ OpenLayers.Control.prototype.setMap.apply(this, [map]);
+ this.clientProj = this.map.projection;
+ },
+
+ /**
+ * APIMethod: getLocation
+ * Geocode an address and call a callback with the response.
+ * If no match is found, callback will receive null.
+ *
+ * Parameters:
+ * address - {String} An address string.
+ * callback - {Function} A function to be called with the resulting
+ * <OpenLayers.LonLat>. If no match is found, callback will receive
+ * null.
+ */
+ getLocation: function(location, callback) {
+
+ params = {
+ appid : this.appid,
+ location: location
+ }
+
+ if(!callback) {
+ callback = function() {};
+ }
+ var bound = OpenLayers.Function.bind(function(request) {
+
+ if(request.status >= 200 && request.status < 300) {
+ // success
+ var xml = new OpenLayers.Format.XML();
+
+ response = xml.read(request.response)
+
+ OpenLayers.Console.log(response);
+ } else {
+ // failure
+ }
+
+ var lonlat = null;
+ if(point) {
+ var lonlat = new OpenLayers.LonLat(point.lng(), point.lat());
+ lonlat.transform(this.serverProj, this.clientProj);
+ }
+ callback(lonlat);
+ }, this);
+
+ this.request = OpenLayers.Request.GET({
+ url: this.proxy + escape(this.yahooUrl),
+ callback: bound,
+ params: params,
+ scope: this
+ });
+
+ return this.request;
+ },
+
+ CLASS_NAME: "OpenLayers.Control.Geocoder"
+});
Modified: sandbox/topp/almanac/lib/OpenLayers.js
===================================================================
--- sandbox/topp/almanac/lib/OpenLayers.js 2008-07-15 08:07:12 UTC (rev 7509)
+++ sandbox/topp/almanac/lib/OpenLayers.js 2008-07-15 20:04:17 UTC (rev 7510)
@@ -169,6 +169,7 @@
"OpenLayers/Control/SelectFeature.js",
"OpenLayers/Control/NavigationHistory.js",
"OpenLayers/Control/Geocoder.js",
+ "OpenLayers/Control/YahooGeocoder.js",
"OpenLayers/Geometry.js",
"OpenLayers/Geometry/Rectangle.js",
"OpenLayers/Geometry/Collection.js",
More information about the Commits
mailing list