Class: Ropenlayer::Openlayer::Feature
- Inherits:
-
Object
- Object
- Ropenlayer::Openlayer::Feature
- Defined in:
- lib/ropenlayer/openlayer/feature.rb
Constant Summary collapse
- DEFAULT_ICON_SIZE =
[ 40, 34 ]
- DEFAULT_ICON_URL =
"/images/ropenlayer/default_marker.png"
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(map, attributes) ⇒ Feature
constructor
A new instance of Feature.
- #to_js ⇒ Object
Constructor Details
#initialize(map, attributes) ⇒ Feature
Returns a new instance of Feature.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 20 def initialize(map, attributes) @map = map @id = attributes[:id] || raise("No defined id for feature #{ attributes.inspect }") @js_id = "#{ @map.js_id }node#{ @id }" @name = attributes[:name] || 'Another Feature' @popup_content = attributes[:popup_content] || false @geometry = attributes[:geometry] || raise("No defined geometry for feature #{ attributes.inspect }") @longitude = attributes[:longitude] || raise("No defined longitude for feature #{ attributes.inspect }") @latitude = attributes[:latitude] || raise("No defined latitude for feature #{ attributes.inspect }") @icon_url = attributes[:icon_url] @icon_size = attributes[:icon_size] @color = attributes[:color] @localizations = attributes[:localizations] end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
8 9 10 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 8 def map @map end |
Class Method Details
.draw_collection(map_object) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 10 def self.draw_collection(map_object) features = map_object.draw_features feature_objects = features.inject([]) do |objects, feature_data| objects << new(map_object, feature_data) objects end %( //Adding features #{ feature_objects.map(&:to_js) } ) end |
Instance Method Details
#to_js ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 35 def to_js %( #{ build_main_geometry } #{ build_vector_feature } #{ build_main_icon } #{ build_main_feature } #{ build_marker_click_function if @popup_content } #{ Ropenlayer::Openlayer::Js.new("#{ @map.markers_layer.js_id }.addMarker(#{ @js_id }MainMarker)").to_js } #{ Ropenlayer::Openlayer::Js.new("#{ @map.vectors_layer.js_id }.addFeatures([#{ @js_id }VectorFeature, #{ @js_id }MainFeature])").to_js } ) end |