private void OnSceneGUI()

in SupportingScripts/Editor/Scripts/MapRendererEditor.cs [155:261]


        private void OnSceneGUI()
        {
            var mapRenderer = target as MapRenderer;
            if (mapRenderer == null)
            {
                return;
            }

            if (Event.current.modifiers == EventModifiers.Control)
            {
                // Turn off the translation tool.
                Tools.hidden = true;

                // Change the cursor to make it obvious you can move the map around. Make the rect big enough to cover the scene view.
                EditorGUIUtility.AddCursorRect(new Rect(0, 0, 999999, 999999), MouseCursor.MoveArrow);

                var currentEvent = Event.current;
                if (currentEvent.type == EventType.Layout)
                {
                    // Adding a control ID disables left-click-and-drag from creating a selection rect, rather than translating the map.
                    int controlID = GUIUtility.GetControlID(ControlIdHint, FocusType.Passive);
                    HandleUtility.AddDefaultControl(controlID);
                }
                else if (currentEvent.type == EventType.ScrollWheel)
                {
                    // Zoom map based on scroll wheel.
                    var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    if (mapRenderer.Raycast(ray, out var hitInfo))
                    {
                        Undo.RecordObject(mapRenderer, "Change ZoomLevel.");
                        var delta = -Event.current.delta;
                        mapRenderer.ZoomLevel += delta.y / 50;
                        currentEvent.Use();

                        EditorApplication.QueuePlayerLoopUpdate();
                    }
                }
                else if (currentEvent.type == EventType.MouseDown)
                {
                    // Begin panning if the mouse ray hits the map.
                    var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    if (mapRenderer.Raycast(ray, out var hitInfo))
                    {
                        if (Event.current.button == 1) // right-click
                        {
                            var menu = new GenericMenu();
                            menu.AddItem(
                                new GUIContent("Add MapPin"),
                                false,
                                (object o) =>
                                {
                                    var location = hitInfo.Location;
                                    var gameObject = new GameObject();
                                    gameObject.name = "MapPin";
                                    gameObject.transform.parent = mapRenderer.transform;
                                    var mapPin = gameObject.AddComponent<MapPin>();
                                    mapPin.Location = location.LatLon;
                                    mapPin.Altitude = location.AltitudeInMeters;
                                    mapPin.AltitudeReference = AltitudeReference.Ellipsoid;
                                    return;
                                },
                                0);
                            menu.ShowAsContext();
                            _isDragging = false;
                        }
                        else
                        {
                            _startingHitPointInWorldSpace = hitInfo.Point;
                            _startingCenterInMercator = mapRenderer.Center.ToMercatorCoordinate();
                            _isDragging = true;
                        }
                        currentEvent.Use();
                    }
                }
                else if (_isDragging && currentEvent.type == EventType.MouseDrag)
                {
                    // Update center 
                    var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    var plane = new Plane(mapRenderer.transform.up, _startingHitPointInWorldSpace);
                    if (plane.Raycast(ray, out var enter))
                    {
                        var updatedHitPointInWorldSpace = ray.GetPoint(enter);
                        var newDeltaInWorldSpace = updatedHitPointInWorldSpace - _startingHitPointInWorldSpace;
                        var newDeltaInLocalSpace = mapRenderer.transform.worldToLocalMatrix * newDeltaInWorldSpace;
                        var newDeltaInMercator = new MercatorCoordinate(newDeltaInLocalSpace.x, newDeltaInLocalSpace.z) / Math.Pow(2, mapRenderer.ZoomLevel - 1);
                        var newCenter = (_startingCenterInMercator - newDeltaInMercator).ToLatLon();

                        Undo.RecordObject(mapRenderer, "Change Center.");
                        mapRenderer.Center = newCenter;

                        EditorApplication.QueuePlayerLoopUpdate();
                    }

                    currentEvent.Use();
                }
                else if (_isDragging && currentEvent.type == EventType.MouseUp)
                {
                    _isDragging = false;

                    currentEvent.Use();
                }
            }
            else
            {
                Tools.hidden = false;
            }
        }