static public bool draw_latlong_raster(latlong_class center, latlong_class latlong1, latlong_class latlong2, Vector2 offset, double zoom, double current_zoom, int resolution, Rect screen, Color color, int width) { // map_latlong_center bool result = true; Vector2 vector = Mathw.latlong_to_pixel(latlong1, center, current_zoom, new Vector2(screen.width, screen.height)); Vector2 vector2 = Mathw.latlong_to_pixel(latlong2, center, current_zoom, new Vector2(screen.width, screen.height)); Vector2 vector3 = vector2 - vector; vector += new Vector2(-offset.x, offset.y); vector2 += new Vector2(-offset.x, offset.y); double num = Mathf.Pow(2, (float)(zoom - current_zoom)); float num2 = (float)(resolution / num); if (Mathf.Abs(Mathf.Round(vector3.x / num2) - vector3.x / num2) > 0.01f || Mathf.Abs(Mathf.Round(vector3.y / num2) - vector3.y / num2) > 0.01f) { result = false; color = Color.red; } for (float num3 = vector.x; num3 < vector.x + vector3.x; num3 += num2) { Drawing_tc1.DrawLine(new Vector2(num3, vector.y), new Vector2(num3, vector2.y), color, width, false, screen); } for (float num4 = vector.y; num4 < vector.y + vector3.y; num4 += num2) { Drawing_tc1.DrawLine(new Vector2(vector.x, num4), new Vector2(vector2.x, num4), color, width, false, screen); } return(result); }
static public latlong_area_class calc_latlong_area_by_tile(latlong_class latlong, tile_class tile, double zoom, int resolution, Vector2 bresolution, Vector2 offset) { float num = Mathf.Pow(2, (float)(19 - zoom)); zoom = 19; resolution = (int)(resolution * num); bresolution *= num; latlong_area_class latlong_area_class = new latlong_area_class(); map_pixel_class map_pixel_class = latlong_to_pixel2(latlong, zoom); Vector2 vector = new Vector2(0, 0); map_pixel_class.x += tile.x * resolution + offset.x; map_pixel_class.y += tile.y * resolution + offset.y; if (tile.x > 0) { map_pixel_class.x += num; vector.x = num; } if (tile.y > 0) { map_pixel_class.y += num; vector.y = num; } latlong_class latlong_class = pixel_to_latlong2(map_pixel_class, zoom); latlong_area_class.latlong1 = latlong_class; map_pixel_class.x += bresolution.x - vector.x; map_pixel_class.y += bresolution.y - vector.y; latlong_class = pixel_to_latlong2(map_pixel_class, zoom); latlong_area_class.latlong2 = latlong_class; return(latlong_area_class); }
void Start() { int counter = 0; latlong[2].latitude = 49.34544372558594; latlong[2].longitude = -119.579584441234; for (int i = 0; i < latlong.Length; i++) { latlong_class p = latlong[i]; Vector2 pos = GetPosition(p.latitude, p.longitude); GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); Transform newT = go.transform; newT.position = new Vector3(pos.x, 0, pos.y); double latitude, longitude; GetLatLong(newT.position, out latitude, out longitude); Debug.Log(latitude + " : " + longitude); go.name = "Test point " + counter; counter++; } }
public double calc_latlong_area_resolution(latlong_class latlong, double zoom) { double pi = 3.14159265358979323846264338327950288419716939937510; double map_resolution = 156543.04 * Mathf.Cos((float)(latlong.latitude * (pi / 180))) / (Mathf.Pow(2, (float)zoom)); return(map_resolution); }
static public map_pixel_class calc_latlong_to_mercator(latlong_class latlong) { map_pixel_class map_pixel_class = new map_pixel_class(); map_pixel_class.x = latlong.latitude * 20037508f / 180; map_pixel_class.y = Mathf.Log(Mathf.Tan((float)((90 + latlong.longitude) * 3.14159274f / 360))) / 0.0174532924f; map_pixel_class.y = map_pixel_class.y * 20037508f / 180; return(map_pixel_class); }
static public latlong_class calc_mercator_to_latlong(map_pixel_class pixel) { latlong_class latlong_class = new latlong_class(); latlong_class.longitude = pixel.x / 20037508f * 180; latlong_class.latitude = pixel.y / 20037508f * 180; latlong_class.latitude = 57.2957764f * (2 * Mathf.Atan(Mathf.Exp((float)(latlong_class.latitude * 3.14159274f / 180))) - 1.57079637f); return(latlong_class); }
static public tile_class calc_latlong_area_tiles(latlong_class latlong1, latlong_class latlong2, double zoom, int resolution) { tile_class tile_class = new tile_class(); map_pixel_class map_pixel_class = latlong_to_pixel2(latlong1, zoom); map_pixel_class map_pixel_class2 = latlong_to_pixel2(latlong2, zoom); tile_class.x = (int)Mathf.Round((float)((map_pixel_class2.x - map_pixel_class.x) / resolution)); tile_class.y = (int)Mathf.Round((float)((map_pixel_class2.y - map_pixel_class.y) / resolution)); return(tile_class); }
static public latlong_class calc_latlong_center(latlong_class latlong1, latlong_class latlong2, double zoom, Vector2 screen_resolution) { map_pixel_class map_pixel_class = latlong_to_pixel2(latlong1, zoom); map_pixel_class map_pixel_class2 = latlong_to_pixel2(latlong2, zoom); return(pixel_to_latlong2(new map_pixel_class { x = (map_pixel_class.x + map_pixel_class2.x) / 2, y = (map_pixel_class.y + map_pixel_class2.y) / 2 }, zoom)); }
static public map_pixel_class calc_latlong_area_size(latlong_class latlong1, latlong_class latlong2, latlong_class latlong_center) { double num = 3.14159274f; map_pixel_class map_pixel_class = latlong_to_pixel2(latlong1, 19); map_pixel_class map_pixel_class2 = latlong_to_pixel2(latlong2, 19); double num2 = 156543.047f * Mathf.Cos((float)(latlong_center.latitude * (num / 180))) / Mathf.Pow(2, 19); return(new map_pixel_class { x = (map_pixel_class2.x - map_pixel_class.x) * num2, y = (map_pixel_class2.y - map_pixel_class.y) * num2 }); }
static public latlong_class calc_latlong_center_by_tile(latlong_class latlong, tile_class tile, tile_class subtile, tile_class subtiles, double zoom, int resolution, Vector2 offset) { float num = Mathf.Pow(2, (float)(19 - zoom)); zoom = 19; resolution = (int)(resolution * num); map_pixel_class map_pixel_class = latlong_to_pixel2(latlong, zoom); map_pixel_class.x += tile.x * subtiles.x * resolution + subtile.x * resolution; map_pixel_class.y += tile.y * subtiles.y * resolution + subtile.y * resolution; map_pixel_class.x += resolution / 2 + offset.x; map_pixel_class.y += resolution / 2 + offset.y; return(pixel_to_latlong2(map_pixel_class, zoom)); }
void GetLatLong(Vector3 pos, out double latitude, out double longitude) { map_pixel_class map_pixel = new map_pixel_class(); map_pixel_class map_pixel_center = latlong_to_pixel2(latlong_center, 19); double map_resolution = calc_latlong_area_resolution(latlong_center, 19); map_pixel.x = ((pos.x - offset.x) / map_resolution) + map_pixel_center.x; map_pixel.y = (-(pos.z - offset.y) / map_resolution) + map_pixel_center.y; latlong_class returnVal = pixel_to_latlong2(map_pixel, 19); latitude = returnVal.latitude; longitude = returnVal.longitude; }
static public latlong_area_class calc_latlong_area_by_tile2(latlong_class latlong, tile_class tile, double zoom, int resolution, Vector2 bresolution) { latlong_area_class latlong_area_class = new latlong_area_class(); map_pixel_class map_pixel_class = latlong_to_pixel2(latlong, zoom); map_pixel_class.x += tile.x * resolution; map_pixel_class.y += tile.y * resolution; latlong_class latlong_class = pixel_to_latlong2(map_pixel_class, zoom); latlong_area_class.latlong1 = latlong_class; map_pixel_class.x += bresolution.x; map_pixel_class.y += bresolution.y; latlong_class = pixel_to_latlong2(map_pixel_class, zoom); latlong_area_class.latlong2 = latlong_class; return(latlong_area_class); }
static public map_pixel_class latlong_to_pixel2(latlong_class latlong, double zoom) { latlong = clip_latlong(latlong); double num = 3.14159274f; double num2 = (latlong.longitude + 180f) / 360f; double num3 = Mathf.Sin((float)(latlong.latitude * num / 180f)); double num4 = 0.5f - Mathf.Log((float)((1f + num3) / (1f - num3))) / (4f * num); num2 *= 256f * Mathf.Pow(2f, (float)zoom); num4 *= 256f * Mathf.Pow(2f, (float)zoom); return(new map_pixel_class { x = num2, y = num4 }); }
Vector2 GetPosition(double lat, double lon) { var latlong = new latlong_class(lat, lon); Vector2 returnVal; map_pixel_class map_pixel = latlong_to_pixel2(latlong, 19); map_pixel_class map_pixel_center = latlong_to_pixel2(latlong_center, 19); double map_resolution = calc_latlong_area_resolution(latlong_center, 19); returnVal.x = (float)((map_pixel.x - map_pixel_center.x) * map_resolution); returnVal.y = (float)((-map_pixel.y + map_pixel_center.y) * map_resolution); returnVal += offset; return(returnVal); }
static public void calc_latlong2_area_from_center(map_area_class area, latlong_class center, double zoom) { map_pixel_class map_pixel_class = latlong_to_pixel2(area.lower_right, zoom); map_pixel_class map_pixel_class2 = latlong_to_pixel2(center, zoom); map_pixel_class map_pixel_class3 = latlong_to_pixel2(area.center, zoom); map_pixel_class map_pixel_class4 = latlong_to_pixel2(area.upper_left, zoom); map_pixel_class map_pixel_class5 = new map_pixel_class(); map_pixel_class5.x = map_pixel_class2.x - map_pixel_class.x; map_pixel_class5.y = map_pixel_class2.y - map_pixel_class.y; map_pixel_class3.x += map_pixel_class5.x; map_pixel_class3.y += map_pixel_class5.y; map_pixel_class4.x += map_pixel_class5.x; map_pixel_class4.y += map_pixel_class5.y; area.lower_right = center; area.center = pixel_to_latlong2(map_pixel_class3, zoom); area.upper_left = pixel_to_latlong2(map_pixel_class4, zoom); }
public latlong_class pixel_to_latlong2(map_pixel_class map_pixel, double zoom) { map_pixel = clip_pixel(map_pixel, zoom); double pi = 3.14159265358979323846264338327950288419716939937510; double mapSize = 256.0f * Mathf.Pow(2.0f, (float)zoom); double x = (map_pixel.x / mapSize) - 0.5; double y = 0.5 - (map_pixel.y / mapSize); latlong_class latlong = new latlong_class(); latlong.latitude = 90.0 - 360.0 * Mathf.Atan(Mathf.Exp((float)(-y * 2.0 * pi))) / pi; latlong.longitude = 360.0 * x; return(latlong); }
static public latlong_class pixel_to_latlong(Vector2 offset, latlong_class latlong_center, double zoom) { double num = 3.14159274f; double num2 = 256 * Mathf.Pow(2, (float)zoom); map_pixel_class map_pixel_class = latlong_to_pixel2(latlong_center, zoom); map_pixel_class map_pixel_class2 = new map_pixel_class(); map_pixel_class2.x = map_pixel_class.x + offset.x; map_pixel_class2.y = map_pixel_class.y + offset.y; double num3 = map_pixel_class2.x / num2 - 0.5f; double num4 = 0.5f - map_pixel_class2.y / num2; return(clip_latlong(new latlong_class { latitude = 90 - 360 * Mathf.Atan(Mathf.Exp((float)(-(float)num4 * (double)2 * num))) / num, longitude = 360 * num3 })); }
static public Vector2 latlong_to_pixel(latlong_class latlong, latlong_class latlong_center, double zoom, Vector2 screen_resolution) { latlong = clip_latlong(latlong); latlong_center = clip_latlong(latlong_center); double num = 3.14159274f; double num2 = (latlong.longitude + 180) / 360; double num3 = Mathf.Sin((float)(latlong.latitude * num / 180)); double num4 = 0.5f - Mathf.Log((float)((1 + num3) / (1 - num3))) / (4 * num); Vector2 vector = new Vector2((float)num2, (float)num4); num2 = (latlong_center.longitude + 180) / 360; num3 = Mathf.Sin((float)(latlong_center.latitude * num / 180)); num4 = 0.5f - Mathf.Log((float)((1 + num3) / (1 - num3))) / (4 * num); Vector2 vector2 = new Vector2((float)num2, (float)num4); Vector2 vector3 = vector - vector2; vector3 *= 256 * Mathf.Pow(2, (float)zoom); return(vector3 + screen_resolution / 2); }
public map_pixel_class latlong_to_pixel2(latlong_class latlong, double zoom) { latlong = clip_latlong(latlong); double pi = 3.14159265358979323846264338327950288419716939937510; double x = (latlong.longitude + 180.0) / 360.0; double sinLatitude = Mathf.Sin((float)latlong.latitude * (float)pi / 180.0f); double y = 0.5 - Mathf.Log((float)((1.0f + sinLatitude) / (1.0f - sinLatitude))) / (4.0f * pi); x *= 256.0 * Mathf.Pow(2.0f, (float)zoom); y *= 256.0 * Mathf.Pow(2.0f, (float)zoom); map_pixel_class map_pixel = new map_pixel_class(); map_pixel.x = x; map_pixel.y = y; return(map_pixel); }
static public latlong_class clip_latlong(latlong_class latlong) { if (latlong.latitude > maxLatitude) { latlong.latitude -= maxLatitude * 2; } else if (latlong.latitude < minLatitude) { latlong.latitude += maxLatitude * 2; } if (latlong.longitude > maxLongitude) { latlong.longitude -= 360; } else if (latlong.longitude < minLongitude) { latlong.longitude += 360; } return(latlong); }
latlong_class clip_latlong(latlong_class latlong) { if (latlong.latitude > maxLatitude) { latlong.latitude -= (maxLatitude * 2); } else if (latlong.latitude < minLatitude) { latlong.latitude += (maxLatitude * 2); } if (latlong.longitude > 180) { latlong.longitude -= 360; } else if (latlong.longitude < -180) { latlong.longitude += 360; } return(latlong); }
static public latlong_area_class calc_latlong_area_rounded(latlong_class latlong1, latlong_class latlong2, double zoom, int resolution, bool square, int mode) { map_pixel_class map_pixel_class = latlong_to_pixel2(latlong1, zoom); map_pixel_class map_pixel_class2 = latlong_to_pixel2(latlong2, zoom); map_pixel_class map_pixel_class3 = new map_pixel_class(); map_pixel_class3.x = Mathf.Round((float)((map_pixel_class2.x - map_pixel_class.x) / resolution)) * resolution; if (square) { map_pixel_class3.y = map_pixel_class3.x; } else { map_pixel_class3.y = Mathf.Round((float)((map_pixel_class2.y - map_pixel_class.y) / resolution)) * resolution; } if (mode == 1) { if (map_pixel_class.x > map_pixel_class2.x - resolution) { map_pixel_class.x = map_pixel_class2.x - resolution; } else { map_pixel_class.x = map_pixel_class2.x - map_pixel_class3.x; } } else if (mode == 2) { if (map_pixel_class2.x < map_pixel_class.x + resolution) { map_pixel_class2.x = map_pixel_class.x + resolution; } else { map_pixel_class2.x = map_pixel_class.x + map_pixel_class3.x; } } else if (mode == 3) { if (map_pixel_class.y > map_pixel_class2.y - resolution) { map_pixel_class.y = map_pixel_class2.y - resolution; } else { map_pixel_class.y = map_pixel_class2.y - map_pixel_class3.y; } } else if (mode == 4) { if (map_pixel_class2.y < map_pixel_class.y + resolution) { map_pixel_class2.y = map_pixel_class.y + resolution; } else { map_pixel_class2.y = map_pixel_class.y + map_pixel_class3.y; } } else if (mode == 5) { if (map_pixel_class.x > map_pixel_class2.x - resolution) { map_pixel_class.x = map_pixel_class2.x - resolution; } else { map_pixel_class.x = map_pixel_class2.x - map_pixel_class3.x; } if (map_pixel_class.y > map_pixel_class2.y - resolution) { map_pixel_class.y = map_pixel_class2.y - resolution; } else { map_pixel_class.y = map_pixel_class2.y - map_pixel_class3.y; } } else if (mode == 6) { if (map_pixel_class2.x < map_pixel_class.x + resolution) { map_pixel_class2.x = map_pixel_class.x + resolution; } else { map_pixel_class2.x = map_pixel_class.x + map_pixel_class3.x; } if (map_pixel_class.y > map_pixel_class2.y - resolution) { map_pixel_class.y = map_pixel_class2.y - resolution; } else { map_pixel_class.y = map_pixel_class2.y - map_pixel_class3.y; } } else if (mode == 7) { if (map_pixel_class.x > map_pixel_class2.x - resolution) { map_pixel_class.x = map_pixel_class2.x - resolution; } else { map_pixel_class.x = map_pixel_class2.x - map_pixel_class3.x; } if (map_pixel_class2.y < map_pixel_class.y + resolution) { map_pixel_class2.y = map_pixel_class.y + resolution; } else { map_pixel_class2.y = map_pixel_class.y + map_pixel_class3.y; } } else if (mode == 8) { if (map_pixel_class2.x - resolution < map_pixel_class.x) { map_pixel_class2.x = map_pixel_class.x + resolution; } else { map_pixel_class2.x = map_pixel_class.x + map_pixel_class3.x; } if (map_pixel_class2.y - resolution < map_pixel_class.y) { map_pixel_class2.y = map_pixel_class.y + resolution; } else { map_pixel_class2.y = map_pixel_class.y + map_pixel_class3.y; } } return(new latlong_area_class { latlong1 = pixel_to_latlong2(map_pixel_class, zoom), latlong2 = pixel_to_latlong2(map_pixel_class2, zoom) }); }
public latlong_area_class() { latlong1 = new latlong_class(); latlong2 = new latlong_class(); }
static public double calc_latlong_area_resolution(latlong_class latlong, double zoom) { double num = 3.14159274f; return(156543.047f * Mathf.Cos((float)(latlong.latitude * (num / 180))) / Mathf.Pow(2, (float)zoom)); }