Ejemplo n.º 1
0
        /// <summary>
        /// Updates the position of the specified marker
        /// </summary>
        /// <param name="marker">Marker</param>
        /// <param name="tlx">Longitude of the left border of the map</param>
        /// <param name="tly">Latitude of the top border of the map</param>
        /// <param name="brx">Longitude of the right border of the map</param>
        /// <param name="bry">Latitude of the bottom border of the map</param>
        private void UpdateMarker(uGUICustomMarkerExample marker, double tlx, double tly, double brx, double bry)
        {
            double px = marker.lng;
            double py = marker.lat;

            if (px < tlx || px > brx || py < bry || py > tly)
            {
                marker.gameObject.SetActive(false);
                return;
            }

            Vector2       screenPosition      = control.GetScreenPosition(px, py);
            RectTransform markerRectTransform = marker.transform as RectTransform;

            if (!marker.gameObject.activeSelf)
            {
                marker.gameObject.SetActive(true);
            }

            screenPosition.y += markerRectTransform.rect.height / 2;

            Vector2 point;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(markerRectTransform.parent as RectTransform, screenPosition, worldCamera, out point);
            markerRectTransform.localPosition = point;
        }
Ejemplo n.º 2
0
            /// <summary>
            /// This method is called to draw each marker
            /// </summary>
            /// <param name="marker">Marker</param>
            /// <param name="tlx">Left longitude of the map</param>
            /// <param name="tly">Top latitude of the map</param>
            /// <param name="brx">Right longitude of the map</param>
            /// <param name="bry">Bottom latitiude of the map</param>
            private void DrawMarker(OnlineMapsMarker marker, double tlx, double tly, double brx, double bry)
            {
                // Get coordinates of the marker
                double px, py;

                marker.GetPosition(out px, out py);

                // Get instance of marker from custom data
                GameObject markerInstance = marker["instance"] as GameObject;

                // If marker outside the map
                if (px < tlx || px > brx || py < bry || py > tly)
                {
                    // If there is an instance, destroy it
                    if (markerInstance != null)
                    {
                        OnlineMapsUtils.Destroy(markerInstance);
                        marker["instance"] = null;
                    }

                    return;
                }

                // If there is no instance, create it and put the reference to custom data
                if (markerInstance == null)
                {
                    marker["instance"] = markerInstance = Instantiate(instance.prefab);
                    (markerInstance.transform as RectTransform).SetParent(instance.container);
                    markerInstance.transform.localScale = Vector3.one;
                }

                // Convert geographic coordinates to screen position
                Vector2 screenPosition = control.GetScreenPosition(px, py);

                // Get rect transform of the instance
                RectTransform markerRectTransform = markerInstance.transform as RectTransform;

                // Add half height to align the marker to the bottom
                screenPosition.y += markerRectTransform.rect.height / 2;

                // Convert screen space to local space in the canvas
                Vector2 point;

                RectTransformUtility.ScreenPointToLocalPointInRectangle(markerRectTransform.parent as RectTransform, screenPosition, instance.worldCamera, out point);

                // Set position of the marker instance
                markerRectTransform.localPosition = point;
            }