aboutsummaryrefslogtreecommitdiff
path: root/app/models/resource.rb
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2021-01-22 05:32:15 +0100
committerhellekin <hellekin@cepheide.org>2021-01-22 05:32:15 +0100
commitb54a8458d5029b3494165b7430e21b3ae34ecc0c (patch)
tree32ea6fc6b8774f672325fec52f0ffc97229a9568 /app/models/resource.rb
parent1c1aead78192982e221179de6688b944e5b01bf6 (diff)
downloadincommon-map-b54a8458d5029b3494165b7430e21b3ae34ecc0c.tar.gz
Upgrade Rails and add StimulusJS support
Diffstat (limited to 'app/models/resource.rb')
-rw-r--r--app/models/resource.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/app/models/resource.rb b/app/models/resource.rb
index 8df106c..bde0c56 100644
--- a/app/models/resource.rb
+++ b/app/models/resource.rb
@@ -44,17 +44,17 @@ class Resource < ApplicationRecord
# You can use, e.g.: res.longitude = 0.123
def longitude
- feature['geometry']['coordinates'][0]
+ format('%<lon>3.7f', lon: feature['geometry']['coordinates'][0]).to_f
end
def longitude=(value)
- feature['geometry']['coordinates'][0] = value
+ feature['geometry']['coordinates'][0] = format('%<lon>3.7f', lon: value).to_f
end
# You can use, e.g.: res.latitude = 0.123
def latitude
- feature['geometry']['coordinates'][1]
+ format('%<lat>2.7f', lat: feature['geometry']['coordinates'][1]).to_f
end
def latitude=(value)
- feature['geometry']['coordinates'][1] = value
+ feature['geometry']['coordinates'][1] = format('%<lat>2.7f', lat: value).to_f
end
# Properties
@@ -68,4 +68,16 @@ class Resource < ApplicationRecord
feature['properties'][prop.to_s] = v
end
end
+
+ # Poor man's GeoJSON output
+ def to_geojson
+ out = feature.dup
+ # Convert original Dewey IDs with local Section IDs
+ out['properties']['categories'] = Section.where(dewey_id: out['properties']['categories']).pluck(:id)
+ # Add IN COMMON Resource UUID property
+ out['properties']['uuid'] = uuid
+ # Add IN COMMON Agent UUID property
+ out['properties']['agent_uuid'] = agent.uuid
+ out
+ end
end