diff options
| author | Luc Donnet | 2015-01-15 16:40:30 +0100 |
|---|---|---|
| committer | Luc Donnet | 2015-01-15 16:40:30 +0100 |
| commit | c89c3508eb953e79165ba61aee878db8e4d15ff5 (patch) | |
| tree | f59b362c96c13bd5facba44f356676f3383e6cd3 /lib | |
| parent | b9a4d3cde1604f4bea01551d8c85624a313a2dfe (diff) | |
| parent | 7d984efe77efd8e610c91fcefc35c4a3e17412fd (diff) | |
| download | chouette-core-c89c3508eb953e79165ba61aee878db8e4d15ff5.tar.bz2 | |
Fix tests and merge master
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ninoxe_extension/projection_fields.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/ninoxe_extension/projection_fields.rb b/lib/ninoxe_extension/projection_fields.rb new file mode 100644 index 000000000..25d30df94 --- /dev/null +++ b/lib/ninoxe_extension/projection_fields.rb @@ -0,0 +1,63 @@ + + module NinoxeExtension::ProjectionFields + extend ActiveSupport::Concern + + included do + #attr_accessible :projection_x,:projection_y,:projection_xy + + # add projection_type set on pre-insert and pre_update action + before_save :set_projections + def set_projections + if ! self.coordinates.blank? + self.long_lat_type = 'WGS84' + else + self.long_lat_type = nil + end + end + + def projection + if self.referential.projection_type.nil? || self.referential.projection_type.empty? + nil + else + self.referential.projection_type + end + end + @point = nil + + def projection_x + if self.long_lat_type.nil? || self.projection.nil? + nil + else + @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i) + @point.x + end + end + def projection_y + if self.long_lat_type.nil? || self.projection.nil? + nil + else + @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i) + @point.y + end + end + def projection_xy + if self.long_lat_type.nil? || self.projection.nil? + nil + else + @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i) + @point.x.to_s+","+@point.y.to_s + end + end + def projection_x=(dummy) + # dummy method + end + def projection_y=(dummy) + # dummy method + end + def projection_xy=(dummy) + # dummy method + end + end + end + + |
