Beispiel #1
0
    private static void ReloadOSMTiles()
    {
        GameObject osmTileProviderBehaviour = GameObject.Find("OSMTiles");

        osmTileProviderBehaviour.gameObject.DeleteChildren();
        OSMTileProvider.Clear();

        OSMTileProvider.GetOSMTileGameObjectsInBoundingBox(OSMTileProviderBehaviour.mapBounds, OSMTileProviderBehaviour.CurrentZoomLevel);
    }
Beispiel #2
0
    public void Awake()
    {
        osmTileProviderBehaviour = (OSMTileProviderBehaviour)target as OSMTileProviderBehaviour;

        Vector2 tilePosition = OSMTileProvider.LonLat2TileIndex(TileManager.OriginLongitude, TileManager.OriginLatitude, 13);

        currentIndexX = (int)tilePosition.x;
        currentIndexY = (int)tilePosition.y;
    }
Beispiel #3
0
    private OSMTile(int x, int y, int zoomLevel)
    {
        this.zoomLevel = zoomLevel;

        this.x = x;
        this.y = y;

        this.longitude = OSMTileProvider.Tile2Longitude(x, zoomLevel);
        this.latitude  = OSMTileProvider.Tile2Latitude(y, zoomLevel);

        this.image     = OSMTileProvider.DownloadTileTexture(x, y, zoomLevel);
        this.mapBounds = OSMTileProvider.Tile2MapBounds(x, y, zoomLevel);

        query             = new OverpassQuery();
        query.BoundingBox = OSMTileProvider.Tile2OSMBoundingBox(x, y, zoomLevel);
    }
Beispiel #4
0
    private void DrawOSMMap(Rect mapRect)
    {
        // Handle Interaction Mouse-Actions
        Move();
        Zoom();
        SetYouAreHere();

        // Draw Map
        for (int x = left % TileSizePixels; x < left + mapRect.width + TileSizePixels; x += TileSizePixels)
        {
            for (int y = top % TileSizePixels; y < top + mapRect.height + TileSizePixels; y += TileSizePixels)
            {
                Rect      tileRect    = new Rect(x, y, TileSizePixels, TileSizePixels);
                Vector2   tileIndex   = CalculateGridIndex(GUIToCoordinateSystemPosition(tileRect.center));
                Texture2D tileTexture = OSMTileProvider.DownloadTileTexture((int)tileIndex.x, (int)tileIndex.y, ZoomLevel);

                GUI.DrawTexture(tileRect, tileTexture, ScaleMode.ScaleToFit);
                //GUI.Label(tileRect, "TileIndex: " + tileIndex.ToString());
            }
        }

        // Draw TileManager-Selection/Boundings-Settings
        DrawSelection();
        DrawYouAreHere();

        #region Debug-Draw-Methods
        //if (drawGrid)
        //    DrawGrid(mapRect);
        //if (drawOrigin)
        //    DrawOrigin(mapRect);
        //if (drawMouse)
        //    DrawMouse(mapRect);
        #endregion // Debug-Draw-Methods

        // Draw Location Search-Bar
        DrawSearchBar();
        DrawSearchResults();

        CustomGUIUtils.DrawOuterFrame(mapRect, 2, XKCDColors.Black);
    }
Beispiel #5
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        GUILayout.Label("OSMTileProvider", EditorStyles.boldLabel);

        int oldZoomLevel = OSMTileProviderBehaviour.CurrentZoomLevel;

        OSMTileProviderBehaviour.CurrentZoomLevel = EditorGUILayout.IntSlider("ZoomLevel", OSMTileProviderBehaviour.CurrentZoomLevel, 0, 18);
        if (OSMTileProviderBehaviour.CurrentZoomLevel != oldZoomLevel)
        {
            //OSMTileProvider.PrepareZoomGameObjects(oldZoomLevel);
            OSMTileProvider.SetZoomLevelVisible(oldZoomLevel, false);
            OSMTileProvider.SetZoomLevelVisible(OSMTileProviderBehaviour.CurrentZoomLevel, true);
        }


        currentIndexX = EditorGUILayout.IntSlider("X", currentIndexX, 0, OSMTileProvider.TileCountForZoomLevel(zoomlevel) - 1);
        currentIndexY = EditorGUILayout.IntSlider("Y", currentIndexY, 0, OSMTileProvider.TileCountForZoomLevel(zoomlevel) - 1);

        if (GUILayout.Button("Download Tile"))
        {
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }


        if (GUILayout.Button("Download Tile (with Neighbours)"))
        {
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);

            OSMTileProvider.GetOSMTileGameObject(currentIndexX - 1, currentIndexY - 1, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX - 1, currentIndexY, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX - 1, currentIndexY + 1, zoomlevel);

            OSMTileProvider.GetOSMTileGameObject(currentIndexX + 1, currentIndexY - 1, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX + 1, currentIndexY, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX + 1, currentIndexY + 1, zoomlevel);

            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY - 1, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY + 1, zoomlevel);
        }


        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        GUILayout.Space(25f);
        if (GUILayout.Button("^", GUILayout.Width(25f)))
        {
            currentIndexY -= 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("<", GUILayout.Width(25f)))
        {
            currentIndexX -= 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.Space(20f);

        if (GUILayout.Button(">", GUILayout.Width(25f)))
        {
            currentIndexX += 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Space(25f);

        if (GUILayout.Button("v", GUILayout.Width(25f)))
        {
            currentIndexY += 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();


        if (GUILayout.Button("ResetProvider --> Delete Children"))
        {
            osmTileProviderBehaviour.gameObject.DeleteChildren();
            OSMTileProvider.Clear();
        }


        if (GUILayout.Button("Download Bounds"))
        {
            OSMTileProvider.GetOSMTileGameObjectsInBoundingBoxCutting(OSMTileProviderBehaviour.mapBounds, OSMTileProviderBehaviour.CurrentZoomLevel);
        }

        //if (GUI.changed)
        //{
        //    EditorUtility.SetDirty(osmTileProviderBehaviour);
        //}

        DrawDefaultInspector();
    }
Beispiel #6
0
    /// <summary>
    /// Update the GUI
    /// </summary>
    public void OnGUI()
    {
        // Initialize GUI-Utils

        if (!OpenStreetMapsWindow.initializedAttributes)
        {
            myGuiUtils = new MyGUIUtils();
            myGuiUtils.Initialize();

            //mybounds = new MapBounds(50.9517f, 6.9258f, 6.9902f, 50.9202f); // Köln Groß
            //mybounds = new MapBounds(50.23513f, 8.04716f, 8.07123f, 50.22266f); // Michelbach
            mybounds = MapBounds.Cologne;


            tileMap = new OSMTileMap();
            //tileMap.centerLatitude = mybounds.CenterLatitude;
            //tileMap.centerLongitude = mybounds.CenterLongitude;
            tileMap.centerLatitude  = 50.9390d;
            tileMap.centerLongitude = 6.9605d; //7.02744f; //6.9605d;//7.56211f;  Basti 6.93728f;

            tileMap.zoomLevel = 13;


            osmMap    = new OSMMap();
            osmParser = new OSMParser();

            moving       = new List <bool>();
            points       = new List <Vector2>();
            pointsCoords = new List <Vector2>();
            point        = new Vector2();


            zoomIn       = Resources.Load("OSMWindowIcons/zoomIn", typeof(Texture2D)) as Texture2D;
            zoomOut      = Resources.Load("OSMWindowIcons/zoomOut", typeof(Texture2D)) as Texture2D;
            titleTexture = Resources.Load("OSMWindowIcons/title", typeof(Texture2D)) as Texture2D;
            //Texture2D titleTexture = Resources.Load("title_small", typeof(Texture2D)) as Texture2D;
            pointTexture      = Resources.Load("OSMWindowIcons/marker", typeof(Texture2D)) as Texture2D;
            selectionTexture  = Resources.Load("OSMWindowIcons/selection", typeof(Texture2D)) as Texture2D;
            navigationTexture = Resources.Load("OSMWindowIcons/navigation", typeof(Texture2D)) as Texture2D;
            downloadTexture   = Resources.Load("OSMWindowIcons/download", typeof(Texture2D)) as Texture2D;


            //nodePrefab = GameObject.Find("BCNodePrefab");
            //if (nodePrefab == null)
            //{
            //    nodePrefab = new GameObject("BCNodePrefab");
            //    nodePrefab.AddComponent(typeof(Node));
            //    nodePrefab.AddComponent<BCIntersection>();
            //}

            //edgePrefab = GameObject.Find("BCEdgePrefab");
            //if (edgePrefab == null)
            //{
            //    edgePrefab = new GameObject("BCEdgePrefab");
            //    edgePrefab.AddComponent<Edge>();
            //    edgePrefab.AddComponent<MeshFilter>();
            //    edgePrefab.AddComponent<MeshRenderer>();
            //    edgePrefab.AddComponent<MeshCollider>();
            //    edgePrefab.AddComponent<BCRoad>();
            //}

            //entrancePrefab = GameObject.Find("BCEntrancePrefab");
            //if (entrancePrefab == null)
            //{
            //    entrancePrefab = new GameObject("BCEntrancePrefab");
            //    entrancePrefab.AddComponent(typeof(BCEntrance));
            //    entrancePrefab.AddComponent<MeshFilter>();
            //    entrancePrefab.AddComponent<MeshRenderer>();
            //    entrancePrefab.AddComponent<MeshCollider>();

            //}


            OpenStreetMapsWindow.initializedAttributes = true;
        }


        // Calculate Center Tile, Position and Coords
        CaculateValues();
        tileMap.DisplayTileMap();

        //osmParser = new OSMParser();
        _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUILayout.ExpandWidth(true));

        GUILayout.BeginVertical("Box", GUILayout.Width(sidebarWidth), GUILayout.ExpandHeight(true));
        GUILayout.Space(100f);

        // Display Title-Texture
        //DisplayTitle();

        // Display Zoom controls and execute zoomControl-handling
        ZoomControl();

        // Scroll-Control
        ScrollControl();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth), GUILayout.Height(300f));
        EditorGUILayout.BeginHorizontal();
        GUIContent[] toolbarOptions = new GUIContent[2];
        toolbarOptions[0] = new GUIContent(navigationTexture, "Navigation Mode");
        toolbarOptions[1] = new GUIContent(selectionTexture, "Selection Mode");
        editorMode        = GUILayout.Toolbar(editorMode, toolbarOptions, GUILayout.Width(zoomButtonWidth), GUILayout.Height(zoomButtonHeight), GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        HandleNavigationOrSelection();
        GUILayout.EndVertical();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth), GUILayout.Height(80f));
        OSMServerSelection();
        GUILayout.EndVertical();
        EditorGUILayout.Separator();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth));

        //TileManager.OriginLatitude = this.mybounds.CenterLatitude;
        //TileManager.OriginLongitude = this.mybounds.CenterLongitude;

        if (GUILayout.Button(downloadTexture, GUILayout.Width(zoomButtonWidth), GUILayout.Height(zoomButtonHeight * 2), GUILayout.ExpandWidth(true)))
        {
            //TileManager.OriginLatitude = this.mybounds.CenterLatitude;
            //TileManager.OriginLongitude = this.mybounds.CenterLongitude;

            OSMTileProviderBehaviour.mapBounds = mybounds;

            OSMTileProvider.GetOSMTileGameObjectsInBoundingBoxCutting(OSMTileProviderBehaviour.mapBounds, OSMTileProviderBehaviour.CurrentZoomLevel);

            //osmParser.BoundsList = new List<MapBounds>();
            //osmParser.BoundsList.Add(this.mybounds);

            //osmParser.StartParsingNoChunks(reloadContentOSM);

            //MapBounds.CenterOffset = GeographicCoordinates.ConvertLonLatToXY(
            //           osmParser.Map.Box.CenterLongitude,
            //           osmParser.Map.Box.CenterLatitude,
            //           GeographicCoordinates.MapCenter);

            //GameObject srtmMap = new GameObject();
            //srtmMap.name = "SRTMMap";


            //mapTile.bounds = this.mybounds;
            //mapTile.latitude = this.mybounds.South;
            //mapTile.longitude = this.mybounds.West;

            //SRTMMapTile mapTile = srtmMap.AddComponent<SRTMMapTile>();
            //mapTile.ParseToCutMap(this.mybounds);
            //mapTile.transform.position = mapTile.verticesMap[0, 0];
            //srtmMap.active = false;

            //GenerateGraph();

            //foreach (Node tmpNode in Editor.FindSceneObjectsOfType(typeof(Node)))
            //{
            //    tmpNode.FirePositionChanged(NodeEvent.Dirty, 1);
            //}

            EditorUtility.ClearProgressBar();
        }
        GUILayout.BeginHorizontal(GUILayout.Width(sidebarWidth));
        //GUILayout.Label(osmParser.FilePath, GUILayout.Width(sidebarWidth - 30f));
        if (GUILayout.Button("...", GUILayout.Width(25f)))
        {
            osmParser.FilePath = EditorUtility.OpenFilePanel("Open OSM-XML-File...", EditorApplication.applicationContentsPath, "");
            this.osmParser.StartParsingNoChunks(true);
            Debug.Log("Done");
            //if(File.Exists(@osmFilename))
            //    osmParser.FilePath = osmFilename;
        }
        GUILayout.EndHorizontal();


        GUILayout.EndVertical();

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
        // TODO: Unity changed its policy on using events  check if this still works without
        //Event.current.Use();
    }
Beispiel #7
0
 public List <GameObject> GetNeightboursGameObjects()
 {
     return(OSMTileProvider.GetOSMTileGameObjects(this.GetNeightbours()));
 }
Beispiel #8
0
 public GameObject GetSuperTileGameObject()
 {
     return(OSMTileProvider.GetOSMTileGameObject(GetSuperTile()));
 }
Beispiel #9
0
 public List <GameObject> GetSubTilesGameObjects()
 {
     return(OSMTileProvider.GetOSMTileGameObjects(GetSubTiles()));
 }
Beispiel #10
0
 public OSMTile GetSuperTile()
 {
     return(OSMTileProvider.GetSupertile(this));
 }
Beispiel #11
0
 public List <OSMTile> GetSubTiles()
 {
     return(OSMTileProvider.GetSubTilesAsList(this.x, this.y, this.zoomLevel));
 }
Beispiel #12
0
    public static OSMTile GetOSMTile(double longitude, double latitude, int zoomLevel)
    {
        Vector2 tilePosition = OSMTileProvider.LonLat2TileIndex(longitude, latitude, zoomLevel);

        return(GetOSMTile((int)tilePosition.x, (int)tilePosition.y, zoomLevel));
    }
Beispiel #13
0
 private static void setOSMTileMapVisibility(bool value)
 {
     OSMTileProvider.SetZoomLevelVisible(OSMTileProviderBehaviour.CurrentZoomLevel, value);
 }
Beispiel #14
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        GUILayout.Label("OSMMapTile-Editor", EditorStyles.boldLabel);

        int oldZoomLevel = OSMTileProviderBehaviour.CurrentZoomLevel;

        OSMTileProviderBehaviour.CurrentZoomLevel = EditorGUILayout.IntSlider("ZoomLevel", OSMTileProviderBehaviour.CurrentZoomLevel, 0, 18);
        if (OSMTileProviderBehaviour.CurrentZoomLevel != oldZoomLevel)
        {
            //OSMTileProvider.PrepareZoomGameObjects(oldZoomLevel);
            OSMTileProvider.SetZoomLevelVisible(oldZoomLevel, false);
            OSMTileProvider.SetZoomLevelVisible(OSMTileProviderBehaviour.CurrentZoomLevel, true);
        }


        EditorGUILayout.IntSlider("X", osmTileBehaviour.tile.X, 0, OSMTileProvider.TileCountForZoomLevel(zoomlevel) - 1);
        EditorGUILayout.IntSlider("Y", osmTileBehaviour.tile.Y, 0, OSMTileProvider.TileCountForZoomLevel(zoomlevel) - 1);

        //if (GUILayout.Button("Download Tile"))
        //{
        //    OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        //}

        if (GUILayout.Button("Download SuperTile"))
        {
            osmTileBehaviour.tile.GetSuperTileGameObject();
        }

        if (GUILayout.Button("Download SubTile"))
        {
            osmTileBehaviour.tile.GetSubTilesGameObjects();
        }

        if (GUILayout.Button("Load Neighbours"))
        {
            osmTileBehaviour.tile.GetNeightboursGameObjects();
        }


        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        GUILayout.Space(25f);
        if (GUILayout.Button("^", GUILayout.Width(25f)))
        {
            OSMTileProvider.GetOSMTileGameObject(osmTileBehaviour.tile.North);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("<", GUILayout.Width(25f)))
        {
            OSMTileProvider.GetOSMTileGameObject(osmTileBehaviour.tile.West);
        }
        GUILayout.Space(20f);

        if (GUILayout.Button(">", GUILayout.Width(25f)))
        {
            OSMTileProvider.GetOSMTileGameObject(osmTileBehaviour.tile.East);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Space(25f);

        if (GUILayout.Button("v", GUILayout.Width(25f)))
        {
            OSMTileProvider.GetOSMTileGameObject(osmTileBehaviour.tile.South);
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();



        if (GUI.changed)
        {
            EditorUtility.SetDirty(osmTileBehaviour);
        }

        DrawDefaultInspector();
    }