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.14.3 lib/avo/fields/area_field.rb
avo-3.14.2 lib/avo/fields/area_field.rb
avo-3.14.1 lib/avo/fields/area_field.rb
avo-3.14.0 lib/avo/fields/area_field.rb
avo-3.13.7 lib/avo/fields/area_field.rb
avo-3.13.6 lib/avo/fields/area_field.rb
avo-3.13.5 lib/avo/fields/area_field.rb
avo-3.13.4 lib/avo/fields/area_field.rb
avo-3.13.3 lib/avo/fields/area_field.rb
avo-3.13.2 lib/avo/fields/area_field.rb
avo-3.13.1 lib/avo/fields/area_field.rb
avo-3.13.0 lib/avo/fields/area_field.rb
avo-2.53.0 lib/avo/fields/area_field.rb
avo-3.12.0 lib/avo/fields/area_field.rb
avo-3.11.10 lib/avo/fields/area_field.rb
avo-3.11.9 lib/avo/fields/area_field.rb
avo-3.11.8 lib/avo/fields/area_field.rb
avo-3.11.7 lib/avo/fields/area_field.rb
avo-3.11.6 lib/avo/fields/area_field.rb
avo-3.11.5 lib/avo/fields/area_field.rb