blob: 64a3804fccc8eff5f850531ca3f8fb0d251afe24 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 | module 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 referential.respond_to?(:projection_type) && referential.projection_type.present?
      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
 |