Skip to content
Browse files

Resolved merge conflict in header

  • Loading branch information...
2 parents d088009 + 1dd5aa9 commit 7a43b7d6156b135889deb3213e91fce4b102b9d0 Jessica Lam committed
Showing with 93 additions and 24 deletions.
  1. +1 −0 .gitignore
  2. +32 −1 README.markdown
  3. +14 −12 lib/v3/cartographer/gicon.rb
  4. +28 −5 lib/v3/cartographer/gmarker.rb
  5. +9 −5 lib/v3/cartographer/header.rb
  6. +9 −1 spec/gmarker_spec.rb
View
1 .gitignore
@@ -1,2 +1,3 @@
.bundler/
Gemfile.lock
+.rvmrc
View
33 README.markdown
@@ -39,9 +39,18 @@ In your controller...
In your view...
<pre><code>
# for Rails 3+ you need to make use of 'raw'
+
+ # in the &lt;head&gt;&lt;/head&gt; tags:
&lt;%= raw Cartographer::Header.new.to_s %&gt;
+
+ # in the &lt;body&gt;&lt;/body&gt;:
&lt;%= raw @map.to_html %&gt;
- &lt;div style=&quot;width:600px;height:400px;&quot; id=&quot;map&quot; &gt; [Map] &lt;/div&gt;
+ &lt;div style=&quot;width:600px;height:400px;&quot; id=&quot;&lt;%= @map.dom_id %&gt;&quot; &gt; [Map] &lt;/div&gt;
+</code></pre>
+
+If your website is served on https, you'll need to switch on SSL in the header (API v3 only):
+<pre><code>
+ &lt;%= raw Cartographer::Header.new(:ssl=>true).to_s %&gt;
</code></pre>
Here is another example with custom icons + clustering
@@ -125,6 +134,28 @@ For example, for a map defined as <tt>@map</tt> in your controller, you would us
* The different formats that the ad can be are [defined here](http://code.google.com/apis/maps/documentation/javascript/advertising.html#AdUnitFormats).
* The different positions the ad can be placed on the map are [defined here](http://code.google.com/apis/maps/documentation/javascript/controls.html#ControlPositioning).
+Labels for Markers
+==================
+
+There is a simple support added for the MarkerWithLabel utility class. <tt>Cartographer::Gmaker</tt> accepts a <tt>label</tt> parameter. In case when <tt>label</tt> is used, the <tt>MarkerWithLabel</tt> class is used for marker instead of the <tt>google.maps.Marker</tt> class.
+
+Example:
+
+<pre><code>
+ marker = Cartographer::Gmarker.new(
+ :name=> "marker_1", :marker_type => "Building",
+ :position => [location.latitude,location.longitude],
+ :icon => @icon,
+ :label => {
+ :content => 'Marker Label',
+ :class => "marker_label",
+ :anchor => 'new google.maps.Point(22, 0)'
+ }
+ )
+</code></pre>
+
+When markers with label are used, the <tt>markerwithlabel</tt> utility library has to be loaded.
+
Install
-------
View
26 lib/v3/cartographer/gicon.rb
@@ -4,7 +4,8 @@ class Cartographer::Gicon
:shadow_width, :shadow_height,
:image_url, :shadow_url,
:anchor_x, :anchor_y,
- :info_anchor_x, :info_anchor_y
+ :info_anchor_x, :info_anchor_y,
+ :flat
def initialize( options = {} )
@name = options[:name] || 'icon'
@@ -18,25 +19,26 @@ def initialize( options = {} )
@anchor_y = options[:anchor_y] || 34
@info_anchor_x = options[:anchor_x] || 5 #to be deprecated
@info_anchor_y = options[:anchor_y] || 1 #to be deprecated
+ @flat = options[:flat] || false # disables shadow if true
end
# turn the object into valid js
def to_js
- "var #{@name} = new google.maps.MarkerImage(
+ html = "var #{@name} = new google.maps.MarkerImage(
\"#{@image_url}\",
new google.maps.Size(#{@width},#{@height}),
new google.maps.Point(0,0),
new google.maps.Point(#{@anchor_x},#{@anchor_y})
- );
- var #{@name}_shadow = new google.maps.MarkerImage(
- \"#{@shadow_url}\",
- new google.maps.Size(#{@shadow_width},#{@shadow_height}),
- new google.maps.Point(0,0),
- new google.maps.Point(#{@anchor_x},#{@anchor_y})
- );
- "
-
-
+ );\n"
+ unless @flat
+ html << "var #{@name}_shadow = new google.maps.MarkerImage(
+ \"#{@shadow_url}\",
+ new google.maps.Size(#{@shadow_width},#{@shadow_height}),
+ new google.maps.Point(0,0),
+ new google.maps.Point(#{@anchor_x},#{@anchor_y})
+ );\n"
+ end
+ html
end
def to_html
View
33 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, :label
def initialize(options = {})
@name = options[:name] || "marker"
@@ -14,6 +14,7 @@ def initialize(options = {})
@map = options[:map]
@highlight = options[:highlight] || false
@draggable = options[:draggable] || false
+ @label = options[:label] || nil
# inherit our 'debug' settings from the map, if there is one, and it's in debug
# you can also just debug this marker, if you like, or debug the map and
@@ -35,6 +36,7 @@ def header_js
script = []
return if @info_window_url
if @info_window.kind_of?Array
+ # this probably won't work with API v3 since it does not support tabs.
script << " var #{@name}_infoTabs = ["
script << @info_window.inject([]) { |tabs,tab|
tabs << " new GInfoWindowTab(\"#{tab[:title]}\",\"#{tab[:html]}\")"
@@ -44,9 +46,14 @@ def header_js
#{@name}.openInfoWindowTabsHtml(#{@name}_infoTabs);
}\n"
else
+ # using API V3 of infowindow (PG)
+ script << "var #{@name}_infowindow = new google.maps.InfoWindow({
+ content: \"#{escape_javascript(@info_window)}\"
+ });"
+
script << "function #{@name}_infowindow_function(){
- #{@name}.openInfoWindowHtml(\"#{@info_window}\")
-}\n"
+ #{@name}_infowindow.open(#{@map.dom_id},#{@name});
+ }\n"
end
end
@@ -55,7 +62,19 @@ def to_js(marker_mgr_flag = false, marker_clusterer_flag = false)
marker_clusterer = marker_clusterer_flag
script = []
script << "// Set up the pre-defined marker" if @debug
- script << "#{@name} = new google.maps.Marker({map: null, position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: #{@draggable}, icon: #{@icon.name}, shadow: #{@icon.name}_shadow}); \n"
+ if @label
+ label_options = []
+ @label.each do |key, value|
+ if :anchor == key
+ label_options << "label#{key.to_s.capitalize}:#{value.to_s}"
+ else
+ label_options << "label#{key.to_s.capitalize}:'#{value.to_s}'"
+ end
+ end
+ script << "#{@name} = new MarkerWithLabel({map: null, position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: #{@draggable}, icon: #{@icon.name}, #{@icon.flat ? 'flat: true' : "shadow: #{@icon.name}_shadow"},#{label_options.join(',')}});\n"
+ else
+ script << "#{@name} = new google.maps.Marker({map: null, position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: #{@draggable}, icon: #{@icon.name}, #{@icon.flat ? 'flat: true' : "shadow: #{@icon.name}_shadow"}}); \n"
+ end
if @click
script << "// Create the listener for your custom click event" if @debug
@@ -88,6 +107,10 @@ def infowindow_link(link_text = 'Show on map', options = {})
def zoom_link(link_text = 'Zoom on map')
"<a href='#' onClick='#{@map.dom_id}.setCenter(new GLatLng(#{@position.first}, #{@position.last}), 8); return false;'>#{link_text}</a>"
end
-
+
+ #Escape string to be used in JavaScript. Lifted from rails.
+ def escape_javascript(javascript)
+ javascript.gsub(/\r\n|\n|\r/, "\\n").gsub("\"") { |m| "\\#{m}" }
+ end
end
View
14 lib/v3/cartographer/header.rb
@@ -6,6 +6,10 @@
class Cartographer::Header
#include Reloadable
+ def initialize(options = {})
+ @ssl = options[:ssl] || false
+ end
+
attr_accessor :uri
@@keys = {} #place holder for config options
@@ -31,10 +35,10 @@ def value_for(uri)
def to_s
# initialize the html with the IE polyline VML code
html = "\n<!--[if IE]>\n<style type=\"text/css\">v\\:* { behavior:url(#default#VML); }</style>\n<![endif]-->"
- html << "<script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=true&libraries=adsense\"></script>"
- html << "<script src='http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markermanager/src/markermanager_packed.js' type='text/javascript'></script>"
- html << "<script src='http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js' type='text/javascript'></script>"
-
+ html << "<script type=\"text/javascript\" src=\"#{@ssl ? 'https://maps-api-ssl.google.com' : 'http://maps.googleapis.com'}/maps/api/js?v=3&sensor=true&libraries=adsense\"></script>"
+ html << "<script src='#{@ssl ? 'https' : 'http'}://google-maps-utility-library-v3.googlecode.com/svn/trunk/markermanager/src/markermanager_packed.js' type='text/javascript'></script>"
+ html << "<script src='#{@ssl ? 'https' : 'http'}://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js' type='text/javascript'></script>"
+ html << "<script src='#{@ssl ? 'https' : 'http'}://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel_packed.js' type='text/javascript'></script>"
return html
end
@@ -44,4 +48,4 @@ def self.header_for(request = {}, version=CARTOGRAPHER_GMAP_VERSION) #request an
mh.to_s
end
-end
+end
View
10 spec/gmarker_spec.rb
@@ -56,4 +56,12 @@
end
-end
+ it 'accepts label parameter' do
+ marker = Cartographer::Gmarker.new(:name=> "org11", :marker_type => "Organization",
+ :position => [ 36.031332, -21.093750],
+ :label => { :content => 'Marker label' },
+ :icon => @icon,
+ :map=>@map)
+ marker.to_js().should include("labelContent:'Marker label'")
+ end
+end

0 comments on commit 7a43b7d

Please sign in to comment.
Something went wrong with that request. Please try again.