Example #1
0
        /// <summary>
        /// Recursively calculates new extents of the map ot cover a certain geo size in meters.
        /// </summary>
        private static IEnvelope CalcNewExtentsCore(
            IPrintableMap map,
            IEnvelope oldExtents,
            GeoSize newSize,
            SizeF paperSize,
            ref int depth)
        {
            depth++;

            GeoSize oldSize;

            if (map.GetGeodesicSize(oldExtents, out oldSize))
            {
                const int maxDepth = 5;

                double newScale = CalcMapScale(newSize, paperSize);
                double oldScale = CalcMapScale(oldSize, paperSize);

                if (NumericHelper.Equal(newScale, oldScale, 1e-6) || depth > maxDepth)
                {
                    return(oldExtents);
                }

                double ratio   = newScale / oldScale - 1;
                double dx      = oldExtents.Width * ratio;
                double dy      = oldExtents.Height * ratio;
                var    extents = oldExtents.Inflate(dx, dy);

                return(CalcNewExtentsCore(map, extents, newSize, paperSize, ref depth));
            }

            return(null);
        }
Example #2
0
        private void UpdatePreview(bool fullExtents)
        {
            int layersCount = _mainMap.Layers.Count;

            if (layersCount == 0 &&
                (_mainMap.TileProvider == TileProvider.None || _mainMap.Projection.IsEmpty))
            {
                MessageService.Current.Info("Map is empty. It's not possible to create an overview image.");
                return;
            }

            if (fullExtents && layersCount == 0)
            {
                MessageService.Current.Info("No layers are loaded to make snapshot.");
                return;
            }

            IEnvelope e = fullExtents ? _mainMap.MaxExtents : _mainMap.Extents;

            e = e.Inflate(e.Width * 0.1, e.Height * 0.1);       // parameter can be introduced

            double ratio = _view.Width / (double)_view.Height;
            var    exts  = e.Adjust(ratio);

            var img = GetSnapshot(exts);

            if (img == null)
            {
                MessageService.Current.Warn("Failed to make screenshot.");
                return;
            }

            img.Dx               = (exts.MaxX - exts.MinX) / img.Width;
            img.Dy               = (exts.MaxY - exts.MinY) / img.Height;
            img.XllCenter        = exts.MinX + 0.5 * img.Dx;
            img.YllCenter        = exts.MinY + 0.5 * img.Dx; // TODO: Shouldn't this be img.Dy?
            img.DownsamplingMode = InterpolationType.HighQualityBicubic;
            img.UpsamplingMode   = InterpolationType.HighQualityBicubic;

            _view.UpdateImage(img);

            _view.UpdateLocatorBox(_mainMap.Extents);
        }