Esempio n. 1
0
    private void Start()
    {
        OriginInMeters = GeoPositioningHelper.GetMetersFromCoordinate(new Coordinate(OriginLatitude, OriginLongitude));

        osmFileParsers    = new List <MultithreadedOsmFileParser>();
        osmGeoJSONParsers = new List <MultithreadedOsmGeoJSONParser>();

        NetworkManager.Instance.OnDowloaded.AddListener(OnNetworkResponse);
    }
Esempio n. 2
0
    public OsmFile(string file)
    {
        keyToNode = new Dictionary <string, OsmNode>();
        keyToWay  = new Dictionary <string, OsmWay>();

        XmlDocument document = new XmlDocument();

        document.LoadXml(file);
        XmlElement root = document.DocumentElement;

        foreach (XmlNode node in root)
        {
            if (node.Name == "node")
            {
                Vector2 coordinates = GeoPositioningHelper.GetMetersFromCoordinate(
                    new Coordinate(
                        Convert.ToSingle(node.Attributes.GetNamedItem("lat").Value, CultureInfoHelper.EnUSInfo),
                        Convert.ToSingle(node.Attributes.GetNamedItem("lon").Value, CultureInfoHelper.EnUSInfo)
                        ));

                keyToNode.Add(node.Attributes.GetNamedItem("id").Value, new OsmNode(coordinates));
            }
        }

        foreach (XmlNode node in root)
        {
            if (node.Name == "way")
            {
                OsmWay way = new OsmWay();

                foreach (XmlNode subNode in node.ChildNodes)
                {
                    if (subNode.Name == "nd")
                    {
                        string key = subNode.Attributes.GetNamedItem("ref").Value;
                        way.AddNode(keyToNode[key]);
                        continue;
                    }

                    if (subNode.Name == "tag")
                    {
                        string key   = subNode.Attributes.GetNamedItem("k").Value;
                        string value = subNode.Attributes.GetNamedItem("v").Value;
                        value = char.ToUpper(value[0]) + value.Substring(1);
                        way.AddTagValue(key, value);
                    }
                }

                keyToWay.Add(node.Attributes.GetNamedItem("id").Value, way);
            }
        }
    }
Esempio n. 3
0
    private void UpdateTerrainTransform(Tile centerTile)
    {
        Vector2 nw = GeoPositioningHelper.GetMetersFromCoordinate(GeoPositioningHelper.GetNWCoordinateFromTile(centerTile));
        Vector2 se = GeoPositioningHelper.GetMetersFromCoordinate(GeoPositioningHelper.GetNWCoordinateFromTile(new Tile(centerTile.X + 1, centerTile.Y + 1, centerTile.Zoom)));

        tileSizeInMeters = new Vector2(Math.Abs(nw.x - se.x), Math.Abs(nw.y - se.y));

        Vector2 position = (nw + se) / 2 - VisualizingManager.Instance.OriginInMeters;

        Terrain.terrainData.size = new Vector3(tileSizeInMeters.x * 3, Terrain.terrainData.size.y, tileSizeInMeters.y * 3);
        Terrain.gameObject.transform.position = new Vector3(position.x - Terrain.terrainData.size.x / 2, 0,
                                                            position.y - Terrain.terrainData.size.z / 2);
    }
Esempio n. 4
0
    public static PolygonLoops GetPolygonLoopsInMeters(BAMCIS.GeoJSON.Polygon polygon, Vector2 originInMeters)
    {
        Vector2[]   outerLoop = null;
        Vector2[][] holeLoops = new Vector2[polygon.Coordinates.Count() - 1][];

        bool isOuterLoop = true;

        int i = 0;

        foreach (var linearRing in polygon.Coordinates)
        {
            List <Vector2> loop = new List <Vector2>(linearRing.Coordinates.Count() - 1);

            foreach (var position in linearRing.Coordinates)
            {
                Vector2 positionInMeters = GeoPositioningHelper.GetMetersFromCoordinate(
                    new Coordinate(
                        (float)position.Latitude,
                        (float)position.Longitude
                        )) - originInMeters;
                loop.Add(positionInMeters);
            }

            loop = loop.Distinct().Reverse().ToList();

            if (isOuterLoop)
            {
                outerLoop = loop.ToArray();
            }
            else
            {
                holeLoops[i - 1] = loop.ToArray();
            }

            isOuterLoop = false;
            i++;
        }

        return(new PolygonLoops(outerLoop, holeLoops));
    }
    private void RetrieveRoads(Tile tile, List <Road> roads, List <Area> areas)
    {
        Vector2 tileOrigin = GeoPositioningHelper.GetMetersFromCoordinate(
            GeoPositioningHelper.GetNWCoordinateFromTile(
                new Tile(tile.X, tile.Y + 1, tile.Zoom)));

        roadsQueue = new PriorityQueue <Road>();
        areasQueue = new PriorityQueue <Area>();

        foreach (var road in roads)
        {
            roadsQueue.Enqueue(new Road(road.Lanes, road.Width,
                                        road.GetNodesRelatedToOrigin(tileOrigin),
                                        road.Type));
        }

        foreach (var area in areas)
        {
            areasQueue.Enqueue(new Area(
                                   area.GetNodesRelatedToOrigin(tileOrigin), area.Type));
        }
    }
    private void InstantiateTile(Tile tile, int[,] surfaceMap)
    {
        Vector2 tileSize   = GeoPositioningHelper.GetTileSizeInMeters(tile);
        Vector2 position2D = GeoPositioningHelper.GetMetersFromCoordinate(GeoPositioningHelper.GetNWCoordinateFromTile(tile)) - VisualizingManager.Instance.OriginInMeters;
        Vector3 position   = new Vector3(position2D.x + tileSize.x / 2, 0, position2D.y - tileSize.y / 2);
        Vector3 scale      = new Vector3(tileSize.x, 0, tileSize.y) / 10;

        for (int l = 0; l < SurfaceLayers.Length; l++)
        {
            Texture2D mask = new Texture2D(surfaceMap.GetLength(0), surfaceMap.GetLength(1));

            for (int i = 0; i < surfaceMap.GetLength(0); i++)
            {
                for (int j = 0; j < surfaceMap.GetLength(1); j++)
                {
                    if (surfaceMap[surfaceMap.GetLength(0) - 1 - i, surfaceMap.GetLength(1) - 1 - j] == l)
                    {
                        mask.SetPixel(i, j, Color.white);
                    }
                    else
                    {
                        mask.SetPixel(i, j, Color.clear);
                    }
                }
            }

            mask.Apply();

            GameObject tileObject = Instantiate(SurfacePrefab);
            Material   material   = tileObject.GetComponent <MeshRenderer>().material;
            material.mainTextureScale = Vector2.one * SurfaceLayers[l].Tiling;
            material.SetTexture("_MainTex", SurfaceLayers[l].Texture);
            material.SetTexture("_Alpha", mask);
            tileObject.transform.position   = position;
            tileObject.transform.localScale = scale;
            gameObjectTilemap.AttachObjectToTile(tile, tileObject);
        }
    }