PageRenderTime 35ms CodeModel.GetById 19ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/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 */ 
 9package 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     /**
26   * Create a flat transform spatial reference. The <code>params</code> passed in constructor should have the following properties:
27   * <li><code>wkid</code>: wkid
28   * <li><code>latlng</code>:  {@link ArcGISEnvelope} in latlng unit;
29   * <li><code>coords</code>: {@link ArcGISEnvelope} in coords unit
30   * @name ArcGISFlatSpatialReference
31   * @param {Object} params
32   * @extends ArcGISSpatialReference
33   */
34    public function FlatSpatialReference(params:Object)
35    {
36      params = params || {};   
37      super(params);
38      this.lng_ = params.latlng.xmin;
39      this.lat_ = params.latlng.ymin;
40      this.x_ = params.coords.xmin;
41      this.y_ = params.coords.ymin;
42      this.xscale_ = (params.coords.xmax - params.coords.xmin) / (params.latlng.xmax - params.latlng.xmin);
43      this.yscale_ = (params.coords.ymax - params.coords.ymin) / (params.latlng.ymax - params.latlng.ymin);
44    }
45    override public function forward(lnglat:Array):Array{
46      var E:Number = this.x_ + (lnglat[0] - this.lng_) * this.xscale_;
47      var N:Number = this.y_ + (lnglat[1] - this.lat_) * this.yscale_;
48      return [E, N];
49    } 
50    override public function reverse(coords:Array):Array{
51      var lng:Number = this.lng_ + (coords[0] - this.x_) / this.xscale_;
52      var lat:Number = this.lat_ + (coords[1] - this.y_) / this.yscale_;
53      return [lng, lat];
54    }
55    override public function getCircumference():Number{
56      return this.xscale_ * 360;
57    }
58  }
59}