// 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"; }
// Adds a circle to the map and holds a refference on this point public void AddCircle(double radius, Color color) { float r = (float)radius / OnlineMapsUtils.tileSize; float step = 360f / segments; double x, y; _Pin.GetPosition(out x, out y); OnlineMapsProjection projection = OnlineMaps.instance.projection; projection.CoordinatesToTile(x, y, OnlineMaps.instance.zoom, out x, out y); points = new List <Vector2>(); for (int i = 0; i < segments; i++) { points.Add(new Vector2()); double px = x + Mathf.Cos(step * i * Mathf.Deg2Rad) * r; double py = y + Mathf.Sin(step * i * Mathf.Deg2Rad) * r; projection.TileToCoordinates(px, py, OnlineMaps.instance.zoom, out px, out py); points[i] = new Vector2((float)px, (float)py); } _Circle = new OnlineMapsDrawingPoly(points, color, 3); OnlineMaps.instance.AddDrawingElement(_Circle); _Acting = false; }
// Removes circle from the map and the refference in this point public void RemoveCircle() { if (_Circle != null) { OnlineMaps.instance.drawingElements.Remove(_Circle); _Circle = null; } _Acting = false; }
public void Clear() { if (polygon != null) { OnlineMapsDrawingElementManager.RemoveItem(polygon); polygon = null; } foreach (OnlineMapsMarker marker in markers) { OnlineMapsMarkerManager.RemoveItem(marker); } markers.Clear(); markerPositions.Clear(); changed = true; }
private void Update() { if (_borderWeight != borderWeight) { _borderWeight = borderWeight; if (polygon != null) { polygon.borderWeight = borderWeight; map.Redraw(); } } // Check the position of the markers. CheckMarkerPositions(); // If nothing happens, then return. if (!changed) { return; } changed = false; // If the number of points is less than 3, then return. if (markers.Count < 3) { map.Redraw(); return; } // If the polygon is not created, then create. if (polygon == null) { // For points, reference to markerPositions. // If you change the values in markerPositions, value in the polygon will be adjusted automatically. polygon = new OnlineMapsDrawingPoly(markerPositions, Color.black, borderWeight, new Color(1, 1, 1, 0.3f)); // Add an element to the map. map.AddDrawingElement(polygon); } // Calculates area of the polygon. // Important: this algorithm works correctly only if the lines do not intersect. float area = 0; // Triangulate points. int[] indexes = OnlineMapsUtils.Triangulate(markerPositions).ToArray(); // Calculate the area of each triangle. for (int i = 0; i < indexes.Length / 3; i++) { // Get the points of the triangle. Vector2 p1 = markerPositions[indexes[i * 3]]; Vector2 p2 = markerPositions[indexes[i * 3 + 1]]; Vector2 p3 = markerPositions[indexes[i * 3 + 2]]; // Calculate the distance between points. float d1 = OnlineMapsUtils.DistanceBetweenPoints(p1, p2).magnitude; float d2 = OnlineMapsUtils.DistanceBetweenPoints(p2, p3).magnitude; float d3 = OnlineMapsUtils.DistanceBetweenPoints(p3, p1).magnitude; // Calculate the area. float p = (d1 + d2 + d3) / 2; area += Mathf.Sqrt(p * (p - d1) * (p - d2) * (p - d2)); } Debug.Log("Area: " + area + " km^2"); map.Redraw(); }
private void Update() { if (_borderWeight != borderWeight) { _borderWeight = borderWeight; if (polygon != null) { polygon.borderWeight = borderWeight; api.Redraw(); } } // Check the position of the markers. CheckMarkerPositions(); // If nothing happens, then return. if (!changed) return; changed = false; // If the number of points is less than 3, then return. if (markers.Count < 3) { api.Redraw(); return; } // If the polygon is not created, then create. if (polygon == null) { // For points, reference to markerPositions. // If you change the values in markerPositions, value in the polygon will be adjusted automatically. polygon = new OnlineMapsDrawingPoly(markerPositions, Color.black, borderWeight, new Color(1, 1, 1, 0.3f)); // Add an element to the map. api.AddDrawingElement(polygon); } // Calculates area of the polygon. // Important: this algorithm works correctly only if the lines do not intersect. float area = 0; // Triangulate points. int[] indexes = OnlineMapsUtils.Triangulate(markerPositions).ToArray(); // Calculate the area of each triangle. for (int i = 0; i < indexes.Length / 3; i++) { // Get the points of the triangle. Vector2 p1 = markerPositions[indexes[i * 3]]; Vector2 p2 = markerPositions[indexes[i * 3 + 1]]; Vector2 p3 = markerPositions[indexes[i * 3 + 2]]; // Calculate the distance between points. float d1 = OnlineMapsUtils.DistanceBetweenPoints(p1, p2).magnitude; float d2 = OnlineMapsUtils.DistanceBetweenPoints(p2, p3).magnitude; float d3 = OnlineMapsUtils.DistanceBetweenPoints(p3, p1).magnitude; // Calculate the area. float p = (d1 + d2 + d3) / 2; area += Mathf.Sqrt(p * (p - d1) * (p - d2) * (p - d2)); } Debug.Log("Area: " + area + " km^2"); api.Redraw(); }