fix(carto): no crash on points with elevation

This commit is contained in:
Paul Chavard 2023-06-12 14:56:41 +02:00
parent 9d8ad9b3d8
commit 6723bdcd9d
3 changed files with 24 additions and 1 deletions

View file

@ -110,7 +110,7 @@ class GeoArea < ApplicationRecord
def location def location
if point? if point?
Geo::Coord.new(*geometry['coordinates'].reverse).to_s Geo::Coord.new(*geometry['coordinates'][0..1].reverse).to_s
end end
end end

View file

@ -116,6 +116,15 @@ FactoryBot.define do
end end
end end
trait :point_with_z do
geometry do
{
"type": "Point",
"coordinates": [2.428439855575562, 46.538476837725796, 42]
}
end
end
trait :invalid_point do trait :invalid_point do
geometry do geometry do
{ {

View file

@ -122,6 +122,20 @@ RSpec.describe GeoArea, type: :model do
end end
end end
context "when geo is a point" do
let(:geo_area) { build(:geo_area, :selection_utilisateur, :point, champ: nil) }
it "should return the label" do
expect(geo_area.label).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
end
end
context "when geo is a point with elevation" do
let(:geo_area) { build(:geo_area, :selection_utilisateur, :point_with_z, champ: nil) }
it "should return the label" do
expect(geo_area.label).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
end
end
context "when geo is a cadastre parcelle" do context "when geo is a cadastre parcelle" do
let(:geo_area) { build(:geo_area, :selection_utilisateur, :cadastre, champ: nil) } let(:geo_area) { build(:geo_area, :selection_utilisateur, :cadastre, champ: nil) }
it "should return the label" do it "should return the label" do