demarches-normaliennes/app/models/user_geometry.rb
2018-11-20 10:53:14 +01:00

40 lines
686 B
Ruby

class UserGeometry
alias :read_attribute_for_serialization :send
def initialize(json_latlngs)
@json_latlngs = json_latlngs
end
def geometry
to_geo_json(@json_latlngs)
end
def type_de_champ
{
id: -1,
libelle: 'user_geometry',
type_champ: 'user_geometry',
order_place: -1,
descripton: ''
}
end
private
def to_geo_json(json_latlngs)
json = JSON.parse(json_latlngs)
coordinates = json.map do |lat_longs|
outbounds = lat_longs.map do |lat_long|
[lat_long['lng'], lat_long['lat']]
end
[outbounds]
end
{
type: 'MultiPolygon',
coordinates: coordinates
}
end
end