private void OnEnable()
    {
        _instance  = this;
        dragMarker = null;

        if (map == null)
        {
            Debug.LogError("Can not find a script OnlineMaps.");
            OnlineMapsUtils.Destroy(this);
            return;
        }

        drawingElementManager = GetComponent <OnlineMapsDrawingElementManager>();
        if (drawingElementManager == null)
        {
            drawingElementManager = gameObject.AddComponent <OnlineMapsDrawingElementManager>();
        }

        markerManager = GetComponent <OnlineMapsMarkerManager>();

        activeTexture = map.texture;
        OnlineMapsMarkerManager.Init();
        OnlineMapsDrawingElementManager.Init();
        if (resultIsTexture)
        {
            markerDrawer = new OnlineMapsMarkerBufferDrawer(this);
        }

        OnEnableLate();
    }
        private void OnComplete(string response)
        {
            Debug.Log("OnComplete");

            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("Something wrong");
                Debug.Log(response);
                return;
            }

            OnlineMapsGoogleDirectionsResult.Route       firstRoute = result.routes[0];
            List <OnlineMapsGoogleDirectionsResult.Step> steps      = firstRoute.legs.SelectMany(l => l.steps).ToList();

            // Create a new marker in first point.
            marker = OnlineMapsMarkerManager.CreateItem(steps[0].start_location, "Car");

            // Gets points of route.
            points = firstRoute.overview_polylineD;

            // Draw the route.
            OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(points, Color.red, 3);

            OnlineMapsDrawingElementManager.AddItem(route);

            pointIndex = 0;
        }
        /// <summary>
        /// This method is called when a response is received.
        /// </summary>
        /// <param name="response">Response string</param>
        private void OnComplete(string response)
        {
            Debug.Log(response);

            // Get result object
            OnlineMapsHereRoutingAPIResult result = OnlineMapsHereRoutingAPI.GetResult(response);

            if (result != null)
            {
                Debug.Log(result.metaInfo.timestamp);

                Color[] colors =
                {
                    Color.green,
                    Color.red,
                    Color.blue,
                    Color.magenta
                };
                int colorIndex = 0;

                // Draw all the routes in different colors.
                foreach (OnlineMapsHereRoutingAPIResult.Route route in result.routes)
                {
                    if (route.shape != null)
                    {
                        OnlineMapsDrawingElement line = new OnlineMapsDrawingLine(route.shape.Select(v => new Vector2((float)v.longitude, (float)v.latitude)).ToList(), colors[colorIndex++]);
                        OnlineMapsDrawingElementManager.AddItem(line);
                    }
                }
            }
        }
        /// <summary>
        /// This method is called when the response from Google Directions API is received
        /// </summary>
        /// <param name="response">Response from Google Direction API</param>
        private void OnGoogleDirectionsComplete(string response)
        {
            Debug.Log(response);

            // Try load result
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            if (result == null || result.routes.Length == 0)
            {
                return;
            }

            // Get the first route
            OnlineMapsGoogleDirectionsResult.Route route = result.routes[0];

            // Draw route on the map
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(route.overview_polyline, Color.red, 3));

            // Calculate the distance
            int distance = route.legs.Sum(l => l.distance.value); // meters

            // Calculate the duration
            int duration = route.legs.Sum(l => l.duration.value); // seconds

            // Log distane and duration
            Debug.Log("Distance: " + distance + " meters, or " + (distance / 1000f).ToString("F2") + " km");
            Debug.Log("Duration: " + duration + " sec, or " + (duration / 60f).ToString("F1") + " min, or " + (duration / 3600f).ToString("F1") + " hours");
        }
Example #5
0
        private void Start()
        {
            List <Vector2> line = new List <Vector2>
            {
                //Geographic coordinates
                new Vector2(3, 3),
                new Vector2(5, 3),
                new Vector2(4, 4),
                new Vector2(9.3f, 6.5f)
            };

            List <Vector2> poly = new List <Vector2>
            {
                //Geographic coordinates
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(2, 2),
                new Vector2(0, 1)
            };

            // Draw line
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(line, Color.green, 5));

            // Draw filled transparent poly
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(poly, Color.red, 1, new Color(1, 1, 1, 0.5f)));

            // Draw filled rectangle
            // (position, size, borderColor, borderWidth, backgroundColor)
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingRect(new Vector2(2, 2), new Vector2(1, 1), Color.green, 1, Color.blue));
        }
Example #6
0
    private OnlineMapsDrawingLine addConnection(GridCluster clusterFrom, GridCluster clusterTo, int numConnections)
    {
        MapPoint from = clusterFrom.getCenter();
        MapPoint to   = clusterTo.getCenter();


        List <Vector2> points = new List <Vector2>();

        points.Add(from.getVector2());
        points.Add(to.getVector2());



        OnlineMapsDrawingLine oLine = new OnlineMapsDrawingLine(points, Color.blue);

        oLine.width   = 1.0f;
        oLine.visible = true;
        OnlineMapsDrawingElementManager.AddItem(oLine);
        oLine.visible = false;
        oLine.name    = "connection";



        return(oLine);
    }
Example #7
0
        private void OnFindDirectionComplete(string response)
        {
            // Get the resut object.
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            // Check that the result is not null, and the number of routes is not zero.
            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("Find direction failed");
                Debug.Log(response);
                return;
            }

            // Showing the console instructions for each step.
            foreach (OnlineMapsGoogleDirectionsResult.Leg leg in result.routes[0].legs)
            {
                foreach (OnlineMapsGoogleDirectionsResult.Step step in leg.steps)
                {
                    Debug.Log(step.string_instructions);
                }
            }

            // Create a line, on the basis of points of the route.
            OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(result.routes[0].overview_polylineD, Color.green);

            // Draw the line route on the map.
            OnlineMapsDrawingElementManager.AddItem(route);
        }
        // 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;
            OnlineMapsDrawingElementManager.AddItem(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;
            OnlineMapsDrawingElementManager.AddItem(polyElement);

            // Create tooltip for poly.
            polyElement.tooltip = "Drawing Element";
        }
Example #9
0
    private void OnRequestDone(string response)
    {
        Debug.Log(response);

        OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

        if (result == null || result.routes.Length == 0)
        {
            return;
        }

        OnlineMapsDrawingElementManager.RemoveAllItems();

        OnlineMapsGoogleDirectionsResult.Route route = result.routes[0];
        OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(route.overview_polyline, Color.blue, 3));
    }
Example #10
0
    // Método que dibuja Quad
    private void drawQuad(List <MapPoint> quadPoints, int q)
    {
        List <Vector2> points = new List <Vector2>();

        points.Add(new Vector2(quadPoints[0].getX(), quadPoints[0].getY()));
        points.Add(new Vector2(quadPoints[1].getX(), quadPoints[1].getY()));
        points.Add(new Vector2(quadPoints[2].getX(), quadPoints[2].getY()));
        points.Add(new Vector2(quadPoints[3].getX(), quadPoints[3].getY()));


        OnlineMapsDrawingLine oLine = new OnlineMapsDrawingLine(points, Color.green);

        oLine.width   = 2.0f;
        oLine.visible = true;
        OnlineMapsDrawingElementManager.AddItem(oLine);
    }
        /// <summary>
        /// This method is called when a user clicks on a map
        /// </summary>
        private void OnMapClick()
        {
            // Get the coordinates under cursor
            double lng, lat;

            OnlineMapsControlBase.instance.GetCoords(out lng, out lat);

            // Create a new marker under cursor
            OnlineMapsMarkerManager.CreateItem(lng, lat, "Marker " + OnlineMapsMarkerManager.CountItems);

            OnlineMaps map = OnlineMaps.instance;

            // Get the coordinate at the desired distance
            double nlng, nlat;

            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, radiusKM, 90, out nlng, out nlat);

            double tx1, ty1, tx2, ty2;

            // Convert the coordinate under cursor to tile position
            map.projection.CoordinatesToTile(lng, lat, 20, out tx1, out ty1);

            // Convert remote coordinate to tile position
            map.projection.CoordinatesToTile(nlng, nlat, 20, out tx2, out ty2);

            // Calculate radius in tiles
            double r = tx2 - tx1;

            // Create a new array for points
            OnlineMapsVector2d[] points = new OnlineMapsVector2d[segments];

            // Calculate a step
            double step = 360d / segments;

            // Calculate each point of circle
            for (int i = 0; i < segments; i++)
            {
                double px = tx1 + Math.Cos(step * i * OnlineMapsUtils.Deg2Rad) * r;
                double py = ty1 + Math.Sin(step * i * OnlineMapsUtils.Deg2Rad) * r;
                map.projection.TileToCoordinates(px, py, 20, out lng, out lat);
                points[i] = new OnlineMapsVector2d(lng, lat);
            }

            // Create a new polygon to draw a circle
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(points, Color.red, 3));
        }
Example #12
0
        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;
        }
    protected override void updateGraphicRelations(MapPoint point, bool show)
    {
        if (isCluster())
        {
            RelationShip relation = getGridCluster().getRelationPerPoint(point);

            if (!graphicRelationsPerPoint.ContainsKey(point))
            {
                List <OnlineMapsDrawingLine> lineList = new List <OnlineMapsDrawingLine>();
                foreach (MapPoint p in relation.getRelatedWith())
                {
                    List <Vector2> points = new List <Vector2>();

                    //points.Add(point.getVector2());
                    points.Add(this.getVector2());
                    points.Add(p.getVector2());

                    OnlineMapsDrawingLine oLine = new OnlineMapsDrawingLine(points, Color.blue);
                    oLine.width             = 1.0f;
                    oLine.visible           = true;
                    oLine.renderQueueOffset = 0;
                    OnlineMapsDrawingElementManager.AddItem(oLine);
                    oLine.visible = !p.isFiltered();
                    lineList.Add(oLine);
                }

                graphicRelationsPerPoint.Add(point, lineList);
            }
            else
            {
                int pos = 0;
                foreach (OnlineMapsDrawingLine line in graphicRelationsPerPoint[point])
                {
                    if (show)
                    {
                        line.visible = relation.isVisibleRelationAt(pos);
                    }
                    else
                    {
                        line.visible = false;
                    }
                    pos++;
                }
            }
        }
    }
Example #14
0
    private void Start()
    {
        points.Add(new OnlineMapsVector2d(120.254126, 36.023108));
        points.Add(new OnlineMapsVector2d(120.264126, 36.023108));
        points.Add(new OnlineMapsVector2d(120.254126, 36.033108));
        points.Add(new OnlineMapsVector2d(120.274126, 36.023108));



        // Draw the route.
        OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(points);

        OnlineMapsDrawingElementManager.AddItem(route);

        route.color = Color.yellow;
        route.width = 3;
        //OnlineMapsDrawingElementManager.instance.Remove(route);
    }
    public override void removeGraphicRelations(string propertyName)
    {
        if (graphicRelationsPerProperty.ContainsKey(propertyName))
        {
            //Debug.Log("Esconde relaciones 2");
            List <OnlineMapsDrawingLine> lineList = graphicRelationsPerProperty[propertyName];
            //Debug.Log("Esconde relaciones 3 hay " + lineList.Count);

            foreach (OnlineMapsDrawingLine line in lineList)
            {
                //line.visible = false;
                OnlineMapsDrawingElementManager.RemoveItem(line, true);
                line.Dispose();
            }

            graphicRelationsPerProperty.Remove(propertyName);
        }
    }
    private void OnDestroy()
    {
        OnMapClick            = null;
        OnMapDoubleClick      = null;
        OnMapDrag             = null;
        OnMapLongPress        = null;
        OnMapPress            = null;
        OnMapRelease          = null;
        OnMapZoom             = null;
        lastClickTimes        = null;
        _map                  = null;
        _dragMarker           = null;
        activeTexture         = null;
        longPressEnumerator   = null;
        _instance             = null;
        markerDrawer          = null;
        drawingElementManager = null;

        OnDestroyLate();
    }
Example #17
0
    public PlayBackExecutor(List <OnlineMapsVector2d> _points, string label)
    {
        points = _points;
        OnlineMaps.instance.SetPosition(points[0].x, points[0].y);

        routeLen     = points.Count;
        fromPosition = points[0];
        toPosition   = points[1];
        routeIndex   = 1;
        // Draw the route.
        OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(points);

        route.color = Color.yellow;
        route.width = 1;

        OnlineMapsDrawingElementManager.AddItem(route);

        marker = OnlineMapsMarkerManager.CreateItem(points[0], label);

        isRun = true;
    }
Example #18
0
        /// <summary>
        /// This method is called when a response is received.
        /// </summary>
        /// <param name="response">Response string</param>
        private void OnRequestComplete(string response)
        {
            Debug.Log(response);

            OnlineMapsOpenRouteServiceDirectionResult result = OnlineMapsOpenRouteService.GetDirectionResults(response);

            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("Open Route Service Directions failed.");
                return;
            }

            // Get the points of the first route.
            List <OnlineMapsVector2d> points = result.routes[0].points;

            // Draw the route.
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(points, Color.red));

            // Set the map position to the first point of route.
            OnlineMaps.instance.position = points[0];
        }
Example #19
0
        private void OnRequestComplete(string response)
        {
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("No result");
                return;
            }

            points = result.routes[0].overview_polylineD;
            if (route == null)
            {
                route = new OnlineMapsDrawingLine(points, Color.green, 3);
                OnlineMapsDrawingElementManager.AddItem(route);
            }
            else
            {
                route.points = points;
            }

            pointIndex = 0;
        }
Example #20
0
    public void update()
    {
        if (!isRun || routeIndex > routeLen - 1)
        {
            needReDraw = false;
            // OnlineMapsDrawingElementManager.instance.RemoveAll();
            return;
        }

        angle += Time.deltaTime;

        if (angle >= perTime)
        {
            angle = 0;
            routeIndex++;
            if (routeIndex < routeLen)
            {
                fromPosition = points[routeIndex - 1];
                toPosition   = points[routeIndex];

                OnlineMapsDrawingLine route1 = new OnlineMapsDrawingLine(new OnlineMapsVector2d[] { points[routeIndex - 1], points[routeIndex], });

                route1.color = Color.yellow;
                route1.width = 3f;
                OnlineMapsDrawingElementManager.AddItem(route1);
            }
            return;
        }
        marker.position = Vector2.Lerp(fromPosition, toPosition, angle / perTime);

        needReDraw = true;
        // Marks the map should be redrawn.
        // Map is not redrawn immediately. It will take some time.

        // OnlineMaps.instance.Redraw();
    }
Example #21
0
        private void Update()
        {
            if (Math.Abs(_borderWidth - borderWidth) > float.Epsilon)
            {
                _borderWidth = borderWidth;
                if (polygon != null)
                {
                    polygon.borderWidth = borderWidth;
                    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, borderWidth, new Color(1, 1, 1, 0.3f));

                // Add an element to the map.
                OnlineMapsDrawingElementManager.AddItem(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 - d3));
            }

            Debug.Log("Area: " + area + " km^2");

            map.Redraw();
        }