Exemplo n.º 1
0
        public MarkupManager(NameValueCollection incomingArgs)
        {
            try
            {
                /*if (IsDebugAssembly(this.GetType().Assembly))
                        System.Diagnostics.Debugger.Launch();*/
            this.args = incomingArgs;
            this.site = new MgSiteConnection();

            this.site.Open(new MgUserInformation(GetParameter(this.args, "SESSION")));
            if (!string.IsNullOrEmpty(GetParameter(this.args, "DIR")))
                libraryPath = GetParameter(this.args, "DIR");

            else
            {
                MgResourceService resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService);

                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);
                //Debug

            //    libraryPath = Path.Combine(String.Format("Library://{0}", path), "Markup/");
             //   libraryPath = "Library://" + path + "Markup/";
              //  Response.Write(libraryPath);
            }
            }
            catch (System.Exception ex)
            {
                throw ex;
             //   Response.Write("\n MarkupManager manager" + ex.InnerException);

            }
        }
Exemplo n.º 2
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ����ͼ���Ϊͼ���ļ�
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public bool GenerateMapImage()
    {
        // ��ȡ��Դ�������Ⱦ�������
        MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgRenderingService renderingService = (MgRenderingService)siteConnection.CreateService(MgServiceType.RenderingService);
        //  �򿪵�ͼ
        MgMap map = new MgMap();
        map.Open(resourceService, "Sheboygan");

        //  ����ѡ��
        MgSelection selection = new MgSelection(map);
        selection.Open(resourceService, "Sheboygan");
        // ָ����Χ
        MgEnvelope extent = map.GetMapExtent();
        double x = 0.5*extent.GetLowerLeftCoordinate().GetX();
        double y = 0.5*extent.GetLowerLeftCoordinate().GetY() ;

        MgColor color = new MgColor("FFFFBF20");
        // ���ɲ�����ͼ���ļ�
        MgByteReader byteReader = renderingService.RenderMap(map, selection, extent, 450, 613, color, "PNG");
        MgByteSink byteSink = new MgByteSink(byteReader);
        string filePath = "C:\\Temp\\Map.PNG";
        byteSink.ToFile(filePath);
        return true;
    }
        private MgByteReader Plot(MapGuideViewerInputModel input, bool useLayout, double? scale)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap map = new MgMap(conn);
            map.Open(input.MapName);

            MgPoint center = map.ViewCenter;
            MgCoordinate coord = center.Coordinate;

            MgMappingService mappingService = (MgMappingService)conn.CreateService(MgServiceType.MappingService);

            MgDwfVersion dwfVersion = new MgDwfVersion("6.01", "1.2");
            MgPlotSpecification plotSpec = new MgPlotSpecification(8.5f, 11f, MgPageUnitsType.Inches, 0f, 0f, 0f, 0f);
            plotSpec.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);

            MgLayout layout = null;
            if (useLayout)
            {
                MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
                layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
            }

            if (!scale.HasValue)
            {
                return mappingService.GeneratePlot(map, plotSpec, layout, dwfVersion);
            }
            else
            {
                MgCoordinate mapCenter = map.GetViewCenter().GetCoordinate();
                return mappingService.GeneratePlot(map, mapCenter, scale.Value, plotSpec, layout, dwfVersion);
            }
        }
Exemplo n.º 4
0
        private MgByteReader Plot(MapGuideViewerInputModel input, bool useLayout, double?scale)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgPoint      center = map.ViewCenter;
            MgCoordinate coord  = center.Coordinate;

            MgMappingService mappingService = (MgMappingService)conn.CreateService(MgServiceType.MappingService);

            MgDwfVersion        dwfVersion = new MgDwfVersion("6.01", "1.2");
            MgPlotSpecification plotSpec   = new MgPlotSpecification(8.5f, 11f, MgPageUnitsType.Inches, 0f, 0f, 0f, 0f);

            plotSpec.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);

            MgLayout layout = null;

            if (useLayout)
            {
                MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
                layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
            }

            if (!scale.HasValue)
            {
                return(mappingService.GeneratePlot(map, plotSpec, layout, dwfVersion));
            }
            else
            {
                MgCoordinate mapCenter = map.GetViewCenter().GetCoordinate();
                return(mappingService.GeneratePlot(map, mapCenter, scale.Value, plotSpec, layout, dwfVersion));
            }
        }
Exemplo n.º 5
0
    public bool ClearSpatialFilter()
    {
        bool result = true;
        MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);

        MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource");

        MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;
        MgFeatureService featureService = siteConnection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
        MgMap map = new MgMap();
        map.Open(resourceService, Request["MAPNAME"]);

        MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

        MgLayer layer = null;
        MgLayerCollection layers = map.GetLayers();
        if (layers.Contains("_QuerySpatialFilter"))
        {
            layer = (MgLayer)layers.GetItem("_QuerySpatialFilter");
            updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0"));
            featureService.UpdateFeatures(sdfResId, updateCommands, false);
            layers.Remove(layer);
            map.Save(resourceService);
        }

        return result;
    }
Exemplo n.º 6
0
        public void AddBuffer()
        {
            MgMap map = new MgMap();
            map.Open(_resourceService, GetParameter(this.args, "MAPNAME"));

            MgSelection selection = new MgSelection(map);
            selection.Open(_resourceService, map.Name);

            MgReadOnlyLayerCollection layers = selection.GetLayers();
            if (layers != null && layers.Count == 1)
            {
                MgFeatureQueryOptions opt = new MgFeatureQueryOptions();
                opt.SetFilter(selection.GenerateFilter(layers[0], layers[0].FeatureClassName));
                MgFeatureReader featureReader = _featureService.SelectFeatures(new MgResourceIdentifier(layers[0].FeatureSourceId), layers[0].FeatureClassName, opt);
                MgAgfReaderWriter agfRW = new MgAgfReaderWriter();

                MgGeometryCollection inputGeometries = new MgGeometryCollection();

                MgClassDefinition classDef = _featureService.GetClassDefinition(
                    new MgResourceIdentifier(layers[0].FeatureSourceId),
                    layers[0].FeatureClassName.Split(':')[0],
                    layers[0].FeatureClassName.Split(':')[1]);

                while (featureReader.ReadNext())
                {
                    MgByteReader byteReader = featureReader.GetGeometry(classDef.DefaultGeometryPropertyName);
                    MgGeometry geom = agfRW.Read(byteReader);
                    inputGeometries.Add(geom);
                }

                if (inputGeometries.Count > 0)
                {
                    MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory();

                    MgCoordinateSystem mapSrs = coordSysFactory.Create(map.MapSRS);
                    double distance = mapSrs.ConvertMetersToCoordinateSystemUnits(7.0);
                    MgCoordinateSystemMeasure measure = mapSrs.GetMeasure();

                    MgGeometryFactory geomFactory = new MgGeometryFactory();
                    MgGeometry buffer = geomFactory.CreateMultiGeometry(inputGeometries).Buffer(distance, measure);

                    if (buffer != null)
                    {
                        MgByteReader byteReader = agfRW.Write(buffer);

                        MgGeometryFactory geometryFactory = new MgGeometryFactory();
                        MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();

                        MgPropertyCollection propertyValues = CreatePropertyCollection(byteReader);

                        this.InsertMarkupFeature(propertyValues);
                    }
                }
            }
        }
Exemplo n.º 7
0
        // GET: Search/Results
        public ActionResult Results(SearchInputModel 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];
            MgFeatureQueryOptions query = new MgFeatureQueryOptions();

            //Don't fret about the input here. This is not a SQL injection attack vector. This filter string is
            //not SQL, it's a FDO filter. A 'DROP TABLE' or any other destructive SQL will fail on
            //query execution when this filter is parsed to a FDO filter.
            switch (input.By)
            {
            case "OWNER":
                query.SetFilter("RNAME LIKE '%" + input.Query.Replace("'", "\'") + "%'");
                break;

            case "ADDRESS":
                query.SetFilter("RPROPAD LIKE '%" + input.Query.Replace("'", "\'") + "%'");
                break;

            case "BBOX":
                double[] parts = input.Query.Split(',').Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
                if (parts.Length != 4)
                {
                    throw new Exception("Invalid BBOX parameter");
                }
                MgWktReaderWriter wktRw      = new MgWktReaderWriter();
                MgGeometry        filterGeom = wktRw.Read(MakeWktPolygon(parts[0], parts[1], parts[2], parts[3]));
                query.SetSpatialFilter(layer.FeatureGeometryName, filterGeom, MgFeatureSpatialOperations.Intersects);
                break;

            default:
                throw new Exception("Unknown query type: " + input.By);
            }

            SearchResultViewModel vm = new SearchResultViewModel();

            vm.Session = input.Session;
            vm.MapName = input.MapName;
            vm.LoadResults(layer, query);
            return(View(vm));
        }
        // GET: Search/Results
        public ActionResult Results(SearchInputModel 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.GetItem(lidx);
            MgFeatureQueryOptions query = new MgFeatureQueryOptions();
            //Don't fret about the input here. This is not a SQL injection attack vector. This filter string is
            //not SQL, it's a FDO filter. A 'DROP TABLE' or any other destructive SQL will fail on
            //query execution when this filter is parsed to a FDO filter.
            switch (input.By)
            {
                case "OWNER":
                    query.SetFilter("RNAME LIKE '%" + input.Query.Replace("'", "\'") + "%'");
                    break;
                case "ADDRESS":
                    query.SetFilter("RPROPAD LIKE '%" + input.Query.Replace("'", "\'") + "%'");
                    break;
                case "BBOX":
                    double[] parts = input.Query.Split(',').Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
                    if (parts.Length != 4)
                    {
                        throw new Exception("Invalid BBOX parameter");
                    }
                    MgWktReaderWriter wktRw = new MgWktReaderWriter();
                    MgGeometry filterGeom = wktRw.Read(MakeWktPolygon(parts[0], parts[1], parts[2], parts[3]));
                    query.SetSpatialFilter(layer.FeatureGeometryName, filterGeom, MgFeatureSpatialOperations.Intersects);
                    break;
                default:
                    throw new Exception("Unknown query type: " + input.By);
            }

            SearchResultViewModel vm = new SearchResultViewModel();
            vm.Session = input.Session;
            vm.MapName = input.MapName;
            vm.LoadResults(layer, query);
            return View(vm);
        }
Exemplo n.º 9
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));
        }
        // GET: DwfPlot
        public ActionResult Index(MapGuideViewerInputModel input)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap map = new MgMap(conn);
            map.Open(input.MapName);

            MgPoint center = map.ViewCenter;
            MgCoordinate coord = center.Coordinate;

            DwfPlotViewModel vm = new DwfPlotViewModel()
            {
                MapName = input.MapName,
                Session = input.Session,
                Scale = map.GetViewScale(),
                X = coord.X,
                Y = coord.Y
            };

            return View(vm);
        }
Exemplo n.º 11
0
 //---------------------------------------------------------------------------------------
 //
 //        ���ܣ�����ѯ���ת��ΪXML��ʽ���ַ�
 //
 //         ���ߣ�
 //
 //         ���ڣ� 2007.5.23
 //        
 //         �޸���ʷ����
 //        
 //---------------------------------------------------------------------------------------
 public void CreateSelectionXML(String queryString)
 {
     //������Դ��Ҫ�ط���
     MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
     MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
     //��ȡҪ��ѯ��Ҫ��������ڵIJ�
     MgMap map = new MgMap();
     map.Open(resService, "Sheboygan");
     MgLayer layer = map.GetLayers().GetItem("Parcels");
     //ִ��Ҫ�ز�ѯ
     MgResourceIdentifier resId = new MgResourceIdentifier(layer.GetFeatureSourceId());
     MgFeatureQueryOptions queryOption = new MgFeatureQueryOptions();
     queryOption.SetFilter(queryString);
     MgFeatureReader featureReader = featureService.SelectFeatures(resId, "Parcels", queryOption);
       //����ѡ��
     MgSelection selection = new MgSelection(map);
     selection.AddFeatures(layer, featureReader, 0);
     //����ѡ�񼯣���ת��ΪXML
     OutputSelectionInHTML(selection, featureService);
     selectionXML = selection.ToXml();
 }
Exemplo n.º 12
0
        // GET: DwfPlot
        public ActionResult Index(MapGuideViewerInputModel input)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgPoint      center = map.ViewCenter;
            MgCoordinate coord  = center.Coordinate;

            DwfPlotViewModel vm = new DwfPlotViewModel()
            {
                MapName = input.MapName,
                Session = input.Session,
                Scale   = map.GetViewScale(),
                X       = coord.X,
                Y       = coord.Y
            };

            return(View(vm));
        }
Exemplo n.º 13
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) + "]})";
 }
        public IActionResult 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.GetItem(lidx);
            MgClassDefinition clsDef = layer.GetClassDefinition();
            MgPropertyDefinitionCollection props = clsDef.GetProperties();
            MgPropertyDefinition idProp = props.GetItem(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();
                selection.Save(resSvc);
            }
            finally
            {
                reader.Close();
            }

            return Content(result, MgMimeType.Xml);
        }
Exemplo n.º 15
0
    public static string TransformGK2Wgs(double x, double y, string ss, string mpN)
    {
        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(',', '.');
    }
Exemplo n.º 16
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) + "]})");
    }
Exemplo n.º 17
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(',', '.'));
    }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
0
        public override Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format, bool keepSelection)
        {
            MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;

            GetByteReaderMethod fetch = () =>
            {
                MgMap mmap = new MgMap();
                mmap.Open(res, map.Name);
                MgSelection sel = new MgSelection(mmap);
                if (selection != null)
                    sel.FromXml(selection.ToXml());

                return rnd.RenderDynamicOverlay(mmap, sel, format, keepSelection);
            };
            LogMethodCall("MgRenderingService::RenderDynamicOverlay", true, "MgMap", "MgSelection", format, keepSelection.ToString());
            return new MgReadOnlyStream(fetch);
        }
Exemplo n.º 20
0
        public Hashtable GetOpenMarkup()
        {
            Hashtable openMarkup = new Hashtable();

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

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

            MgLayerGroupCollection layerGroups = map.GetLayerGroups();
            if (layerGroups.Contains("_Markup"))
            {
                MgLayerCollection layers = map.GetLayers();

                for (int i = 0; i < layers.GetCount(); i++)
                {
                    MgLayer layer = (MgLayer)layers.GetItem(i);
                    if ((layer.GetGroup() != null) && (layer.GetGroup().GetName().Equals("_Markup")))
                    {
                        openMarkup[libraryPath + layer.GetLegendLabel() + ".LayerDefinition"] = layer.GetLegendLabel();
                    }
                }
            }
            return openMarkup;
        }
Exemplo n.º 21
0
        public bool DeleteMarkup()
        {
            bool result = false;

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

            MgResourceIdentifier markupLayerResId = new MgResourceIdentifier(GetParameter(args, "MARKUPLAYER"));
            MgResourceIdentifier markupSdfResId = new MgResourceIdentifier(libraryPath + markupLayerResId.GetName() + ".FeatureSource");

            //Check related entries in maintenance
            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);
            path = Path.Combine(String.Format("Library://{0}", path), "Maintenance/Data/Maintenance.FeatureSource");

            MgResourceIdentifier maintenanceResId = new MgResourceIdentifier(path);

            MgLayer layer = new MgLayer(markupLayerResId, resourceService);
            if (!map.GetLayers().Contains(layer))
            {
                if (resourceService.ResourceExists(maintenanceResId))
                {
                    MgFeatureQueryOptions opt = new MgFeatureQueryOptions();
                    opt.SetFilter(String.Format("FeatureSource='{0}'", markupSdfResId.ToString()));

                    MgFeatureReader reader = featureService.SelectFeatures(maintenanceResId, "Maintenance:Maintenance", opt);
                    if (!reader.ReadNext())
                    {
                        resourceService.DeleteResource(markupLayerResId);
                        resourceService.DeleteResource(markupSdfResId);
                        result = true;
                    }
                }
                else
                {*/
                    resourceService.DeleteResource(markupLayerResId);
                    resourceService.DeleteResource(markupSdfResId);
                    result = true;
            /*    }
            }*/

            //================================================

            return result;
        }
Exemplo n.º 22
0
        public void CreateMarkup(string mgSessionId,string  mgMap)
        {
            //Response.Write("CreateMarkup" );
            MgUserInformation userInfo = new MgUserInformation(mgSessionId);
            MgSiteConnection siteConnection = new MgSiteConnection();
            siteConnection.Open(userInfo);

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

            MgMap map = new MgMap();
            map.Open(resourceService, mgMap);
            //    map.Open(resourceService, GetParameter(args, "MAPNAME"));

            // Create the Markup Feature Source (SDF)

            MgResourceIdentifier markupSdfResId = new MgResourceIdentifier(libraryPath + GetParameter(this.args, "MARKUPNAME") + ".FeatureSource");

            MgFeatureSchema markupSchema = MarkupSchemaFactory.CreateMarkupSchema();
            MgCreateSdfParams sdfParams = new MgCreateSdfParams("XY-M", map.MapSRS, markupSchema);
            featureService.CreateFeatureSource(markupSdfResId, sdfParams);

            String url = "concat(&apos;" + GetParameter(this.args, "MARKUPURL") + "&apos;, concat(&apos;?key=&apos;, &quot;ID&quot;))";
            //Link to ProjectManager
              /*  if (GetParameter(this.args, "LINKTOPROJECTMANAGER").ToLower() == "on"
                && !String.IsNullOrEmpty(GetParameter(this.args, "ProjectCollectionName"))
                && GetParameter(this.args, "ProjectCollectionName") != "áçø îøùéîä")
            {
                string projectCollectionName = GetParameter(this.args, "ProjectCollectionName");
                if (projectCollectionName == "àçø...")
                {
                    projectCollectionName = GetParameter(this.args, "ProjectCollectionOtherName");
                }
                int projectId = 0;
                using (var conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ProjectManagerConnectionString"].ConnectionString))
                {
                    var cmd = conn.CreateCommand();
                    cmd.CommandText = "INSERT INTO ProjectCollections(LayoutId, FeatureId, ProjectCollectionName) VALUES(@LayoutId, @FeatureId, @ProjectCollectionName); SELECT @@IDENTITY AS [NEWID]";
                    cmd.CommandType = System.Data.CommandType.Text;

                    var layoutIdParam = new System.Data.SqlClient.SqlParameter("@LayoutId", System.Data.SqlDbType.NVarChar, 255);
                    layoutIdParam.Value = GetParameter(args, "LAYOUT");
                    cmd.Parameters.Add(layoutIdParam);

                    var featureIdParam = new System.Data.SqlClient.SqlParameter("@FeatureId", System.Data.SqlDbType.NVarChar, 255);
                    featureIdParam.Value = markupSdfResId.ToString();
                    cmd.Parameters.Add(featureIdParam);

                    var pcNameParam = new System.Data.SqlClient.SqlParameter("@ProjectCollectionName", System.Data.SqlDbType.NVarChar, 50);
                    pcNameParam.Value = projectCollectionName;
                    cmd.Parameters.Add(pcNameParam);

                    conn.Open();
                    //projectId = (int)cmd.ExecuteScalar();
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            projectId = Convert.ToInt32(reader[0]);
                        }
                    }
                }
                string host = HttpContext.Current.Request.Url.Host;
                url = String.Format("concat('http://{0}/MgExtensions/ProjectManager/default.aspx?ProjectId={1}&UID=', \"UID\")", host, projectId);
            }
            */
            // Create the Markup Layer Definition

            String hexFgTransparency = String.Format("{0:X2}", 255 * (100 - Int32.Parse(GetParameter(this.args, "FILLTRANSPARENCY"))) / 100); // Convert % to an alpha value
            String hexBgTransparency = GetParameter(this.args, "FILLBACKTRANS").Length > 0 ? "FF" : "00";							 // All or nothing
            String bold = GetParameter(this.args, "LABELBOLD").Length > 0 ? "true" : "false";
            String italic = GetParameter(this.args, "LABELITALIC").Length > 0 ? "true" : "false";
            String underline = GetParameter(this.args, "LABELUNDERLINE").Length > 0 ? "true" : "false";

            String markupLayerDefinition = File.ReadAllText(HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "Extensions\\markup\\templates\\markuplayerdefinition.xml");
            markupLayerDefinition = String.Format(markupLayerDefinition,
                markupSdfResId.ToString(),						                //<ResourceId> - Feature Source
                GetParameter(this.args, "LABELSIZEUNITS"),						//<Unit> - Mark Label
                GetParameter(this.args, "LABELFONTSIZE"),						//<SizeX> - Mark Label Size
                GetParameter(this.args, "LABELFONTSIZE"),						//<SizeY> - Mark Label Size
                "FF" + GetParameter(this.args, "LABELFORECOLOR"),				//<ForegroundColor> - Mark Label
                "FF" + GetParameter(this.args, "LABELBACKCOLOR"),				//<BackgroundColor> - Mark Label
                GetParameter(this.args, "LABELBACKSTYLE"),						//<BackgroundStyle> - Mark Label
                bold,												            //<Bold> - Mark Label
                italic,											                //<Bold> - Mark Label
                underline,											            //<Underlined> - Mark Label
                GetParameter(this.args, "MARKERSIZEUNITS"),						//<Unit> - Mark
                GetParameter(this.args, "MARKERSIZE"),							//<SizeX> - Mark
                GetParameter(this.args, "MARKERSIZE"),							//<SizeY> - Mark
                GetParameter(this.args, "MARKERTYPE"),							//<Shape> - Mark
                "FF" + GetParameter(this.args, "MARKERCOLOR"),					//<ForegroundColor> - Mark
                "FF" + GetParameter(this.args, "MARKERCOLOR"),					//<Color> - Mark
                GetParameter(this.args, "LABELSIZEUNITS"),						//<Unit> - Line Label
                GetParameter(this.args, "LABELFONTSIZE"),						//<SizeX> - Line Label Size
                GetParameter(this.args, "LABELFONTSIZE"),						//<SizeY> - Line Label Size
                "FF" + GetParameter(this.args, "LABELFORECOLOR"),				//<ForegroundColor> - Line Label
                "FF" + GetParameter(this.args, "LABELBACKCOLOR"),				//<BackgroundColor> - Line Label
                GetParameter(this.args, "LABELBACKSTYLE"),						//<BackgroundStyle> - Line Label
                bold,												            //<Bold> - Line Label
                italic,											                //<Bold> - Line Label
                underline,											            //<Underlined> - Line Label
                GetParameter(this.args, "LINEPATTERN"),							//<LineStyle> - Line
                GetParameter(this.args, "LINETHICKNESS"),						//<Thickness> - Line
                "FF" + GetParameter(this.args, "LINECOLOR"),					//<Color> - Line
                GetParameter(this.args, "LINESIZEUNITS"),						//<Unit> - Line
                GetParameter(this.args, "LABELSIZEUNITS"),						//<Unit> - Polygon Label
                GetParameter(this.args, "LABELFONTSIZE"),						//<SizeX> - Polygon Label Size
                GetParameter(this.args, "LABELFONTSIZE"),						//<SizeY> - Polygon Label Size
                "FF" + GetParameter(this.args, "LABELFORECOLOR"),				//<ForegroundColor> - Polygon Label
                "FF" + GetParameter(this.args, "LABELBACKCOLOR"),				//<BackgroundColor> - Polygon Label
                GetParameter(this.args, "LABELBACKSTYLE"),						//<BackgroundStyle> - Polygon Label
                bold,												            //<Bold> - Polygon Label
                italic,											                //<Bold> - Polygon Label
                underline,											            //<Underlined> - Polygon Label
                GetParameter(this.args, "FILLPATTERN"), 						//<FillPattern> - Fill
                hexFgTransparency + GetParameter(this.args, "FILLFORECOLOR"), 	//<ForegroundColor> - Fill
                hexBgTransparency + GetParameter(this.args, "FILLBACKCOLOR"), 	//<BackgroundColor> - Fill
                GetParameter(this.args, "BORDERPATTERN"),						//<LineStyle> - Fill
                GetParameter(this.args, "BORDERTHICKNESS"), 					//<Thickness> - Fill
                "FF" + GetParameter(this.args, "BORDERCOLOR"), 					//<Color> - Fill
                GetParameter(this.args, "BORDERSIZEUNITS"), 					//<Unit> - Fill
                HttpContext.Current.Server.HtmlEncode(url)); //<Url> - url link

            MgByteReader byteReader = new MgByteReader(markupLayerDefinition, "text/xml");
            resourceService.SetResource(new MgResourceIdentifier(libraryPath + GetParameter(this.args, "MARKUPNAME") + ".LayerDefinition"), byteReader, null);
        }
Exemplo n.º 23
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ������ʱ��
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public bool CreatePointsLayer(String rootPath, String sessionId)
    {
        // ��ȡҪ�ط������Դ����
        MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        //  �򿪵�ͼ
        MgMap map = new MgMap();
        map.Open(resourceService, "Sheboygan");
        // ---Ҫ�����Ҫ�ز������û��������������滹Ҫ���ܣ�--��ʼ
        // ���������ݵ�Ҫ��Դ
        CreateFeatureSource(sessionId);
        String featureSourceName = "Session:" + sessionId + "//Points.FeatureSource";
        MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName);

        MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
        MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
        MgGeometryFactory geometryFactory = new MgGeometryFactory();

        // �������¼
        MgPropertyCollection propertyCollection = MakePoint("Point A", -87.727, 43.748);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point B", -87.728, 43.730);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point C", -87.726, 43.750);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point D", -87.728, 43.750);
        batchPropertyCollection.Add(propertyCollection);

        // ��������Ҫ��������ӵ�Ҫ��Դ
        MgInsertFeatures Insertcmd = new MgInsertFeatures("Points", batchPropertyCollection);
        MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
        featureCommandCollection.Add(Insertcmd);
        featureService.UpdateFeatures(resourceIdentifier, featureCommandCollection, false);
        MgResourceIdentifier resourceID = null;
        //--------------Ҫ�����Ҫ�ز��� ����

        // �����㣬ͨ���㹤��LayerDefinitionFactory
        LayerDefinitionFactory factory = new LayerDefinitionFactory();
        factory.RootDirectoryPath = rootPath;

        //-------------------��������ʽ------------------------//
        // ������Ƿ���l
        string resourceSymbel = "Library://MgTutorial/Symbols/BasicSymbols.SymbolLibrary";
        string symbolName = "PushPin";
        string width = "24";  // unit = points
        string height = "24"; // unit = points
        string color = "FFFF0000";
        string markSymbol = factory.CreateMarkSymbol(resourceSymbel, symbolName, width, height, color);

        // �����ı�
        string text = "ID";
        string fontHeight = "12";
        string foregroundColor = "FF000000";
        string textSymbol = factory.CreateTextSymbol(text, fontHeight, foregroundColor);

        // ���������
        string legendLabel = "trees";
        string filter = "";
        string pointRule = factory.CreatePointRule(legendLabel, filter, textSymbol, markSymbol);

        // ��������ʽ
        string pointTypeStyle = factory.CreatePointTypeStyle(pointRule);

        // �������ŷ�Χ
        string minScale = "0";
        string maxScale = "1000000000000";
        string pointScaleRange = factory.CreateScaleRange(minScale, maxScale, pointTypeStyle);

        // �����㶨��
        string featureName = "PointSchema:Points";
        string geometry = "GEOM";
        string layerDefinition = factory.CreateLayerDefinition(featureSourceName, featureName, geometry, pointScaleRange);

        MgByteSource byteSource = new MgByteSource(Encoding.UTF8.GetBytes(layerDefinition), layerDefinition.Length);
        MgByteReader byteReader = byteSource.GetReader();

        resourceID = new MgResourceIdentifier("Session:" + sessionId + "//Points.LayerDefinition");
        resourceService.SetResource(resourceID, byteReader, null);
        //��������IJ㶨�����ݣ������ã�
        MgByteSink byteSink = new MgByteSink(resourceService.GetResourceContent(resourceID));
        string filePath = "C:\\Temp\\LayerDefinition.xml";
        byteSink.ToFile(filePath);

        // �����㲢��ӵ�����͵�ͼ��
        MgLayer newLayer = CreateLayerResource(resourceID, resourceService, "Points", "��ʱ��", map);

        AddLayerToGroup(newLayer, "Analysis", "����", map);

        MgLayerCollection layerCollection = map.GetLayers();
        if (layerCollection.Contains("Points"))
        {
            MgLayer pointsLayer = layerCollection.GetItem("Points");
            pointsLayer.SetVisible(true);
        }
        // �����ͼ
        map.Save(resourceService);

        return true;
    }
Exemplo n.º 24
0
        public String GetSelectionXML()
        {
            MgMap map = new MgMap();
            map.Open(_resourceService, GetParameter(this.args, "MAPNAME"));
            MgLayerBase markupLayer = map.GetLayers().GetItem("_" + this.GetMarkupName());

            MgSelection selection = new MgSelection(map);
            selection.AddFeatureIdInt32(markupLayer, markupLayer.FeatureClassName, Int32.Parse(GetParameter(this.args, "MARKUPFEATURE")));

            return selection.ToXml();
        }
Exemplo n.º 25
0
        string GetLegendInfo()
        {
            MgSiteConnection conn = new MgSiteConnection();
            conn.Open(new MgUserInformation(sessionId));

            MgResourceService resourceService = conn.CreateService(MgServiceType.ResourceService) as MgResourceService;

            MgMap map = new MgMap();
            map.Open(resourceService, mapName);

            List<LayerLegendInfo> infos = new List<LayerLegendInfo>();

            foreach (MgLayer layer in map.GetLayers())
            {
                if (layer.DisplayInLegend && layer.IsVisible() && !String.IsNullOrEmpty(layer.Name) && layer.LegendLabel != "MapOverview")
                {
                    LayerLegendInfo layerInfo = GetLayerContent(resourceService, layer, Convert.ToDouble(scale));
                    if (layerInfo != null)
                        infos.Add(layerInfo);
                }
            }

            System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
             new System.Web.Script.Serialization.JavaScriptSerializer();
            string sJSON = oSerializer.Serialize(infos);
            return sJSON;
            //return string.Empty;
        }
Exemplo n.º 26
0
        public override System.IO.Stream RenderRuntimeMap(RuntimeMap rtmap, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format, bool clip)
        {
            var resourceId = rtmap.ResourceID;
            MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
            MgGeometryFactory gf = new MgGeometryFactory();

            string mapname = new ResourceIdentifier(resourceId).Path;

            //TODO: The render is missing the clip param for the extent override method

            GetByteReaderMethod fetch = () =>
            {
                MgMap map = new MgMap();
                map.Open(res, mapname);
                MgSelection sel = new MgSelection(map);
                //The color accepted by MgColor has alpha as the last value, but the returned has alpha first
                MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor()));
                MgEnvelope env = new MgEnvelope(gf.CreateCoordinateXY(x1, y1), gf.CreateCoordinateXY(x2, y2));

                return rnd.RenderMap(map, sel, env, width, height, color, format);
            };
            LogMethodCall("MgRenderingService::RenderMap", true, "MgMap", "MgSelection", "MgEnvelope", width.ToString(), height.ToString(), "MgColor", format);
            return new MgReadOnlyStream(fetch);
        }
Exemplo n.º 27
0
        public override System.IO.Stream RenderRuntimeMap(RuntimeMap rtmap, double x, double y, double scale, int width, int height, int dpi, string format, bool clip)
        {
            var resourceId = rtmap.ResourceID;
            MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
            MgGeometryFactory gf = new MgGeometryFactory();

            string mapname = new ResourceIdentifier(resourceId).Path;

            GetByteReaderMethod fetch = () =>
            {
                MgMap map = new MgMap();
                map.Open(res, mapname);
                MgSelection sel = new MgSelection(map);
                //The color accepted by MgColor has alpha as the last value, but the returned has alpha first
                MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor()));
                MgCoordinate coord = gf.CreateCoordinateXY(x, y);
                return rnd.RenderMap(map, sel, coord, scale, width, height, color, format, true);
            };
            LogMethodCall("MgRenderingService::RenderMap", true, "MgMap", "MgSelection", "MgPoint("+ x + "," + y + ")", scale.ToString(), width.ToString(), height.ToString(), "MgColor", format, true.ToString());
            return new MgReadOnlyStream(fetch);
        }
Exemplo n.º 28
0
        public Stream RenderMapLegend(RuntimeMap map, int width, int height, System.Drawing.Color backgroundColor, string format)
        {
            MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;

            GetByteReaderMethod fetch = () =>
            {
                MgMap mmap = new MgMap();
                mmap.Open(res, map.Name);
                MgSelection sel = new MgSelection(mmap);
                MgColor color = new MgColor(backgroundColor);
                return rnd.RenderMapLegend(mmap, width, height, color, format);
            };
            LogMethodCall("MgRenderingService::RenderMapLegend", true, "MgMap", width.ToString(CultureInfo.InvariantCulture), height.ToString(CultureInfo.InvariantCulture), "#" + ColorTranslator.ToHtml(backgroundColor), format);
            return new MgReadOnlyStream(fetch);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ����ͼ���ΪDWF�ļ�
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public bool PlotMap()
    {
        // ��ȡ��Դ����͵�ͼ�������
        MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgMappingService mappingService = (MgMappingService)siteConnection.CreateService(MgServiceType.MappingService);
        //  �򿪵�ͼ
        MgMap map = new MgMap();
        map.Open(resourceService, "Sheboygan");
        // ����DWF��������Ϣ
        MgDwfVersion dwfVer = new MgDwfVersion("6.01", "1.2");
        MgPlotSpecification plotSpec = new MgPlotSpecification(8.5f, 11.0f, MgPageUnitsType.Inches, 0f, 0f, 0f, 0f);
        plotSpec.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);

         // ���DWF�ļ�
        MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://MgTutorial/Layouts/SheboyganMap.PrintLayout");
        MgLayout layout = new MgLayout(layoutRes, " DWF�ļ�����ʾ��", MgPageUnitsType.Inches);
        MgByteReader byteReader = mappingService.GeneratePlot(map, plotSpec, layout, dwfVer);
         //�����ļ�
        MgByteSink byteSink = new MgByteSink(byteReader);
        string filePath = "C:\\Temp\\Map.DWF";
        byteSink.ToFile(filePath);

        return true;
    }
Exemplo n.º 31
0
        public void OpenMarkup()
        {
            MgResourceService resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService);

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

            // Create the Layer Groups

            MgLayerGroup markupGroup = null;
            MgLayerGroupCollection layerGroups = map.GetLayerGroups();
            if (layerGroups.Contains("_Markup"))
            {
                markupGroup = layerGroups.GetItem("_Markup");
            }
            else
            {
                markupGroup = new MgLayerGroup("_Markup");
                markupGroup.SetVisible(true);
                markupGroup.SetLegendLabel("Markup");
                markupGroup.SetDisplayInLegend(false);
                layerGroups.Add(markupGroup);
            }

            // Add the Markup Layer

            MgResourceIdentifier markupLayerResId = new MgResourceIdentifier(GetParameter(this.args, "MARKUPLAYER"));
            MgLayer markupLayer = new MgLayer(markupLayerResId, resourceService);
            markupLayer.SetName("_" + markupLayerResId.GetName());
            markupLayer.SetLegendLabel(markupLayerResId.GetName());
            markupLayer.SetDisplayInLegend(false);
            markupLayer.SetSelectable(true);
            markupLayer.SetGroup(markupGroup);
            map.GetLayers().Insert(0, markupLayer);

            map.Save(resourceService);
        }
Exemplo n.º 32
0
        public void CloseMarkup()
        {
            MgResourceService resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService);

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

            // Add the Markup Layer

            MgResourceIdentifier markupLayerResId = new MgResourceIdentifier(GetParameter(this.args, "OPENMARKUP"));
            int index = map.GetLayers().IndexOf("_" + markupLayerResId.GetName());
            map.GetLayers().RemoveAt(index);

            map.Save(resourceService);
        }
Exemplo n.º 33
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());
     }
 }
Exemplo n.º 34
0
    public bool ShowSpatialFilter()
    {
        bool result = true;
        MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);

        MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource");

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

        MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

        MgMap map = new MgMap();
        map.Open(resourceService, Request["MAPNAME"]);

        MgLayer layer = null;
        MgLayerCollection layers = map.GetLayers();
        if (layers.Contains("_QuerySpatialFilter"))
        {
            layer = (MgLayer)layers.GetItem("_QuerySpatialFilter");
            //updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0"));
        }
        else
        {
            // Create the Feature Source (SDF)

            MgFeatureSchema sdfSchema = this.CreateFilterSchema();
            MgCreateSdfParams sdfParams = new MgCreateSdfParams("MAPCS", map.GetMapSRS(), sdfSchema);
            featureService.CreateFeatureSource(sdfResId, sdfParams);

            // Create the Layer

            MgResourceIdentifier layerResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.LayerDefinition");
            String layerDefinition = File.ReadAllText(GetQueryXmlTemplatePath());
            layerDefinition = layerDefinition.Replace("%s", sdfResId.ToString());

            MgByteReader reader = new MgByteReader(layerDefinition, "text/xml");
            resourceService.SetResource(layerResId, reader, null);

            layer = new MgLayer(layerResId, resourceService);

            layer.SetName("_QuerySpatialFilter");
            layer.SetLegendLabel("תחום זמני");
            layer.SetDisplayInLegend(true);
            layer.SetSelectable(true);
            layer.ForceRefresh();
            layer.NeedsRefresh();

            layers.Insert(0, layer);
        }

        // Make the layer visible

        layer.SetVisible(true);
        map.Save(resourceService);

        // Add the geometry to the filter feature source
        MgPolygon polygon = this.CreatePolygonFromGeomText(Request["GEOMTEXT"].ToString());
        MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();
        MgByteReader byteReader = agfWriter.Write(polygon);

        MgPropertyCollection propertyValues = new MgPropertyCollection();
        propertyValues.Add(new MgGeometryProperty("Geometry", byteReader));
        try
        {
            updateCommands.Add(new MgInsertFeatures("Filter", propertyValues));

            featureService.UpdateFeatures(sdfResId, updateCommands, false);
        }
        catch { }

        return result;
    }
Exemplo n.º 35
0
        public override string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions)
        {
            string runtimeMapName = rtMap.Name;
            MgRenderingService rs = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
            MgMap map = new MgMap();
            string mapname = runtimeMapName.IndexOf(":") > 0 ? new ResourceIdentifier(runtimeMapName).Path : runtimeMapName;
            map.Open(res, mapname);

            MgWktReaderWriter r = new MgWktReaderWriter();
            MgStringCollection layerNames = null;
            string featureFilter = "";
            int layerAttributeFilter = 0;
            int op = MgFeatureSpatialOperations.Intersects;
            if (selectionVariant == "TOUCHES")
                op = MgFeatureSpatialOperations.Touches;
            else if (selectionVariant == "INTERSECTS")
                op = MgFeatureSpatialOperations.Intersects;
            else if (selectionVariant == "WITHIN")
                op = MgFeatureSpatialOperations.Within;
            else if (selectionVariant == "ENVELOPEINTERSECTS")
                op = MgFeatureSpatialOperations.EnvelopeIntersects;
            else
                throw new ArgumentException("Unknown or unsupported selection variant: " + selectionVariant);

            if (extraOptions != null)
            {
                if (!string.IsNullOrEmpty(extraOptions.FeatureFilter))
                    featureFilter = extraOptions.FeatureFilter;
                if (extraOptions.LayerNames != null && extraOptions.LayerNames.Length > 0)
                {
                    layerNames = new MgStringCollection();
                    foreach (var name in extraOptions.LayerNames)
                        layerNames.Add(name);
                }
                layerAttributeFilter = (int)extraOptions.LayerAttributeFilter;
            }

            MgFeatureInformation info = rs.QueryFeatures(map, layerNames, r.Read(wkt), op, featureFilter, maxFeatures, layerAttributeFilter);

            string xml = "";
            GetByteReaderMethod fetch = () => { return info.ToXml(); };
            using (var sr = new StreamReader(new MgReadOnlyStream(fetch)))
            {
                xml = sr.ReadToEnd();
            }

            //We only want the FeatureSet element
            var doc = new System.Xml.XmlDocument();
            doc.LoadXml(xml);
            xml = doc.DocumentElement["FeatureSet"].OuterXml;

            MgSelection sel = new MgSelection(map, xml);
            sel.Save(res, mapname);

            LogMethodCall("QueryMapFeatures", true, runtimeMapName, wkt, persist, selectionVariant, extraOptions == null ? "null" : "QueryMapOptions");

            return xml;
        }
Exemplo n.º 36
0
        public override Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format, Color selectionColor, int behaviour)
        {
            MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;

            MgMap mmap = new MgMap();
            mmap.Open(res, map.Name);
            MgSelection sel = new MgSelection(mmap);
            if (selection != null)
                sel.FromXml(selection.ToXml());

            var rndOpts = new MgRenderingOptions(format, behaviour, new MgColor(selectionColor));
            GetByteReaderMethod fetch = () =>
            {
                return rnd.RenderDynamicOverlay(mmap, sel, rndOpts);
            };
            LogMethodCall("MgRenderingService::RenderDynamicOverlay", true, "MgMap", "MgSelection", "MgRenderingOptions");

            return new MgReadOnlyStream(fetch);
        }
Exemplo n.º 37
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string sessionId = GetRequestParameters(Request)["SESSION"];
            string mapName   = GetRequestParameters(Request)["MAPNAME"];
            string locale    = GetRequestParameters(Request)["LOCALE"];

            if (string.IsNullOrEmpty(sessionId))
            {
                Response.Clear();
                Response.End();
                return;
            }

            if (string.IsNullOrEmpty(mapName))
            {
                Response.Clear();
                Response.End();
                return;
            }

            MgResourceService resourceSrvc = GetMgResurceService(sessionId);
            MgFeatureService  featureSrvc  = GetMgFeatureService(sessionId);

            MgMap map = new MgMap();
            map.Open(resourceSrvc, mapName);

            string layernames = GetRequestParameters(Request)["LAYERNAMES"];
            string GEOMETRY   = GetRequestParameters(Request)["GEOMETRY"];
            string selVar     = GetRequestParameters(Request)["SELECTIONVARIANT"];
            string type       = GetRequestParameters(Request)["tp"];
            string inputSel   = GetRequestParameters(Request)["SELECTION"];

            bool hasInputGeom = false;
            if (!string.IsNullOrEmpty(GEOMETRY))
            {
                hasInputGeom = true;
            }

            //selection ima prednost pred podano geometrijo ...
            MgWktReaderWriter wktrw = new MgWktReaderWriter();
            if (!string.IsNullOrEmpty(inputSel))
            {
                MgGeometry inputGeom = MultiGeometryFromSelection(featureSrvc, map, inputSel);
                GEOMETRY = wktrw.Write(inputGeom);
            }

            MgAgfReaderWriter agfRW = new MgAgfReaderWriter();

            int nLayer = 0;
            // pobrišem in zgradim na novo samo tiste, ki imajo zadetke ...
            int           nSloj  = 0;
            string        filter = "";
            StringBuilder sbOut  = new StringBuilder();
            sbOut.Append("<table width=\"100%\" class=\"results\">");
            sbOut.Append("<tr><td class='header'></td><td class='header'>" + "Layer" + "</td><td class='header' align=\"center\">" + "Select" + "</td><td class='header' align=\"center\">" + "Report" + "</td></tr>");

            MgSelection selAll = new MgSelection(map);

            foreach (MgLayer layer in map.GetLayers())
            {
                if (type != "2")
                {
                    if (!layer.IsVisible())
                    {
                        goto nextlay;
                    }
                }

                if (layer.LegendLabel == "")
                {
                    goto nextlay;
                }

                try
                {
                    nLayer++;

                    filter = String.Format("{0} {1} GeomFromText('{2}')", layer.GetFeatureGeometryName(), selVar, GEOMETRY);

                    //preveriti še filter na Layerju. Ker ne gre drugače, je potrebno pogledati v XML
                    MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
                    MgByteReader         byteReader    = resourceSrvc.GetResourceContent(layerDefResId);

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

                    KALI.MGE.Objects.KALILayerDefinition.LayerDefinition ld = KALI.MGE.Objects.KALILayerDefinition.LayerDefinition.Parse(xmlLayerDef);

                    if (!string.IsNullOrEmpty(ld.VectorLayerDefinition.Filter))
                    {
                        filter += " AND (" + ld.VectorLayerDefinition.Filter + ")";
                    }

                    //query the features
                    MgFeatureQueryOptions opts = new MgFeatureQueryOptions();
                    opts.SetFilter(filter);
                    String featureClassName    = layer.GetFeatureClassName();
                    MgResourceIdentifier srcId = new MgResourceIdentifier(layer.GetFeatureSourceId());

                    MgFeatureReader features = featureSrvc.SelectFeatures(srcId, featureClassName, opts);

                    bool hasResult = features.ReadNext();

                    if (hasResult)
                    {
                        nSloj++;

                        int n = 0;

                        MgClassDefinition classDef = features.GetClassDefinition();

                        MgPropertyDefinitionCollection classDefProps = classDef.GetIdentityProperties();
                        ArrayList idPropNames = new ArrayList(classDefProps.GetCount());
                        for (int j = 0; j < classDefProps.GetCount(); j++)
                        {
                            MgPropertyDefinition idProp = classDefProps.GetItem(j);
                            idPropNames.Add(idProp.GetName());
                        }

                        MgSelection sel = new MgSelection(map);
                        do
                        {
                            // Generate XML to selection this feature
                            MgPropertyCollection idProps = new MgPropertyCollection();
                            foreach (string id in idPropNames)
                            {
                                int idPropType = features.GetPropertyType(id);
                                switch (idPropType)
                                {
                                case MgPropertyType.Int32:
                                    idProps.Add(new MgInt32Property(id, features.GetInt32(id)));
                                    break;

                                case MgPropertyType.String:
                                    idProps.Add(new MgStringProperty(id, features.GetString(id)));
                                    break;

                                case MgPropertyType.Int64:
                                    idProps.Add(new MgInt64Property(id, features.GetInt64(id)));
                                    break;

                                case MgPropertyType.Double:
                                    idProps.Add(new MgDoubleProperty(id, features.GetDouble(id)));
                                    break;

                                case MgPropertyType.Single:
                                    idProps.Add(new MgSingleProperty(id, features.GetSingle(id)));
                                    break;

                                case MgPropertyType.DateTime:
                                    idProps.Add(new MgDateTimeProperty(id, features.GetDateTime(id)));
                                    break;

                                default:
                                    //throw new SearchError(String.Format(MgLocalizer.GetString("SEARCHTYYPENOTSUP", locale), new Object[] { idPropType.ToString() }), searchError);
                                    break;
                                }
                            }

                            sel.AddFeatureIds(layer, featureClassName, idProps);
                            selAll.AddFeatureIds(layer, featureClassName, idProps);

                            n++;

                            //if (n > 1000) break;
                        } while (features.ReadNext());

                        features.Close();
                        features.Dispose();

                        string selText = EscapeForHtml(sel.ToXml());
                        string seljs   = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/></div>";
                        string seljs3  = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/></div>";

                        string linfo = "<b>" + layer.LegendLabel + "</b><br />" + n.ToString() + " " + "Hits";
                        sbOut.Append("<tr><td class=\"results\">" + nSloj.ToString() + "</td><td class=\"results\">" + linfo + "</td><td align=\"center\" class=\"results\">" + seljs + "</td><td align=\"center\" class=\"results\">" + seljs3 + "</td></tr>");
                    }
                }
                catch (Exception)
                {
                    continue;
                }

nextlay:
                continue;
            }

            sbOut.Append("</table>");

            string selAllText = EscapeForHtml(selAll.ToXml());
            string seljsAll   = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/>" + "Select All" + "</div>";
            string seljsAll3  = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/>" + "Report All" + "</div>";

            sbOut.Append(string.Format("<br /><table width=\"100%\" class=\"results\"><tr><td class=\"results\">{0}</td><td class=\"results\">{1}</td></tr></table>", seljsAll, seljsAll3));


            featureSrvc.Dispose();
            resourceSrvc.Dispose();

            if (nSloj > 0)
            {
                litPrebodi.Text = sbOut.ToString();
            }
            else
            {
                litPrebodiTitle.Visible = false;
                litPrebodi.Text         = "<b>" + "None layer lies below the selected item/area!" + "</b>";
            }

            MgGeometry inGeom = wktrw.Read(GEOMETRY);

            double rw = map.ViewScale / Math.Sqrt(inGeom.Area);

            //koordinate
            if (hasInputGeom & rw > 400)
            {
                string output = "";

                output = pointTransformAndWriteZ(GEOMETRY, map);

                litKoordinate.Text      = output;
                litKoordinateTitle.Text = "Coordinates of selected points:";
            }
        }
    }