Support different colors and headings on each feature

We're making sure each feature contains properties in order to avoid
possible JavaScript errors.

We're also adding a default color to a geozone.
This commit is contained in:
CoslaJohn
2024-07-19 12:15:00 +01:00
committed by Javi Martín
parent 5dbe2cbf24
commit cb8b0ad6ff
4 changed files with 59 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
class Geozone < ApplicationRecord
include Graphqlable
attribute :color, default: "#0000ff"
has_many :proposals
has_many :debates
has_many :users
@@ -31,10 +33,18 @@ class Geozone < ApplicationRecord
parsed_geojson = JSON.parse(geojson)
if parsed_geojson["type"] == "FeatureCollection"
parsed_geojson["features"].each do |feature|
feature["properties"] ||= {}
end
parsed_geojson
elsif parsed_geojson["type"] == "Feature"
parsed_geojson["properties"] ||= {}
wrap_in_feature_collection(parsed_geojson)
elsif parsed_geojson["geometry"]
parsed_geojson["properties"] ||= {}
wrap_in_feature_collection(wrap_in_feature(parsed_geojson["geometry"]))
elsif parsed_geojson["type"] && parsed_geojson["coordinates"]
wrap_in_feature_collection(wrap_in_feature(parsed_geojson))
@@ -47,7 +57,8 @@ class Geozone < ApplicationRecord
def wrap_in_feature(geometry)
{
type: "Feature",
geometry: geometry
geometry: geometry,
properties: {}
}
end