Example #1
0
 public G_LatLng fromPointToLatLng(G_Point point)
 {
     G_Point origin = pixelOrigin_;
     float lng = (point.x - origin.x) / pixelsPerLonDegree_;
     float latRadians = (point.y - origin.y) / pixelsPerLonRadian_;
     float lat = radiansToDegrees(2 * Mathf.Atan(Mathf.Exp(latRadians)) - Mathf.PI / 2);
     return new G_LatLng(lat, lng);
 }
Example #2
0
 public MercatorProjection()
 {
     pixelOrigin_ = new G_Point( MERCATOR_RANGE / 2, MERCATOR_RANGE / 2);
     pixelsPerLonDegree_ = MERCATOR_RANGE / 360;
     pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Mathf.PI);
 }
Example #3
0
        public G_Point fromLatLngToPoint(G_LatLng latLng)
        {
            //$me = $this;
            //fromLatLngToPoint(G_LatLng latLng, G_Point opt_point=null
            //G_Point point = (opt_point!=null) ? opt_point : new G_Point(0,0);
            G_Point point =  new G_Point(0,0);

            G_Point origin = pixelOrigin_;
            point.x = origin.x + latLng.lng * pixelsPerLonDegree_;
            // NOTE(appleton): Truncating to 0.9999 effectively limits latitude to
            // 89.189.  This is about a third of a tile past the edge of the world tile.
            float siny = bound(Mathf.Sin(degreesToRadians(latLng.lat)), -0.9999f, 0.9999f);
            point.y = origin.y + 0.5f * Mathf.Log((1 + siny) / (1 - siny)) * -pixelsPerLonRadian_;
            return point;
        }
Example #4
0
    float[] getCorners(G_LatLng center, float zoom, float mapWidth, float mapHeight)
    {
        float scale = Mathf.Pow(2, zoom);
        MercatorProjection proj = new MercatorProjection();

        G_Point centerPx = proj.fromLatLngToPoint(center);
        //G_LatLng centerPx = new G_LatLng (0, 0);
        G_Point SWPoint = new G_Point(centerPx.x-(mapWidth/2)/scale, centerPx.y+(mapHeight/2)/scale);
        G_LatLng SWLatLon = proj.fromPointToLatLng(SWPoint);
        G_Point NEPoint = new G_Point(centerPx.x+(mapWidth/2)/scale, centerPx.y-(mapHeight/2)/scale);
        G_LatLng NELatLon = proj.fromPointToLatLng(NEPoint);
        return new float[]{NELatLon.lat,
             NELatLon.lng,
             -SWLatLon.lat,
            SWLatLon.lng}; // north east south west
    }