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.9.0 lib/avo/fields/area_field.rb
avo-3.8.1 lib/avo/fields/area_field.rb
avo-3.8.0 lib/avo/fields/area_field.rb
avo-3.6.4 lib/avo/fields/area_field.rb
avo-3.6.3 lib/avo/fields/area_field.rb
avo-3.6.2 lib/avo/fields/area_field.rb
avo-2.49.0 lib/avo/fields/area_field.rb
avo-3.6.1 lib/avo/fields/area_field.rb
avo-3.6.0 lib/avo/fields/area_field.rb
avo-3.5.8 lib/avo/fields/area_field.rb
avo-3.5.7 lib/avo/fields/area_field.rb
avo-3.5.6 lib/avo/fields/area_field.rb
avo-3.5.6.beta1 lib/avo/fields/area_field.rb
avo-3.5.5 lib/avo/fields/area_field.rb
avo-3.5.4 lib/avo/fields/area_field.rb
avo-3.5.3 lib/avo/fields/area_field.rb
avo-3.5.2 lib/avo/fields/area_field.rb
avo-3.5.1 lib/avo/fields/area_field.rb
avo-3.5.0 lib/avo/fields/area_field.rb
avo-3.4.4 lib/avo/fields/area_field.rb