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 ⇒ String<HTML, JavaScript>
Return a Google Map for a Query 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 ⇒ String<HTML, JavaScript>
Return a Google Map for a Query Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ipdb/map.rb', line 45 def render @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(@start, @map) end |