/src/com/google/maps/extras/arcgislink/FlatSpatialReference.as

http://gmaps-utility-library-flash.googlecode.com/ · ActionScript · 59 lines · 36 code · 1 blank · 22 comment · 1 complexity · f316c8032043efb1508de16fadfbff49 MD5 · raw file

  1. /*
  2. * ArcGIS for Google Maps Flash API
  3. *
  4. * License http://www.apache.org/licenses/LICENSE-2.0
  5. */
  6. /**
  7. * @author nianwei at gmail dot com
  8. */
  9. package com.google.maps.extras.arcgislink
  10. {
  11. /**
  12. * This class is a special type of coordinate reference assuming lat/lng will increase
  13. * evenly as if earth is flat. Approximate for small regions without implementing
  14. * a real projection.
  15. */
  16. public class FlatSpatialReference extends SpatialReference
  17. {
  18. private var lng_:Number;
  19. private var lat_:Number;
  20. private var x_:Number;
  21. private var y_:Number;
  22. private var xscale_:Number;
  23. private var yscale_:Number;
  24. /**
  25. * Create a flat transform spatial reference. The <code>params</code> passed in constructor should have the following properties:
  26. * <li><code>wkid</code>: wkid
  27. * <li><code>latlng</code>: {@link ArcGISEnvelope} in latlng unit;
  28. * <li><code>coords</code>: {@link ArcGISEnvelope} in coords unit
  29. * @name ArcGISFlatSpatialReference
  30. * @param {Object} params
  31. * @extends ArcGISSpatialReference
  32. */
  33. public function FlatSpatialReference(params:Object)
  34. {
  35. params = params || {};
  36. super(params);
  37. this.lng_ = params.latlng.xmin;
  38. this.lat_ = params.latlng.ymin;
  39. this.x_ = params.coords.xmin;
  40. this.y_ = params.coords.ymin;
  41. this.xscale_ = (params.coords.xmax - params.coords.xmin) / (params.latlng.xmax - params.latlng.xmin);
  42. this.yscale_ = (params.coords.ymax - params.coords.ymin) / (params.latlng.ymax - params.latlng.ymin);
  43. }
  44. override public function forward(lnglat:Array):Array{
  45. var E:Number = this.x_ + (lnglat[0] - this.lng_) * this.xscale_;
  46. var N:Number = this.y_ + (lnglat[1] - this.lat_) * this.yscale_;
  47. return [E, N];
  48. }
  49. override public function reverse(coords:Array):Array{
  50. var lng:Number = this.lng_ + (coords[0] - this.x_) / this.xscale_;
  51. var lat:Number = this.lat_ + (coords[1] - this.y_) / this.yscale_;
  52. return [lng, lat];
  53. }
  54. override public function getCircumference():Number{
  55. return this.xscale_ * 360;
  56. }
  57. }
  58. }