// GET: Home
        public ActionResult Index()
        {
            MgUserInformation user = new MgUserInformation("Anonymous", "");
            MgSiteConnection  conn = new MgSiteConnection();

            conn.Open(user);

            MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);

            var vm = new HomeViewModel()
            {
                HasSampleResources = true,
                AjaxLayout         = AJAX_LAYOUT,
                FlexLayout         = FLEX_LAYOUT
            };

            MgResourceIdentifier mdfId   = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
            MgResourceIdentifier sample1 = new MgResourceIdentifier(vm.AjaxLayout);
            MgResourceIdentifier sample2 = new MgResourceIdentifier(vm.FlexLayout);

            vm.HasSampleResources = resSvc.ResourceExists(mdfId) &&
                                    resSvc.ResourceExists(sample1) &&
                                    resSvc.ResourceExists(sample2);

            return(View(vm));
        }
        public LocalGetResourceContents(LocalConnection conn)
        {
            this.Parent = conn;
            var fact = new MgdServiceFactory();

            _resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
        }
예제 #3
0
        public MgBufferControlImpl(IMapViewer viewer, string defaultLayerName, MeasurementUnit units)
        {
            InitializeComponent();
            this.Title = Strings.TitleBuffer;
            _viewer = viewer;
            _sessionId = Guid.NewGuid().ToString();
            var provider = viewer.GetProvider();
            _resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            _featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);

            cmbUnits.DataSource = Enum.GetValues(typeof(MeasurementUnit));
            cmbUnits.SelectedItem = units;
            cmbBorderPattern.DataSource = Enum.GetValues(typeof(StockPattern));
            cmbFillPattern.DataSource = Enum.GetValues(typeof(StockPattern));

            cmbBorderPattern.SelectedItem = StockPattern.Solid;
            cmbFillPattern.SelectedItem = StockPattern.Solid;

            pnlFillColor.BackColor = Color.Red;
            pnlBorderColor.BackColor = Color.Black;

            numBufferDistance.Value = 1;
            numFillTransparency.Value = 50;
            numLineThickness.Value = 1;

            txtBufferLayer.Text = defaultLayerName;

            _viewer.SelectionChanged += new EventHandler(OnViewerSelectedChanged);
            OnViewerSelectedChanged(this, EventArgs.Empty);
        }
예제 #4
0
        public MgBufferControlImpl(IMapViewer viewer, string defaultLayerName, MeasurementUnit units)
        {
            InitializeComponent();
            this.Title = Strings.TitleBuffer;
            _viewer    = viewer;
            _sessionId = Guid.NewGuid().ToString();
            var provider = viewer.GetProvider();

            _resSvc  = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            _featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);

            cmbUnits.DataSource         = Enum.GetValues(typeof(MeasurementUnit));
            cmbUnits.SelectedItem       = units;
            cmbBorderPattern.DataSource = Enum.GetValues(typeof(StockPattern));
            cmbFillPattern.DataSource   = Enum.GetValues(typeof(StockPattern));

            cmbBorderPattern.SelectedItem = StockPattern.Solid;
            cmbFillPattern.SelectedItem   = StockPattern.Solid;

            pnlFillColor.BackColor   = Color.Red;
            pnlBorderColor.BackColor = Color.Black;

            numBufferDistance.Value   = 1;
            numFillTransparency.Value = 50;
            numLineThickness.Value    = 1;

            txtBufferLayer.Text = defaultLayerName;

            _viewer.SelectionChanged += new EventHandler(OnViewerSelectedChanged);
            OnViewerSelectedChanged(this, EventArgs.Empty);
        }
예제 #5
0
        private static void LoadResource(MgResourceService resSvc, string resIdStr, string path)
        {
            MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
            MgByteSource         bs    = new MgByteSource(path);
            MgByteReader         br    = bs.GetReader();

            resSvc.SetResource(resId, br, null);
        }
예제 #6
0
        private static void LoadResourceData(MgResourceService resSvc, string resIdStr, string dataName, string dataType, string path)
        {
            MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
            MgByteSource         bs    = new MgByteSource(path);
            MgByteReader         br    = bs.GetReader();

            resSvc.SetResourceData(resId, dataName, dataType, br);
        }
예제 #7
0
 public MgLegendControlPresenter(ILegendView legend, MgMapViewerProvider provider)
 {
     _legend = legend;
     _provider = provider;
     _map = _provider.GetMap();
     InitInitialSelectabilityStates();
     _resSvc = (MgResourceService)_provider.CreateService(MgServiceType.ResourceService);
     _selectableIcon = Properties.Resources.lc_select;
     _unselectableIcon = Properties.Resources.lc_unselect;
 }
예제 #8
0
 void OnDisposed(object sender, EventArgs e)
 {
     _properties.Clear();
     _layers.Clear();
     if (_resSvc != null)
     {
         _resSvc.Dispose();
         _resSvc = null;
     }
 }
예제 #9
0
        public RedlineManager(IMapViewer viewer)
        {
            _map    = viewer.GetMap();
            _viewer = viewer;
            var provider = _viewer.GetProvider();

            _resSvc   = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            _featSvc  = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);
            _registry = new RedlineRegistry(SessionID, _resSvc, _featSvc);
        }
예제 #10
0
    private MgResourceService GetMgResurceService(string sessionId)
    {
        MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"] + "../webconfig.ini");
        MgUserInformation userInfo = new MgUserInformation(sessionId);
        MgSiteConnection  site     = new MgSiteConnection();

        site.Open(userInfo);

        MgResourceService resourceService = (MgResourceService)site.CreateService(MgServiceType.ResourceService);

        return(resourceService);
    }
예제 #11
0
        public MgdLayer CreateBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId)
        {
            // Load the layer definition template into
            // a XmlDocument object, find the "ResourceId" element, and
            // modify its content to reference the temporary
            // feature source.

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Layers.BufferLayerDefinition);
            XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];

            featureSourceNode.InnerText = bufferFeatureResId.ToString();

            // Get the updated layer definition from the XmlDocument
            // and save it to the session repository using the
            // ResourceService object.

            MgByteSource byteSource = null;

            using (MemoryStream ms = new MemoryStream())
            {
                doc.Save(ms);
                ms.Position = 0L;

                //Note we do this to ensure our XML content is free of any BOM characters
                byte[]   layerDefinition = ms.ToArray();
                Encoding utf8            = Encoding.UTF8;
                String   layerDefStr     = new String(utf8.GetChars(layerDefinition));
                layerDefinition = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);

                byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
                byteSource.SetMimeType(MgMimeType.Xml);
            }

            MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");

            resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

            // Create an MgLayer object based on the new layer definition
            // and return it to the caller.

            MgdLayer bufferLayer = new MgdLayer(tempLayerResId, resourceService);

            bufferLayer.SetName("Buffer");
            bufferLayer.SetLegendLabel("Buffer");
            bufferLayer.SetDisplayInLegend(true);
            bufferLayer.SetSelectable(false);

            return(bufferLayer);
        }
        public ActionResult LoadSampleData(SetupInputModel input)
        {
            MgUserInformation user = new MgUserInformation(input.Username, input.Password);
            MgSiteConnection  conn = new MgSiteConnection();

            conn.Open(user);

            MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);

            //Load the package file if specified
            if (input.Package != null && input.Package.ContentLength > 0)
            {
                var path = Path.GetTempFileName();
                try
                {
                    input.Package.SaveAs(path);
                    MgByteSource bs = new MgByteSource(path);
                    MgByteReader br = bs.GetReader();

                    resSvc.ApplyResourcePackage(br);
                }
                finally
                {
                    try
                    {
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                    catch { }
                }
            }

            //Load in our sample-specific resources
            MgResourceIdentifier sample1 = new MgResourceIdentifier(AJAX_LAYOUT);
            MgResourceIdentifier sample2 = new MgResourceIdentifier(FLEX_LAYOUT);

            MgByteSource bs1 = new MgByteSource(Server.MapPath("~/App_Data/SheboyganAspMvc.WebLayout.xml"));
            MgByteReader br1 = bs1.GetReader();

            resSvc.SetResource(sample1, br1, null);

            MgByteSource bs2 = new MgByteSource(Server.MapPath("~/App_Data/SheboyganAspMvc.ApplicationDefinition.xml"));
            MgByteReader br2 = bs2.GetReader();

            resSvc.SetResource(sample2, br2, null);

            return(RedirectToAction("Index"));
        }
예제 #13
0
    private static MgResourceService GetMgResurceService(string sessionId)
    {
        // Initialize web tier with the site configuration file.  The config
        // file should be in the same directory as this script.
        // MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"] + "../webconfig.ini");

        MgUserInformation userInfo = new MgUserInformation(sessionId);
        MgSiteConnection  site     = new MgSiteConnection();

        site.Open(userInfo);

        MgResourceService resourceService = (MgResourceService)site.CreateService(MgServiceType.ResourceService);

        return(resourceService);
    }
예제 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MgdServiceFactory fact   = new MgdServiceFactory();
                MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);

                MgByteReader response = resSvc.EnumerateUnmanagedData(txtPath.Text, chkRecursive.Checked, txtType.Text, txtFilter.Text);
                new XmlResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #15
0
        public MgdLayer CreateBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId)
        {
            // Load the layer definition template into
            // a XmlDocument object, find the "ResourceId" element, and
            // modify its content to reference the temporary
            // feature source.

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(Layers.BufferLayerDefinition);
            XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];
            featureSourceNode.InnerText = bufferFeatureResId.ToString();

            // Get the updated layer definition from the XmlDocument
            // and save it to the session repository using the
            // ResourceService object.

            MgByteSource byteSource = null;
            using (MemoryStream ms = new MemoryStream())
            {
                doc.Save(ms);
                ms.Position = 0L;

                //Note we do this to ensure our XML content is free of any BOM characters
                byte[] layerDefinition = ms.ToArray();
                Encoding utf8 = Encoding.UTF8;
                String layerDefStr = new String(utf8.GetChars(layerDefinition));
                layerDefinition = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);

                byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
                byteSource.SetMimeType(MgMimeType.Xml);
            }

            MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");

            resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

            // Create an MgLayer object based on the new layer definition
            // and return it to the caller.

            MgdLayer bufferLayer = new MgdLayer(tempLayerResId, resourceService);
            bufferLayer.SetName("Buffer");
            bufferLayer.SetLegendLabel("Buffer");
            bufferLayer.SetDisplayInLegend(true);
            bufferLayer.SetSelectable(false);

            return bufferLayer;
        }
예제 #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService    resSvc   = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier resId    = new MgResourceIdentifier(textBox1.Text);
                MgByteReader         response = resSvc.EnumerateResourceData(resId);

                new XmlResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService    resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier resId  = new MgResourceIdentifier(textBox1.Text);
                resSvc.DeleteResourceData(resId, textBox2.Text);

                MessageBox.Show("Success");
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #18
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);

                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);
                bool exists = resSvc.ResourceExists(resId);
                MessageBox.Show("Exists: " + exists);
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #19
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         var fact = new MgdServiceFactory();
         MgResourceService    resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
         MgResourceIdentifier resId  = new MgResourceIdentifier(txtResourceId.Text);
         string       type           = txtType.Text;
         int          depth          = Convert.ToInt32(txtDepth.Text);
         MgByteReader response       = resSvc.EnumerateResources(resId, depth, type);
         new XmlResponseDialog(response).ShowDialog();
     }
     catch (MgException ex)
     {
         MessageBox.Show(ex.ToString(), "Error from MapGuide");
     }
 }
예제 #20
0
        private string[] GetScaleRanges(MgLayerBase layer)
        {
            if (_resSvc == null)
            {
                var provider = _viewer.GetProvider();
                _resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            }

            MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
            MgByteReader         byteReader    = _resSvc.GetResourceContent(layerDefResId);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(byteReader.ToString());
            XmlNodeList nodeList = doc.GetElementsByTagName("VectorScaleRange"); //NOXLATE

            var scaleRanges = new List <string>();

            foreach (XmlElement node in nodeList)
            {
                String range = null;

                XmlNodeList minNodeList = node.GetElementsByTagName("MinScale"); //NOXLATE
                if (minNodeList.Count > 0)
                {
                    range = minNodeList.Item(0).FirstChild.Value;
                }
                else
                {
                    range = "0"; //NOXLATE
                }

                XmlNodeList maxNodeList = node.GetElementsByTagName("MaxScale"); //NOXLATE
                if (maxNodeList.Count > 0)
                {
                    range = range + " - " + maxNodeList.Item(0).FirstChild.Value; //NOXLATE
                }
                else
                {
                    range = range + " - " + Strings.Infinity; //NOXLATE
                }

                scaleRanges.Add(range);
            }
            return(scaleRanges.ToArray());
        }
예제 #21
0
        public override void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            try
            {
                MgResourceService resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);

                var root = "../../TestData/TileService/";
                LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
                LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
                LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");

                LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
                LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
                LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");

                LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
                LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
                LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");

                byte[]               tsd        = Properties.Resources.UT_XYZ;
                MgByteSource         sourceTSD  = new MgByteSource(tsd, tsd.Length);
                MgByteReader         contentTSD = sourceTSD.GetReader();
                MgResourceIdentifier resTSD     = new MgResourceIdentifier("Library://UnitTests/TileSets/Test.TileSetDefinition");

                resSvc.SetResource(resTSD, contentTSD, null);

                string mdf = Encoding.UTF8.GetString(Properties.Resources.UT_BaseMap);
                mdf = string.Format(mdf, resTSD.ToString());
                byte[]               mdfBytes   = Encoding.UTF8.GetBytes(mdf);
                MgByteSource         sourceMDF  = new MgByteSource(mdfBytes, mdfBytes.Length);
                MgByteReader         contentMDF = sourceMDF.GetReader();
                MgResourceIdentifier resMDF     = new MgResourceIdentifier("Library://UnitTests/Maps/LinkedTileSet.MapDefinition");

                resSvc.SetResource(resMDF, contentMDF, null);

                //This should throw because making a MgMap from a Map Defintion that links to a XYZ tile set
                //is not supported
                MgMapBase map = factory.CreateMap(resMDF);

                Assert.Fail("Expected MgUnsupportedTileProviderException to be thrown");
            }
            catch (MgUnsupportedTileProviderException)
            {
            }
        }
예제 #22
0
 public static bool DataSourceExists(MgResourceService resourceSrvc, MgResourceIdentifier dataSourceId)
 {
     try
     {
         string MGServerVersion = ConfigurationManager.AppSettings["MGServerVersion"];
         if (MGServerVersion == "2009")
         {
             MgByteReader cnt = resourceSrvc.GetResourceContent(dataSourceId);
             cnt = null;
             return true;
         }
         return resourceSrvc.ResourceExists(dataSourceId);
     }
     catch (MgResourceNotFoundException)
     {
         return false;
     }
 }
예제 #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService    resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier source = new MgResourceIdentifier(textBox1.Text);
                MgResourceIdentifier target = new MgResourceIdentifier(textBox2.Text);

                resSvc.CopyResource(source, target, checkBox1.Checked);

                MessageBox.Show("Success");
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #24
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);

                MgByteSource source = new MgByteSource(textBox1.Text);
                MgByteReader reader = source.GetReader();

                resSvc.ApplyResourcePackage(reader);

                MessageBox.Show("Success");
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #25
0
        public ActionResult SelectFeature(SelectInputModel input)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgLayerCollection layers = map.GetLayers();
            int lidx = layers.IndexOf("Parcels");

            if (lidx < 0)
            {
                throw new Exception("Layer not found on map: Parcels");
            }
            MgLayerBase       layer               = layers[lidx];
            MgClassDefinition clsDef              = layer.GetClassDefinition();
            MgPropertyDefinitionCollection props  = clsDef.GetProperties();
            MgPropertyDefinition           idProp = props[0];
            string idPropName           = idProp.Name;
            MgFeatureQueryOptions query = new MgFeatureQueryOptions();

            query.SetFilter(idPropName + " = " + input.id);

            MgFeatureReader   reader    = layer.SelectFeatures(query);
            MgSelection       selection = new MgSelection(map, "");
            MgResourceService resSvc    = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);
            string            result    = "";

            try
            {
                selection.Open(resSvc, input.MapName);
                selection.FromXml(""); //Clear existing
                selection.AddFeatures(layer, reader, 0);
                result = selection.ToXml();
            }
            finally
            {
                reader.Close();
            }

            return(Content(result, MgMimeType.Xml));
        }
예제 #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService    resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier resId  = new MgResourceIdentifier(textBox1.Text);
                string       dataName       = textBox2.Text;
                MgByteSource source         = new MgByteSource(textBox3.Text);
                MgByteReader reader         = source.GetReader();

                resSvc.SetResourceData(resId, dataName, "File", reader);

                MessageBox.Show("Success");
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #27
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService    resSvc   = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier resId    = new MgResourceIdentifier(textBox1.Text);
                MgByteReader         response = resSvc.GetResourceData(resId, textBox2.Text);

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    MgByteSink sink = new MgByteSink(response);
                    sink.ToFile(saveFileDialog1.FileName);
                    MessageBox.Show("Saved to: " + saveFileDialog1.FileName);
                }
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
예제 #28
0
    public static string GetVisSelLayers(string ss, string mpN)
    {
        MgMap             map          = new MgMap();
        MgResourceService resourceSrvc = GetMgResurceService(ss);

        map.Open(resourceSrvc, mpN);
        StringBuilder sb = new StringBuilder();

        sb.Append("({");
        sb.Append("'layers': [");
        foreach (var item in map.GetLayers())
        {
            if (item.IsVisible() && item.Selectable)
            {
                sb.Append("{'name':");
                sb.Append("'" + item.Name + "', ");
                sb.Append("'legend':");
                sb.Append("'" + item.LegendLabel + "'");
                sb.Append("},");
            }
        }
        return(sb.ToString().Substring(0, sb.ToString().Length - 1) + "]})");
    }
예제 #29
0
        static void Main(string[] args)
        {
            var webConfigPath = @"C:\Program Files\OSGeo\MapGuide\Web\www\webconfig.ini";

            MapGuideApi.MgInitializeWebTier(webConfigPath);

            MgUserInformation user = new MgUserInformation("Anonymous", "");
            MgSiteConnection  conn = new MgSiteConnection();

            conn.Open(user);
            MgSite site      = conn.GetSite();
            string sessionId = site.CreateSession();

            Console.WriteLine("Session ID: " + sessionId);
            MgResourceIdentifier wlId   = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganAsp.WebLayout");
            MgResourceService    resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);

            MgWebLayout layout = new MgWebLayout(resSvc, wlId);

            Console.WriteLine("Web Layout Title: " + layout.GetTitle());
            Console.WriteLine("Looks good! Press any key to continue");
            Console.Read();
        }
예제 #30
0
    public static string TransformGK2Wgs(double x, double y, string ss, string mpN) //Transform from Map to WGS 84 Coordtnate System
    {
        MgMap             map          = new MgMap();
        MgResourceService resourceSrvc = GetMgResurceService(ss);

        map.Open(resourceSrvc, mpN);

        //Create coordinate system factory
        MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory();
        string wktFrom = map.GetMapSRS();
        string wktTo   = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";

        MgCoordinateSystem coordinateSystemSource = fact.Create(wktFrom);
        MgCoordinateSystem coordinateSystemTarget = fact.Create(wktTo);

        MgGeometryFactory geomFact = new MgGeometryFactory();

        MgCoordinateSystemTransform coordTransform = fact.GetTransform(coordinateSystemSource, coordinateSystemTarget);

        MgCoordinate coord = coordTransform.Transform(x, y);

        return(coord.X.ToString().Replace(',', '.') + ";" + coord.Y.ToString().Replace(',', '.'));
    }
예제 #31
0
        public MarkupEditor(NameValueCollection incomingArgs)
        {
            this.args = incomingArgs;
            this.site = new MgSiteConnection();
            this.site.Open(new MgUserInformation(GetParameter(this.args, "SESSION")));

            _resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService);
            _featureService = (MgFeatureService)this.site.CreateService(MgServiceType.FeatureService);

            if (!string.IsNullOrEmpty(GetParameter(this.args, "DIR")))
                libraryPath = GetParameter(this.args, "DIR");
            else
            {

                MgMap map = new MgMap();
                map.Open(_resourceService, GetParameter(this.args, "MAPNAME"));
                string path = map.MapDefinition.Path;
                if (path.ToLower().EndsWith("maps")) path = path.Substring(0, path.Length - 4);
                /*libraryPath = Path.Combine(String.Format("Library://{0}", path), "Markup/");*/
                libraryPath = ConfigurationManager.AppSettings["MarkupLibraryPath"].ToString();

            }
            FeatureHasProjectIdField();
        }
예제 #32
0
        private void btnFindFeaturesInBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase           selection      = _viewer.GetSelection();
            MgReadOnlyLayerCollection selectedLayers = selection.GetLayers();

            if (selectedLayers == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }
            MgLayerBase parcels = null;

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                MgLayerBase layer = selectedLayers.GetItem(i);
                if (layer.Name == "Parcels")
                {
                    parcels = layer;
                    break;
                }
            }
            if (parcels == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }

            int bufferRingSize = 500; // measured in metres

            // Set up some objects for coordinate conversion

            MgMapBase           map             = _viewer.GetMap();
            MgLayerCollection   mapLayers       = map.GetLayers();
            MgMapViewerProvider provider        = _viewer.GetProvider();
            MgResourceService   resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);
            string           sessionId      = Guid.NewGuid().ToString();

            String                    mapWktSrs               = map.GetMapSRS();
            MgAgfReaderWriter         agfReaderWriter         = new MgAgfReaderWriter();
            MgWktReaderWriter         wktReaderWriter         = new MgWktReaderWriter();
            MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem        srs        = coordinateSystemFactory.Create(mapWktSrs);
            MgMeasure                 srsMeasure = srs.GetMeasure();

            // Check for a buffer layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the buffer.

            BufferHelper helper      = new BufferHelper();
            MgdLayer     bufferLayer = null;
            int          layerIndex  = map.GetLayers().IndexOf("Buffer");

            if (layerIndex < 0)
            {
                // The layer does not exist and must be created.

                MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
                helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
                bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
                map.GetLayers().Insert(0, bufferLayer);
            }
            else
            {
                bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                bufferLayer.DeleteFeatures("ID like '%'");
            }

            // Check for a parcel marker layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the parcel markers.

            MgdLayer parcelMarkerLayer = null;

            layerIndex = map.GetLayers().IndexOf("ParcelMarker");
            if (layerIndex < 0)
            {
                MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource");
                helper.CreateParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId);
                parcelMarkerLayer = helper.CreateParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId);
                map.GetLayers().Insert(0, parcelMarkerLayer);
            }
            else
            {
                parcelMarkerLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                parcelMarkerLayer.DeleteFeatures("ID like '%'");
            }

            // Check each layer in the selection.

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                // Only check selected features in the Parcels layer.

                MgdLayer layer = (MgdLayer)selectedLayers.GetItem(i);

                if (layer.GetName() == "Parcels")
                {
                    string geomName = layer.GetFeatureGeometryName();
                    System.Diagnostics.Trace.TraceInformation("Marking all parcels inside the buffer that are of type 'MFG'");

                    MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);


                    // Process each item in the MgFeatureReader. Get the
                    // geometries from all the selected features and
                    // merge them into a single geometry.

                    MgGeometryCollection inputGeometries = new MgGeometryCollection();
                    while (featureReader.ReadNext())
                    {
                        MgByteReader featureGeometryData = featureReader.GetGeometry(geomName);
                        MgGeometry   featureGeometry     = agfReaderWriter.Read(featureGeometryData);

                        inputGeometries.Add(featureGeometry);
                    }

                    MgGeometryFactory geometryFactory  = new MgGeometryFactory();
                    MgGeometry        mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);

                    // Create a buffer from the merged geometries

                    double     bufferDist     = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize);
                    MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                    // Create a filter to select parcels within the buffer. Combine
                    // a basic filter and a spatial filter to select all parcels
                    // within the buffer that are of type "MFG".

                    MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
                    queryOptions.SetFilter("RTYPE = 'MFG'");
                    queryOptions.SetSpatialFilter(geomName, bufferGeometry, MgFeatureSpatialOperations.Inside);

                    featureReader = layer.SelectFeatures(queryOptions);

                    // Get the features from the feature source,
                    // determine the centroid of each selected feature, and
                    // add a point to the ParcelMarker layer to mark the
                    // centroid.
                    // Collect all the points into an MgFeatureCommandCollection,
                    // so they can all be added in one operation.

                    MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection();
                    int inserted = 0;
                    while (featureReader.ReadNext())
                    {
                        MgByteReader byteReader = featureReader.GetGeometry(geomName);
                        MgGeometry   geometry   = agfReaderWriter.Read(byteReader);
                        MgPoint      point      = geometry.GetCentroid();

                        // Create an insert command for this parcel.
                        MgPropertyCollection properties = new MgPropertyCollection();
                        properties.Add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.Write(point)));
                        //parcelMarkerCommands.Add(new MgInsertFeatures("ParcelMarkerClass", properties));
                        MgFeatureReader fr = parcelMarkerLayer.InsertFeatures(properties);
                        fr.Close();
                        inserted++;
                    }
                    featureReader.Close();

                    if (inserted == 0)
                    {
                        MessageBox.Show("No parcels within the buffer area match.");
                        return;
                    }

                    // Create a feature in the buffer feature source to show the area covered by the buffer.

                    MgPropertyCollection props = new MgPropertyCollection();
                    props.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));
                    bufferLayer.InsertFeatures(props);

                    // Ensure that the buffer layer is visible and in the legend.

                    bufferLayer.SetVisible(true);
                    bufferLayer.ForceRefresh();
                    bufferLayer.SetDisplayInLegend(true);
                    parcelMarkerLayer.SetVisible(true);
                    parcelMarkerLayer.ForceRefresh();

                    MessageBox.Show("Done");
                    _viewer.RefreshMap();
                    IMapLegend legend = Shell.Instance.Legend;
                    if (legend != null)
                    {
                        legend.RefreshLegend();
                    }
                }
            }
        }
예제 #33
0
    // Create a temporary Layer to display geocode results.
    public MgLayer CreateLocationMarkerLayer(MgResourceService resourceService, MgResourceIdentifier locationMarkerDataResId, String sessionId)
    {
        // Load the AddressMarker layer definition template into
        // a ASPX XML object, find the "ResourceId" element, and
        // modify it's content to reference the temporary
        // feature source.

        XmlDocument doc = new XmlDocument();
        doc.PreserveWhitespace = true;
        string path =HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "Extensions/findlocation/templates/locationmarker.xml";
        doc.Load(path);
        XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId").Item(0);
        XmlNode resContent = doc.CreateTextNode(locationMarkerDataResId.ToString());
        featureSourceNode.AppendChild(resContent);

        // Get the updated layer definition from the DOM object
        // and save it to the session repository using the
        // ResourceService object.
        MemoryStream xmlStream = new MemoryStream();
        doc.Save(xmlStream);
        byte[] layerDefinition = xmlStream.ToArray();
        Encoding utf8 = Encoding.UTF8;
        String layerDefStr = new String(utf8.GetChars(layerDefinition));
        layerDefinition = new byte[layerDefStr.Length - 1];
        int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);
        MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
        byteSource.SetMimeType(MgMimeType.Xml);

        MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//LocationMarker.LayerDefinition");
        //MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Library://findLocation/" + sessionId + "/LocationMarker.LayerDefinition");
        resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

        // Create an MgLayer object based on the new layer definition
        // and return it to the caller.

        MgLayer locationLayer = new MgLayer(tempLayerResId, resourceService);
        locationLayer.SetName("LocationMarker");
        locationLayer.SetLegendLabel("LocationMarker");
        locationLayer.SetDisplayInLegend(false);
        locationLayer.SetSelectable(false);

        return locationLayer;
    }
예제 #34
0
 //----------------------------------------------------------------------------------------
 // �� �ܣ� �ж���Դ�Ƿ����
 //
 // �� �ߣ�
 //
 //
 // �� �ڣ�2007.05.#
 //
 //-----------------------------------------------------------------------------------------
 public bool IsDataSourceExists(MgResourceService resourceService, MgResourceIdentifier dataSourceId)
 {
     try
     {
         MgByteReader cnt = resourceService.GetResourceContent(dataSourceId);
         return true;
     }
     catch (MgResourceNotFoundException)
     {
         return false;
     }
 }
예제 #35
0
 //----------------------------------------------------------------------------------------
 // �� �ܣ� ��Ӳ㵽���飬������鲻���ڣ��򴴽�
 //
 // �� �ߣ�
 //
 //
 // �� �ڣ�2007.05.#
 //
 //-----------------------------------------------------------------------------------------
 public MgLayer CreateLayerResource(MgResourceIdentifier layerResourceID, MgResourceService resourceService, string layerName, string layerLegendLabel, MgMap map)
 {
     MgLayer newLayer = new MgLayer(layerResourceID, resourceService);
     //  �����㲢��Ӽҵ���ͼ��
     newLayer.SetName(layerName);
     newLayer.SetVisible(true);
     newLayer.SetLegendLabel(layerLegendLabel);
     newLayer.SetDisplayInLegend(true);
     MgLayerCollection layerCollection = map.GetLayers();
     if (!layerCollection.Contains(layerName))
     {
         // ��Insert��������㣬�´����IJ�λ�ڻ��ƴ�������
         layerCollection.Insert(0, newLayer);
     }
     newLayer.SetDisplayInLegend(true);
     return newLayer;
 }
예제 #36
0
 void OnDisposed(object sender, EventArgs e)
 {
     _properties.Clear();
     _layers.Clear();
     if (_resSvc != null)
     {
         _resSvc.Dispose();
         _resSvc = null;
     }
 }
예제 #37
0
        private string[] GetScaleRanges(MgLayerBase layer)
        {
            if (_resSvc == null)
            {
                var provider = _viewer.GetProvider();
                _resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            }

            MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
            MgByteReader byteReader = _resSvc.GetResourceContent(layerDefResId);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(byteReader.ToString());
            XmlNodeList nodeList = doc.GetElementsByTagName("VectorScaleRange"); //NOXLATE

            var scaleRanges = new List<string>();
            foreach (XmlElement node in nodeList)
            {
                String range = null;

                XmlNodeList minNodeList = node.GetElementsByTagName("MinScale"); //NOXLATE
                if (minNodeList.Count > 0)
                {
                    range = minNodeList.Item(0).FirstChild.Value;
                }
                else
                {
                    range = "0"; //NOXLATE
                }

                XmlNodeList maxNodeList = node.GetElementsByTagName("MaxScale"); //NOXLATE
                if (maxNodeList.Count > 0)
                {
                    range = range + " - " + maxNodeList.Item(0).FirstChild.Value; //NOXLATE
                }
                else
                {
                    range = range + " - " + Strings.Infinity; //NOXLATE
                }

                scaleRanges.Add(range);
            }
            return scaleRanges.ToArray();
        }
예제 #38
0
파일: MgMapViewer.cs 프로젝트: kanbang/Colt
        /// <summary>
        /// Initializes this viewer with the specified viewer provider, if the provider contains a map
        /// it will load that as well. Otherwise a call to <see cref="LoadMap"/> is required afterwards
        /// </summary>
        /// <param name="provider">The provider.</param>
        public void Init(MgMapViewerProvider provider)
        {
            if (_agfRW == null)
                _agfRW = new MgAgfReaderWriter();

            if (_wktRW == null)
                _wktRW = new MgWktReaderWriter();

            if (_geomFact == null)
                _geomFact = new MgGeometryFactory();

            _provider = provider;

            if (_resSvc != null) //Forward looking, dispose the existing one as it may be of a different implementation
            {
                _resSvc.Dispose();
                _resSvc = null;
            }
            _resSvc = (MgResourceService)_provider.CreateService(MgServiceType.ResourceService);

            _overlayRenderOpts = CreateMapRenderingOptions(0, 0, 255);
            _selectionRenderOpts = CreateSelectionRenderingOptions(0, 0, 255);

            if (_provider != null)
            {
                _provider.MapLoaded -= OnMapSetOnProvider;
                _provider = null;
            }

            _provider = provider;
            _provider.MapLoaded += OnMapSetOnProvider;
            var map = _provider.GetMap();
            if (map != null)
                OnMapSetOnProvider(this, EventArgs.Empty);
        }
예제 #39
0
        private string ApplyTheme(ThemeParams themeParams)
        {
            var provider = _viewer.GetProvider();
            var map      = _viewer.GetMap();
            var layers   = map.GetLayers();

            MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            MgFeatureService  featureService  = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);

            MgResourceIdentifier resId         = new MgResourceIdentifier(themeParams.layer.GetFeatureSourceId());
            MgResourceIdentifier layerDefResId = themeParams.layer.GetLayerDefinition();
            MgByteReader         byteReader    = resourceService.GetResourceContent(layerDefResId);

            // Load the Layer Definition and Navigate to the specified <VectorScaleRange>

            XmlDocument doc         = new XmlDocument();
            String      xmlLayerDef = byteReader.ToString();

            doc.LoadXml(xmlLayerDef);
            XmlNodeList nodeList = doc.GetElementsByTagName("VectorScaleRange"); //NOXLATE

            XmlElement vectorScaleRangecElement = (XmlElement)nodeList.Item(themeParams.scaleRangeIndex);
            XmlElement areaTypeStyle            = (XmlElement)vectorScaleRangecElement.GetElementsByTagName("AreaTypeStyle").Item(0); //NOXLATE

            // Remove any existing <AreaRule> elements.

            XmlNodeList areaRuleList = areaTypeStyle.GetElementsByTagName("AreaRule"); //NOXLATE
            int         count        = areaRuleList.Count;

            for (int i = 0; i < count; i++)
            {
                //The areaRuleList shrinks as we remove items, so always
                //remove the first item (don't use the index i)
                areaTypeStyle.RemoveChild(areaRuleList.Item(0));
            }

            // Now create the new <AreaRule> elements.

            String areaRuleTemplate = Properties.Resources.AreaRuleTemplate;
            MgFeatureAggregateOptions aggregateOptions = new MgFeatureAggregateOptions();

            String      value       = null;
            String      filterText  = null;
            String      areaRuleXML = null;
            XmlDocument areaDoc     = null;
            XmlNode     areaNode    = null;
            double      portion     = 0.0;
            double      increment   = (themeParams.numRules > 1) ? 1.0 / (themeParams.numRules - 1) : 1.0;

            if (THEME_INDIVIDUAL == themeParams.distro)
            {
                aggregateOptions.AddComputedProperty("THEME_VALUE", "UNIQUE(\"" + themeParams.property.Name + "\")"); //NOXLATE

                MgDataReader dataReader = featureService.SelectAggregate(resId, themeParams.layer.GetFeatureClassName(), aggregateOptions);
                while (dataReader.ReadNext())
                {
                    value = Util.GetFeaturePropertyValue(dataReader, "THEME_VALUE"); //NOXLATE

                    filterText = "&quot;" + themeParams.property.Name + "&quot; = "; //NOXLATE
                    if (themeParams.property.DataType == MgPropertyType.String)
                    {
                        filterText = filterText + "'" + value + "'"; //NOXLATE
                    }
                    else
                    {
                        filterText = filterText + value;
                    }

                    areaRuleXML = String.Format(areaRuleTemplate,
                                                themeParams.property.Name + ":" + value, //NOXLATE
                                                filterText,
                                                Util.InterpolateColor(portion, themeParams.fillFrom, themeParams.fillTo, themeParams.fillTrans),
                                                Util.InterpolateColor(portion, themeParams.borderFrom, themeParams.borderTo, 0));
                    areaDoc = new XmlDocument();
                    areaDoc.LoadXml(areaRuleXML);
                    areaNode = doc.ImportNode(areaDoc.DocumentElement, true);
                    areaTypeStyle.AppendChild(areaNode);

                    portion = portion + increment;
                }
                dataReader.Close();
            }
            else
            {
                var values = new List <string>();

                var expr = themeParams.distro + "(\"" + themeParams.property.Name + "\"," + themeParams.numRules + "," + themeParams.minValue + "," + themeParams.maxValue + ")"; //NOXLATE
                aggregateOptions.AddComputedProperty("THEME_VALUE", expr);                                                                                                        //NOXLATE
                MgDataReader dataReader = featureService.SelectAggregate(resId, themeParams.layer.GetFeatureClassName(), aggregateOptions);
                while (dataReader.ReadNext())
                {
                    value = Util.GetFeaturePropertyValue(dataReader, "THEME_VALUE"); //NOXLATE
                    values.Add(value);
                }
                dataReader.Close();

                for (int i = 0; i < values.Count - 1; i++)
                {
                    filterText = "&quot;" + themeParams.property.Name + "&quot; &gt;= " + values[i] + " AND &quot;" + themeParams.property.Name; //NOXLATE
                    if (i == values.Count - 1)
                    {
                        filterText = filterText + "&quot; &lt;= " + values[i + 1]; //NOXLATE
                    }
                    else
                    {
                        filterText = filterText + "&quot; &lt; " + values[i + 1]; //NOXLATE
                    }
                    areaRuleXML = String.Format(areaRuleTemplate,
                                                themeParams.property.Name + ":" + values[i] + " - " + values[i + 1], //NOXLATE
                                                filterText,
                                                Util.InterpolateColor(portion, themeParams.fillFrom, themeParams.fillTo, themeParams.fillTrans),
                                                Util.InterpolateColor(portion, themeParams.borderFrom, themeParams.borderTo, 0));

                    areaDoc = new XmlDocument();
                    areaDoc.LoadXml(areaRuleXML);
                    areaNode = doc.ImportNode(areaDoc.DocumentElement, true);
                    areaTypeStyle.AppendChild(areaNode);

                    portion = portion + increment;
                }
            }

            // Now save our new layer definition to the session and add it to the map.

            String xmlString   = doc.DocumentElement.OuterXml;
            String uniqueName  = Util.MakeUniqueLayerName(map, themeParams.layer.Name, themeParams.themeName);
            String legendLabel = themeParams.layer.GetLegendLabel();

            if (!string.IsNullOrEmpty(themeParams.themeName))
            {
                legendLabel = legendLabel + " (" + themeParams.themeName + ")";                                                           //NOXLATE
            }
            MgResourceIdentifier layerResId = new MgResourceIdentifier("Session:" + _sessionId + "//" + uniqueName + ".LayerDefinition"); //NOXLATE

            resourceService.SetResource(layerResId, new MgByteReader(xmlString, "text/xml"), null);                                       //NOXLATE

            var newLayer = provider.CreateLayer(layerResId);

            newLayer.SetName(uniqueName);
            newLayer.SetLegendLabel(legendLabel);
            newLayer.SetDisplayInLegend(themeParams.layer.GetDisplayInLegend());
            newLayer.SetVisible(true);
            newLayer.SetSelectable(themeParams.layer.GetSelectable());
            //HACK: This has to be true otherwise owner-drawn nodes will not display its children (the theme rules)
            provider.SetLayerExpandInLegend(newLayer, true);
            layers.Insert(layers.IndexOf(themeParams.layer), newLayer);

            //map.Save(resourceService);

            return(uniqueName);
        }
예제 #40
0
 public RedlineRegistry(string sessionID, MgResourceService resSvc, MgFeatureService featSvc)
 {
     _sessionID = sessionID;
     _resSvc = resSvc;
     _featSvc = featSvc;
 }
예제 #41
0
 public MgMapCreator(MgResourceService resSvc)
 {
     _resSvc = resSvc;
 }
예제 #42
0
 public LocalGetResourceContents(LocalConnection conn)
 {
     this.Parent = conn;
     var fact = new MgdServiceFactory();
     _resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
 }
예제 #43
0
        private void btnCreateBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase           selection = _viewer.GetSelection();
            MgReadOnlyLayerCollection layers    = selection.GetLayers();

            if (layers == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }
            MgLayerBase parcels = null;

            for (int i = 0; i < layers.GetCount(); i++)
            {
                MgLayerBase layer = layers.GetItem(i);
                if (layer.Name == "Parcels")
                {
                    parcels = layer;
                    break;
                }
            }
            if (parcels == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }

            int bufferRingSize  = 100; // measured in metres
            int bufferRingCount = 5;

            // Set up some objects for coordinate conversion
            MgMapBase           map             = _viewer.GetMap();
            MgLayerCollection   mapLayers       = map.GetLayers();
            MgMapViewerProvider provider        = _viewer.GetProvider();
            MgResourceService   resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);

            String                    mapWktSrs               = map.GetMapSRS();
            MgAgfReaderWriter         agfReaderWriter         = new MgAgfReaderWriter();
            MgWktReaderWriter         wktReaderWriter         = new MgWktReaderWriter();
            MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem        srs        = coordinateSystemFactory.Create(mapWktSrs);
            MgMeasure                 srsMeasure = srs.GetMeasure();
            string                    sessionId  = Guid.NewGuid().ToString();

            BufferHelper helper = new BufferHelper();

            // Check for a buffer layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the buffer.

            MgdLayer bufferLayer = null;
            int      layerIndex  = mapLayers.IndexOf("Buffer");

            if (layerIndex < 0)
            {
                // The layer does not exist and must be created.

                MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
                helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
                bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
                mapLayers.Insert(0, bufferLayer);
            }
            else
            {
                bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                bufferLayer.DeleteFeatures("ID like '%'");
            }

            // Get the selected features from the MgSelection object
            MgFeatureReader featureReader = selection.GetSelectedFeatures(parcels, parcels.GetFeatureClassName(), false);

            // Process each item in the MgFeatureReader. Get the
            // geometries from all the selected features and
            // merge them into a single geometry.

            MgGeometryCollection inputGeometries = new MgGeometryCollection();

            while (featureReader.ReadNext())
            {
                MgByteReader featureGeometryData = featureReader.GetGeometry(parcels.GetFeatureGeometryName());
                MgGeometry   featureGeometry     = agfReaderWriter.Read(featureGeometryData);

                inputGeometries.Add(featureGeometry);
            }

            MgGeometryFactory geometryFactory  = new MgGeometryFactory();
            MgGeometry        mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);

            // Add buffer features to the temporary feature source.
            // Create multiple concentric buffers to show area.
            // If the stylization for the layer draws the features
            // partially transparent, the concentric rings will be
            // progressively darker towards the center.
            // The stylization is set in the layer template file, which
            // is used in function CreateBufferLayer().

            for (int bufferRing = 0; bufferRing < bufferRingCount; bufferRing++)
            {
                double     bufferDist     = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize * (bufferRing + 1));
                MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                MgPropertyCollection properties = new MgPropertyCollection();
                properties.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));

                MgFeatureReader fr = bufferLayer.InsertFeatures(properties);
                fr.Close();
            }

            bufferLayer.SetVisible(true);
            bufferLayer.ForceRefresh();
            bufferLayer.SetDisplayInLegend(true);

            MessageBox.Show("Buffer created");
            _viewer.RefreshMap();
            IMapLegend legend = Shell.Instance.Legend;

            if (legend != null)
            {
                legend.RefreshLegend();
            }
        }
 protected ResourceServiceOperationExecutor(MgResourceService resSvc, string unitTestVm)
     : base(typeof(T).Name.ToUpper(), ApiTypes.Platform, unitTestVm)
 {
     _resourceService = resSvc;
 }
예제 #45
0
        public MgCoordinateSystemTransform GetTransform()
        {
            MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory();
            _resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService);

            MgMap map = new MgMap();
            map.Open(_resourceService, GetParameter(this.args, "MAPNAME"));

            MgCoordinateSystem source = coordSysFactory.Create(map.GetMapSRS());
            //MgCoordinateSystem target = coordSysFactory.Create(MarkupManager.LL84WKT);
            MgCoordinateSystem target = coordSysFactory.Create(map.GetMapSRS());

            return coordSysFactory.GetTransform(source, target);
        }
예제 #46
0
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����Ԥ�����XML������
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    private MgLayer createTempParcelLayer(MgResourceService resService, MgResourceIdentifier resId, string sessionId)
    {
        MgLayer tempParcelLayer = null;

        // ����XML�ĵ�
        XmlDocument doc = new XmlDocument();
        doc.PreserveWhitespace = false;
        doc.Load(@"C:\inetpub\wwwroot\MapguideTutorial\CH05-2\tempParcels.xml");
        // ��XML�ĵ��е�ResourceId���滻Ϊ�������ԴID���˴�ӦΪ�������ĻỰ�ִ��е���ʱ��ԴID
        XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId").Item(0);
        XmlNode resContent = doc.CreateTextNode(resId.ToString());
        featureSourceNode.AppendChild(resContent);
        // ����XML
        MemoryStream xmlStream = new MemoryStream();
        doc.Save(xmlStream);
        byte[] layerDef = xmlStream.ToArray();
        Encoding utf8 = Encoding.UTF8;
        string layerDefStr = new string(utf8.GetChars(layerDef));
        layerDef = new byte[layerDefStr.Length - 1];
        int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDef, 0);

        MgByteSource byteSource = new MgByteSource(layerDef, layerDef.Length);
        byteSource.SetMimeType(MgMimeType.Xml);
        // ������Դ
        MgResourceIdentifier tempParcelLayerId = new MgResourceIdentifier("Session:" + sessionId + "//TempParcel.LayerDefinition");
        resService.SetResource(tempParcelLayerId, byteSource.GetReader(), null);
        //������ʱ��
        tempParcelLayer = new MgLayer(tempParcelLayerId, resService);
        tempParcelLayer.SetName("TempParcels");
        tempParcelLayer.SetLegendLabel("New Parcels");
        tempParcelLayer.SetDisplayInLegend(true);
        tempParcelLayer.SetSelectable(false);

        return tempParcelLayer;
    }
예제 #47
0
 public LocalGetResourceContents(LocalNativeConnection conn)
 {
     this.Parent = conn;
     _resSvc = (MgResourceService)conn.Connection.CreateService(MgServiceType.ResourceService);
 }
예제 #48
0
        LayerLegendInfo GetLayerContent(MgResourceService resourceService, MgLayer layer, double scale)
        {
            bool insertInToList = false;

            string[] styleTypes = new[] { "PointTypeStyle", "LineTypeStyle", "AreaTypeStyle", "CompositeTypeStyle" };
            string[] ruleNames = new[] { "PointRule", "LineRule", "AreaRule", "CompositeRule" };

            LayerLegendInfo layerInfo = new LayerLegendInfo { Name = layer.Name, Label = layer.LegendLabel, Path = layer.LayerDefinition.ToString() };

            string xmlContent = resourceService.GetResourceContent(layer.LayerDefinition).ToString();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlContent);

            XmlNodeList scaleNodes = doc.GetElementsByTagName("VectorScaleRange");
            foreach (XmlElement scaleRange in scaleNodes)
            {
                double minScale = 0.0;
                double maxScale = 1000000000000.0;

                XmlNode minScaleNode = scaleRange.SelectSingleNode("MinScale");
                XmlNode maxScaleNode = scaleRange.SelectSingleNode("MaxScale");
                if (minScaleNode != null) minScale =Convert.ToDouble(minScaleNode.InnerText);
                if (maxScaleNode != null) maxScale = Convert.ToDouble(maxScaleNode.InnerText);
                if (scale > minScale && scale < maxScale)
                {

                    for (int stylesIndex = 0; stylesIndex < styleTypes.Length; stylesIndex++)
                    {
                        foreach (XmlElement element in (scaleRange).GetElementsByTagName(styleTypes[stylesIndex]))
                        {
                            int legendIndex = -1;
                            foreach (XmlElement rule in element.GetElementsByTagName(ruleNames[stylesIndex]))
                            {
                                string legendLabel = rule.SelectSingleNode("LegendLabel").InnerText;
                                if (string.IsNullOrEmpty(legendLabel)) continue;
                                LayerLegendInfo info = new LayerLegendInfo { Label = HttpUtility.HtmlAttributeEncode(legendLabel), Path = layerInfo.Path, GeomType = stylesIndex + 1, LegendIndex = ++legendIndex };
                                layerInfo.Children.Add(info);
                            }
                            insertInToList = true;
                        }
                    }
                    break;
                }
            }
            return insertInToList ? layerInfo : null;
            //return layerInfo;
        }
예제 #49
0
 private void BuildClientSideTree(System.Collections.ArrayList tree, Legend.TreeItem parent, string parentName, bool fulldata, string container, MgResourceService resSrvc, System.Collections.Hashtable layerMap)
 {
     int treeIndex = 0;
     for (int pass = 0; pass < 2; pass++)
     {
         for (int i = 0; i < tree.Count; i++)
         {
             Legend.TreeItem node = (Legend.TreeItem)tree[i];
             if (node.isGroup)
             {
                 if (pass == 1)
                 {
                     string groupName = "grp" + this.intermediateVar++;
                     string arrChildName;
                     if (node.children != null)
                     {
                         arrChildName = "c" + this.intermediateVar++;
                         this.output = this.output + "var " + arrChildName + " = new Array();\n";
                     }
                     else
                     {
                         arrChildName = "null";
                     }
                     MgLayerGroup rtLayerGroup = (MgLayerGroup)node.rtObject;
                     if (fulldata)
                     {
                         this.output += string.Format("var {0} = new GroupItem(\"{1}\", {2}, {3}, {4},{5}, \"{6}\", \"{7}\", {8});\n", new object[]
                     {
                         groupName,
                         this.StrEscape(rtLayerGroup.GetLegendLabel()),
                         rtLayerGroup.GetExpandInLegend() ? "true" : "false",
                         parentName,
                         rtLayerGroup.GetVisible() ? "true" : "false",
                         rtLayerGroup.GetDisplayInLegend() ? "true" : "false",
                         rtLayerGroup.GetObjectId(),
                         this.StrEscape(rtLayerGroup.GetName()),
                         (rtLayerGroup.GetLayerGroupType() == 2) ? "true" : "false"
                     });
                     }
                     else
                     {
                         this.output += string.Format("var {0} = new GroupSummary(\"{1}\", \"{2}\", {3}, {4});\n", new object[]
                     {
                         groupName,
                         this.StrEscape(rtLayerGroup.GetName()),
                         rtLayerGroup.GetObjectId(),
                         arrChildName,
                         parentName
                     });
                     }
                     this.output += string.Format("{0}[{1}] = {2};\n", container, treeIndex, groupName);
                     treeIndex++;
                     if (node.children != null)
                     {
                         this.BuildClientSideTree(node.children, node, groupName, fulldata, arrChildName, resSrvc, null);
                         this.output += string.Format("{0}.children = {1};\n", groupName, arrChildName);
                     }
                 }
             }
             else if (pass == 0)
             {
                 MgLayer rtLayer = (MgLayer)node.rtObject;
                 if (fulldata)
                 {
                     MgResourceIdentifier resId = rtLayer.GetLayerDefinition();
                     string layerData = node.layerData;
                     string layerName = "lyr" + this.intermediateVar++;
                     string objectId = rtLayer.GetObjectId();
                     this.output += string.Format("var {0} = new LayerItem(\"{1}\", \"{2}\", {3}, {4}, {5}, {6}, {7}, \"{8}\", \"{9}\", {10});\n", new object[]
                 {
                     layerName,
                     rtLayer.GetLegendLabel(),
                     this.StrEscape(rtLayer.GetName()),
                     rtLayer.GetExpandInLegend() ? "true" : "false",
                     parentName,
                     rtLayer.GetVisible() ? "true" : "false",
                     rtLayer.GetDisplayInLegend() ? "true" : "false",
                     rtLayer.GetSelectable() ? "true" : "false",
                     resId.ToString(),
                     objectId,
                     (rtLayer.GetLayerType() == 2) ? "true" : "false"
                 });
                     this.output += string.Format("{0}[{1}] = {2};\n", container, treeIndex, layerName);
                     treeIndex++;
                     if (layerMap == null || !layerMap.ContainsKey(objectId))
                     {
                         this.BuildLayerDefinitionData(layerData, layerName);
                     }
                 }
                 else
                 {
                     this.output += string.Format("{0}[{1}] = new LayerSummary(\"{2}\", \"{3}\", \"{4}\");\n", new object[]
                 {
                     container,
                     i,
                     rtLayer.GetName(),
                     rtLayer.GetObjectId(),
                     rtLayer.GetLayerDefinition().ToString()
                 });
                 }
             }
         }
     }
 }
예제 #50
0
 public MgWebLayoutCreator(MgResourceService resSvc)
 {
     _resSvc = resSvc;
 }
예제 #51
0
파일: MgMapViewer.cs 프로젝트: kanbang/Colt
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control"/> and its child controls and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                base.MouseUp -= OnMapMouseUp;
                base.MouseMove -= OnMapMouseMove;
                base.MouseDown -= OnMapMouseDown;
                base.MouseClick -= OnMapMouseClick;
                base.MouseDoubleClick -= OnMapMouseDoubleClick;
                base.MouseHover -= OnMapMouseHover;
                base.MouseEnter -= OnMouseEnter;
                base.MouseLeave -= OnMapMouseLeave;

                if (renderWorker != null)
                {
                    renderWorker.DoWork -= renderWorker_DoWork;
                    renderWorker.RunWorkerCompleted -= renderWorker_RunWorkerCompleted;
                }

                if (_csFact != null)
                {
                    _csFact.Dispose();
                    _csFact = null;
                }

                if (_resSvc != null)
                {
                    _resSvc.Dispose();
                    _resSvc = null;
                }

                if (_selection != null)
                {
                    _selection.Dispose();
                    _selection = null;
                }

                if (_mapCs != null)
                {
                    _mapCs.Dispose();
                    _mapCs = null;
                }

                if (_agfRW != null)
                {
                    _agfRW.Dispose();
                    _agfRW = null;
                }

                if (_wktRW != null)
                {
                    _wktRW.Dispose();
                    _wktRW = null;
                }

                if (_geomFact != null)
                {
                    _geomFact.Dispose();
                    _geomFact = null;
                }

                if (_mapMeasure != null)
                {
                    _mapMeasure.Dispose();
                    _mapMeasure = null;
                }
            }
            base.Dispose(disposing);
        }
예제 #52
0
 protected void Page_Load(object sender, System.EventArgs e)
 {
     try
     {
         if (this.Session["MapSession"] != null)
         {
             this.GetParameters();
             MgSiteConnection site = MGMapObject.GetMgSite(this.Session["MapSession"].ToString());
             if (site == null)
             {
                 MGMapObject.ShowError(this.Page, "עקב אי שימוש ממושך , יש לרענן את האתר , לחיצה על כפתור בעמוד הראשי");
             }
             this.resSrvc = (MgResourceService)site.CreateService(0);
             MgMap map = MGMapObject.GetMgMap(this.resSrvc, this.Session["mapName"].ToString());
             if (map == null)
             {
                 MGMapObject.ShowError(this.Page, "עקב אי שימוש ממושך , יש לרענן את האתר , לחיצה על כפתור בעמוד הראשי");
             }
             this.BuildLayerTree(map);
             if (this.summary)
             {
                 this.updateType = 0;
                 this.BuildClientSideTree(this.tree, null, "null", false, "layerData", this.resSrvc, null);
             }
             else
             {
                 System.Collections.Hashtable layerMap = null;
                 if (this.layerCount == 0)
                 {
                     this.updateType = 1;
                 }
                 else
                 {
                     this.updateType = 2;
                     layerMap = this.BuildLayerMap(map);
                 }
                 this.BuildClientSideTree(this.tree, null, "null", true, "layerData", this.resSrvc, layerMap);
             }
             if (this.Session["MyMapSession"].ToString() != "")
             {
                 site = MGMapObject.GetMgSite(this.Session["MyMapSession"].ToString());
                 this.resSrvc = (MgResourceService)site.CreateService(0);
                 map = new MgMap();
                 map.Open(this.resSrvc, this.Session["MyMapName"].ToString());
                 this.BuildLayerTree(map);
                 if (this.summary)
                 {
                     this.updateType = 0;
                     this.BuildClientSideTree(this.tree, null, "null", false, "layerData", this.resSrvc, null);
                 }
                 else
                 {
                     System.Collections.Hashtable layerMap = null;
                     if (this.layerCount == 0)
                     {
                         this.updateType = 1;
                     }
                     else
                     {
                         this.updateType = 2;
                         layerMap = this.BuildLayerMap(map);
                     }
                     this.BuildClientSideTree(this.tree, null, "null", true, "layerData", this.resSrvc, layerMap);
                 }
             }
         }
     }
     catch (MgException mge)
     {
         base.Response.Write(mge.Message);
         base.Response.Write("<br>");
         base.Response.Write(mge.GetDetails());
     }
 }