Add user_geo_area do champ carte
This commit is contained in:
parent
971a08c92a
commit
d92364b90b
2 changed files with 22 additions and 1 deletions
|
@ -46,4 +46,24 @@ class Champs::CarteChamp < Champ
|
|||
def geo_json
|
||||
@geo_json ||= value.blank? ? [] : JSON.parse(value)
|
||||
end
|
||||
|
||||
def user_geometry
|
||||
{
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
geo_json[0].map do |polygon|
|
||||
[polygon['lat'], polygon['lng']]
|
||||
end
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def user_geo_area
|
||||
if geo_json.present?
|
||||
GeoArea.new(
|
||||
geometry: user_geometry,
|
||||
source: GeoArea.sources.fetch(:selection_utilisateur)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,8 @@ class GeoArea < ApplicationRecord
|
|||
enum source: {
|
||||
quartier_prioritaire: 'quartier_prioritaire',
|
||||
cadastre: 'cadastre',
|
||||
parcelle_agricole: 'parcelle_agricole'
|
||||
parcelle_agricole: 'parcelle_agricole',
|
||||
selection_utilisateur: 'selection_utilisateur'
|
||||
}
|
||||
|
||||
scope :quartiers_prioritaires, -> { where(source: sources.fetch(:quartier_prioritaire)) }
|
||||
|
|
Loading…
Add table
Reference in a new issue