Exemple #1
0
        protected void UpdateImage()
        {
            updateTimer.Stop();

            if (updateInProgress)
            {
                updateTimer.Start(); // update image on next timer tick
            }
            else if (ParentMap != null && ParentMap.RenderSize.Width > 0 && ParentMap.RenderSize.Height > 0)
            {
                updateInProgress = true;

                var relativeSize = Math.Max(RelativeImageSize, 1d);
                var width        = ParentMap.RenderSize.Width * relativeSize;
                var height       = ParentMap.RenderSize.Height * relativeSize;
                var dx           = (ParentMap.RenderSize.Width - width) / 2d;
                var dy           = (ParentMap.RenderSize.Height - height) / 2d;

                var loc1 = ParentMap.ViewportPointToLocation(new Point(dx, dy));
                var loc2 = ParentMap.ViewportPointToLocation(new Point(dx + width, dy));
                var loc3 = ParentMap.ViewportPointToLocation(new Point(dx, dy + height));
                var loc4 = ParentMap.ViewportPointToLocation(new Point(dx + width, dy + height));

                var west  = Math.Min(loc1.Longitude, Math.Min(loc2.Longitude, Math.Min(loc3.Longitude, loc4.Longitude)));
                var east  = Math.Max(loc1.Longitude, Math.Max(loc2.Longitude, Math.Max(loc3.Longitude, loc4.Longitude)));
                var south = Math.Min(loc1.Latitude, Math.Min(loc2.Latitude, Math.Min(loc3.Latitude, loc4.Latitude)));
                var north = Math.Max(loc1.Latitude, Math.Max(loc2.Latitude, Math.Max(loc3.Latitude, loc4.Latitude)));

                if (!double.IsNaN(MinLongitude) && west < MinLongitude)
                {
                    west = MinLongitude;
                }

                if (!double.IsNaN(MaxLongitude) && east > MaxLongitude)
                {
                    east = MaxLongitude;
                }

                if (!double.IsNaN(MinLatitude) && south < MinLatitude)
                {
                    south = MinLatitude;
                }

                if (!double.IsNaN(MaxLatitude) && north > MaxLatitude)
                {
                    north = MaxLatitude;
                }

                var p1 = ParentMap.MapTransform.Transform(new Location(south, west));
                var p2 = ParentMap.MapTransform.Transform(new Location(north, east));

                UpdateImage(new BoundingBox(west, east, south, north),
                            (int)Math.Round((p2.X - p1.X) * ParentMap.ViewportScale),
                            (int)Math.Round((p2.Y - p1.Y) * ParentMap.ViewportScale));
            }
        }
Exemple #2
0
        protected void UpdateImage()
        {
            if (updateInProgress)
            {
                updateTimer.Start(); // update image on next timer tick
            }
            else
            {
                updateTimer.Stop();

                if (ParentMap != null && RenderSize.Width > 0 && RenderSize.Height > 0)
                {
                    updateInProgress = true;

                    var relativeSize = Math.Max(RelativeImageSize, 1d);
                    var width        = RenderSize.Width * relativeSize;
                    var height       = RenderSize.Height * relativeSize;
                    var dx           = (RenderSize.Width - width) / 2d;
                    var dy           = (RenderSize.Height - height) / 2d;

                    var loc1 = ParentMap.ViewportPointToLocation(new Point(dx, dy));
                    var loc2 = ParentMap.ViewportPointToLocation(new Point(dx + width, dy));
                    var loc3 = ParentMap.ViewportPointToLocation(new Point(dx, dy + height));
                    var loc4 = ParentMap.ViewportPointToLocation(new Point(dx + width, dy + height));

                    var west  = Math.Min(loc1.Longitude, Math.Min(loc2.Longitude, Math.Min(loc3.Longitude, loc4.Longitude)));
                    var east  = Math.Max(loc1.Longitude, Math.Max(loc2.Longitude, Math.Max(loc3.Longitude, loc4.Longitude)));
                    var south = Math.Min(loc1.Latitude, Math.Min(loc2.Latitude, Math.Min(loc3.Latitude, loc4.Latitude)));
                    var north = Math.Max(loc1.Latitude, Math.Max(loc2.Latitude, Math.Max(loc3.Latitude, loc4.Latitude)));

                    var p1 = ParentMap.MapTransform.Transform(new Location(south, west));
                    var p2 = ParentMap.MapTransform.Transform(new Location(north, east));

                    width  = Math.Round((p2.X - p1.X) * ParentMap.ViewportScale);
                    height = Math.Round((p2.Y - p1.Y) * ParentMap.ViewportScale);

                    var image = GetBitmap(west, east, south, north, (int)width, (int)height);

                    UpdateImage(west, east, south, north, image);
                }
            }
        }
Exemple #3
0
        private void UpdateImage(object sender, EventArgs e)
        {
            if (updateInProgress)
            {
                return; // update image on next timer tick
            }

            updateTimer.Stop();

            if (ParentMap != null && ActualWidth > 0 && ActualHeight > 0)
            {
                updateInProgress = true;

                var relativeSize = Math.Max(RelativeImageSize, 1d);
                var width        = ActualWidth * relativeSize;
                var height       = ActualHeight * relativeSize;
                var dx           = (ActualWidth - width) / 2d;
                var dy           = (ActualHeight - height) / 2d;
                var loc1         = ParentMap.ViewportPointToLocation(new Point(dx, dy));
                var loc2         = ParentMap.ViewportPointToLocation(new Point(width, dy));
                var loc3         = ParentMap.ViewportPointToLocation(new Point(dx, height));
                var loc4         = ParentMap.ViewportPointToLocation(new Point(width, height));

                ThreadPool.QueueUserWorkItem(o =>
                {
                    var west  = Math.Min(loc1.Longitude, Math.Min(loc2.Longitude, Math.Min(loc3.Longitude, loc4.Longitude)));
                    var east  = Math.Max(loc1.Longitude, Math.Max(loc2.Longitude, Math.Max(loc3.Longitude, loc4.Longitude)));
                    var south = Math.Min(loc1.Latitude, Math.Min(loc2.Latitude, Math.Min(loc3.Latitude, loc4.Latitude)));
                    var north = Math.Max(loc1.Latitude, Math.Max(loc2.Latitude, Math.Max(loc3.Latitude, loc4.Latitude)));
                    var image = GetImage(west, east, south, north, (int)Math.Round(width), (int)Math.Round(height));

                    Dispatcher.BeginInvoke((Action)(() => UpdateImage(west, east, south, north, image)));

                    updateInProgress = false;
                });
            }
        }