demarches-normaliennes/app/services/module_api_carto_service.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

class ModuleApiCartoService
def self.save_qp!(dossier, json_latlngs)
if dossier.procedure.module_api_carto.quartiers_prioritaires?
2018-10-15 15:48:01 +02:00
qp_list = generate_qp(JSON.parse(json_latlngs))
qp_list.each do |qp|
2017-11-20 18:55:59 +01:00
qp[:dossier_id] = dossier.id
qp[:geometry] = qp[:geometry].to_json
QuartierPrioritaire.create(qp)
end
end
end
def self.save_cadastre!(dossier, json_latlngs)
if dossier.procedure.module_api_carto.cadastre?
cadastre_list = generate_cadastre JSON.parse(json_latlngs)
cadastre_list.each do |cadastre|
2017-11-20 18:55:59 +01:00
cadastre[:dossier_id] = dossier.id
cadastre[:geometry] = cadastre[:geometry].to_json
Cadastre.create(cadastre)
end
end
end
def self.generate_qp(coordinates)
coordinates.flat_map do |coordinate|
2018-10-15 16:54:38 +02:00
ApiCarto::QuartiersPrioritaires::Adapter.new(
coordinate.map { |element| [element['lng'], element['lat']] }
2018-10-15 16:25:16 +02:00
).results
end
end
def self.generate_cadastre(coordinates)
2018-01-15 21:33:29 +01:00
coordinates.flat_map do |coordinate|
2018-10-15 16:54:38 +02:00
ApiCarto::Cadastre::Adapter.new(
coordinate.map { |element| [element['lng'], element['lat']] }
2018-10-15 16:25:16 +02:00
).results
2018-01-15 21:33:29 +01:00
end
end
end