示例#1
0
    void drawWay(ref Texture2D tex, GISway way, Vector2d chunkLow, Vector2d chunkHigh)
    {
        GISnode  prev       = null;
        Vector2d?pprev      = null;
        bool     renderPrev = false;
        float    thickness  = 10;

        foreach (var node in way.localNodeContainer)
        {
            var p = new Vector2d();
            p.x = (node.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * 256.0;
            p.y = (node.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * 256.0;

            //if (prev == null) {prev = node; continue;}
            if (((p.x >= 0 && p.y >= 0 && p.x < 256 && p.y < 256) || renderPrev) && pprev != null)
            {
                //punkt node jest w chunku
                for (int y = 0; y < 256; y++)
                {
                    for (int x = 0; x < 256; x++)
                    {
                        bool rysuj = GISparser.lineChecker((Vector2d)pprev, p, new Vector2d(x, y), thickness);
                        if (rysuj)
                        {
                            tex.SetPixel(x, y, Color.black);
                        }
                    }
                }
                //koniec
                renderPrev = true;
            }
            else
            {
                renderPrev = false;
            }
            pprev = p;
        }
    }
示例#2
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;
    }