PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 61 lines | 32 code | 2 blank | 27 comment | 4 complexity | f6f6f1a23e7bed50529638663086caba 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
10package com.google.maps.extras.arcgislink
11{
12  /**
13  * A special type of spatial reference system that uses mercator projection and consider earth as sphere.
14  */ 
15  public class SphereMercator extends SpatialReference
16  {
17     private var a_:Number;
18     private var lamdaF_:Number;
19     
20    /**
21 * Creates a Spatial Reference based on Sphere Mercator Projection. 
22 * The <code>params</code> passed in constructor should have the following properties:
23 * <code><br/>-wkid: wkid
24 * <br/>-semi_major:  ellipsoidal semi-major axis 
25 * <br/>-unit: meters per unit
26 * <br/>-central_meridian: lamdaF, longitude of the false origin  (with respect to the prime meridian)
27 * </code>
28 * <br/>e.g. The "Web Mercator" used in  Server:<br/>
29 * <code> var web_mercator  = new ArcGISSphereMercator({wkid: 102113,  semi_major:6378137.0,  central_meridian:0, unit: 1 });
30 * </code>
31 * @name ArcGISSphereMercator
32 * @class This class (<code>google.maputils.arcgis.SphereMercator</code>) is the Projection Default Google Maps uses. It is a special form of Mercator.
33 * @param {Object} params 
34 * @extends ArcGISSpatialReference
35 */
36    public function SphereMercator(params:Object)
37    {
38      params = params || {};
39      super(params);
40      this.a_ = (params.semi_major || 6378137.0) / (params.unit || 1);
41      this.lamdaF_ = (params.central_meridian || 0.0) * RAD_DEG;//(Math.PI / 180);
42    }
43    override public function forward(lnglat:Array):Array{
44      var phi:Number = lnglat[1] * RAD_DEG;//(Math.PI / 180);
45      var lamda:Number = lnglat[0] * RAD_DEG;
46      var E:Number = this.a_ * (lamda - this.lamdaF_);
47      var N:Number = (this.a_ / 2) * Math.log((1 + Math.sin(phi)) / (1 - Math.sin(phi)));
48      return [E, N];
49    } 
50    override public function reverse(coords:Array):Array{
51      var E:Number = coords[0];
52      var N:Number = coords[1];
53      var phi:Number = Math.PI / 2 - 2 * Math.atan(Math.exp(-N / this.a_));
54      var lamda:Number = E / this.a_ + this.lamdaF_;
55      return [lamda / RAD_DEG, phi / RAD_DEG];
56    }
57    override public function getCircumference():Number{
58      return Math.PI * 2 * this.a_;
59    }
60  }
61}