2016-01-27 15:48:27 +01:00
|
|
|
class ModuleApiCartoService
|
2018-03-20 17:47:37 +01:00
|
|
|
def self.save_qp!(dossier, json_latlngs)
|
2016-01-27 15:48:27 +01:00
|
|
|
if dossier.procedure.module_api_carto.quartiers_prioritaires?
|
|
|
|
qp_list = generate_qp JSON.parse(json_latlngs)
|
|
|
|
|
|
|
|
qp_list.each_value do |qp|
|
2017-11-20 18:55:59 +01:00
|
|
|
qp[:dossier_id] = dossier.id
|
2016-01-27 15:48:27 +01:00
|
|
|
qp[:geometry] = qp[:geometry].to_json
|
|
|
|
QuartierPrioritaire.create(qp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-20 17:47:37 +01:00
|
|
|
def self.save_cadastre!(dossier, json_latlngs)
|
2016-01-27 15:48:27 +01:00
|
|
|
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
|
2016-01-27 15:48:27 +01:00
|
|
|
cadastre[:geometry] = cadastre[:geometry].to_json
|
|
|
|
Cadastre.create(cadastre)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-20 17:47:37 +01:00
|
|
|
def self.generate_qp(coordinates)
|
2016-01-27 15:48:27 +01:00
|
|
|
coordinates.inject({}) { |acc, coordinate|
|
|
|
|
acc.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new(
|
2018-01-15 19:29:44 +01:00
|
|
|
coordinate.map { |element| [element['lng'], element['lat']] }
|
|
|
|
).to_params
|
2017-06-12 14:10:49 +02:00
|
|
|
}
|
2016-01-27 15:48:27 +01:00
|
|
|
end
|
|
|
|
|
2018-03-20 17:47:37 +01:00
|
|
|
def self.generate_cadastre(coordinates)
|
2018-01-15 21:33:29 +01:00
|
|
|
coordinates.flat_map do |coordinate|
|
|
|
|
CARTO::SGMAP::Cadastre::Adapter.new(
|
2018-01-15 19:29:44 +01:00
|
|
|
coordinate.map { |element| [element['lng'], element['lat']] }
|
|
|
|
).to_params
|
2018-01-15 21:33:29 +01:00
|
|
|
end
|
2016-01-27 15:48:27 +01:00
|
|
|
end
|
|
|
|
end
|