Пример #1
0
    public void extra(string key, string value)
    {
        const float mnoznik = 1;
        //Destroy(mapplane);
        var        tmp = Resources.Load("Prefabs/GISplane", typeof(GameObject));
        GameObject go  = (GameObject)Instantiate(tmp);

        go.transform.position = new Vector3(ghostPivot.transform.position.x, 0, ghostPivot.transform.position.z);
        //go.transform.localScale = Vector3.one * (tmpsize * (float)planeSize / 1000.0f)/2.0f;
        go.transform.localScale = Vector3.one * (tmpsize * 2.0f * 100.0f / planeSize) * whproportion / mnoznik;
        var comp = go.GetComponent <MapPlane>();
        var spr  = go.GetComponent <SpriteRenderer>();

        comp.resolution = new Vector2Int((int)(planeSize * mnoznik), (int)(planeSize * mnoznik));
        //go.transform.rotation.eulerAngles(90,0,0);
        MapPlane mp = go.GetComponent <MapPlane>();

        go.transform.parent = this.transform;
        mapplane            = mp;
        spr.sortingOrder    = orderCounter;
        ++orderCounter;

        //texture
        var min = GISparser.LatlonToXY(new Vector2d(gisdata.minLon, gisdata.minLat));
        var max = GISparser.LatlonToXY(new Vector2d(gisdata.maxLon, gisdata.maxLat));

        var sr = (max - min) / 2;

        sr += max;

        double kat    = 0.005;
        double obszar = kat * tmpsize * 2.0f * whproportion;

        min = sr - new Vector2d(obszar, obszar);
        max = sr + new Vector2d(obszar, obszar);

        min += new Vector2d(ghostPivot.transform.position.x * kat * 2.0f, ghostPivot.transform.position.z * kat * 2.0f);
        max += new Vector2d(ghostPivot.transform.position.x * kat * 2.0f, ghostPivot.transform.position.z * kat * 2.0f);

        comp.fillHeatMap(min, max, gisdata, key, value);
    }
Пример #2
0
    public void fillHeatMap(Vector2d min, Vector2d max, GISdata data, string key, string value)
    {
        rend = GetComponent <SpriteRenderer>();
        tex  = new Texture2D(resolution.x, resolution.y);

        var maxD = GISparser.LatlonToXY(new Vector2d(data.maxLat, data.maxLon));
        var minD = GISparser.LatlonToXY(new Vector2d(data.minLat, data.minLon));

        maxL = max;
        minL = min;

        float[,] heatmap = new float[resolution.x, resolution.y];
        float maxOdl = 255;
        float minOdl = 10000;

        foreach (var node in data.nodeContainer)
        {
            try
            {
                if (node.tags[key] == value)
                {
                    minOdl = 10000;
                    Vector2Int pos = XYtoPixel(GISparser.LatlonToXY(node.latlon));
                    float[,] heatmapLocal = new float[resolution.x, resolution.y];
                    //heatmapLocal[pos.x, pos.y] = 255;
                    for (int y = 0; y < resolution.y; ++y)
                    {
                        for (int x = 0; x < resolution.x; ++x)
                        {
                            float odl = 1000 - Mathf.Sqrt((pos.x - x) * (pos.x - x) + (pos.y - y) * (pos.y - y));
                            //odl = Mathf.Sqrt(odl);
                            if (odl > maxOdl)
                            {
                                maxOdl = odl;
                            }
                            heatmapLocal[x, y] = odl;
                        }
                    }
                    for (int y = 0; y < resolution.y; ++y)
                    {
                        for (int x = 0; x < resolution.x; ++x)
                        {
                            if (heatmapLocal[x, y] > heatmap[x, y])
                            {
                                heatmap[x, y] = heatmapLocal[x, y];
                            }
                            if (heatmap[x, y] < minOdl)
                            {
                                minOdl = heatmap[x, y];
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
        for (int y = 0; y < resolution.y; ++y)
        {
            for (int x = 0; x < resolution.x; ++x)
            {
                heatmap[x, y] = (heatmap[x, y] - minOdl) / (maxOdl - minOdl);
                heatmap[x, y] = 1 - heatmap[x, y];
                Color c = new Color(heatmap[x, y], 0, heatmap[x, y]);
                tex.SetPixel(x, y, c);
            }
        }
        tex.filterMode = FilterMode.Point;
        tex.Apply();

        Sprite newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f);

        rend.sprite = newSprite;
    }
Пример #3
0
    public void fillTexture(Vector2d min, Vector2d max, GISdata data)
    {
        rend = GetComponent <SpriteRenderer>();
        tex  = new Texture2D(resolution.x, resolution.y);

        var maxD = GISparser.LatlonToXY(new Vector2d(data.maxLat, data.maxLon));
        var minD = GISparser.LatlonToXY(new Vector2d(data.minLat, data.minLon));

        maxL = max;
        minL = min;

        /*if (maxD.x < max.y) return;
        *  if (maxD.y < max.y) return;
        *
        *  if (minD.x > min.y) return;
        *  if (minD.y > min.y) return;*/

        /*for (int y = 0; y < resolution.y; ++y)
         * {
         *  for (int x = 0; x < resolution.x; ++x)
         *  {
         *
         *
         *
         *      tex.SetPixel(x, y, randomColor());
         *  }
         * }*/

        foreach (var way in data.wayContainer)
        {
            Color    color = Color.black;
            Vector2d pos0  = Vector2d.zero;
            bool     first = true;

            try
            {
                if (way.tags["highway"] == "residential")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "living_street")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "primary")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "secondary")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "tertiary")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "service")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "track")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "motorway")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "road")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "path")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "motorway")
                {
                    color = Color.red;
                }
                if (way.tags["highway"] == "motorway")
                {
                    color = Color.red;
                }
                if (way.tags["route"] == "road")
                {
                    color = Color.red;
                }
            }
            catch
            {
            }


            foreach (var node in way.localNodeContainer)
            {
                var pos1 = GISparser.LatlonToXY(node.latlon);
                if (first)
                {
                    first = false;
                    pos0  = pos1;
                    continue;
                }

                var pixel0 = XYtoPixel(pos0);
                var pixel1 = XYtoPixel(pos1);

                double thickness = 0.00001;

                double pixelSize = ((0.5) / (double)(resolution.y)) * (maxL.y - minL.y);

                int pthick = (int)(pixelSize / thickness);


                int pixminx = 0; int pixminy = 0;
                int pixmaxx = 0; int pixmaxy = 0;
                if (pixel0.x < pixel1.x)
                {
                    pixminx = pixel0.x - pthick;
                    pixmaxx = pixel1.x + pthick;
                }
                else
                {
                    pixminx = pixel1.x - pthick;
                    pixmaxx = pixel0.x + pthick;
                }

                if (pixel0.y < pixel1.y)
                {
                    pixminy = pixel0.y - pthick;
                    pixmaxy = pixel1.y + pthick;
                }
                else
                {
                    pixminy = pixel1.y - pthick;
                    pixmaxy = pixel0.y + pthick;
                }

                if (pixminx < 0)
                {
                    pixminx = 0;
                }
                if (pixminy < 0)
                {
                    pixminy = 0;
                }

                if (pixmaxx >= resolution.x)
                {
                    pixmaxx = resolution.x;
                }
                if (pixmaxy >= resolution.y)
                {
                    pixmaxy = resolution.y;
                }

                for (int y = pixminy; y <= pixmaxy; ++y)
                {
                    for (int x = pixminx; x < pixmaxx; ++x)
                    {
                        bool check = GISparser.lineChecker(pos0, pos1, pixelToXY(new Vector2Int(x, y)), (float)thickness);
                        if (check)
                        {
                            tex.SetPixel(x, y, color);
                        }
                    }
                }
                pos0 = pos1;
            }
        }

        tex.filterMode = FilterMode.Point;
        tex.Apply();

        Sprite newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f);

        rend.sprite = newSprite;
    }
Пример #4
0
    //public GISquadtree qt;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            Move(Vector2.up);
        }
        if (Input.GetKey(KeyCode.A))
        {
            Move(Vector2.left);
        }
        if (Input.GetKey(KeyCode.S))
        {
            Move(Vector2.down);
        }
        if (Input.GetKey(KeyCode.D))
        {
            Move(Vector2.right);
        }
        if (Input.GetKey(KeyCode.Q))
        {
            Rotate(1);
        }
        if (Input.GetKey(KeyCode.E))
        {
            Rotate(-1);
        }
        if (Input.GetKey(KeyCode.Z))
        {
            Bend(1);
        }
        if (Input.GetKey(KeyCode.C))
        {
            Bend(-1);
        }
        if (Input.mouseScrollDelta.y < 0)
        {
            ZoomOut();
        }
        if (Input.mouseScrollDelta.y > 0)
        {
            ZoomIn();
        }
        if (Input.GetKey(KeyCode.X))
        {
            extra(ikey.text, ivalue.text);
        }
        if (Input.GetKey(KeyCode.L))
        {
            loadFile(ipath.text);
        }
        if (Input.GetKey(KeyCode.M))
        {
            czyszczenie();
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            //quadtree

            /*qt.clear();
             * foreach (var way in gisdata.wayContainer)
             * {
             *  qt.insert(way);
             * }
             * Debug.Log("zaladowano drzewo");*/
            Vector2d tmp;
            tmp = GISparser.LatlonToXY(new Vector2d(-85.06, -180));
            Debug.Log(tmp.x + " " + tmp.y);
            tmp = GISparser.LatlonToXY(new Vector2d(85.06, 180));
            Debug.Log(tmp.x + " " + tmp.y);

            tmp = GISparser.LatLonToWeb(new Vector2d(-85.051129, 180), 0);
            Debug.Log("web: " + tmp.x + " " + tmp.y);
            tmp = GISparser.LatLonToWeb(new Vector2d(0, 0), 0);
            Debug.Log("web: " + tmp.x + " " + tmp.y);
            tmp = GISparser.LatLonToWeb(new Vector2d(85.051129, -180), 0);
            Debug.Log("web: " + tmp.x + " " + tmp.y);
        }
        camUpdate();
        planeUpdate();
    }