[Jifty-commit] r3647 - in jifty/trunk: lib/Jifty/Plugin/GoogleMap share/web/static/js

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jul 10 10:26:57 EDT 2007


Author: clkao
Date: Tue Jul 10 10:26:55 2007
New Revision: 3647

Added:
   jifty/trunk/share/web/static/css/google_map.css
Modified:
   jifty/trunk/lib/Jifty/Plugin/GoogleMap/Widget.pm
   jifty/trunk/share/web/static/css/main.css
   jifty/trunk/share/web/static/js/google_map.js

Log:
Address search!

Modified: jifty/trunk/lib/Jifty/Plugin/GoogleMap/Widget.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/GoogleMap/Widget.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/GoogleMap/Widget.pm	Tue Jul 10 10:26:55 2007
@@ -38,7 +38,8 @@
     ($x, $y) = (-71.2, 42.4) if $use_default;
     my $zoom_level = $use_default ? 1 : 13;
     my $element_id = $self->element_id;
-    Jifty->web->out(qq{<div @{[$self->_widget_class]} id="$element_id" style="left: 200px; width: 250px; height: 250px"></div>});
+    Jifty->web->out(qq{<div class="googlemap-widget-wrapper" style="left: 200px; width: 250px; height: 250px"><div @{[$self->_widget_class]} id="$element_id" style="left: 200px; width: 250px; height: 250px"></div>});
+    Jifty->web->out(qq{<div class="googlemap-search-results" id="$element_id-result">FNORD</div></div>});
     Jifty->web->out(qq{<script type="text/javascript">
 Jifty.GMap.location_editor( \$("$element_id"), $x, $y, "$xid", "$yid", $zoom_level, $use_default, $readonly);
 </script>

Added: jifty/trunk/share/web/static/css/google_map.css
==============================================================================
--- (empty file)
+++ jifty/trunk/share/web/static/css/google_map.css	Tue Jul 10 10:26:55 2007
@@ -0,0 +1,15 @@
+/* XXX: move to Plugin::GoogleMap */
+
+div .googlemap-search-results {
+    background-color:white;
+    border-width: 2px;
+    border-color: black;
+    border-style:dashed;
+    display:none;
+    height:450px;
+    left:250px;
+    position:relative;
+    top:-300px;
+    width:250px;
+    z-index:10;
+}

Modified: jifty/trunk/share/web/static/css/main.css
==============================================================================
--- jifty/trunk/share/web/static/css/main.css	(original)
+++ jifty/trunk/share/web/static/css/main.css	Tue Jul 10 10:26:55 2007
@@ -12,3 +12,4 @@
 @import "yui/calendar/calendar.css";
 @import "yui/menu/menu.css";
 @import "notices.css";
+ at import "google_map.css";

Modified: jifty/trunk/share/web/static/js/google_map.js
==============================================================================
--- jifty/trunk/share/web/static/js/google_map.js	(original)
+++ jifty/trunk/share/web/static/js/google_map.js	Tue Jul 10 10:26:55 2007
@@ -11,6 +11,7 @@
 
     var map = new GMap2(element);
     map.enableScrollWheelZoom();
+    map._jifty_search_result = element.nextSibling;
     map.addControl(new GSmallZoomControl());
     if(!readonly)
 	map.addControl(new EditLocationControl());
@@ -62,17 +63,18 @@
   });
 
   GEvent.addDomListener(SearchDiv, "click", function() {
-	  var element = document.createElement('form');
-	  element._map = map;
-	  element.setAttribute('onsubmit','_handle_search(this._map, this.firstChild.value); return false;');
-	  var field= document.createElement('input');
-	  field.setAttribute('type', 'text');
-	  field.style.width = '150px';
-	  element.appendChild(field);
-	  var submit= document.createElement('input');
-	  submit.setAttribute('type', 'submit');
-	  element.appendChild(submit);
-	  map.openInfoWindow(map.getCenter(), element, { maxWidth: 100 } );
+      var element = document.createElement('form');
+      element._map = map;
+      element.setAttribute('onsubmit','_handle_search(this._map, this.firstChild.value); return false;');
+      var field= document.createElement('input');
+      field.setAttribute('type', 'text');
+      field.style.width = '150px';
+      element.appendChild(field);
+      var submit= document.createElement('input');
+      submit.setAttribute('type', 'submit');
+      element.appendChild(submit);
+      map.openInfoWindow(map.getCenter(), element, { maxWidth: 100 } );
+      field.focus();
   });
 
   map.getContainer().appendChild(container);
@@ -81,31 +83,53 @@
   return container;
 }
 
+function _mark_new_location(map, placemark) {
+    var point = placemark.Point.coordinates;
+    if (map._jifty_location)
+	map.removeOverlay(map._jifty_location);
+    map._jifty_location = new GMarker(new GLatLng(point[1], point[0]));
+    map.addOverlay(map._jifty_location);
+    map.closeInfoWindow();
+    map.setCenter(map._jifty_location.getPoint(), 8+placemark.AddressDetails.Accuracy);
+}
+
 function _handle_search(map, address) {
     var geocoder = new GClientGeocoder();
-    geocoder.getLocations(address,
-			  function (result) {
-			      if(result.Placemark) {
-				  if (result.Placemark.length == 1) {
-				      var point = result.Placemark[0].Point.coordinates;
-				      map.removeOverlay(map._jifty_location);
-				      map._jifty_location = new GMarker(new GLatLng(point[1], point[0]));
-				      map.addOverlay(map._jifty_location);
-				      map.closeInfoWindow();
-				      map.setCenter(map._jifty_location.getPoint(), 8+result.Placemark[0].AddressDetails.Accuracy);
-				  }
-				  else {
-				      _handle_multiple_results(map, result);
-				  }
-			      }
-			      else {
-				  alert('address not found');
-			      }
-			  });
+    geocoder.getLocations
+      (address,
+       function (result) {
+	   if(result.Placemark) {
+	       if (result.Placemark.length == 1)
+		   _mark_new_location(map, result.Placemark[0]);
+	       else
+		   _handle_multiple_results(map, result);
+	   }
+	   else {
+	       // TODO: show error in warning box in infowindow rather than alert
+	       alert('address not found');
+	   }
+       });
+}
+
+function _handle_multiple_results(map, result) {
+    var buf = '<a href="#" onclick="_handle_result_click(this, null); return false;">Close</a><ul>';
+    for (var i = 0; i < result.Placemark.length; ++i) {
+	var data = result.Placemark[i];
+	buf += '<li><a href="#" onclick='+"'"+
+            '_handle_result_click(this.parentNode.parentNode.parentNode, '+JSON.stringify(data)+'); return false;' +
+          "'>"+data.address+'</a></li>';
+    }
+    buf += '</ul>';
+    map._jifty_search_result.innerHTML = buf;
+    map._jifty_search_result.style.display = "block";
+    map._jifty_search_result._map = map;
 }
 
-function _handle_multiple_results {
-
+function _handle_result_click(e, data) {
+    e.style.display = 'none';
+    var map = e._map; e._map = null; /* circular reference? */
+    if (data)
+	_mark_new_location(map, data);
 }
 
 EditLocationControl.prototype.getDefaultPosition = function() {


More information about the Jifty-commit mailing list