Example #1
0
    public override byte[] renderSegmentThreadSafe(int x, int y, int z)
    {
        //Debug.Log("BING_MAP_RENDER");
        var    qpath  = GISparser.getQuadPath(x, y, z);
        string qpaths = "";

        foreach (var ele in qpath)
        {
            qpaths += ele.ToString();
        }
        //Debug.Log("BING_MAP_RENDER qpaths");
        string url      = @"http://t.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/" + qpaths + @"?mkt=pl-PL&it=A,G,RL&shading=hill&n=z&og=268&c4w=1";
        string name     = "BING." + z + "." + x + "." + y + ".png";
        string filePath = GISparser.webImagesPath + name;

        byte[] fileData = null;
        //Debug.Log("BING_MAP_RENDER WebClient next");
        using (WebClient client = new WebClient())
        {
            if (File.Exists(filePath))
            {
                //Debug.Log("BING_MAP_RENDER Exists: "+ filePath);
                fileData = GISlayer.bingPath(filePath);
                //Debug.Log("BING_MAP_RENDER Exists: udalo sie");
            }
            else
            {
                //Debug.Log("BING_MAP_RENDER not exists");
                //client.DownloadFile(new Uri(url), filePath);//tu jest problem
                //Debug.Log("BING_MAP_RENDER after download");
                try
                {
                    client.DownloadFile(new Uri(url), filePath);
                }
                catch (Exception ex)
                {
                    Debug.Log(ex.Message);
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }
                if (File.Exists(filePath))
                {
                    //Debug.Log("BING_MAP_RENDER exists now");
                    fileData = GISlayer.bingPath(filePath);
                }
                else
                {
                    Debug.Log("Błąd sieci, nie można pobrać pliku png");
                }
            }
        }
        //Debug.Log("BING_MAP_RENDER koniec");
        return(fileData);
    }
Example #2
0
 public void insertLayerAt(GISlayer l, int index = -1)
 {
     clearSegmentCache();
     _layerPool.WaitOne();
     if (index == -1)
     {
         layers.Add(l);
     }
     else
     {
         layers.Insert(index, l);
     }
     _layerPool.Release();
 }
Example #3
0
    public void buttonPlus()
    {
        string wybrane = listaRozwijana.captionText.text;

        Debug.Log(wybrane);
        GISlayer l = null;

        switch (wybrane)
        {
        case "Testowa":
            l = new GISlayerTest();
            break;

        case "Open Street Map":
            l = new GISlayerOSM();
            break;

        case "Bing":
            l = new GISlayerBING();
            break;

        case "OSMXML":
            l = new GISlayerOSMXML();
            break;

        case "HeatMap":
            l = new GISlayerHeatMap();
            break;

        case "2137":
            l = new GISlayer2137();
            break;
        }
        if (l != null)
        {
            l.map = map;
            map.insertLayerAt(l);
        }
        foreach (Transform element in content.transform)
        {
            var button = element.GetComponentInChildren <Button>();
            if (button != null)
            {
                var te = button.GetComponentInChildren <Text>();
                Debug.Log(te.text);
            }
        }
    }
Example #4
0
    public GISlayer getLayerById(int id, out int index)
    {
        var layers = getLayers();

        index = 0;
        GISlayer layer = null;

        foreach (var l in layers)
        {
            if (l.getId() == id)
            {
                layer = l;
                break;
            }
            index++;
        }
        return(layer);
    }
Example #5
0
    //zwraca pozycje segmentów które są widoczne
    List <Vector3Int> getVisibleSegmentCoordsList()
    {
        List <Vector3Int> result = new List <Vector3Int>();
        int      width           = cam.pixelWidth;
        int      height          = cam.pixelHeight;
        Vector2d c0;
        Vector2d c1;

        getGhostCamCorners(width, height, out c0, out c1);
        Vector3Int ch0 = GISlayer.unitaryToSegment(c0, zoom);
        Vector3Int ch1 = GISlayer.unitaryToSegment(c1, zoom);

        if (ch0.x < 0)
        {
            ch0.x = 0;
        }
        if (ch0.y < 0)
        {
            ch0.y = 0;
        }
        if (ch1.x < 0)
        {
            ch1.x = 0;
        }
        if (ch1.y < 0)
        {
            ch1.y = 0;
        }

        for (int y = ch0.y; y <= ch1.y && y < (1 << zoom); ++y)
        {
            for (int x = ch0.x; x <= ch1.x && x < (1 << zoom); ++x)
            {
                result.Add(new Vector3Int(x, y, zoom));
            }
        }

        return(result);
    }
Example #6
0
    public void removeLayerById(int id)
    {
        clearSegmentCache();
        _layerPool.WaitOne();
        int      index = 0;
        GISlayer layer = null;

        foreach (var l in layers)
        {
            if (l.getId() == id)
            {
                layer = l;
                break;
            }
            index++;
        }
        if (layer != null)
        {
            layers.RemoveAt(index);
        }
        _layerPool.Release();
    }
Example #7
0
    public override byte[] renderSegmentThreadSafe(int x, int y, int z)
    {
        string url      = @"http://a.tile.openstreetmap.org/" + z + @"/" + x + @"/" + y + @".png";
        string name     = "OSM." + z + "." + x + "." + y + ".png";
        string filePath = GISparser.webImagesPath + name;

        byte[] fileData = null;
        using (WebClient client = new WebClient())
        {
            if (File.Exists(filePath))
            {
                fileData = GISlayer.osmPath(filePath);
            }
            else
            {
                try
                {
                    client.DownloadFile(new Uri(url), filePath);
                } catch (Exception ex)
                {
                    Debug.Log(ex.Message);
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }
                if (File.Exists(filePath))
                {
                    fileData = GISlayer.osmPath(filePath);
                }
                else
                {
                    Debug.Log("Błąd sieci, nie można pobrać pliku png");
                }
            }
        }
        return(fileData);
    }
Example #8
0
    GameObject createNewSegmentNoTexture(Vector3Int pos)
    {
        GameObject nowySegment = new GameObject("Segment-" + segmentCounter + ",x:" + pos.x + ",y:" + pos.y + ",z:" + pos.z); segmentCounter++;

        nowySegment.transform.parent      = this.transform;
        nowySegment.transform.localScale *= 1 / 2.56f;
        var sprite  = nowySegment.AddComponent <SpriteRenderer>();
        var segment = nowySegment.AddComponent <GISlayerSegment>();

        nowySegment.transform.rotation = Quaternion.Euler(180, 0, 0);
        //segment.setTexture(tex);
        segment.segmentPosition           = pos;
        segment.position                  = GISlayer.segmentToUnitary(pos);
        nowySegment.transform.localScale /= ((1 << zoom) * 1f);
        //segment.rend;

        segment.refreshWorldPosition(worldOffset);//nooffset
        allSegments.Add(nowySegment);
        //_cachePool.WaitOne();
        segmentCache.Add(pos, nowySegment);
        //_cachePool.Release();
        return(nowySegment);
    }
Example #9
0
    // Use this for initialization
    void Start()
    {
        rend = GetComponent <SpriteRenderer>();

        _pool = new Semaphore(1, 1);

        int    x      = 0;
        int    y      = 0;
        int    z      = 1;
        var    qpath  = GISparser.getQuadPath(x, y, z);
        string qpaths = "";

        foreach (var ele in qpath)
        {
            qpaths += ele.ToString();
        }
        string url      = @"http://t.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/" + qpaths + @"?mkt=pl-PL&it=A,G,RL&shading=hill&n=z&og=268&c4w=1";
        string name     = "BING." + z + "." + x + "." + y + ".png";
        string filePath = GISparser.webImagesPath + name;

        byte[] fileData;
        using (WebClient client = new WebClient())
        {
            if (File.Exists(filePath))
            {
                //fileData = File.ReadAllBytes(filePath);
                Bitmap original = new Bitmap(filePath);
                Bitmap clone    = new Bitmap(original.Width, original.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                //var arr = GISlayer.ImageToByte2(clone);

                //var arr = GISlayer.getImageRasterBytes(clone, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                Texture2D tex = new Texture2D(256, 256, TextureFormat.RGBA32, false);
                //Texture2D tex = new Texture2D(16, 16, TextureFormat.PVRTC_RGBA4, false);

                /*for (int xx = 0; xx < tex.width; ++xx)
                 * {
                 *  for (int yy = 0; yy < tex.height; ++yy)
                 *  {
                 *      tex.SetPixel(xx, yy, randomColor());
                 *  }
                 * }
                 * tex.SetPixel(0, 0, UnityEngine.Color.black);
                 * tex.SetPixel(1, 0, UnityEngine.Color.black);
                 * tex.SetPixel(2, 0, UnityEngine.Color.black);
                 * tex.filterMode = FilterMode.Point;*/
                var arr2 = GISlayer.bingPath(filePath);
                tex.LoadRawTextureData(arr2);
                tex.filterMode = FilterMode.Point;
                tex.Apply();

                /*fileData = File.ReadAllBytes(filePath);
                 * tex = new Texture2D(2, 2);
                 * tex.LoadImage(fileData);*/

                Sprite newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0));
                rend.sprite = newSprite;
                Debug.Log("obrazek");
                //tex.LoadImage(fileData);
            }
            else
            {
                Debug.Log("Błąd sieci, nie można pobrać pliku png");
            }
        }
    }