示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);

                MgResourceIdentifier mdfId = new MgResourceIdentifier(txtMapDefinition.Text);
                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(mdfId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);

                map.SetViewScale(Convert.ToDouble(txtScale.Text));
                sw.Reset();
                sw.Start();
                MgByteReader response = renSvc.RenderTile(map, txtBaseGroup.Text, Convert.ToInt32(txtCol.Text), Convert.ToInt32(txtRow.Text));
                sw.Stop();
                Trace.TraceInformation("RenderTile executed in {0}ms", sw.ElapsedMilliseconds);
                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);

                MgResourceIdentifier mdfId = new MgResourceIdentifier(txtMapDefinition.Text);
                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(mdfId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);

                map.SetViewScale(Convert.ToDouble(txtScale.Text));
                sw.Reset();
                sw.Start();
                MgByteReader response = renSvc.RenderTile(map, txtBaseGroup.Text, Convert.ToInt32(txtCol.Text), Convert.ToInt32(txtRow.Text));
                sw.Stop();
                Trace.TraceInformation("RenderTile executed in {0}ms", sw.ElapsedMilliseconds);
                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
示例#3
0
        public void LoadMap(MgResourceIdentifier resId)
        {
            var map = new MgdMap(resId);

            viewer.Init(new MgDesktopMapViewerProvider(map));
            //viewer.RefreshMap();
        }
示例#4
0
        private void btnSinglePlot_Click(object sender, EventArgs e)
        {
            MgdMap map = (MgdMap)_viewer.GetMap();
            MgMapViewerProvider  provider   = _viewer.GetProvider();
            MgdMappingService    mappingSvc = (MgdMappingService)provider.CreateService(MgServiceType.MappingService);
            MgResourceIdentifier layoutId   = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");

            using (SaveFileDialog save = new SaveFileDialog())
            {
                save.Filter = "DWF Files (*.dwf)|*.dwf";
                if (save.ShowDialog() == DialogResult.OK)
                {
                    MgdDwfVersion dwfVer = new MgdDwfVersion("6.01", "1.2");

                    MgdLayout            layout   = new MgdLayout(layoutId, "City of Sheboygan", MgdPageUnitsType.Inches);
                    MgdPlotSpecification plotSpec = new MgdPlotSpecification(8.5f, 11.0f, MgdPageUnitsType.Inches, 0.5f, 0.5f, 0.5f, 0.5f);

                    MgByteReader result = mappingSvc.GeneratePlot(map, plotSpec, layout, dwfVer);
                    MgByteSink   sink   = new MgByteSink(result);
                    sink.ToFile(save.FileName);

                    MessageBox.Show("Saved to " + save.FileName);
                }
            }
        }
示例#5
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     _viewer.ClearSelection();
     MgResourceIdentifier mdfId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
     MgdMap map = new MgdMap(mdfId);
     MgDesktopMapViewerProvider provider = new MgDesktopMapViewerProvider(map);
     Shell.Instance.ReloadViewer(provider);
 }
 private void OnDisposed(object sender, EventArgs e)
 {
     if (_map != null)
     {
         _map.Dispose();
         _map = null;
     }
 }
示例#7
0
 public LocalRuntimeMap(LocalConnection conn, MgdMap map, bool suppressErrors)
     : base(conn)
 {
     _impl = map;
     _conn = conn;
     InitializeLayersAndGroups(suppressErrors);
     _disableChangeTracking = false;
 }
示例#8
0
 public LocalRuntimeMap(LocalConnection conn, MgdMap map, bool suppressErrors)
     : base(conn)
 {
     _impl = map;
     _conn = conn;
     InitializeLayersAndGroups(suppressErrors);
     _disableChangeTracking = false;
 }
示例#9
0
        private void btnReload_Click(object sender, EventArgs e)
        {
            _viewer.ClearSelection();
            MgResourceIdentifier mdfId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
            MgdMap map = new MgdMap(mdfId);
            MgDesktopMapViewerProvider provider = new MgDesktopMapViewerProvider(map);

            Shell.Instance.ReloadViewer(provider);
        }
示例#10
0
文件: Program.cs 项目: achilex/MgDev
        static void Main(string [] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

            //Must call MgPlatform.Initialize() before we can work with anything from the MapGuide API
            try
            {
                var sw = new Stopwatch();
                sw.Start();
                MgdPlatform.Initialize("Platform.ini");
                sw.Stop();
                Trace.TraceInformation("Platform initialization took {0}ms", sw.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
                return;
            }

            //MgAppWindow is our Main Window class full of drag-and-drop component goodness. Go ahead and
            //take a look at MgAppWindow.cs source, not much code there except for the 3 generic invoke components and the
            //single custom selection handler. Everything else is encapsulated by designer-friendly drag and drop components
            //Most of the work is dragging and dropping components into the designer surface, and setting lots of properties
            var frm = new MgAppWindow();

            //We can initialize without specifying a map (allowing for components that do not
            //require a loaded map to still be used). You just have to call LoadMap() on the MgMapViewer
            //instance when ready (not demonstrated here). So if you do load a package here, you will
            //have to restart the application
            MgResourceIdentifier resId = null;

            if (args.Length == 1)
            {
                resId = new MgResourceIdentifier(args[0]);
                resId.Validate();
            }

            var    fact   = new MgdServiceFactory();
            var    resSvc = (MgdResourceService)fact.CreateService(MgServiceType.ResourceService);
            MgdMap map    = null;

            if (resId != null && resSvc.ResourceExists(resId))
            {
                map = new MgdMap(resId);
            }

            //This is just a pass-through call to MgMapViewer.Init()
            frm.LoadMap(new MgDesktopMapViewerProvider(map));

            Application.ApplicationExit += new EventHandler(OnAppExit);
            Application.Run(frm);
        }
示例#11
0
文件: Program.cs 项目: kanbang/Colt
        static void Main(string [] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            
            //Must call MgPlatform.Initialize() before we can work with anything from the MapGuide API
            try
            {
                var sw = new Stopwatch();
                sw.Start();
                MgdPlatform.Initialize("Platform.ini");
                sw.Stop();
                Trace.TraceInformation("Platform initialization took {0}ms", sw.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
                return;
            }
            
            //MgAppWindow is our Main Window class full of drag-and-drop component goodness. Go ahead and
            //take a look at MgAppWindow.cs source, not much code there except for the 3 generic invoke components and the
            //single custom selection handler. Everything else is encapsulated by designer-friendly drag and drop components
            //Most of the work is dragging and dropping components into the designer surface, and setting lots of properties
            var frm = new MgAppWindow();
            
            //We can initialize without specifying a map (allowing for components that do not 
            //require a loaded map to still be used). You just have to call LoadMap() on the MgMapViewer
            //instance when ready (not demonstrated here). So if you do load a package here, you will
            //have to restart the application
            MgResourceIdentifier resId = null;
            if (args.Length == 1)
            {
                resId = new MgResourceIdentifier(args[0]);
                resId.Validate();
            }

            var fact = new MgdServiceFactory();
            var resSvc = (MgdResourceService)fact.CreateService(MgServiceType.ResourceService);
            MgdMap map = null;

            if (resId != null && resSvc.ResourceExists(resId))
                map = new MgdMap(resId);

            //This is just a pass-through call to MgMapViewer.Init()
            frm.LoadMap(new MgDesktopMapViewerProvider(map));

            Application.ApplicationExit += new EventHandler(OnAppExit);
            Application.Run(frm);
        }
示例#12
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);
                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);

                MgdMap map = new MgdMap(resId);

                double x;
                double y;
                if (double.TryParse(textBox2.Text, out x) &&
                    double.TryParse(textBox3.Text, out y))
                {
                    map.SetViewCenterXY(x, y);
                }

                int w;
                int h;
                if (int.TryParse(txtWidth.Text, out w) &&
                    int.TryParse(txtHeight.Text, out h))
                {
                    map.SetDisplaySize(w, h);
                }

                double scale;
                if (double.TryParse(textBox4.Text, out scale))
                {
                    map.SetViewScale(scale);
                }

                var sw = new Stopwatch();
                sw.Start();
                MgByteReader response = renSvc.RenderMap(map, null, textBox5.Text);
                sw.Stop();
                Trace.TraceInformation("RenderMap executed in {0}ms", sw.ElapsedMilliseconds);

                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#13
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService  renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);
                MgResourceIdentifier resId  = new MgResourceIdentifier(textBox1.Text);

                MgdMap map = new MgdMap(resId);

                double x;
                double y;
                if (double.TryParse(textBox2.Text, out x) &&
                    double.TryParse(textBox3.Text, out y))
                {
                    map.SetViewCenterXY(x, y);
                }

                int w;
                int h;
                if (int.TryParse(txtWidth.Text, out w) &&
                    int.TryParse(txtHeight.Text, out h))
                {
                    map.SetDisplaySize(w, h);
                }

                double scale;
                if (double.TryParse(textBox4.Text, out scale))
                {
                    map.SetViewScale(scale);
                }

                var sw = new Stopwatch();
                sw.Start();
                MgByteReader response = renSvc.RenderMap(map, null, textBox5.Text);
                sw.Stop();
                Trace.TraceInformation("RenderMap executed in {0}ms", sw.ElapsedMilliseconds);

                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#14
0
        protected override void OnLoad(EventArgs e)
        {
            mgMapViewer1.UseRenderMapIfTiledLayersExist = true;
            mgMapViewer1.RespectFiniteDisplayScales     = true;
            new MapViewerController(mgMapViewer1,          //The MgMapViewer
                                    mgLegend1,             //The MgLegend
                                    this,                  //The IMapStatusBar
                                    mgPropertyPane1,       //The MgPropertyPane
                                    mgDefaultToolbar1);    //The MgDefaultToolbar

            MgdServiceFactory    factory  = new MgdServiceFactory();
            MgdResourceService   resSvc   = (MgdResourceService)factory.CreateService(MgServiceType.ResourceService);
            MgResourceIdentifier mapDefId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");

            //If this map definition doesn't exist, we ask the user to
            //load the Sheboygan package
            if (!resSvc.ResourceExists(mapDefId))
            {
                using (OpenFileDialog diag = new OpenFileDialog())
                {
                    diag.Filter = "MapGuide Packages (*.mgp)|*.mgp";
                    if (diag.ShowDialog() == DialogResult.OK)
                    {
                        MgByteSource source = new MgByteSource(diag.FileName);
                        MgByteReader reader = source.GetReader();
                        resSvc.ApplyResourcePackage(reader);
                    }
                    else
                    {
                        //No map, nothing to do here
                        Application.Exit();
                    }
                }
            }

            //Create our runtime map
            MgdMap map = new MgdMap(mapDefId);
            //Create our viewer provider
            MgMapViewerProvider provider = new MgDesktopMapViewerProvider(map);

            //Initialize our viewer with this provider
            mgMapViewer1.Init(provider);
        }
示例#15
0
 public void Init(MgResourceIdentifier mapResId)
 {
     _map = new MgdMap(mapResId);
     var groups = _map.GetLayerGroups();
     if (groups != null && groups.GetCount() > 0)
     {
         for (int i = 0; i < groups.GetCount(); i++)
         {
             var grp = groups.GetItem(i);
             if (grp.LayerGroupType == MgLayerGroupType.BaseMap)
             {
                 MessageBox.Show(Strings.TiledLayerSupportWarning);
                 break;
             }
         }
     }
     var fact = new MgdServiceFactory();
     viewer.Init(new MgDesktopMapViewerProvider(_map));
     viewer.RefreshMap();
 }
示例#16
0
文件: MainForm.cs 项目: kanbang/Colt
        protected override void OnLoad(EventArgs e)
        {
            _wktRw = new MgWktReaderWriter();
            _geomFact = new MgGeometryFactory();
            new MapViewerController(mgMapViewer1,          //The MgMapViewer
                                    mgLegend1,             //The MgLegend
                                    this,                  //The IMapStatusBar
                                    mgPropertyPane1);      //The MgPropertyPane

            MgdServiceFactory factory = new MgdServiceFactory();
            MgdResourceService resSvc = (MgdResourceService)factory.CreateService(MgServiceType.ResourceService);
            MgResourceIdentifier mapDefId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
            //If this map definition doesn't exist, we ask the user to
            //load the Sheboygan package
            if (!resSvc.ResourceExists(mapDefId))
            {
                using (OpenFileDialog diag = new OpenFileDialog())
                {
                    diag.Filter = "MapGuide Packages (*.mgp)|*.mgp";
                    if (diag.ShowDialog() == DialogResult.OK)
                    {
                        MgByteSource source = new MgByteSource(diag.FileName);
                        MgByteReader reader = source.GetReader();
                        resSvc.ApplyResourcePackage(reader);
                    }
                    else
                    {
                        //No map, nothing to do here
                        Application.Exit();
                    }
                }
            }

            //Create our runtime map
            MgdMap map = new MgdMap(mapDefId);
            //Create our viewer provider
            MgMapViewerProvider provider = new MgDesktopMapViewerProvider(map);
            //Initialize our viewer with this provider
            mgMapViewer1.Init(provider);
            UpdateButtonCheckedState();
        }
        public void Init(MgResourceIdentifier mapResId)
        {
            _map = new MgdMap(mapResId);
            var groups = _map.GetLayerGroups();

            if (groups != null && groups.GetCount() > 0)
            {
                for (int i = 0; i < groups.GetCount(); i++)
                {
                    var grp = groups.GetItem(i);
                    if (grp.LayerGroupType == MgLayerGroupType.BaseMap)
                    {
                        MessageBox.Show(Strings.TiledLayerSupportWarning);
                        break;
                    }
                }
            }
            var fact = new MgdServiceFactory();

            viewer.Init(new MgDesktopMapViewerProvider(_map));
            viewer.RefreshMap();
        }
示例#18
0
        private void btnMultiPlot_Click(object sender, EventArgs e)
        {
            MgdMap map = (MgdMap)_viewer.GetMap();
            MgMapViewerProvider  provider   = _viewer.GetProvider();
            MgdMappingService    mappingSvc = (MgdMappingService)provider.CreateService(MgServiceType.MappingService);
            MgResourceIdentifier layoutId   = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");

            using (SaveFileDialog save = new SaveFileDialog())
            {
                save.Filter = "DWF Files (*.dwf)|*.dwf";
                if (save.ShowDialog() == DialogResult.OK)
                {
                    MgdDwfVersion dwfVer = new MgdDwfVersion("6.01", "1.2");

                    MgdLayout            layout   = new MgdLayout(layoutId, "City of Sheboygan", MgdPageUnitsType.Inches);
                    MgdPlotSpecification plotSpec = new MgdPlotSpecification(8.5f, 11.0f, MgdPageUnitsType.Inches, 0.5f, 0.5f, 0.5f, 0.5f);

                    MgdMapPlotCollection plotCollection = new MgdMapPlotCollection();

                    MgdMapPlot plot1 = new MgdMapPlot(map, plotSpec, layout);
                    plot1.SetCenterAndScale(map.GetViewCenter().GetCoordinate(), map.GetViewScale() * 2);
                    plotCollection.Add(plot1);

                    // Create a second map for the second sheet in the DWF. This second sheet uses the print layout
                    // to display a page title and legend.

                    MgdMap     map2  = new MgdMap(map.GetMapDefinition(), "Sheet 2");
                    MgdMapPlot plot2 = new MgdMapPlot(map2, plotSpec, layout);
                    plot2.SetCenterAndScale(map.GetViewCenter().GetCoordinate(), map.GetViewScale());
                    plotCollection.Add(plot2);

                    MgByteReader result = mappingSvc.GenerateMultiPlot(plotCollection, dwfVer);
                    MgByteSink   sink   = new MgByteSink(result);
                    sink.ToFile(save.FileName);

                    MessageBox.Show("Saved to " + save.FileName);
                }
            }
        }
示例#19
0
        private void btnRenderMap2_Click(object sender, EventArgs e)
        {
            //Note we're casting to mg-desktop specific subclasses as this is what mg-desktop rendering APIs expect
            MgdMap              map         = (MgdMap)_viewer.GetMap();
            MgdSelection        selection   = (MgdSelection)_viewer.GetSelection();
            MgMapViewerProvider provider    = _viewer.GetProvider();
            MgdRenderingService renderSvc   = (MgdRenderingService)provider.CreateService(MgServiceType.RenderingService);
            MgPoint             centerPt    = map.ViewCenter;
            MgCoordinate        centerCoord = centerPt.Coordinate;

            //MgdTransientMapState is a helper class which lets us apply transient state to a map, which is automatically
            //undone on disposal. This is how we can render custom views of a map with specific display parameters without
            //permanently changing the display parameters used by the map viewer
            using (MgTransientMapState tempState = provider.CreateTransientState(map))
            {
                MgMapDisplayParameters state = new MgMapDisplayParameters(centerCoord.X, centerCoord.Y, 5000, 1024, 768, 96);
                tempState.PushState(state);

                MgByteReader br = renderSvc.RenderMap(map, selection, "PNG");
                using (SaveFileDialog save = new SaveFileDialog())
                {
                    save.Filter = "Portable Network Graphics (*.png)|*.png";
                    if (save.ShowDialog() == DialogResult.OK)
                    {
                        //MgReadOnlyStream is a stream adapter class that provides a .net stream
                        //interface to the MgByteReader, allowing MgByteReader objects to be used
                        //anywhere a System.IO.Stream is expected.
                        using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                        {
                            Image img = Image.FromStream(stream);
                            img.Save(save.FileName);
                            MessageBox.Show("Image saved to: " + save.FileName);
                        }
                    }
                    br.Dispose();
                }
            }
        }
示例#20
0
 public override void SetGroupExpandInLegend(MgLayerGroup group, bool bExpanded)
 {
     MgdMap.SetGroupExpandInLegend(group, bExpanded);
 }
示例#21
0
 public override void SetLayerExpandInLegend(MgLayerBase layer, bool bExpanded)
 {
     MgdMap.SetLayerExpandInLegend(layer, bExpanded);
 }
示例#22
0
 public MgDesktopMapViewerProvider(MgdMap map) : base(map)
 {
     _implMap = map;
 }
示例#23
0
        static void Main(string [] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

            //Must call MgPlatform.Initialize() before we can work with anything from the MapGuide API
            try
            {
#if PROFILE
                using (new CallMeasure("MgdPlatform.Initialize"))
                {
                    MgdPlatform.Initialize("Platform.ini");
                }
#else
                MgdPlatform.Initialize("Platform.ini");
#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
                return;
            }

            AppLayout layout = null;

            var ser = new XmlSerializer(typeof(AppLayout));
            if (args.Length == 1)
            {
                using (var file = File.OpenRead(args[0]))
                {
                    layout = (AppLayout)ser.Deserialize(file);
                }
            }/*
              * else
              * {
              * layout = AppLayout.CreateDefault("MapGuide Desktop App Layout Example", "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
              * using (var file = File.OpenWrite("Sheboygan.AppLayout"))
              * {
              *     ser.Serialize(file, layout);
              * }
              * }*/

            var mdfId    = new MgResourceIdentifier(layout.Map.MapDefinition);
            var provider = new MgDesktopMapViewerProvider(null);
            var resSvc   = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            if (resSvc.ResourceExists(mdfId))
            {
#if PROFILE
                using (new CallMeasure("MgdMap constructor (cold start)"))
                {
                    var mapCold = new MgdMap(mdfId);
                }
                MgdMap map = null;
                using (new CallMeasure("MgdMap constructor (warm start)"))
                {
                    map = new MgdMap(mdfId);
                }
                using (new CallMeasure("MgMapViewerProvider.LoadMap"))
                {
                    provider.LoadMap(map);
                }
#else
                provider.LoadMap(new MgdMap(mdfId));
#endif
            }
            var frm = Shell.Instance;
            ((Shell)frm).Initialize(layout, provider);
            Application.Run((Shell)frm);
            MgdPlatform.Terminate();
        }
示例#24
0
        public override MgMapBase CreateMap(MgResourceIdentifier mapDefinitionId, string name)
        {
            var map = new MgdMap(mapDefinitionId, name);

            return(map);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService  renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);
                MgResourceIdentifier resId  = new MgResourceIdentifier(textBox1.Text);

                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(resId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);
                MgdSelection selection = null;

                if (!string.IsNullOrEmpty(txtSelectLayer.Text) &&
                    !string.IsNullOrEmpty(txtSelectFilter.Text))
                {
                    selection = new MgdSelection(map);

                    var layers = map.GetLayers();
                    if (layers.IndexOf(txtSelectLayer.Text) >= 0)
                    {
                        var layer = layers.GetItem(txtSelectLayer.Text);

                        var query = new MgFeatureQueryOptions();
                        query.SetFilter(txtSelectFilter.Text);

                        var reader = layer.SelectFeatures(query);

                        selection.AddFeatures(layer, reader, 0);

                        Trace.TraceInformation("{0} features in selection set", selection.GetSelectedFeaturesCount(layer, layer.GetFeatureClassName()));
                    }
                }

                double x;
                double y;
                if (double.TryParse(textBox2.Text, out x) &&
                    double.TryParse(textBox3.Text, out y))
                {
                    map.SetViewCenterXY(x, y);
                }

                int w;
                int h;
                if (int.TryParse(txtWidth.Text, out w) &&
                    int.TryParse(txtHeight.Text, out h))
                {
                    map.SetDisplaySize(w, h);
                }

                double scale;
                if (double.TryParse(textBox4.Text, out scale))
                {
                    map.SetViewScale(scale);
                }
                int mode;
                if (int.TryParse(textBox6.Text, out mode))
                {
                }

                MgColor             selColor   = new MgColor("0x0000FFFF");
                MgdRenderingOptions renderOpts = new MgdRenderingOptions(textBox5.Text, mode, selColor);

                sw.Start();
                MgByteReader response = renSvc.RenderDynamicOverlay(map, selection, renderOpts);
                sw.Stop();
                Trace.TraceInformation("RenderDynamicOverlay executed in {0}ms", sw.ElapsedMilliseconds);

                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#26
0
文件: Program.cs 项目: kanbang/Colt
        static void Main(string [] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            
            //Must call MgPlatform.Initialize() before we can work with anything from the MapGuide API
            try
            {
#if PROFILE
                using (new CallMeasure("MgdPlatform.Initialize"))
                {
                    MgdPlatform.Initialize("Platform.ini");
                }
#else
                MgdPlatform.Initialize("Platform.ini");
#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
                return;
            }

            AppLayout layout = null;

            var ser = new XmlSerializer(typeof(AppLayout));
            if (args.Length == 1)
            {
                using (var file = File.OpenRead(args[0]))
                {
                    layout = (AppLayout)ser.Deserialize(file);
                }
            }/*
            else
            {
                layout = AppLayout.CreateDefault("MapGuide Desktop App Layout Example", "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
                using (var file = File.OpenWrite("Sheboygan.AppLayout"))
                {
                    ser.Serialize(file, layout);
                }
            }*/

            var mdfId = new MgResourceIdentifier(layout.Map.MapDefinition);
            var provider = new MgDesktopMapViewerProvider(null);
            var resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            if (resSvc.ResourceExists(mdfId))
            {
#if PROFILE
                using (new CallMeasure("MgdMap constructor (cold start)"))
                {
                    var mapCold = new MgdMap(mdfId);
                }
                MgdMap map = null;
                using (new CallMeasure("MgdMap constructor (warm start)"))
                {
                    map = new MgdMap(mdfId);
                }
                using (new CallMeasure("MgMapViewerProvider.LoadMap"))
                {
                    provider.LoadMap(map);
                }
#else
                provider.LoadMap(new MgdMap(mdfId));
#endif
            }
            var frm = Shell.Instance;
            ((Shell)frm).Initialize(layout, provider);
            Application.Run((Shell)frm);
            MgdPlatform.Terminate();
        }
示例#27
0
 public override Mapping.RuntimeMap CreateMap(string runtimeMapResourceId, ObjectModels.MapDefinition.IMapDefinition mdf, double metersPerUnit, bool suppressErrors)
 {
     var mdfId = new MgResourceIdentifier(mdf.ResourceID);
     var implMap = new MgdMap(mdfId);
     var map = new LocalRuntimeMap(this, implMap, suppressErrors);
     map.ResourceID = runtimeMapResourceId;
     map.ResetDirtyState();
     return map;
 }
示例#28
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);
                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);

                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(resId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);
                MgdSelection selection = null;

                if (!string.IsNullOrEmpty(txtSelectLayer.Text) &&
                    !string.IsNullOrEmpty(txtSelectFilter.Text))
                {
                    selection = new MgdSelection(map);

                    var layers = map.GetLayers();
                    if (layers.IndexOf(txtSelectLayer.Text) >= 0)
                    {
                        var layer = layers.GetItem(txtSelectLayer.Text);

                        var query = new MgFeatureQueryOptions();
                        query.SetFilter(txtSelectFilter.Text);

                        var reader = layer.SelectFeatures(query);

                        selection.AddFeatures(layer, reader, 0);

                        Trace.TraceInformation("{0} features in selection set", selection.GetSelectedFeaturesCount(layer, layer.GetFeatureClassName()));
                    }
                }

                double x;
                double y;
                if (double.TryParse(textBox2.Text, out x) &&
                    double.TryParse(textBox3.Text, out y))
                {
                    map.SetViewCenterXY(x, y);
                }

                int w;
                int h;
                if (int.TryParse(txtWidth.Text, out w) &&
                    int.TryParse(txtHeight.Text, out h))
                {
                    map.SetDisplaySize(w, h);
                }

                double scale;
                if (double.TryParse(textBox4.Text, out scale))
                {
                    map.SetViewScale(scale);
                }
                int mode;
                if (int.TryParse(textBox6.Text, out mode))
                { 
                    
                }

                MgColor selColor = new MgColor("0x0000FFFF");
                MgdRenderingOptions renderOpts = new MgdRenderingOptions(textBox5.Text, mode, selColor);

                sw.Start();
                MgByteReader response = renSvc.RenderDynamicOverlay(map, selection, renderOpts);
                sw.Stop();
                Trace.TraceInformation("RenderDynamicOverlay executed in {0}ms", sw.ElapsedMilliseconds);

                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#29
0
        private static MgdSelection Convert(MgdMap map, Mapping.MapSelection sel)
        {
            if (sel == null)
                return null;

            MgdSelection impl = new MgdSelection(map);
            var xml = sel.ToXml();
            if (!string.IsNullOrEmpty(xml))
                impl.FromXml(xml);
            return impl;
        }
示例#30
0
 protected override void OnNewMapLoaded(MgMapBase map)
 {
     _implMap = (MgdMap)map;
 }
示例#31
0
 public MgDesktopMapViewerProvider(MgdMap map) : base(map) 
 {
     _implMap = map;
 }
示例#32
0
 public override MgMapBase CreateMap(MgResourceIdentifier mapDefinitionId, string name)
 {
     var map = new MgdMap(mapDefinitionId, name);
     return map;
 }
示例#33
0
        private void btnMultiPlot_Click(object sender, EventArgs e)
        {
            MgdMap map = (MgdMap)_viewer.GetMap();
            MgMapViewerProvider provider = _viewer.GetProvider();
            MgdMappingService mappingSvc = (MgdMappingService)provider.CreateService(MgServiceType.MappingService);
            MgResourceIdentifier layoutId = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
            using (SaveFileDialog save = new SaveFileDialog())
            {
                save.Filter = "DWF Files (*.dwf)|*.dwf";
                if (save.ShowDialog() == DialogResult.OK)
                {
                    MgdDwfVersion dwfVer = new MgdDwfVersion("6.01", "1.2");

                    MgdLayout layout = new MgdLayout(layoutId, "City of Sheboygan", MgdPageUnitsType.Inches);
                    MgdPlotSpecification plotSpec = new MgdPlotSpecification(8.5f, 11.0f, MgdPageUnitsType.Inches, 0.5f, 0.5f, 0.5f, 0.5f);

                    MgdMapPlotCollection plotCollection = new MgdMapPlotCollection();

                    MgdMapPlot plot1 = new MgdMapPlot(map, plotSpec, layout);
                    plot1.SetCenterAndScale(map.GetViewCenter().GetCoordinate(), map.GetViewScale() * 2);
                    plotCollection.Add(plot1);

                    // Create a second map for the second sheet in the DWF. This second sheet uses the print layout
                    // to display a page title and legend.

                    MgdMap map2 = new MgdMap(map.GetMapDefinition(), "Sheet 2");
                    MgdMapPlot plot2 = new MgdMapPlot(map2, plotSpec, layout);
                    plot2.SetCenterAndScale(map.GetViewCenter().GetCoordinate(), map.GetViewScale());
                    plotCollection.Add(plot2);

                    MgByteReader result = mappingSvc.GenerateMultiPlot(plotCollection, dwfVer);
                    MgByteSink sink = new MgByteSink(result);
                    sink.ToFile(save.FileName);

                    MessageBox.Show("Saved to " + save.FileName);
                }
            }
        }
示例#34
0
 public void LoadMap(MgResourceIdentifier resId)
 {
     var map = new MgdMap(resId);
     viewer.Init(new MgDesktopMapViewerProvider(map));
     //viewer.RefreshMap();
 }
示例#35
0
 protected override void OnNewMapLoaded(MgMapBase map)
 {
     _implMap = (MgdMap)map;
 }
示例#36
0
        private void CheckRedlineLayer()
        {
            if (_redlineLayer == null)
            {
                MgdMap map = (MgdMap)_viewer.GetMap();
                MgMapViewerProvider provider = _viewer.GetProvider();
                MgdFeatureService   featSvc  = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);
                MgResourceService   resSvc   = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);

                string sessionId           = Guid.NewGuid().ToString();
                MgResourceIdentifier fsId  = new MgResourceIdentifier("Session:" + sessionId + "//Redline.FeatureSource");
                MgResourceIdentifier ldfId = new MgResourceIdentifier("Session:" + sessionId + "//Redline.LayerDefinition");
                string featureClass        = "Default:Redline";
                string geometry            = "Geometry";
                string xml = string.Format(Layers.Redline, fsId.ToString(), featureClass, geometry);

                //Construct our schema for the redline data store
                MgFeatureSchema   schema = new MgFeatureSchema("Default", "Redline schema");
                MgClassDefinition cls    = new MgClassDefinition();
                cls.Name = "Redline";

                MgDataPropertyDefinition id = new MgDataPropertyDefinition("ID");
                id.DataType = MgPropertyType.Int32;
                id.SetAutoGeneration(true);

                MgGeometricPropertyDefinition geom = new MgGeometricPropertyDefinition(geometry);
                geom.SpatialContextAssociation = "Default";
                geom.GeometryTypes             = MgFeatureGeometricType.Curve | MgFeatureGeometricType.Point | MgFeatureGeometricType.Solid | MgFeatureGeometricType.Surface;

                MgPropertyDefinitionCollection clsProps = cls.GetProperties();
                clsProps.Add(id);
                clsProps.Add(geom);

                MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                idProps.Add(id);

                cls.DefaultGeometryPropertyName = geometry;
                MgClassDefinitionCollection classes = schema.GetClasses();
                classes.Add(cls);

                //Create the feature source
                MgFileFeatureSourceParams create = new MgFileFeatureSourceParams("OSGeo.SDF", "Default", map.GetMapSRS(), schema);
                featSvc.CreateFeatureSource(fsId, create);

                //Then the layer definition
                byte[]       bytes  = Encoding.UTF8.GetBytes(xml);
                MgByteSource source = new MgByteSource(bytes, bytes.Length);
                resSvc.SetResource(ldfId, source.GetReader(), null);

                //Now create the runtime layer and add to map
                _redlineLayer                 = new MgdLayer(ldfId, resSvc);
                _redlineLayer.LegendLabel     = "Redlining";
                _redlineLayer.Name            = "Redline";
                _redlineLayer.Visible         = true;
                _redlineLayer.Selectable      = true;
                _redlineLayer.DisplayInLegend = true;

                MgLayerCollection layers = map.GetLayers();
                layers.Insert(0, _redlineLayer);
            }
        }
示例#37
0
 void OnDisposed(object sender, EventArgs e)
 {
     if (_map != null)
     {
         _map.Dispose();
         _map = null;
     }
 }