Class: MapLayers::Map

Inherits:
Object
  • Object
show all
Includes:
JsWrapper
Defined in:
lib/map_layers/map.rb

Overview

Map viewer main class

Instance Attribute Summary

Attributes included from JsWrapper

#variable

Instance Method Summary collapse

Methods included from JsWrapper

#[], #assign_to, #declare, #declare_random, #declared?, escape_javascript, #get_property, javascriptify_method, #javascriptify_method_call, javascriptify_variable, #method_missing, #set_property, #to_javascript, #to_json

Constructor Details

#initialize(map, options = {}) {|_self, @js| ... } ⇒ Map

Returns a new instance of Map.

Yields:

  • (_self, @js)

Yield Parameters:



53
54
55
56
57
58
59
# File 'lib/map_layers/map.rb', line 53

def initialize(map, options = {}, &block)
  @container = map
  @variable = map
  @options = {:theme => false}.merge(options)
  @js = JsGenerator.new
  yield(self, @js) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MapLayers::JsWrapper

Instance Method Details

#createObject

Outputs in JavaScript the creation of a OpenLayers.Map object



62
63
64
# File 'lib/map_layers/map.rb', line 62

def create
  "new OpenLayers.Map('#{@container}', #{JsWrapper::javascriptify_variable(@options)})"
end

#to_html(options = {}) ⇒ Object

Outputs the initialization code for the map



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/map_layers/map.rb', line 67

def to_html(options = {})
  no_script_tag = options[:no_script_tag]
  no_declare = options[:no_declare]
  no_global = options[:no_global]

  html = ""
  html << "<script defer=\"defer\" type=\"text/javascript\">\n" if !no_script_tag
  #put the functions in a separate javascript file to be included in the page
  html << "var #{@variable};\n" if !no_declare and !no_global

  if !no_declare and no_global
    html << "#{declare(@variable)}\n"
  else
    html << "#{assign_to(@variable)}\n"
  end
  html << @js.to_s
  html << "</script>\n" if !no_script_tag

  html
end