// Use this for initialization private void Start() { // Create a new rect element. OnlineMapsDrawingRect element = new OnlineMapsDrawingRect(-119.0807f, 34.58658f, 3, 3, Color.black, 1f, Color.blue); // Subscribe to events. element.OnClick += OnClick; element.OnPress += OnPress; element.OnRelease += OnRelease; element.OnDoubleClick += OnDoubleClick; OnlineMaps.instance.AddDrawingElement(element); List<Vector2> poly = new List<Vector2> { //Geographic coordinates new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 2), new Vector2(0, 1) }; // Create a new poly element. OnlineMapsDrawingPoly polyElement = new OnlineMapsDrawingPoly(poly, Color.red, 1f); // Subscribe to events. polyElement.OnClick += OnClick; polyElement.OnPress += OnPress; polyElement.OnRelease += OnRelease; polyElement.OnDoubleClick += OnDoubleClick; OnlineMaps.instance.AddDrawingElement(polyElement); // Create tooltip for poly. polyElement.tooltip = "Drawing Element"; }
// Use this for initialization private void Start() { // Create a new rect element. OnlineMapsDrawingRect element = new OnlineMapsDrawingRect(-119.0807f, 34.58658f, 3, 3, Color.black, 1f, Color.blue); // Subscribe to events. element.OnClick += OnClick; element.OnPress += OnPress; element.OnRelease += OnRelease; element.OnDoubleClick += OnDoubleClick; OnlineMaps.instance.AddDrawingElement(element); List <Vector2> poly = new List <Vector2> { //Geographic coordinates new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 2), new Vector2(0, 1) }; // Create a new poly element. OnlineMapsDrawingPoly polyElement = new OnlineMapsDrawingPoly(poly, Color.red, 1f); // Subscribe to events. polyElement.OnClick += OnClick; polyElement.OnPress += OnPress; polyElement.OnRelease += OnRelease; polyElement.OnDoubleClick += OnDoubleClick; OnlineMaps.instance.AddDrawingElement(polyElement); // Create tooltip for poly. polyElement.tooltip = "Drawing Element"; }
/// <summary> /// Get boundaries of drawing elements /// </summary> /// <param name="lx">Left longitude</param> /// <param name="ty">Top latitude</param> /// <param name="rx">Right longitude</param> /// <param name="by">Bottom latitude</param> private void GetBounds(out double lx, out double ty, out double rx, out double by) { // Initialize boundaries lx = double.MaxValue; ty = double.MinValue; rx = double.MinValue; by = double.MaxValue; // Iterate each drawing element foreach (var el in OnlineMapsDrawingElementManager.instance) { // If it is a rectangle, update the boundaries using corners if (el is OnlineMapsDrawingRect) { OnlineMapsDrawingRect rect = el as OnlineMapsDrawingRect; Encapsulate(ref lx, ref ty, ref rx, ref by, rect.x, rect.y); Encapsulate(ref lx, ref ty, ref rx, ref by, rect.x + rect.width, rect.y + rect.height); continue; } // Get the points of drawing element IEnumerable points; if (el is OnlineMapsDrawingLine) { points = (el as OnlineMapsDrawingLine).points; } else if (el is OnlineMapsDrawingPoly) { points = (el as OnlineMapsDrawingPoly).points; } else { continue; } int valueType = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d object v1 = null; int i = -1; double ppx = 0; // Iterate each point foreach (object p in points) { i++; // If the type of the value is unknown, check by value if (valueType == -1) { if (p is Vector2) { valueType = 0; } else if (p is float) { valueType = 1; } else if (p is double) { valueType = 2; } else if (p is OnlineMapsVector2d) { valueType = 3; } } object v2 = v1; v1 = p; double px = 0; double py = 0; if (valueType == 0) { if (i == 0) { Vector2 p1 = (Vector2)v1; ppx = p1.x; Encapsulate(ref lx, ref ty, ref rx, ref by, p1.x, p1.y); continue; } Vector2 v = (Vector2)v1; px = v.x; py = v.y; } else if (valueType == 3) { if (i == 0) { OnlineMapsVector2d p1 = (OnlineMapsVector2d)v1; ppx = p1.x; Encapsulate(ref lx, ref ty, ref rx, ref by, p1.x, p1.y); continue; } Vector2 v = (OnlineMapsVector2d)v1; px = v.x; py = v.y; } else if (i % 2 == 1) { if (i == 1) { if (valueType == 1) { ppx = (float)v2; Encapsulate(ref lx, ref ty, ref rx, ref by, ppx, (float)v1); } else { ppx = (double)v2; Encapsulate(ref lx, ref ty, ref rx, ref by, ppx, (double)v1); } continue; } if (valueType == 1) { px = (float)v2; py = (float)v1; } else { px = (double)v2; py = (double)v1; } } while (true) { double ox = px - ppx; if (ox > 180) { px -= 360; } else if (ox < -180) { px += 360; } else { break; } } Encapsulate(ref lx, ref ty, ref rx, ref by, px, py); ppx = px; } } }