Beispiel #1
1
        protected virtual ElementImage LoadMissingTileFromServer(int zoom, int x, int y)
        {
            try
            {
                // calculate the tiles bounding box and set its properties.
                GeoCoordinate top_left = TileToWorldPos(x, y, zoom);
                GeoCoordinate bottom_right = TileToWorldPos(x + 1, y + 1, zoom);

                string url = string.Format(_tiles_url,
                    zoom,
                    x,
                    y);

                // get file from tile server.
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
                    url);
                request.Timeout = 5000;
                //Debug.WriteLine(url);

                WebResponse myResp = request.GetResponse();

                Stream stream = myResp.GetResponseStream();
                Image img = Bitmap.FromStream(stream);

                if (_transparency_color != null)
                {
                    Bitmap transparent_map = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    Graphics transparent_map_graphics = Graphics.FromImage(transparent_map);
                    ImageAttributes imageAttributes = new ImageAttributes();
                    //substitute blue for white to achieve the expected aim
                    ColorMap colorMap = new ColorMap();
                    colorMap.OldColor = _transparency_color.Value;
                    colorMap.NewColor = Color.Transparent;
                    //set up color remapping table
                    ColorMap[] remapTable = { colorMap };
                    //set up the color info for the image
                    imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
                    transparent_map_graphics.DrawImage(img,
                        new Rectangle(0, 0, transparent_map.Width, transparent_map.Height), //target rectangle
                        0, 0, // upper left corner of the source image
                        transparent_map.Width, // width of the source image
                        transparent_map.Height, // height of the source image
                        GraphicsUnit.Pixel,
                        //color info
                        imageAttributes);
                    img = transparent_map;
                }

                ElementImage tile = new ElementImage(top_left, bottom_right, img);

                stream.Close();
                stream.Dispose();

                return tile;
            }
            catch (WebException)
            {

            }
            catch (ArgumentException)
            {

            }
            return null;
        }
Beispiel #2
0
        public ElementImage AddImage(
            Image image,
            GeoCoordinate coordinate)
        {
            ElementImage image_element =
                new ElementImage(coordinate, image);
            lock (_elements)
            {
                _elements.Add(image_element);
            }

            return image_element;
        }
Beispiel #3
0
        public ElementImage SubTile(bool xTop, bool yTop)
        {
            Image im = new Bitmap(_image.Width >> 1, Image.Height >> 1);
            Graphics g = Graphics.FromImage(im);

            Rectangle rec = new Rectangle(
                xTop ? _image.Width >> 1 : 0,
                yTop ? _image.Height >> 1 : 0,
                _image.Width >> 1,
                _image.Height >> 1);

            g.DrawImage(_image, 0, 0, rec, GraphicsUnit.Pixel);

            double bott = this.Box.MinLat;
            double left = this.Box.MinLon;
            double h = (this.Box.MaxLat - this.Box.MinLat) / 2;
            double w = (this.Box.MaxLon - this.Box.MinLon) / 2;

            if (xTop) left += w;
            if (!yTop) bott += h;

            ElementImage tile = new ElementImage(bott + h, bott, left, left + w, im);

            return tile;
        }
        protected override Elements.ElementImage LoadMissingTileFromServer(int zoom, int x, int y)
        {
            string quad_key = this.TileXYToQuadKey(x,y,zoom);
            int server = OsmSharp.Tools.Math.Random.StaticRandomGenerator.Get().Generate(4);
            string url = string.Format(this.TilesUrl, server, quad_key, _version, "en", string.Empty);
            try
            {
                // calculate the tiles bounding box and set its properties.
                GeoCoordinate top_left = TileToWorldPos(x, y, zoom);
                GeoCoordinate bottom_right = TileToWorldPos(x + 1, y + 1, zoom);

                // get file from tile server.
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
                    url);
                request.Timeout = 60000;
                Debug.WriteLine(url);

                WebResponse myResp = request.GetResponse();

                Stream stream = myResp.GetResponseStream();
                Image img = Bitmap.FromStream(stream);

                ElementImage tile = new ElementImage(top_left, bottom_right, img);

                stream.Close();
                stream.Dispose();

                return tile;
            }
            catch (WebException)
            {

            }
            return null;
        }
Beispiel #5
0
        public static ElementImage Merge4Tiles(ElementImage[] tiles)
        {
            if (tiles.Length == 0) return null;

            Image im = new Bitmap(tiles[0].Image.Width << 1, tiles[0].Image.Height << 1);
            Graphics g = Graphics.FromImage(im);

            double bott = tiles.Min(t => t.Box.MinLat);
            double left = tiles.Min(t => t.Box.MinLon);
            double h = tiles.Max(t => t.Box.MaxLat) - bott;
            double w = tiles.Max(t => t.Box.MaxLon) - left;

            for (int i = 0; i < tiles.Length; i++)
            {
                Point pt = new Point();

                int x = Convert.ToInt32((tiles[i].Box.MinLon - left) / w * im.Width);
                int y = Convert.ToInt32((tiles[i].Box.MinLat - bott) / h * im.Width);

                pt.X = x;
                pt.Y = im.Height >> 1 - y;

                g.DrawImageUnscaled(tiles[i].Image, pt);
            }

            ElementImage tile = new ElementImage(bott + h, bott, left, left + w, im);
            return tile;
        }