コード例 #1
0
        public void LoadConfiguration(GP.MetaData.GPMetaData serviceInfo, Uri taskEndPoint)
        {
            if (serviceInfo == null)
            {
                return;
            }

            TaskEndPoint = taskEndPoint;
            TaskName     = Title = serviceInfo.DisplayName;
            HelpUrl      = serviceInfo.HelpUrl;
            if (InputParameters == null)
            {
                InputParameters = new List <ParameterSupport.ParameterConfig>();
            }
            else
            {
                InputParameters.Clear();
            }

            if (OutputParameters == null)
            {
                OutputParameters = new List <ParameterSupport.ParameterConfig>();
            }
            else
            {
                OutputParameters.Clear();
            }

            if (LayerOrder == null)
            {
                LayerOrder = new ObservableCollection <string>();
            }
            else
            {
                LayerOrder.Clear();
            }

            Collection <LayerInformation> resultMapserviceLayerInfos = string.IsNullOrEmpty(serviceInfo.ResultMapServerName) || string.IsNullOrEmpty(serviceInfo.CurrentVersion) ? null : new Collection <LayerInformation>();

            #region Get parameter configs
            if (serviceInfo.Parameters != null)
            {
                int layerId = 0;
                foreach (ESRI.ArcGIS.Mapping.GP.MetaData.GPParameter param in serviceInfo.Parameters)
                {
                    ParameterConfig config = null;
                    if (param.DataType == "GPFeatureRecordSetLayer")
                    {
                        if (!string.IsNullOrEmpty(serviceInfo.ResultMapServerName) && param.Direction != "esriGPParameterDirectionInput")
                        {
                            if (!string.IsNullOrEmpty(serviceInfo.CurrentVersion)) // A resultmapservice can only be accessed at http://.../<resultMapservice>/MapServer/jobs/<jobId> when server version can be determined.
                            {
                                resultMapserviceLayerInfos.Add(ToLayerInfo(param, layerId++));
                            }
                            else
                            {
                                MapServiceLayerParameterConfig layerConfig = new MapServiceLayerParameterConfig
                                {
                                    Name                = param.Name,
                                    LayerName           = param.DisplayName,
                                    Type                = GPParameterType.MapServiceLayer,
                                    SupportsJobResource = false,
                                    Opacity             = 1,
                                };
                                OutputParameters.Add(layerConfig);
                                LayerOrder.Add(layerConfig.Name);
                            }
                        }
                        else
                        {
                            #region No result GP mapserver
                            GP.ParameterSupport.FeatureLayerParameterConfig layerConfig = new ParameterSupport.FeatureLayerParameterConfig()
                            {
                                ShownAtRunTime = true
                            };
                            layerConfig.Name     = param.Name;
                            layerConfig.Label    = layerConfig.DisplayName = string.IsNullOrEmpty(param.DisplayName) ? param.Name : param.DisplayName;
                            layerConfig.Mode     = ParameterSupport.FeatureLayerParameterConfig.InputMode.SketchLayer;
                            layerConfig.Type     = GPParameterType.FeatureLayer;
                            layerConfig.Required = param.ParameterType == "esriGPParameterTypeRequired";
                            ESRI.ArcGIS.Mapping.GP.MetaData.GPFeatureRecordSetLayer frs = param.DefaultValue as ESRI.ArcGIS.Mapping.GP.MetaData.GPFeatureRecordSetLayer;
                            if (frs != null)
                            {
                                if (frs.GeometryType == "esriGeometryPolyline")
                                {
                                    layerConfig.GeometryType = ESRI.ArcGIS.Mapping.Core.GeometryType.Polyline;
                                    layerConfig.HelpText     = Resources.Strings.DrawLine;
                                }
                                else if (frs.GeometryType == "esriGeometryPolygon")
                                {
                                    layerConfig.GeometryType = ESRI.ArcGIS.Mapping.Core.GeometryType.Polygon;
                                    layerConfig.HelpText     = Resources.Strings.DrawPolygon;
                                }
                                else if (frs.GeometryType == "esriGeometryPoint")
                                {
                                    layerConfig.GeometryType = ESRI.ArcGIS.Mapping.Core.GeometryType.Point;
                                    layerConfig.HelpText     = Resources.Strings.DrawPoint;
                                }
                                else if (frs.GeometryType == "esriGeometryMultipoint")
                                {
                                    layerConfig.GeometryType = ESRI.ArcGIS.Mapping.Core.GeometryType.MultiPoint;
                                    layerConfig.HelpText     = Resources.Strings.DrawPoint;
                                }
                                #region Layer with field info, geometry type and renderer
                                GraphicsLayer layer = new GraphicsLayer();
                                if (frs.Fields != null && frs.Fields.Length > 0)
                                {
                                    Collection <ESRI.ArcGIS.Mapping.Core.FieldInfo> fields = new Collection <ESRI.ArcGIS.Mapping.Core.FieldInfo>();

                                    List <string> doubleFields = new List <string>();
                                    List <string> singleFields = new List <string>();
                                    foreach (MetaData.Field field in frs.Fields)
                                    {
                                        #region Get Single and Double Fields
                                        string type = field.Type;
                                        if (type.StartsWith(GPConfiguration.esriFieldType, StringComparison.Ordinal))
                                        {
                                            type = type.Substring(GPConfiguration.esriFieldType.Length);
                                            ESRI.ArcGIS.Client.Field.FieldType fieldType =
                                                (ESRI.ArcGIS.Client.Field.FieldType)Enum.Parse(typeof(ESRI.ArcGIS.Client.Field.FieldType), type, true);

                                            if (fieldType == ESRI.ArcGIS.Client.Field.FieldType.Double)
                                            {
                                                doubleFields.Add(field.Name);
                                            }
                                            else if (fieldType == Client.Field.FieldType.Single)
                                            {
                                                singleFields.Add(field.Name);
                                            }
                                        }
                                        #endregion

                                        #region Get FieldInfos
                                        if (field.Type == "esriGeometry")
                                        {
                                            continue;
                                        }

                                        fields.Add(new ESRI.ArcGIS.Mapping.Core.FieldInfo()
                                        {
                                            DisplayName = field.Alias,
                                            FieldType   = mapFieldType(field.Type),
                                            Name        = field.Name,
                                            VisibleInAttributeDisplay = true,
                                            VisibleOnMapTip           = true,
                                        });
                                        #endregion
                                    }

                                    ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetFields(layer, fields);
                                    layerConfig.SingleFields = singleFields.ToArray();
                                    layerConfig.DoubleFields = doubleFields.ToArray();
                                }
                                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetGeometryType(layer, layerConfig.GeometryType);
                                layer.Renderer = FeatureLayerParameterConfig.GetSimpleRenderer(layerConfig.GeometryType);

                                // Disable pop-ups by default for input layers
                                if (param.Direction == "esriGPParameterDirectionInput")
                                {
                                    LayerProperties.SetIsPopupEnabled(layer, false);
                                }
                                layerConfig.Layer = layer;
                                #endregion
                            }
                            else
                            {
                                layerConfig.GeometryType = ESRI.ArcGIS.Mapping.Core.GeometryType.Unknown;
                                layerConfig.HelpText     = Resources.Strings.UnknownGeometryType;
                            }
                            layerConfig.LayerName = layerConfig.Label;
                            layerConfig.ToolTip   = layerConfig.HelpText;
                            layerConfig.Opacity   = 1;

                            config = layerConfig;
                            LayerOrder.Add(layerConfig.Name);
                            #endregion
                        }
                    }
                    else if (param.DataType == "GPRasterDataLayer" || param.DataType == "GPRasterData")
                    {
                        if (string.IsNullOrEmpty(serviceInfo.ResultMapServerName) || param.Direction == "esriGPParameterDirectionInput")
                        {
                            config = new RasterDataParameterConfig()
                            {
                                Name           = param.Name,
                                ShownAtRunTime = true,
                                FormatToolTip  = "e.g. tif, jpg",
                                Type           = param.DataType == "GPRasterDataLayer" ? GPParameterType.RasterDataLayer : GPParameterType.RasterData,
                                ToolTip        = param.DataType == "GPRasterDataLayer" ? Resources.Strings.EnterUrlForRasterDataLayer : Resources.Strings.EnterUrlForRasterData,
                                HelpText       = param.DataType == "GPRasterDataLayer" ? Resources.Strings.EnterUrlForRasterDataLayer : Resources.Strings.EnterUrlForRasterData,
                                Label          = param.DisplayName,
                                DisplayName    = param.DisplayName,
                                Required       = param.ParameterType == "esriGPParameterTypeRequired",
                                Input          = param.Direction == "esriGPParameterDirectionInput"
                            };
                        }
                        else if (string.IsNullOrEmpty(serviceInfo.CurrentVersion))
                        {
                            MapServiceLayerParameterConfig layerConfig = new MapServiceLayerParameterConfig
                            {
                                Name                = param.Name,
                                LayerName           = param.DisplayName,
                                Type                = GPParameterType.MapServiceLayer,
                                SupportsJobResource = false,
                                Opacity             = 1,
                            };
                            OutputParameters.Add(layerConfig);
                            LayerOrder.Add(layerConfig.Name);
                        }
                        else
                        {
                            resultMapserviceLayerInfos.Add(ToLayerInfo(param, layerId++));
                        }
                    }
                    else
                    {
                        #region other param types
                        if (param.DataType == "GPMultiValue:GPString")
                        {
                            config = new MultiValueStringConfig()
                            {
                                ShownAtRunTime = true
                            }
                        }
                        ;
                        else
                        {
                            config = new ParameterConfig()
                            {
                                ShownAtRunTime = true
                            }
                        };

                        config.Name     = param.Name;
                        config.Label    = config.DisplayName = param.DisplayName;
                        config.Required = param.ParameterType == "esriGPParameterTypeRequired";

                        string defaultString = param.DefaultValue == null ? null : param.DefaultValue.ToString();

                        switch (param.DataType)
                        {
                            #region
                        case "GPBoolean":
                            config.Type = GPParameterType.Boolean;
                            if (param.DefaultValue != null)
                            {
                                config.DefaultValue = new Client.Tasks.GPBoolean(param.Name, (bool)param.DefaultValue);
                            }
                            break;

                        case "GPDouble":
                            config.Type = GPParameterType.Double;
                            if (!string.IsNullOrEmpty(defaultString))
                            {
                                double val = 0;
                                if (double.TryParse(defaultString, System.Globalization.NumberStyles.Any, CultureHelper.GetCurrentCulture(), out val))
                                {
                                    config.DefaultValue = new Client.Tasks.GPDouble(param.Name, val);
                                }
                            }
                            break;

                        case "GPLong":
                            config.Type = GPParameterType.Long;
                            if (!string.IsNullOrEmpty(defaultString))
                            {
                                int val = 0;
                                if (int.TryParse(defaultString, out val))
                                {
                                    config.DefaultValue = new ESRI.ArcGIS.Client.Tasks.GPLong(param.Name, val);
                                }
                            }
                            break;

                        case "GPDate":
                            config.Type = GPParameterType.Date;
                            if (!string.IsNullOrEmpty(defaultString))
                            {
                                long ticks = 0;
                                if (long.TryParse(defaultString, out ticks))
                                {
                                    config.DefaultValue = new ESRI.ArcGIS.Client.Tasks.GPDate(param.Name, Epoch.AddMilliseconds(ticks));
                                }
                            }
                            break;

                        case "GPLinearUnit":
                            config.Type = GPParameterType.LinearUnit;
                            if (param.DefaultValue is ESRI.ArcGIS.Mapping.GP.MetaData.GPLinearUnit)
                            {
                                ESRI.ArcGIS.Mapping.GP.MetaData.GPLinearUnit value = (param.DefaultValue as ESRI.ArcGIS.Mapping.GP.MetaData.GPLinearUnit);
                                config.DefaultValue = new ESRI.ArcGIS.Client.Tasks.GPLinearUnit(param.Name,
                                                                                                (ESRI.ArcGIS.Client.Tasks.esriUnits)(Enum.Parse(typeof(ESRI.ArcGIS.Client.Tasks.esriUnits), value.Units, true)),
                                                                                                value.Distance);
                            }
                            break;

                        case "GPString":
                            config.Type         = GPParameterType.String;
                            config.DefaultValue = new ESRI.ArcGIS.Client.Tasks.GPString(param.Name, defaultString);
                            if (param.ChoiceList != null && param.ChoiceList.Length > 0)
                            {
                                config.ChoiceList = new List <Choice>(param.ChoiceList.Length);
                                for (int i = 0; i < param.ChoiceList.Length; i++)
                                {
                                    config.ChoiceList.Add(new Choice()
                                    {
                                        DisplayText = param.ChoiceList[i],
                                        Value       =
                                            new ESRI.ArcGIS.Client.Tasks.GPString(param.Name, param.ChoiceList[i])
                                    });
                                }
                            }
                            break;

                        case "GPMultiValue:GPString":
                            config.Type = GPParameterType.MultiValueString;

                            object[] defaultStrings = param.DefaultValue as object[];
                            // the default value could be an array of strings
                            if (defaultStrings != null && defaultStrings.Length > 0)
                            {
                                List <GPString> list =
                                    (from string s in defaultStrings select new GPString(param.Name, s)).ToList();

                                config.DefaultValue = new GPMultiValue <GPString>(param.Name, list);
                            }

                            if (param.ChoiceList != null && param.ChoiceList.Length > 0)
                            {
                                config.ChoiceList = new List <Choice>(param.ChoiceList.Length);
                                foreach (string t in param.ChoiceList)
                                {
                                    config.ChoiceList.Add(new Choice
                                    {
                                        DisplayText = t,
                                        Value       = new GPString(param.Name, t)
                                    });
                                }
                            }
                            break;

                        case "GPRecordSet":
                            config.Type    = GPParameterType.RecordSet;
                            config.ToolTip = config.HelpText = Resources.Strings.EnterUrlForRecordset;
                            break;

                        case "GPDataFile":
                            config.Type    = GPParameterType.DataFile;
                            config.ToolTip = config.HelpText = Resources.Strings.EnterUrlForFile;
                            break;

                        default:
                            break;
                            #endregion
                        }
                        #endregion
                    }
                    if (config != null)
                    {
                        if (param.Direction == "esriGPParameterDirectionInput")
                        {
                            config.Input = true;
                            InputParameters.Add(config);
                        }
                        else
                        {
                            config.Input = false;
                            OutputParameters.Add(config);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(serviceInfo.ResultMapServerName) && !string.IsNullOrEmpty(serviceInfo.CurrentVersion))
            {
                MapServiceLayerParameterConfig layerConfig = new MapServiceLayerParameterConfig
                {
                    Name                = serviceInfo.ResultMapServerName,
                    LayerName           = serviceInfo.ResultMapServerName,
                    Type                = GPParameterType.MapServiceLayer,
                    LayerInfos          = resultMapserviceLayerInfos,
                    SupportsJobResource = true,
                    Opacity             = 1,
                };
                OutputParameters.Add(layerConfig);
                LayerOrder.Add(layerConfig.Name);
            }

            #endregion
        }
コード例 #2
0
        void addInput(ESRI.ArcGIS.Client.Geometry.Geometry geometry)
        {
            GraphicsLayer layer = getLayer();

            #region Create layer if not already there and add to map
            if (layer == null)
            {
                InputLayerID = Guid.NewGuid().ToString("N");
                layer        = new GraphicsLayer();
                if (config.Layer != null)
                {
                    layer.Renderer = config.Layer.Renderer;
                    Core.LayerExtensions.SetFields(layer, Core.LayerExtensions.GetFields(config.Layer));
                    Core.LayerExtensions.SetGeometryType(layer, Core.LayerExtensions.GetGeometryType(config.Layer));
                    Core.LayerExtensions.SetDisplayField(layer, Core.LayerExtensions.GetDisplayField(config.Layer));
                    Core.LayerExtensions.SetPopUpsOnClick(layer, Core.LayerExtensions.GetPopUpsOnClick(config.Layer));
                    LayerProperties.SetIsPopupEnabled(layer, LayerProperties.GetIsPopupEnabled(config.Layer));
                }
                layer.ID = InputLayerID;

                layer.SetValue(MapApplication.LayerNameProperty,
                               string.IsNullOrEmpty(config.LayerName) ?
                               string.IsNullOrEmpty(config.Label) ? config.Name : config.Label
                        : config.LayerName);
                layer.Opacity = config.Opacity;
                Map.Layers.Add(layer);
            }
            #endregion

            #region Add geometry to layer
            if (config.GeometryType == Core.GeometryType.MultiPoint) // Special handling for MultiPoint geometry
            {
                if (layer.Graphics.Count == 0)
                {
                    // Create a new MultiPoint geometry and add the passed-in point to it
                    var multipoint = new MultiPoint()
                    {
                        SpatialReference = geometry.SpatialReference
                    };
                    multipoint.Points.Add((MapPoint)geometry);
                    var g = new Graphic()
                    {
                        Geometry = multipoint
                    };
                    layer.Graphics.Add(g);
                }
                else
                {
                    // Get the sketch graphic's MultiPoint geometry and add the passed-in point to it
                    var multipoint = (MultiPoint)layer.Graphics[0].Geometry;
                    multipoint.Points.Add((MapPoint)geometry);
                    layer.Refresh();
                }
            }
            else
            {
                Graphic g = new Graphic()
                {
                    Geometry = geometry
                };
                layer.Graphics.Add(g);
            }
            #endregion
        }
コード例 #3
0
        private void addToMap(GPFeatureRecordSetLayer result, ParameterConfig config)
        {
            if (result == null)
            {
                return;
            }

            SpatialReference sr = Map.SpatialReference.Clone();

            ESRI.ArcGIS.Mapping.Core.GeometryType geomType = Core.GeometryType.Unknown;
            FeatureLayerParameterConfig           flConfig = config as FeatureLayerParameterConfig;

            foreach (Graphic item in result.FeatureSet.Features)
            {
                if (item.Geometry != null)
                {
                    item.Geometry.SpatialReference = sr;
                    if (geomType == Core.GeometryType.Unknown)
                    {
                        if (item.Geometry is MapPoint)
                        {
                            geomType = Core.GeometryType.Point;
                        }
                        else if (item.Geometry is MultiPoint)
                        {
                            geomType = Core.GeometryType.MultiPoint;
                        }
                        else if (item.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
                        {
                            geomType = Core.GeometryType.Polygon;
                        }
                        else if (item.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
                        {
                            geomType = Core.GeometryType.Polyline;
                        }
                    }
                    if (flConfig != null && flConfig.DoubleFields != null && flConfig.DoubleFields.Length > 0)
                    {
                        foreach (string name in flConfig.DoubleFields)
                        {
                            if (item.Attributes.ContainsKey(name) && item.Attributes[name] != null &&
                                (!(item.Attributes[name] is double)))
                            {
                                double d;
                                if (double.TryParse(item.Attributes[name].ToString(), System.Globalization.NumberStyles.Any, CultureHelper.GetCurrentCulture(), out d))
                                {
                                    item.Attributes[name] = d;
                                }
                            }
                        }
                    }
                    if (flConfig != null && flConfig.SingleFields != null && flConfig.SingleFields.Length > 0)
                    {
                        foreach (string name in flConfig.SingleFields)
                        {
                            if (item.Attributes.ContainsKey(name) && item.Attributes[name] != null &&
                                (!(item.Attributes[name] is Single)))
                            {
                                Single s;
                                if (Single.TryParse(item.Attributes[name].ToString(), out s))
                                {
                                    item.Attributes[name] = s;
                                }
                            }
                        }
                    }
                }
            }
            GraphicsLayer layer = GraphicsLayer.FromGraphics(result.FeatureSet.Features, new SimpleRenderer());

            if (flConfig != null)
            {
                if (flConfig.GeometryType == geomType)
                {
                    layer.Renderer = flConfig.Layer.Renderer;
                }
                else
                {
                    layer.Renderer = FeatureLayerParameterConfig.GetSimpleRenderer(geomType);
                }

                setLayerProps(config, layer);
                if (flConfig.Layer != null)
                {
                    Core.LayerExtensions.SetFields(layer, Core.LayerExtensions.GetFields(flConfig.Layer));
                    Core.LayerExtensions.SetDisplayField(layer, Core.LayerExtensions.GetDisplayField(flConfig.Layer));
                    Core.LayerExtensions.SetGeometryType(layer, Core.LayerExtensions.GetGeometryType(flConfig.Layer));

                    // Set whether pop-ups are enabled and whether to show them on click or on hover
                    LayerProperties.SetIsPopupEnabled(layer, LayerProperties.GetIsPopupEnabled(flConfig.Layer));
                    Core.LayerExtensions.SetPopUpsOnClick(layer, Core.LayerExtensions.GetPopUpsOnClick(flConfig.Layer));
                }
            }

            GraphicsLayerTypeFixer.CorrectDataTypes(layer.Graphics, layer);

            Map.Layers.Add(layer);
            layerParamNameIDLookup.Add(config.Name, layer.ID);
        }