Object
Bounds represents a rectangular bounds, defined by the SW and NE corners
returns an instance of bounds which completely encompases the given circle
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 498
498: def from_point_and_radius(point,radius,options={})
499: point=LatLng.normalize(point)
500: p0=point.endpoint(0,radius,options)
501: p90=point.endpoint(90,radius,options)
502: p180=point.endpoint(180,radius,options)
503: p270=point.endpoint(270,radius,options)
504: sw=Geokit::LatLng.new(p180.lat,p270.lng)
505: ne=Geokit::LatLng.new(p0.lat,p90.lng)
506: Geokit::Bounds.new(sw,ne)
507: end
provide sw and ne to instantiate a new Bounds instance
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 441
441: def initialize(sw,ne)
442: raise ArgumentError if !(sw.is_a?(Geokit::LatLng) && ne.is_a?(Geokit::LatLng))
443: @sw,@ne=sw,ne
444: end
Takes two main combinations of arguments to create a bounds: point,point (this is the only one which takes two arguments [point,point] . . . where a point is anything LatLng#normalize can handle (which is quite a lot)
NOTE: everything combination is assumed to pass points in the order sw, ne
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 515
515: def normalize (thing,other=nil)
516: # maybe this will be simple -- an actual bounds object is passed, and we can all go home
517: return thing if thing.is_a? Bounds
518:
519: # no? OK, if there's no "other," the thing better be a two-element array
520: thing,other=thing if !other && thing.is_a?(Array) && thing.size==2
521:
522: # Now that we're set with a thing and another thing, let LatLng do the heavy lifting.
523: # Exceptions may be thrown
524: Bounds.new(Geokit::LatLng.normalize(thing),Geokit::LatLng.normalize(other))
525: end
Returns true if the candidate object is logically equal. Logical equivalence is true if the lat and lng attributes are the same for both objects.
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 481
481: def ==(other)
482: other.is_a?(Bounds) ? self.sw == other.sw && self.ne == other.ne : false
483: end
returns the a single point which is the center of the rectangular bounds
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 447
447: def center
448: @sw.midpoint_to(@ne)
449: end
Returns true if the bounds contain the passed point. allows for bounds which cross the meridian
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 463
463: def contains?(point)
464: point=Geokit::LatLng.normalize(point)
465: res = point.lat > @sw.lat && point.lat < @ne.lat
466: if crosses_meridian?
467: res &= point.lng < @ne.lng || point.lng > @sw.lng
468: else
469: res &= point.lng < @ne.lng && point.lng > @sw.lng
470: end
471: res
472: end
returns true if the bounds crosses the international dateline
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 475
475: def crosses_meridian?
476: @sw.lng > @ne.lng
477: end
a two-element array of two-element arrays: sw,ne
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 457
457: def to_a
458: [@sw.to_a, @ne.to_a]
459: end
a simple string representation:sw,ne
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 452
452: def to_s
453: "#{@sw.to_s},#{@ne.to_s}"
454: end
Equivalent to Google Maps API’s .toSpan() method on GLatLng’s.
Returns a LatLng object, whose coordinates represent the size of a rectangle defined by these bounds.
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 489
489: def to_span
490: lat_span = (@ne.lat - @sw.lat).abs
491: lng_span = (crosses_meridian? ? 360 + @ne.lng - @sw.lng : @ne.lng - @sw.lng).abs
492: Geokit::LatLng.new(lat_span, lng_span)
493: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.