示例#1
0
        private void lnkViewer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            TreeNode root = MapTree.SelectedNode;

            while (root.Parent != null)
            {
                root = root.Parent;
            }

            IMapDefinition mdf = root.Tag as IMapDefinition;

            if (mdf != null)
            {
                BusyWaitDelegate worker = () =>
                {
                    IMappingService mapSvc = (IMappingService)m_connection.GetService((int)ServiceType.Mapping);
                    var             rtMap  = mapSvc.CreateMap(mdf);
                    return(rtMap);
                };
                Action <object, Exception> onComplete = (obj, ex) =>
                {
                    if (ex != null)
                    {
                        throw ex;
                    }

                    if (obj != null)
                    {
                        var rtMap = (RuntimeMap)obj;
                        using (var diag = new MapExtentsDialog(rtMap))
                        {
                            if (diag.ShowDialog() == DialogResult.OK)
                            {
                                var env = diag.GetEnvelope();
                                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);
                            }
                        }
                    }
                };
                BusyWaitDialog.Run(Strings.PreparingMap, worker, onComplete);
            }
        }
示例#2
0
        private void LoadMap(IServerConnection conn, string mapDefinitionId)
        {
            //To render a map, we need to create a runtime map instance. IMappingService gives us
            //the required services. This is not a standard service, so you need to call GetService()
            //with the correct ServiceType to get the IMappingService reference.
            IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);

            //Get an IMapDefinition from the specified resource id. GetResource() returns an instance
            //of IResource, which IMapDefinition extends. As long as you pass in a valid resource id
            //of the right type, you can safely cast the returned object to the expected type.
            IMapDefinition mapDef = (IMapDefinition)conn.ResourceService.GetResource(mapDefinitionId);

            //Create a runtime map
            var rtMap = mapSvc.CreateMap(mapDef);

            //Load it into the viewer
            mapViewer.LoadMap(rtMap);
        }
        /// <summary>
        /// Binds the specified editor service to this editor
        /// </summary>
        /// <param name="service"></param>
        public override void Bind(IEditorService service)
        {
            this.EditorService = service;
            service.RegisterCustomNotifier(this);

            _shadowCopy = (IMapDefinition)service.GetEditedResource();
            _mapSvc     = (IMappingService)service.CurrentConnection.GetService((int)ServiceType.Mapping);
            _rtMap      = _mapSvc.CreateMap(_shadowCopy);
            repoView.Init(service.CurrentConnection.ResourceService, new string[] {
                ResourceTypes.LayerDefinition.ToString(),
                ResourceTypes.FeatureSource.ToString()
            }, new string[] {
                ResourceTypes.LayerDefinition.ToString(),
                ResourceTypes.FeatureSource.ToString()
            });

            ReloadViewer();
        }
示例#4
0
        private void LoadMap(IServerConnection conn, string mapDefinitionId)
        {
            //To render a map, we need to create a runtime map instance. IMappingService gives us
            //the required services. This is not a standard service, so you need to call GetService()
            //with the correct ServiceType to get the IMappingService reference.
            IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);

            //Get an IMapDefinition from the specified resource id. GetResource() returns an instance
            //of IResource, which IMapDefinition extends. As long as you pass in a valid resource id
            //of the right type, you can safely cast the returned object to the expected type.
            IMapDefinition mapDef = (IMapDefinition)conn.ResourceService.GetResource(mapDefinitionId);

            //Create a runtime map
            var rtMap = mapSvc.CreateMap(mapDef);

            //Set map display to match the size of our picture box
            rtMap.InitialiseDisplayParameters(pictureBox1.Width, pictureBox1.Height);

            //Note: Sometimes the meters-per-unit value may be inaccurate. This has ramifications on
            //display and measuring. If you have access to the MgCoordinateSystem API, create an instance
            //using the Map Definition's WKT and use the meters-per-unit value obtained like so:
            //
            // MgCoordinateSystemFactory csFactory = new MgCoordinateSystemFactory();
            // MgCoordinateSystem cs = csFactory.Create(srs);
            // double metersPerUnit = cs.ConvertCoordinateSystemUnitsToMeters(1.0);
            //
            //This result gives a more accurate MPU

            //Before we can do anything with this map, it must first be saved.
            //Anytime you manipulate this map, you need to save it for the changes to be
            //applied back to the MapGuide Server
            rtMap.Save();

            //Render the map with its current display parameters in PNG format. A System.IO.Stream
            //is returned.
            using (var stream = rtMap.Render("PNG"))
            {
                //Create a System.Drawing.Image from the stream and load it into our picture box.
                pictureBox1.Image = Image.FromStream(stream);
            }
        }
        /// <summary>
        /// Binds the specified editor service to this editor
        /// </summary>
        /// <param name="service"></param>
        public override void Bind(IEditorService service)
        {
            this.EditorService = service;
            service.RegisterCustomNotifier(this);

            _shadowCopy = (IMapDefinition)service.GetEditedResource();
            _mapSvc = (IMappingService)_shadowCopy.CurrentConnection.GetService((int)ServiceType.Mapping);
            _rtMap = _mapSvc.CreateMap(_shadowCopy);
            repoView.Init(service.ResourceService, new ResourceTypes[] {
                ResourceTypes.LayerDefinition,
                ResourceTypes.FeatureSource
            }, new ResourceTypes[] {
                ResourceTypes.LayerDefinition,
                ResourceTypes.FeatureSource
            });

            ReloadViewer();
        }
示例#6
0
        /// <summary>
        /// Previews the given resource
        /// </summary>
        /// <param name="res"></param>
        /// <param name="edSvc"></param>
        /// <param name="locale"></param>
        public void Preview(IResource res, IEditorService edSvc, string locale)
        {
            IServerConnection conn = edSvc.CurrentConnection;

            if (this.UseLocal && IsLocalPreviewableType(res) && SupportsMappingService(conn))
            {
                BusyWaitDelegate worker = () =>
                {
                    IMappingService mapSvc     = (IMappingService)conn.GetService((int)ServiceType.Mapping);
                    IMapDefinition  previewMdf = null;
                    switch (res.ResourceType)
                    {
                    case "LayerDefinition":
                    {
                        ILayerDefinition ldf       = (ILayerDefinition)res;
                        string           layerName = string.Empty;
                        if (edSvc.IsNew)
                        {
                            layerName = ResourceIdentifier.GetName(ldf.SubLayer.ResourceId);
                        }
                        else
                        {
                            layerName = ResourceIdentifier.GetName(edSvc.ResourceID);
                        }
                        previewMdf = ResourcePreviewEngine.CreateLayerPreviewMapDefinition(ldf, edSvc.SessionID, layerName, conn);
                    }
                    break;

                    case "WatermarkDefinition":
                    {
                        previewMdf = Utility.CreateWatermarkPreviewMapDefinition((IWatermarkDefinition)res);
                    }
                    break;

                    case "MapDefinition":
                    {
                        previewMdf = (IMapDefinition)res;
                    }
                    break;
                    }

                    if (string.IsNullOrEmpty(previewMdf.ResourceID))
                    {
                        var sessionId = edSvc.SessionID;
                        var mdfId     = "Session:" + sessionId + "//" + Guid.NewGuid() + ".MapDefinition"; //NOXLATE

                        conn.ResourceService.SaveResourceAs(previewMdf, mdfId);
                        previewMdf.ResourceID = mdfId;
                    }

                    if (previewMdf != null)
                    {
                        return(mapSvc.CreateMap(previewMdf, false));
                    }
                    else
                    {
                        return(null);
                    }
                };
                Action <object, Exception> onComplete = (obj, ex) =>
                {
                    if (ex != null)
                    {
                        throw ex;
                    }

                    if (obj != null)
                    {
                        var rtMap = (RuntimeMap)obj;
                        if (_viewManager != null)
                        {
                            _viewManager.OpenContent(ViewRegion.Document, () => new MapPreviewViewContent(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID));
                        }
                        else
                        {
                            var diag = new MapPreviewDialog(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID);
                            diag.Show(null);
                        }
                    }
                    else //Fallback, shouldn't happen
                    {
                        _inner.Preview(res, edSvc, locale);
                    }
                };
                BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete);
            }
            else
            {
                _inner.Preview(res, edSvc, locale);
            }
        }
 /// <summary>
 /// Rebuilds the current Runtime Map
 /// </summary>
 public void RebuildRuntimeMap()
 {
     _rtMap = _mapSvc.CreateMap(_shadowCopy);
 }