Sha256: 0e9eb52c029968e118fc445b56ea17d018fcb3d5deda070f032a1c497429c9f0

Contents?: true

Size: 887 Bytes

Versions: 169

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module Avo
  module Fields
    class AreaField < BaseField
      attr_reader :mapkick_options
      attr_reader :datapoint_options

      def initialize(id, **args, &block)
        hide_on :index

        super(id, **args, &block)

        @geometry = args[:geometry].presence || :polygon # Accepts: `:polygon` or `:multi_polygon`
        @mapkick_options = args[:mapkick_options].presence || {}
        @datapoint_options = args[:datapoint_options].presence || {}
      end

      def map_data
        data_source = {
          geometry: {
            type: @geometry.to_s.classify,
            coordinates: value
          }
        }

        [data_source.merge(datapoint_options)]
      end

      def coordinates
        value.present? ? JSON.parse(value) : []
      end

      def geometry
        @geometry.to_s.classify
      end
    end
  end
end

Version data entries

169 entries across 169 versions & 1 rubygems

Version Path
avo-3.0.1.beta19 lib/avo/fields/area_field.rb
avo-3.0.1.beta24 lib/avo/fields/area_field.rb
avo-3.0.1.beta15 lib/avo/fields/area_field.rb
avo-3.0.1.beta16 lib/avo/fields/area_field.rb
avo-3.0.1.beta14 lib/avo/fields/area_field.rb
avo-3.0.1.beta12 lib/avo/fields/area_field.rb
avo-3.0.1.beta13 lib/avo/fields/area_field.rb
avo-3.0.1.beta10 lib/avo/fields/area_field.rb
avo-3.0.1.beta11 lib/avo/fields/area_field.rb
avo-3.0.0.pre19 lib/avo/fields/area_field.rb
avo-3.0.1.beta8 lib/avo/fields/area_field.rb
avo-3.0.1.beta9 lib/avo/fields/area_field.rb
avo-3.0.1.beta6 lib/avo/fields/area_field.rb
avo-3.0.1.beta7 lib/avo/fields/area_field.rb
avo-3.0.1.beta5 lib/avo/fields/area_field.rb
avo-3.0.1.beta2 lib/avo/fields/area_field.rb
avo-3.0.1.beta4 lib/avo/fields/area_field.rb
avo-3.0.1.beta3 lib/avo/fields/area_field.rb
avo-3.0.0.beta1 lib/avo/fields/area_field.rb
avo-3.0.1.beta1 lib/avo/fields/area_field.rb