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.11.4 lib/avo/fields/area_field.rb
avo-3.11.3 lib/avo/fields/area_field.rb
avo-3.11.2 lib/avo/fields/area_field.rb
avo-3.11.1 lib/avo/fields/area_field.rb
avo-3.11.0 lib/avo/fields/area_field.rb
avo-2.52.0 lib/avo/fields/area_field.rb
avo-3.10.10 lib/avo/fields/area_field.rb
avo-3.10.9 lib/avo/fields/area_field.rb
avo-3.10.8 lib/avo/fields/area_field.rb
avo-3.10.7 lib/avo/fields/area_field.rb
avo-3.10.6 lib/avo/fields/area_field.rb
avo-3.10.5 lib/avo/fields/area_field.rb
avo-3.10.4 lib/avo/fields/area_field.rb
avo-3.10.3 lib/avo/fields/area_field.rb
avo-3.10.2 lib/avo/fields/area_field.rb
avo-3.10.1 lib/avo/fields/area_field.rb
avo-3.10.0 lib/avo/fields/area_field.rb
avo-3.9.2 lib/avo/fields/area_field.rb
avo-3.9.1 lib/avo/fields/area_field.rb
avo-3.8.2 lib/avo/fields/area_field.rb