public void Preview(IResource res, IEditorService edSvc, string locale)
        {
            IMapDefinition mapDef = null;
            var            conn   = edSvc.CurrentConnection;

            if (res.ResourceType == ResourceTypes.LayerDefinition.ToString())
            {
                var    ldf = (ILayerDefinition)res;
                string wkt;
                var    env = ldf.GetSpatialExtent(conn, true, out wkt);
                if (env == null)
                {
                    throw new ApplicationException(Strings.CouldNotComputeExtentsForPreview);
                }
                mapDef = Utility.CreateMapDefinition(conn, "Preview");
                mapDef.CoordinateSystem = wkt;
                mapDef.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
                string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString();
                conn.ResourceService.SetResourceXmlData(resId, ObjectFactory.Serialize(res));
                mapDef.AddLayer(null, "PreviewLayer", resId);
            }
            else if (res.ResourceType == ResourceTypes.MapDefinition.ToString())
            {
                mapDef = (IMapDefinition)res;
            }
            else if (res.ResourceType == ResourceTypes.WatermarkDefinition.ToString())
            {
                string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString();
                conn.ResourceService.SetResourceXmlData(resId, ObjectFactory.Serialize(res));

                var csFact = new MgCoordinateSystemFactory();
                var arbXY  = csFact.ConvertCoordinateSystemCodeToWkt("XY-M");
                mapDef = ObjectFactory.CreateMapDefinition(new Version(2, 3, 0), "Preview");
                mapDef.CoordinateSystem = arbXY;
                mapDef.SetExtents(-100000, -100000, 100000, 100000);
                var wm = ((IMapDefinition2)mapDef).AddWatermark(((IWatermarkDefinition)res));
                wm.ResourceId = resId;
            }

            var mapResId = new MgResourceIdentifier("Session:" + edSvc.SessionID + "//" + mapDef.ResourceType.ToString() + "Preview" + Guid.NewGuid() + "." + mapDef.ResourceType.ToString());

            conn.ResourceService.SetResourceXmlData(mapResId.ToString(), ObjectFactory.Serialize(mapDef));

            //MgdMap map = new MgdMap(mapResId);

            //var diag = new MapPreviewWindow(map, conn);
            //diag.ShowDialog();

            var diag = new UI.MapPreviewWindow(conn);

            diag.Init(mapResId);
            diag.ShowDialog();
        }
Пример #2
0
        /// <summary>
        /// Sets the extents of the map definition from the id of the the given layer definition
        /// Does nothing if the extent is already set
        /// </summary>
        /// <param name="mdf"></param>
        /// <param name="layerDefinitionId"></param>
        public static void AutoSetExtentsFromLayer(this IMapDefinition mdf, string layerDefinitionId)
        {
            //Do nothing if this is false
            if (!mdf.Extents.IsEmpty())
            {
                return;
            }

            var calc = mdf.ExtentCalculator;

            if (calc != null)
            {
                var res = calc.GetLayerExtent(layerDefinitionId, mdf.CoordinateSystem);
                if (res != null)
                {
                    //Set the coordinate system if empty
                    if (string.IsNullOrEmpty(mdf.CoordinateSystem))
                    {
                        mdf.CoordinateSystem = res.LayerCoordinateSystem;
                    }
                    //Set the bounds if empty
                    if (mdf.Extents.IsEmpty())
                    {
                        var env = res.Extent;
                        mdf.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
                    }
                }
            }
        }
Пример #3
0
        private void MakeTempMap()
        {
            if (m_tempmap == null)
            {
                IMapDefinition m = Utility.CreateMapDefinition(m_connection, string.Empty);
                m.CoordinateSystem = @"LOCAL_CS[""*XY-M*"", LOCAL_DATUM[""*X-Y*"", 10000], UNIT[""Meter"", 1], AXIS[""X"", EAST], AXIS[""Y"", NORTH]]"; //NOXLATE
                m.SetExtents(-1, -1, 1, 1);

                //AIMS 2012 demands this checks out. Can't flub it anymore
                m.ResourceID = "Session:" + m_connection.SessionID + "//non-existing.MapDefinition"; //NOXLATE
                var mpsvc = (IMappingService)m_connection.GetService((int)ServiceType.Mapping);
                var rid   = new ResourceIdentifier(Guid.NewGuid().ToString(), ResourceTypes.Map, m_connection.SessionID);

                m_tempmap = mpsvc.CreateMap(m);
            }
        }
        private void btnSetZoom_Click(object sender, EventArgs e)
        {
            var diag = new ExtentCalculationDialog(_service.CurrentConnection, _map.CoordinateSystem, CollectLayerIds);

            if (diag.ShowDialog() == DialogResult.OK)
            {
                var env = diag.Extents;
                if (env != null)
                {
                    _map.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
                }
                else
                {
                    MessageBox.Show(Strings.ErrorMapExtentCalculationFailed, Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnSetZoom_Click(object sender, EventArgs e)
        {
            var diag = new ExtentCalculationDialog(_conn, _mdf.CoordinateSystem, CollectLayerIds);

            if (diag.ShowDialog() == DialogResult.OK)
            {
                var env = diag.Extents;
                if (env != null)
                {
                    _mdf.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
                    txtLowerX.Text = env.MinX.ToString(CultureInfo.InvariantCulture);
                    txtLowerY.Text = env.MinY.ToString(CultureInfo.InvariantCulture);
                    txtUpperX.Text = env.MaxX.ToString(CultureInfo.InvariantCulture);
                    txtUpperY.Text = env.MaxY.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    MessageBox.Show(Strings.ErrorMapExtentCalculationFailed, Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }