Example #1
0
 public userMapOverlay(IMapDrawable drawable, Geocode geocode, Library.User user)
 {
     _drawable = (userMapDrawable)drawable;
     _geocode = geocode;
     _user = user;
     _offset = new Point((ClientSettings.SmallArtSize + (ClientSettings.Margin * 2) / 2), (ClientSettings.SmallArtSize + (ClientSettings.Margin * 2)));
 }
Example #2
0
        Point GeocodeToScreen(Geocode geocode, int zoom, int adjustX, int adjustY)
        {
            Point p = new Point(LongitudeToXAtZoom(geocode.Longitude, zoom), LatitudeToYAtZoom(geocode.Latitude, zoom));

            p.X += adjustX;
            p.Y += adjustY;
            return(p);
        }
Example #3
0
        public Geocode CenterRelativePointToGeocode(Point point)
        {
            Geocode ret = new Geocode();

            ret.Longitude = XToLongitudeAtZoom((myCenterTile.X << 8) + myCenterOffset.X + point.X, myZoom + 8);
            ret.Latitude  = YToLatitudeAtZoom((myCenterTile.Y << 8) + myCenterOffset.Y + point.Y, myZoom + 8);
            return(ret);
        }
Example #4
0
        public Point GeocodeToCenterRelativePoint(Geocode geocode)
        {
            int centerXReference = (myCenterTile.X << 8) + myCenterOffset.X;
            int centerYReference = (myCenterTile.Y << 8) + myCenterOffset.Y;
            int px = LongitudeToXAtZoom(geocode.Longitude, myZoom + 8);
            int py = LatitudeToYAtZoom(geocode.Latitude, myZoom + 8);

            return(new Point(px - centerXReference, py - centerYReference));
        }
Example #5
0
        void DrawAtGeocode(Geocode tlGeo, Geocode brGeo, IMapRenderer renderer, Geocode geocode, int pixelLevelZoom, int adjustX, int adjustY, IMapDrawable drawable)
        {
            if (!GeocodeBoxContains(tlGeo, brGeo, geocode) || drawable == null)
            {
                return;
            }
            Point p = GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY);

            renderer.Draw(drawable, new Rectangle(p.X - drawable.Width / 2, p.Y - drawable.Height / 2, drawable.Width, drawable.Height), new Rectangle(0, 0, drawable.Width, drawable.Height));
        }
Example #6
0
        static List <Segment> DecodeSteps(char[] chars)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(chars);
            string         blob    = builder.ToString();
            Regex          regex   = new Regex(@"new VE_RouteInstruction\('(.*?)',(-*[\d]+.[\d]+),(-*[\d]+.[\d]+),(-*[\d]+.[\d]+)");
            Regex          cleaner = new Regex(@"&#[\d]+;.*?&#[\d]+;");
            Regex          bolder  = new Regex(@"( [A-Z][A-Z]+ )");
            Match          m       = regex.Match(blob);
            List <Segment> ret     = new List <Segment>();

            while (m.Success)
            {
                Segment segment = new Segment();
                Geocode geocode = new Geocode();
                geocode.Latitude  = double.Parse(m.Groups[2].Value);
                geocode.Longitude = double.Parse(m.Groups[3].Value);
                segment.Geocode   = geocode;
                segment.Distance  = string.Format("{0} miles", m.Groups[4].Value);

                string text = m.Groups[1].Value;
                Match  m2   = cleaner.Match(text);
                while (m2.Success)
                {
                    text = text.Replace(m2.Value, string.Empty);
                    m2   = cleaner.Match(text);
                }

                string formattedText = text;
                m2 = bolder.Match(text);
                while (m2.Success)
                {
                    text          = text.Replace(m2.Value, m2.Value.ToLower());
                    formattedText = formattedText.Replace(m2.Value, string.Format("<b>{0}</b>", m2.Value.ToLower()));
                    m2            = bolder.Match(text);
                }

                text          = text.Replace("  ", " ");
                formattedText = formattedText.Replace("  ", " ").Replace("<b> ", " <b>").Replace(" </b>", "</b> ");

                segment.FormattedText = formattedText;
                segment.Text          = text;

                ret.Add(segment);
                m = m.NextMatch();
            }

            return(ret);
        }
Example #7
0
        public void FitPOIToDimensions(int width, int height, int maxZoom, params Geocode[] geocodes)
        {
            // find the center
            Geocode topLeft     = new Geocode(double.MinValue, double.MaxValue);
            Geocode bottomRight = new Geocode(double.MaxValue, double.MinValue);

            foreach (Geocode geocode in geocodes)
            {
                topLeft.Latitude      = Math.Max(topLeft.Latitude, geocode.Latitude);
                topLeft.Longitude     = Math.Min(topLeft.Longitude, geocode.Longitude);
                bottomRight.Latitude  = Math.Min(bottomRight.Latitude, geocode.Latitude);
                bottomRight.Longitude = Math.Max(bottomRight.Longitude, geocode.Longitude);
            }
            Geocode center = new Geocode((topLeft.Latitude + bottomRight.Latitude) / 2, (topLeft.Longitude + bottomRight.Longitude) / 2);

            // center the map on the center
            myZoom = maxZoom;
            int y = LatitudeToYAtZoom(center.Latitude, myZoom + 8);
            int x = LongitudeToXAtZoom(center.Longitude, myZoom + 8);

            myCenterTile.X   = x / 256;
            myCenterTile.Y   = y / 256;
            myCenterOffset.X = x % 256;
            myCenterOffset.Y = y % 256;

            int halfWidth  = width / 2;
            int halfHeight = height / 2;

            while (myZoom > 0)
            {
                ZoomOut();
                y = LatitudeToYAtZoom(center.Latitude, myZoom + 8);
                x = LongitudeToXAtZoom(center.Longitude, myZoom + 8);
                int tly = LatitudeToYAtZoom(topLeft.Latitude, myZoom + 8);
                int tlx = LongitudeToXAtZoom(topLeft.Longitude, myZoom + 8);
                int bry = LatitudeToYAtZoom(bottomRight.Latitude, myZoom + 8);
                int brx = LongitudeToXAtZoom(bottomRight.Longitude, myZoom + 8);
                if (tlx - x > -halfWidth && tly - y > -halfHeight && brx - x < halfWidth && bry - y < halfHeight)
                {
                    break;
                }
            }
        }
Example #8
0
        public static Directions GetDirections(Geocode startLoc, Geocode endLoc)
        {
            string uri = string.Format("http://dev.virtualearth.net/legacyService/directions.ashx?mkt=en-us&startlat={0}&startlon={1}&endlat={2}&endlon={3}&units=m&type=q", startLoc.Latitude, startLoc.Longitude, endLoc.Latitude, endLoc.Longitude);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "GET";

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                    return null;

                using (MemoryStream memory = new MemoryStream())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        byte[] buffer = new byte[1024];
                        int read = -1;
                        while (read != 0)
                        {
                            read = stream.Read(buffer, 0, buffer.Length);
                            memory.Write(buffer, 0, read);
                        }
                    }

                    string stepsStartString = "new VE_RouteInstruction";
                    int stepsStart = FindFirstOccurence(memory, stepsStartString, 0);
                    if (stepsStart == -1)
                        throw new Exception("Could not find Directions Steps blob.");
                    stepsStart -= stepsStartString.Length;
                    int stepsEnd = FindFirstOccurence(memory, "]", stepsStart);
                    if (stepsEnd == -1)
                        throw new Exception("Could not find Directions Steps blob.");
                    memory.Seek(stepsStart, SeekOrigin.Begin);
                    char [] charBuffer = new char[stepsEnd - stepsStart - 1];
                    StreamReader reader = new StreamReader(memory);
                    reader.Read(charBuffer, 0, charBuffer.Length);
                    List<Segment> steps = DecodeSteps(charBuffer);

                    int latsStart = FindFirstOccurence(memory, ",'", stepsEnd);
                    if (latsStart == -1)
                        throw new Exception("Could not find lats blob.");
                    int latsEnd = FindFirstOccurence(memory, "','", latsStart);
                    if (latsEnd == -1)
                        throw new Exception("Could not find lats blob.");
                    memory.Seek(latsStart, SeekOrigin.Begin);
                    byte[] subset = new byte[latsEnd - latsStart - 1];
                    memory.Read(subset, 0, subset.Length);
                    MemoryStream ms = new MemoryStream(subset);
                    reader = new StreamReader(ms);
                    List<double> lats = DecodeDoubles(reader.ReadToEnd());

                    int lonsStart = latsEnd;
                    if (lonsStart == -1)
                        throw new Exception("Could not find lons blob.");
                    int lonsEnd = FindFirstOccurence(memory, "',", lonsStart);
                    if (lonsEnd == -1)
                        throw new Exception("Could not find lons blob.");
                    memory.Seek(lonsStart, SeekOrigin.Begin);
                    subset = new byte[lonsEnd - lonsStart - 1];
                    memory.Read(subset, 0, subset.Length);
                    ms = new MemoryStream(subset);
                    reader = new StreamReader(ms, Encoding.UTF8);
                    List<double> lons = DecodeDoubles(reader.ReadToEnd());

                    Directions ret = new Directions();
                    ret.Segments = steps.ToArray();
                    ret.PolyLine = new Geocode[lats.Count];
                    ret.Levels = new int[lats.Count];
                    for (int i = 0; i < lats.Count; i++)
                    {
                        ret.Levels[i] = 3;
                        ret.PolyLine[i] = new Geocode(lats[i], lons[i]);
                    }

                    return ret;
                }
            }
        }
Example #9
0
        public static Directions GetDirections(Geocode startLoc, Geocode endLoc)
        {
            string         uri     = string.Format("http://dev.virtualearth.net/legacyService/directions.ashx?mkt=en-us&startlat={0}&startlon={1}&endlat={2}&endlon={3}&units=m&type=q", startLoc.Latitude, startLoc.Longitude, endLoc.Latitude, endLoc.Longitude);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method = "GET";

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(null);
                }

                using (MemoryStream memory = new MemoryStream())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        byte[] buffer = new byte[1024];
                        int    read   = -1;
                        while (read != 0)
                        {
                            read = stream.Read(buffer, 0, buffer.Length);
                            memory.Write(buffer, 0, read);
                        }
                    }

                    string stepsStartString = "new VE_RouteInstruction";
                    int    stepsStart       = FindFirstOccurence(memory, stepsStartString, 0);
                    if (stepsStart == -1)
                    {
                        throw new Exception("Could not find Directions Steps blob.");
                    }
                    stepsStart -= stepsStartString.Length;
                    int stepsEnd = FindFirstOccurence(memory, "]", stepsStart);
                    if (stepsEnd == -1)
                    {
                        throw new Exception("Could not find Directions Steps blob.");
                    }
                    memory.Seek(stepsStart, SeekOrigin.Begin);
                    char []      charBuffer = new char[stepsEnd - stepsStart - 1];
                    StreamReader reader     = new StreamReader(memory);
                    reader.Read(charBuffer, 0, charBuffer.Length);
                    List <Segment> steps = DecodeSteps(charBuffer);

                    int latsStart = FindFirstOccurence(memory, ",'", stepsEnd);
                    if (latsStart == -1)
                    {
                        throw new Exception("Could not find lats blob.");
                    }
                    int latsEnd = FindFirstOccurence(memory, "','", latsStart);
                    if (latsEnd == -1)
                    {
                        throw new Exception("Could not find lats blob.");
                    }
                    memory.Seek(latsStart, SeekOrigin.Begin);
                    byte[] subset = new byte[latsEnd - latsStart - 1];
                    memory.Read(subset, 0, subset.Length);
                    MemoryStream ms = new MemoryStream(subset);
                    reader = new StreamReader(ms);
                    List <double> lats = DecodeDoubles(reader.ReadToEnd());

                    int lonsStart = latsEnd;
                    if (lonsStart == -1)
                    {
                        throw new Exception("Could not find lons blob.");
                    }
                    int lonsEnd = FindFirstOccurence(memory, "',", lonsStart);
                    if (lonsEnd == -1)
                    {
                        throw new Exception("Could not find lons blob.");
                    }
                    memory.Seek(lonsStart, SeekOrigin.Begin);
                    subset = new byte[lonsEnd - lonsStart - 1];
                    memory.Read(subset, 0, subset.Length);
                    ms     = new MemoryStream(subset);
                    reader = new StreamReader(ms, Encoding.UTF8);
                    List <double> lons = DecodeDoubles(reader.ReadToEnd());

                    Directions ret = new Directions();
                    ret.Segments = steps.ToArray();
                    ret.PolyLine = new Geocode[lats.Count];
                    ret.Levels   = new int[lats.Count];
                    for (int i = 0; i < lats.Count; i++)
                    {
                        ret.Levels[i]   = 3;
                        ret.PolyLine[i] = new Geocode(lats[i], lons[i]);
                    }

                    return(ret);
                }
            }
        }
Example #10
0
 public MapOverlay(IMapDrawable drawable, Geocode geocode, Point offset)
 {
     myDrawable = drawable;
     myOffset   = offset;
     myGeocode  = geocode;
 }
Example #11
0
 Point GeocodeToScreen(Geocode geocode, int zoom, int adjustX, int adjustY)
 {
     Point p = new Point(LongitudeToXAtZoom(geocode.Longitude, zoom), LatitudeToYAtZoom(geocode.Latitude, zoom));
     p.X += adjustX;
     p.Y += adjustY;
     return p;
 }
Example #12
0
 void DrawAtGeocode(Geocode tlGeo, Geocode brGeo, IMapRenderer renderer, Geocode geocode, int pixelLevelZoom, int adjustX, int adjustY, IMapDrawable drawable)
 {
     if (!GeocodeBoxContains(tlGeo, brGeo, geocode) || drawable == null)
         return;
     Point p = GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY);
     renderer.Draw(drawable, new Rectangle(p.X - drawable.Width / 2, p.Y - drawable.Height / 2, drawable.Width, drawable.Height), new Rectangle(0, 0, drawable.Width, drawable.Height));
 }
Example #13
0
 static bool GeocodeBoxContains(Geocode tlGeo, Geocode brGeo, Geocode geocode)
 {
     return geocode.Latitude > brGeo.Latitude && geocode.Latitude < tlGeo.Latitude && geocode.Longitude > tlGeo.Longitude && geocode.Longitude < brGeo.Longitude;
 }
Example #14
0
 public Point GeocodeToCenterRelativePoint(Geocode geocode)
 {
     int centerXReference = (myCenterTile.X << 8) + myCenterOffset.X;
     int centerYReference = (myCenterTile.Y << 8) + myCenterOffset.Y;
     int px = LongitudeToXAtZoom(geocode.Longitude, myZoom + 8);
     int py = LatitudeToYAtZoom(geocode.Latitude, myZoom + 8);
     return new Point(px - centerXReference, py - centerYReference);
 }
Example #15
0
        public void FitPOIToDimensions(int width, int height, int maxZoom, params Geocode[] geocodes)
        {
            // find the center
            Geocode topLeft = new Geocode(double.MinValue, double.MaxValue);
            Geocode bottomRight = new Geocode(double.MaxValue, double.MinValue);
            foreach (Geocode geocode in geocodes)
            {
                topLeft.Latitude = Math.Max(topLeft.Latitude, geocode.Latitude);
                topLeft.Longitude = Math.Min(topLeft.Longitude, geocode.Longitude);
                bottomRight.Latitude = Math.Min(bottomRight.Latitude, geocode.Latitude);
                bottomRight.Longitude = Math.Max(bottomRight.Longitude, geocode.Longitude);
            }
            Geocode center = new Geocode((topLeft.Latitude + bottomRight.Latitude) / 2, (topLeft.Longitude + bottomRight.Longitude) / 2);

            // center the map on the center
            myZoom = maxZoom;
            int y = LatitudeToYAtZoom(center.Latitude, myZoom + 8);
            int x = LongitudeToXAtZoom(center.Longitude, myZoom + 8);
            myCenterTile.X = x / 256;
            myCenterTile.Y = y / 256;
            myCenterOffset.X = x % 256;
            myCenterOffset.Y = y % 256;

            int halfWidth = width / 2;
            int halfHeight = height / 2;

            while (myZoom > 0)
            {
                ZoomOut();
                y = LatitudeToYAtZoom(center.Latitude, myZoom + 8);
                x = LongitudeToXAtZoom(center.Longitude, myZoom + 8);
                int tly = LatitudeToYAtZoom(topLeft.Latitude, myZoom + 8);
                int tlx = LongitudeToXAtZoom(topLeft.Longitude, myZoom + 8);
                int bry = LatitudeToYAtZoom(bottomRight.Latitude, myZoom + 8);
                int brx = LongitudeToXAtZoom(bottomRight.Longitude, myZoom + 8);
                if (tlx - x > -halfWidth && tly - y > -halfHeight && brx - x < halfWidth && bry - y < halfHeight)
                    break;
            }
        }
Example #16
0
 public Geocode CenterRelativePointToGeocode(Point point)
 {
     Geocode ret = new Geocode();
     ret.Longitude = XToLongitudeAtZoom((myCenterTile.X << 8) + myCenterOffset.X + point.X, myZoom + 8);
     ret.Latitude = YToLatitudeAtZoom((myCenterTile.Y << 8) + myCenterOffset.Y + point.Y, myZoom + 8);
     return ret;
 }
Example #17
0
 static bool GeocodeBoxContains(Geocode tlGeo, Geocode brGeo, Geocode geocode)
 {
     return(geocode.Latitude > brGeo.Latitude && geocode.Latitude < tlGeo.Latitude && geocode.Longitude > tlGeo.Longitude && geocode.Longitude < brGeo.Longitude);
 }
Example #18
0
 public MapOverlay(IMapDrawable drawable, Geocode geocode, Point offset)
 {
     myDrawable = drawable;
     myOffset = offset;
     myGeocode = geocode;
 }
Example #19
0
        public int DrawMap(IMapRenderer renderer, int x, int y, int width, int height, WaitCallback callback, object state)
        {
            int unavailable = 0;

            // approximate the the top left tile (it may be off by 1), but the loop
            // below will kept it from being drawn
            int       midX        = x + width / 2 - myCenterOffset.X;
            int       midY        = y + height / 2 - myCenterOffset.Y;
            int       xTiles      = (midX - x) / 256 + 1;
            int       yTiles      = (midY - y) / 256 + 1;
            Key       currentXKey = new Key(myCenterTile.X - xTiles, myCenterTile.Y - yTiles, myZoom);
            int       xStart      = midX - xTiles * 256;
            int       yStart      = midY - yTiles * 256;
            Rectangle rect        = new Rectangle(x, y, width, height);

            int tickCount = Environment.TickCount;

            for (int currentX = xStart; currentX < x + width; currentX += 256, currentXKey.X++)
            {
                Key key = currentXKey;
                for (int currentY = yStart; currentY < y + height; currentY += 256, key.Y++)
                {
                    IMapDrawable tile = null;

                    // find the intersect region of the tile that we are drawing
                    Rectangle tileRect = new Rectangle(currentX, currentY, 256, 256);
                    tileRect.Intersect(rect);
                    Rectangle sourceRect = new Rectangle(tileRect.X - currentX, tileRect.Y - currentY, tileRect.Width, tileRect.Height);

                    // dont draw off the map tiles
                    if (!key.IsValid)
                    {
                        // dont draw gray rect if we're drawing transparent
                        if (!HasAlpha)
                        {
                            renderer.FillRectangle(BackColor, tileRect);
                        }
                        continue;
                    }

                    // first try to get the tile from the tileData
                    TileData tileData = GetTile(key, renderer, callback, state);

                    if (tileData != null)
                    {
                        tile = tileData.Bitmap;
                        tileData.LastUsed = tickCount;
                    }

                    if (tile == null)
                    {
                        // tile not available, so try to generate a tile from child tiles
                        unavailable++;

                        Key      childKey = new Key(key.X * 2, key.Y * 2, key.Zoom + 1);
                        Key      tl       = childKey;
                        Key      tr       = new Key(childKey.X + 1, childKey.Y, childKey.Zoom);
                        Key      br       = new Key(childKey.X + 1, childKey.Y + 1, childKey.Zoom);
                        Key      bl       = new Key(childKey.X, childKey.Y + 1, childKey.Zoom);
                        TileData tld;
                        TileData trd;
                        TileData bld;
                        TileData brd;

                        // see if the children are available
                        // we also need to null check, because they could be loading
                        if (TileCache.TryGetValue(tl, out tld) && TileCache.TryGetValue(tr, out trd) && TileCache.TryGetValue(br, out brd) && TileCache.TryGetValue(bl, out bld) &&
                            tld != null && trd != null && bld != null & brd != null &&
                            tld.Bitmap != null && trd.Bitmap != null && bld.Bitmap != null && brd.Bitmap != null)
                        {
                            // children are available, so mark them as recently used
                            tld.LastUsed = trd.LastUsed = bld.LastUsed = brd.LastUsed = tickCount;

                            // calculate the destination rects of each child tile
                            Rectangle tlr = new Rectangle(currentX, currentY, 128, 128);
                            Rectangle trr = new Rectangle(currentX + 128, currentY, 128, 128);
                            Rectangle blr = new Rectangle(currentX, currentY + 128, 128, 128);
                            Rectangle brr = new Rectangle(currentX + 128, currentY + 128, 128, 128);

                            tlr.Intersect(rect);
                            trr.Intersect(rect);
                            blr.Intersect(rect);
                            brr.Intersect(rect);

                            // calculate the source rect of each child tile
                            Rectangle tlsr = new Rectangle(tlr.X - currentX, tlr.Y - currentY, tlr.Width * 2, tlr.Height * 2);
                            Rectangle trsr = new Rectangle(trr.X - currentX - 128, trr.Y - currentY, trr.Width * 2, trr.Height * 2);
                            Rectangle blsr = new Rectangle(blr.X - currentX, blr.Y - currentY - 128, blr.Width * 2, blr.Height * 2);
                            Rectangle brsr = new Rectangle(brr.X - currentX - 128, brr.Y - currentY - 128, brr.Width * 2, brr.Height * 2);

                            // don't attempt to draw tiles that we don't need to
                            if (tlsr.Width > 0 && tlsr.Height > 0)
                            {
                                renderer.Draw(tld.Bitmap, tlr, tlsr);
                            }
                            if (trsr.Width > 0 && trsr.Height > 0)
                            {
                                renderer.Draw(trd.Bitmap, trr, trsr);
                            }
                            if (blsr.Width > 0 && blsr.Height > 0)
                            {
                                renderer.Draw(bld.Bitmap, blr, blsr);
                            }
                            if (brsr.Width > 0 && brsr.Height > 0)
                            {
                                renderer.Draw(brd.Bitmap, brr, brsr);
                            }
                            continue;
                        }
                        else
                        {
                            // can't generate from children, so try generating one of the parents
                            Key       parent     = key;
                            Rectangle parentRect = sourceRect;
                            TileData  parentData = null;
                            while (parent.Zoom >= 0 && parentData == null)
                            {
                                parentRect.Width  /= 2;
                                parentRect.Height /= 2;
                                parentRect.X      /= 2;
                                parentRect.Y      /= 2;
                                if (parent.X % 2 == 1)
                                {
                                    parentRect.X += 128;
                                }
                                if (parent.Y % 2 == 1)
                                {
                                    parentRect.Y += 128;
                                }
                                parent.X /= 2;
                                parent.Y /= 2;
                                parent.Zoom--;
                                TileCache.TryGetValue(parent, out parentData);
                            }

                            if (parentData != null && parentData.Bitmap != null)
                            {
                                // mark this tile as used recently
                                parentData.LastUsed = tickCount;
                                if (tileRect.Width > 0 && tileRect.Height > 0)
                                {
                                    renderer.Draw(parentData.Bitmap, tileRect, parentRect);
                                }
                                continue;
                            }
                            else
                            {
                                // tile is being downloaded, and we have no parent or child images we can use to draw a temp
                                // image. let's try to use a refresh bitmap.

                                // tile is not available, and this is a transparent draw,
                                // so dont draw at all
                                if (HasAlpha)
                                {
                                    continue;
                                }
                                if ((tile = RefreshBitmap) == null)
                                {
                                    renderer.FillRectangle(BackColor, tileRect);
                                    continue;
                                }
                            }
                        }
                    }

                    if (tile != null && tileRect.Width > 0 && tileRect.Height > 0)
                    {
                        renderer.Draw(tile, tileRect, sourceRect);
                    }
                }
            }

            int     pixelLevelZoom   = myZoom + 8;
            int     centerXReference = myCenterTile.X << 8;
            int     centerYReference = myCenterTile.Y << 8;
            Geocode tlGeo            = PointToGeocode(new Point(Math.Max(centerXReference + myCenterOffset.X - width / 2, 0), Math.Max(centerYReference + myCenterOffset.Y - height / 2, 0)), pixelLevelZoom);
            Geocode brGeo            = PointToGeocode(new Point(Math.Min(centerXReference + myCenterOffset.X + width / 2, 1 << pixelLevelZoom), Math.Min(centerYReference + myCenterOffset.Y + height / 2, 1 << pixelLevelZoom)), pixelLevelZoom);
            int     adjustX          = midX - centerXReference;
            int     adjustY          = midY - centerYReference;

            foreach (Route route in myRoutes)
            {
                List <Point> points             = new List <Point>();
                Geocode      lastOffscreenPoint = Geocode.Null;
                for (int i = 0; i < route.PolyLine.Length; i++)
                {
                    Geocode geocode = route.PolyLine[i];
                    if (myLevelToZoom[route.Levels[i]] > myZoom)
                    {
                        continue;
                    }

                    // check if we're drawing off the screen
                    if (!GeocodeBoxContains(tlGeo, brGeo, geocode))
                    {
                        // if we're drawing from on screen to off screen, draw it, but note that
                        // we are now off screen
                        if (lastOffscreenPoint == Geocode.Null)
                        {
                            points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY));
                        }

                        lastOffscreenPoint = geocode;
                        continue;
                    }

                    // draw in from off the screen if necessary
                    if (lastOffscreenPoint != Geocode.Null)
                    {
                        points.Add(GeocodeToScreen(lastOffscreenPoint, pixelLevelZoom, adjustX, adjustY));
                    }
                    // note that we are now in screen space
                    lastOffscreenPoint = Geocode.Null;

                    points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY));
                }
                if (points.Count > 1)
                {
                    renderer.DrawLines(route.LineWidth, Color.Cyan, points.ToArray());
                }
            }

            foreach (IMapOverlay overlay in Overlays)
            {
                DrawAtGeocode(tlGeo, brGeo, renderer, overlay.Geocode, pixelLevelZoom, adjustX + overlay.Offset.X, adjustY + overlay.Offset.Y, overlay.Drawable);
            }

            return(unavailable);
        }
Example #20
0
 private void SetMarkers()
 {
     float fSize = 9;
     List<string> seenLocs = new List<string>();
     List<Geocode> codes = new List<Geocode>();
     SizeF currentScreen = this.CurrentAutoScaleDimensions;
     if (currentScreen.Height == 192)
     {
         fSize = 4;
     }
     foreach (Library.User user in _Users)
     {
         string location = user.location;
         if (!seenLocs.Contains(location))
         {
             seenLocs.Add(location);
             Yedda.GoogleGeocoder.Coordinate c;
             if (!Yedda.GoogleGeocoder.Coordinate.tryParse(location, out c))
             {
                 c = Yedda.GoogleGeocoder.Geocode.GetCoordinates(location);
             }
             if (c.Latitude != 0 && c.Longitude != 0)
             {
                 userMapDrawable marker = new userMapDrawable();
                 marker.userToDraw = user;
                 marker.fSize = fSize;
                 Geocode g = new Geocode((double)c.Latitude, (double)c.Longitude);
                 MapOverlay o = new MapOverlay(marker, g, new Point(0, -marker.Height / 2));
                 codes.Add(g);
                 mySession.Overlays.Add(o);
             }
         }
     }
     mySession.FitPOIToDimensions(myPictureBox.Width, myPictureBox.Height, 8, codes.ToArray());
 }
Example #21
0
 private void SearchNearHere()
 {
     Point OutsidePoint =  new Point(0, this.Height / 2);
     Point CenterPoint = new Point(this.Width / 2, this.Height / 2);
     Geocode g = mySession.CenterRelativePointToGeocode(OutsidePoint);
     Geocode c = mySession.CenterRelativePointToGeocode(CenterPoint);
     double dist = distance(g.Latitude, g.Longitude, c.Latitude, c.Longitude, 'K');
     System.Diagnostics.Debug.WriteLine(dist);
     this.Range = dist;
     this.CenterLocation = c;
     this.Close();
 }
Example #22
0
        public override bool Equals(object obj)
        {
            Geocode other = (Geocode)obj;

            return(this == other);
        }
Example #23
0
        static List<Segment> DecodeSteps(char[] chars)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(chars);
            string blob = builder.ToString();
            Regex regex = new Regex(@"new VE_RouteInstruction\('(.*?)',(-*[\d]+.[\d]+),(-*[\d]+.[\d]+),(-*[\d]+.[\d]+)");
            Regex cleaner = new Regex(@"&#[\d]+;.*?&#[\d]+;");
            Regex bolder = new Regex(@"( [A-Z][A-Z]+ )");
            Match m = regex.Match(blob);
            List<Segment> ret = new List<Segment>();
            while (m.Success)
            {
                Segment segment = new Segment();
                Geocode geocode = new Geocode();
                geocode.Latitude = double.Parse(m.Groups[2].Value);
                geocode.Longitude = double.Parse(m.Groups[3].Value);
                segment.Geocode = geocode;
                segment.Distance = string.Format("{0} miles", m.Groups[4].Value);

                string text = m.Groups[1].Value;
                Match m2 = cleaner.Match(text);
                while (m2.Success)
                {
                    text = text.Replace(m2.Value, string.Empty);
                    m2 = cleaner.Match(text);
                }

                string formattedText = text;
                m2 = bolder.Match(text);
                while (m2.Success)
                {
                    text = text.Replace(m2.Value, m2.Value.ToLower());
                    formattedText = formattedText.Replace(m2.Value, string.Format("<b>{0}</b>", m2.Value.ToLower()));
                    m2 = bolder.Match(text);
                }

                text = text.Replace("  ", " ");
                formattedText = formattedText.Replace("  ", " ").Replace("<b> ", " <b>").Replace(" </b>", "</b> ");

                segment.FormattedText = formattedText;
                segment.Text = text;

                ret.Add(segment);
                m = m.NextMatch();
            }

            return ret;
        }