Class: Ipdb::Map
- Inherits:
-
Object
- Object
- Ipdb::Map
- Defined in:
- lib/ipdb/map.rb
Instance Method Summary collapse
-
#initialize(addr = nil, options = {}) ⇒ MAP
constructor
Creates a new Map object.
-
#render(js = true) ⇒ String<HTML, JavaScript>
Return a Google Map for a Query Object.
- #render_div ⇒ Object
- #render_js ⇒ Object
Constructor Details
#initialize(addr = nil, options = {}) ⇒ MAP
Creates a new Map object.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ipdb/map.rb', line 26 def initialize(addr=nil, ={}) @timeout = [:timeout] || 10 @units = ([:units] || :px).to_sym @width = [:width] || 600 @height = [:height] || 350 @zoom = [:zoom] || 10 @div_id = [:div_id] || 'map_canvas' @div_class = [:div_class] || 'ipdb' ip = [addr].flatten @url = "#{SCRIPT}?ip=#{URI.escape(ip.join(','))}" @xml = Nokogiri::XML.parse(open(@url)).xpath('//Location') end |
Instance Method Details
#render(js = true) ⇒ String<HTML, JavaScript>
Return a Google Map for a Query Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ipdb/map.rb', line 47 def render(js=true) @map = ""; @id = 0 @xml.each do |x| location = Location.new(x, @timeout) id = "ip_#{@id += 1}_id" @start = new_location(location.latitude, location.longitude) if @id == 1 @map += add_marker(id, location.address, location.latitude, location.longitude) @map += add_window(id, location.address, location.city, location.country) @map += add_listener(id) end if js build_map(@start, @map) else build_map_without_js(@start, @map) end end |
#render_div ⇒ Object
77 78 79 |
# File 'lib/ipdb/map.rb', line 77 def render_div "<div id='#{@div_id}' class='#{@div_class}' style='width: #{@width}#{@units}; height: #{@height}#{@units}'></div>" end |
#render_js ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ipdb/map.rb', line 64 def render_js @map = ""; @id = 0 @xml.each do |x| location = Location.new(x, @timeout) id = "ip_#{@id += 1}_id" @start = new_location(location.latitude, location.longitude) if @id == 1 @map += add_marker(id, location.address, location.latitude, location.longitude) @map += add_window(id, location.address, location.city, location.country) @map += add_listener(id) end build_map_just_js(@start, @map) end |