Class: Ropenlayer::Openlayer::Feature
- Inherits:
-
Object
- Object
- Ropenlayer::Openlayer::Feature
- Defined in:
- lib/ropenlayer/openlayer/feature.rb
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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 54 def initialize(map, attributes) @map = map @id = attributes[:id] || raise("No defined id for feature #{ attributes.inspect }") @js_id = "#{ @map.js_id }node#{ @id }" @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 }") @localizations = attributes[:localizations] @attributes = attributes @name = attributes[:name] || 'Another Feature' [:icon_url, :popup_content, :popup_bgcolor ].each do |render_attribute| build_render_attribute(render_attribute, String) end [:icon_size, :popup_size, :icon_offset ].each do |render_attribute| build_render_attribute(render_attribute, Array) end end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
5 6 7 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 5 def map @map end |
Class Method Details
.all_attributes ⇒ Object
40 41 42 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 40 def self.all_attributes default_attributes.map{|attr| attr.last.keys }.flatten end |
.default_attributes ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 7 def self.default_attributes { # Style Attributes :style => { :cursor => 'pointer', :graphic_width => 32, :graphic_height => 32, :stroke_color => '#008600', :stroke_opacity => 0.9, :stroke_width => 2, :fill_color => '#008600', :fill_opacity => 0.9, :point_radius => 5, :pointer_events => 'visiblePainted', :font_size => '12px', :font_weight => 'bold' }, :render => { # Render Attributes :name => 'Another Feature', :icon_url => '/images/ropenlayer/default_marker.png', :icon_size => [ 40, 34 ], # iccon offsset attribute must be writen as js code. # x offset (first value) and y offset (last value) should maybe fixed values or mathematical operations with size var who is actually icon_size x and y values... # for example, to offset half of icon dimensions, just type # [ '-(size.w/2)', '-(size.h/2)' ] :icon_offset => ['-(size.w/2)', '-(size.h/2)'], :popup_size => [ 600, 400 ], :popup_bgcolor => '#16b87d', :popup_content => false } } end |
.draw_collection(map_object) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 44 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
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ropenlayer/openlayer/feature.rb', line 75 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 |