コード例 #1
0
        /// <summary>
        /// Show form for set case location
        /// </summary>
        /// <param name="countryID">Id of country for auto zoom</param>
        /// <param name="regionID">Id of region for auto zoom</param>
        /// <param name="rayonID">Id of rayon for auto zoom</param>
        /// <param name="settlementID">Id of settlement for auto zoom</param>
        /// <param name="x">longitude, if case already has coordinates</param>
        /// <param name="y">latitude, if case already has coordinates</param>
        /// <param name="onCaseHandler"></param>
        public static void SetCaseLocation(long countryID, long regionID, long rayonID, long settlementID, decimal x,
                                           decimal y, SetCaseMapForm.OnCaseEvenHandler onCaseHandler)
        {
            bv.common.Core.Utils.CheckNotNull(onCaseHandler, "onCaseHandler");

            try
            {
                var mapForm    = new SetCaseMapForm();
                var screenSize = Screen.GetWorkingArea(new System.Drawing.Point(0, 0));
                if (mapForm.Height > screenSize.Height)
                {
                    mapForm.Height = screenSize.Height;
                }
                if (mapForm.Width > screenSize.Width)
                {
                    mapForm.Width = screenSize.Width;
                }
                using (new TemporaryWaitCursor())
                {
                    mapForm.OnCase       += onCaseHandler;
                    mapForm.InitAdminBBox = Extents.GetMinimalExtent(ConnectionManager.DefaultInstance.ConnectionString,
                                                                     countryID == 0 ? null : (long?)countryID,
                                                                     regionID == 0 ? null : (long?)regionID,
                                                                     rayonID == 0 ? null : (long?)rayonID,
                                                                     settlementID == 0 ? null : (long?)settlementID);
                    if (x != 0 && y != 0)
                    {
                        mapForm.InitWgsPoint = new Point((double)x, (double)y);
                    }
                    else if (settlementID != 0)
                    {
                        double _x, _y;
                        GetSettlementCoordinates(settlementID, out _x, out _y);
                        mapForm.InitWgsPoint = new Point(_x, _y);
                    }
                    else
                    {
                        mapForm.InitWgsPoint = null;
                    }
                }
                mapForm.ShowDialog();
            }
            catch (Exception ex)
            {
                if (BaseSettings.ThrowExceptionOnError)
                {
                    throw;
                }
                ErrorForm.ShowError(ex);
            }
        }
コード例 #2
0
        public static Bitmap GetPrintMap
            (long countryId, long regionId, long rayonId, long settlementId, decimal x, decimal y)
        {
            var setCaseMapControl = new SetCaseMapControl();

            setCaseMapControl.MapSpatRef = CoordinateSystems.SphericalMercatorCS;

            Point initWgsPoint;

            if (x != 0 && y != 0)
            {
                initWgsPoint = new Point((double)x, (double)y);
            }
            else
            {
                initWgsPoint = null;
            }


            if (initWgsPoint != null)
            {
                var point = initWgsPoint.Clone();

                if (setCaseMapControl.MapSpatRef != CoordinateSystems.WGS84)
                {
                    point = GeometryTransform.TransformPoint(point, CoordinateSystems.WGS84,
                                                             setCaseMapControl.MapSpatRef);
                }

                setCaseMapControl.InputTool.Point = point;
            }
            else
            {
                double _x, _y;
                if (GetSettlementCoordinates(settlementId, out _x, out _y))
                {
                    initWgsPoint = new Point(_x, _y);
                    var point = initWgsPoint.Clone();

                    if (setCaseMapControl.MapSpatRef != CoordinateSystems.WGS84)
                    {
                        point = GeometryTransform.TransformPoint(point, CoordinateSystems.WGS84,
                                                                 setCaseMapControl.MapSpatRef);
                    }

                    setCaseMapControl.InputTool.Point = point;
                }
            }

            var defPath = string.IsNullOrEmpty(BaseSettings.DefaultMapProject)
                ? MapProjectsStorage.DefaultMapPath
                : BaseSettings.DefaultMapProject;

            setCaseMapControl.LoadMap(defPath);//MapProjectsStorage.DefaultMapPath);

            // get min WGS-extent
            var extent = Extents.GetMinimalExtent(ConnectionManager.DefaultInstance.ConnectionString,
                                                  countryId == 0 ? null : (long?)countryId,
                                                  regionId == 0 ? null : (long?)regionId,
                                                  rayonId == 0 ? null : (long?)rayonId,
                                                  settlementId == 0 ? null : (long?)settlementId);
            var extentPrj = GeometryTransform.TransformBox(extent, CoordinateSystems.WGS84,
                                                           CoordinateSystems.SphericalMercatorCS);

            var k = extentPrj.Width / extentPrj.Height;

            const double w = 180;
            var          h = w / k;

            setCaseMapControl.Width  = (int)(w * 10);
            setCaseMapControl.Height = (int)(h * 10);

            setCaseMapControl.ZoomToBox(extentPrj);

            setCaseMapControl.InputTool.TemporaryLayerName             = "Vet. Case Location";
            setCaseMapControl.InputTool.TemporaryLayerStyle.MarkerType = MarkerTypes.Cross;
            var result = setCaseMapControl.m_mapImage.GetMapImage(w, h, 300);

            //setCaseMapControl.Dispose();

            return(result);
        }