Example #1
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
        }
        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);
        }