diff --git a/README.markdown b/README.markdown index ce87384..f5813ea 100644 --- a/README.markdown +++ b/README.markdown @@ -103,6 +103,41 @@ Here is another example with custom icons + clustering @map.markers << marker2 +Here is an example of handling a marker being dropped. + +In your controller... +
+ @map = Cartographer::Gmap.new( 'map' )
+ @map.zoom = :bound
+ @map.icons << Cartographer::Gicon.new
+ marker1 = Cartographer::Gmarker.new(:name=> "taj_mahal", :marker_type => "Building",
+ :position => [27.173006,78.042086],
+ :draggable => true, # make it draggable
+ :drag_end => 'handleMarkerDrop(mouseEvent.latLng);', # javascript code to handle the event.
+ :info_window_url => "/url_for_info_content")
+ marker2 = Cartographer::Gmarker.new(:name=> "raj_bhawan", :marker_type => "Building",
+ :position => [28.614309,77.201353],
+ :info_window_url => "/url_for_info_content")
+
+ @map.markers << marker1
+ @map.markers << marker2
+
+
+In your view...
+
+ # for Rails 3+ you need to make use of 'raw'
+ <%= raw Cartographer::Header.new.to_s %>
+ <%= raw @map.to_html %>
+ <div style="width:600px;height:400px;" id="map" > [Map] </div>
+
+ <script type="text/javascript">
+ function handleMarkerDrop(latLng){
+ alert('You moved marker to LAT: '+latLng.lat()+' and LNG: '+latLng.lng()+'!');
+ }
+ </script>
+
+
+
Adsense for Maps
----------------
diff --git a/lib/v3/cartographer/gmarker.rb b/lib/v3/cartographer/gmarker.rb
index d4c932f..496a04f 100644
--- a/lib/v3/cartographer/gmarker.rb
+++ b/lib/v3/cartographer/gmarker.rb
@@ -1,6 +1,6 @@
class Cartographer::Gmarker
#include Reloadable
- attr_accessor :name, :marker_type, :highlight, :icon, :position, :click, :info_window, :info_window_url, :map, :min_zoom, :max_zoom, :dblclick, :draggable
+ attr_accessor :name, :marker_type, :highlight, :icon, :position, :click, :info_window, :info_window_url, :map, :min_zoom, :max_zoom, :dblclick, :draggable, :drag_end
def initialize(options = {})
@name = options[:name] || "marker"
@@ -9,6 +9,7 @@ def initialize(options = {})
@icon = options[:icon] || Cartographer::Gicon.new
@click = options[:click] # javascript to execute on click
@dblclick = options[:dblclick] # javascript to execute on double click
+ @drag_end = options[:drag_end] # javascript to execute on dragend event
@info_window = options[:info_window] # html to pop up on click
@info_window_url = options[:info_window_url] # html to pop up on click fetched from a URL
@map = options[:map]
@@ -75,6 +76,10 @@ def to_js(marker_mgr_flag = false, marker_clusterer_flag = false)
script << "google.maps.event.addListener(#{name}, 'dblclick', function() {#{@dblclick}});\n"
end
+ if @drag_end
+ script << "google.maps.event.addListener(#{name}, 'dragend', function(mouseEvent) {#{@drag_end}});\n"
+ end
+
script << " // Add the marker to a new overlay on the map" if @debug
script << " #{@name}.setMap(#{@map.dom_id});\n" if self.highlight || (!marker_mgr && !marker_clusterer)
return @debug? script.join("\n ") : script.join.gsub(/\s+/, ' ')
diff --git a/spec/gmarker_spec.rb b/spec/gmarker_spec.rb
index bf55819..4870cbe 100644
--- a/spec/gmarker_spec.rb
+++ b/spec/gmarker_spec.rb
@@ -46,6 +46,16 @@
end
+ it "should accept configuration for dragend event" do
+ marker = Cartographer::Gmarker.new(:name=> "org11", :marker_type => "Organization",
+ :position => [ 36.031332, -21.093750],
+ :drag_end => "alert(\"DragEnd Works!\");",
+ :icon => @icon,
+ :map=>@map)
+ marker.to_js().should include("google.maps.event.addListener(org11, 'dragend', function(mouseEvent) {alert(\"DragEnd Works!\");});")
+
+ end
+
it "should accept configuration for info window url" do
marker = Cartographer::Gmarker.new(:name=> "org11", :marker_type => "Organization",
:position => [ 36.031332, -21.093750],