Exemplo n.º 1
0
        public static bool GetGeodesicSizePrecise(this IPrintableMap map, IEnvelope extents, out GeoSize size)
        {
            size = null;
            double width, height;

            if (map.Projection.HasTransformation)
            {
                // the projection supports coordinate tranformation to WGS84
                if (CalculateExtentsWidth(map, extents, out width) &&
                    CalculateExtentsHeight(map, extents, out height))
                {
                    size = new GeoSize(width, height);
                    return(true);
                }
            }

            if (map.Projection.IsGeographic)
            {
                // it's WGS84
                var center = extents.Center;

                width  = GeodesicDistance(center.Y, extents.MinX, center.Y, extents.MaxX);
                height = GeodesicDistance(extents.MinY, center.X, extents.MaxY, center.X);

                size = new GeoSize(width, height);

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public void Initialize(IPrintableMap map, LayoutControl lc)
 {
     if (map == null)
     {
         throw new ArgumentNullException("map");
     }
     if (lc == null)
     {
         throw new ArgumentNullException("lc");
     }
     _layoutControl = lc;
     _map           = map;
 }
Exemplo n.º 4
0
        public void Initialize(IPrintableMap map, LayoutControl layoutControl)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (layoutControl == null)
            {
                throw new ArgumentNullException("layoutControl");
            }

            _map           = map;
            _layoutControl = layoutControl;

            _map.TilesLoaded += TilesLoaded;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Calculates the size of specified map extents in meters.
        /// </summary>
        public static bool GetGeodesicSize(this IPrintableMap map, IEnvelope extents, out GeoSize size)
        {
            bool result = GetGeodesicSizePrecise(map, extents, out size);

            if (result)
            {
                return(true);
            }

            // we have nothing better but return width and height of the extents in original
            // coordinate system; only let's convert them to meters (geodesic size is always in meters)
            double width  = UnitConversionHelper.Convert(map.MapUnits, LengthUnits.Meters, extents.Width);
            double height = UnitConversionHelper.Convert(map.MapUnits, LengthUnits.Meters, extents.Height);

            size = new GeoSize(width, height);
            return(true);
        }
Exemplo n.º 6
0
        private static bool CalculateExtentsWidth(this IPrintableMap map, IEnvelope extents, out double width)
        {
            var    center = extents.Center;
            double lng    = extents.MinX;
            double lat    = center.Y;
            double lng2   = extents.MaxX;
            double lat2   = center.Y;

            width = 0.0;

            if (map.Projection.Transform(ref lng, ref lat) && map.Projection.Transform(ref lng2, ref lat2))
            {
                width = GeodesicDistance(lat, lng, lat2, lng2);
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        private static bool CalculateExtentsHeight(this IPrintableMap map, IEnvelope extents, out double height)
        {
            var center = extents.Center;

            double lng  = center.X;
            double lat  = extents.MinY;
            double lng2 = center.X;
            double lat2 = extents.MaxY;

            height = 0.0;

            if (map.Projection.Transform(ref lng, ref lat) && map.Projection.Transform(ref lng2, ref lat2))
            {
                height = GeodesicDistance(lat, lng, lat2, lng2);
                return(true);
            }

            return(false);
        }
Exemplo n.º 8
0
        public LayoutMenuListener(IAppContext context, ILayoutView view, PdfExportService pdfService)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            if (pdfService == null)
            {
                throw new ArgumentNullException("pdfService");
            }

            _context       = context;
            _view          = view;
            _pdfService    = pdfService;
            _map           = context.Map;
            _layoutControl = view.LayoutControl;
        }
Exemplo n.º 9
0
        public void Initialize(IPrintableMap map, TileLoadingService loadingService)
        {
            // TODO: assign page settings explicitly
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (loadingService == null)
            {
                throw new ArgumentNullException("loadingService");
            }

            _map            = map;
            _loadingService = loadingService;
            _loadingService.Initialize(_map, this);

            _initialized = true;

            ZoomFitToScreen();

            UpdateScrollBars();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Calculates the size of currently selected map extents in meters
 /// </summary>
 public static bool GetGeodesicSize(this IPrintableMap map, out GeoSize size)
 {
     return(GetGeodesicSize(map, map.Extents, out size));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Calculates new extents of the map given that they must cover certain geo size in meters.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="oldExtents">The extents.</param>
        /// <param name="newSize">The new size.</param>
        /// <param name="paperSize"></param>
        /// <returns>New extents</returns>
        public static IEnvelope CalcNewExtents(IPrintableMap map, IEnvelope oldExtents, GeoSize newSize, SizeF paperSize)
        {
            int depth = 0;

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