/// <summary>
        /// Creates the permanent layer from the results of the Query
        /// </summary>
        /// <returns>Permanent <see cref="ESRI.ArcGIS.Client.FeatureLayer"/></returns>
        /// <remarks>The permanent layer uses the default renderer of the layer.
        /// The permanent layer is visible in the Map Contents panel.</remarks>
        private FeatureLayer CreatePermanentLayer()
        {
            // Check that the results layer is not null and use the results layer to create the permanent layer
            if (resultsLayer != null)
            {
                permanentLayer = resultsLayer;

                // Create a layer ID for displaying the layer in the map contents and attribute table
                string permanentLayerID = string.Format(Strings.RelatedTo, permanentLayer.LayerInfo.Name, PopupInfo.PopupItem.Title);

                // If there is more than one layer with the same name, add a number to the end of the name
                int layerCountSuffix = 0;

                string layerName;
                // Verify the next number in the sequence hasn't been used. If layers are renamed after the name is generated, a scenario may occur where
                // the last number used in the name is actually greater than the number of existing layers with the same name. We don't want a number to
                // repeat, so we check the last number used.
                foreach (Layer layer in map.Layers)
                {
                    layerName = MapApplication.GetLayerName(layer);
                    if (layerName != null && layerName.StartsWith(permanentLayerID))
                    {
                        if (layerName.EndsWith(")"))
                        {
                            // Split the layer name at the end to get the last number used (number contained within the parentheses)
                            string[] splitLayerName     = layerName.Split('(');
                            int      lastNumberAppended = Convert.ToInt32(splitLayerName.Last <string>().TrimEnd(')'));
                            // If the last number used is greater than the count of number of existing layers with the same name,
                            // set the count to the last number used.
                            if (lastNumberAppended > layerCountSuffix)
                            {
                                layerCountSuffix = lastNumberAppended;
                            }
                        }
                        else // Found a layer with the same name, but no (#) suffix.  This is the first layer added with this name.
                        {
                            // Only set the suffix based on this layer if the suffix has not yet been set (i.e. is still zero)
                            if (layerCountSuffix == 0)
                            {
                                layerCountSuffix = 1;
                            }
                        }
                    }
                }

                if (layerCountSuffix != 0)
                {
                    permanentLayerID += string.Format(" ({0})", layerCountSuffix + 1);
                }


                MapApplication.SetLayerName(permanentLayer, permanentLayerID);

                // Create a unique ID for the layer.
                permanentLayer.ID = Guid.NewGuid().ToString();

                // If the results layer is a table, don't show it in the map contents.
                if (resultsLayer.LayerInfo.Type == "Table")
                {
                    LayerProperties.SetIsVisibleInMapContents(permanentLayer, false);
                }
                else
                {
                    LayerProperties.SetIsVisibleInMapContents(permanentLayer, true);
                }

                // Set the layer renderer to the renderer of the original layer
                permanentLayer.Renderer = resultsLayer.LayerInfo.Renderer;
            }

            return(permanentLayer);
        }
예제 #2
0
        }         // private void resultsLayer_Initialized(object sender, EventArgs e)

        /// <summary>
        /// Get related records ID's from query result, add filtered by ID's layer to map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void doResultsLayer_Initialized(object sender, EventArgs e)
        {
            // Get the FeatureLayer's OID field off the LayerInfo
            string oidField      = resultsLayer.getFL().LayerInfo.ObjectIdField;
            var    reslyr        = resultsLayer;
            string oidFieldAlias = reslyr.getFieldAlias(oidField);

            log(string.Format("doResultsLayer_Initialized, resultsLayer.oidfield='{0}', alias='{1}'", oidField, oidFieldAlias));
            oidField = "";

            // Create a List to hold the ObjectIds
            List <int>            list = new List <int>();
            IEnumerable <Graphic> RelatedRecords;

            //Go through the RelatedRecordsGroup and add the Graphic to the IEnumerable<Graphic>
            foreach (var records in queryResult.RelatedRecordsGroup)
            {
                RelatedRecords = records.Value;
                foreach (Graphic graphic in RelatedRecords)
                {
                    if (oidField == "")
                    {
                        var oid = resultsLayer.getOID(graphic);
                        oidField = resultsLayer.getOIDFieldnameOrAlias();
                        log(string.Format("doResultsLayer_Initialized, real resultsLayer.oidfield='{0}', alias='{1}'", oidField, oidFieldAlias));
                    }
                    list.Add((int)graphic.Attributes[oidField]);
                }
            }
            log(string.Format("doResultsLayer_Initialized, relatedRecords.oidList.Count='{0}'", list.Count));
            if (list.Count <= 0)
            {
                throw new Exception("Для указанного обьекта связанные записи отсутствуют");
            }

            resultsLayer.getFL().UpdateCompleted += resultsLayer_UpdateCompleted;
            int[] objectIDs = list.ToArray();
            resultsLayer.getFL().ObjectIDs = objectIDs;
            log(string.Format("doResultsLayer_Initialized, ID's set"));

            // Specify renderers for Point, Polyline, and Polygon features if the related features have geometry.
            if (resultsLayer.getFL().LayerInfo.GeometryType == GeometryType.Point)
            {
                log(string.Format("doResultsLayer_Initialized, MapPoint"));
                resultsLayer.getFL().Renderer = new SimpleRenderer()
                {
                    Symbol = new SimpleMarkerSymbol()
                    {
                        Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
                    }
                };
            }
            else if (resultsLayer.getFL().LayerInfo.GeometryType == GeometryType.Polyline)
            {
                log(string.Format("doResultsLayer_Initialized, Polyline"));
                resultsLayer.getFL().Renderer = new SimpleRenderer()
                {
                    Symbol = new SimpleLineSymbol()
                    {
                        Color = new SolidColorBrush(Colors.Red),
                        Width = 2
                    }
                };
            }
            else if (resultsLayer.getFL().LayerInfo.GeometryType == GeometryType.Polygon)
            {
                log(string.Format("doResultsLayer_Initialized, Polygon"));
                resultsLayer.getFL().Renderer = new SimpleRenderer()
                {
                    Symbol = new SimpleFillSymbol()
                    {
                        Fill        = new SolidColorBrush(Color.FromArgb(125, 255, 0, 0)),
                        BorderBrush = new SolidColorBrush(Colors.Red)
                    }
                };
            }
            log(string.Format("doResultsLayer_Initialized, resultsLayer.Geometry is '{0}'", resultsLayer.getFL().LayerInfo.GeometryType));

            // Specify a layer name so that it displays on the Attribute table, but do not display the layer in the Map Contents.
            // old style
            string mapLayerName = resultsLayer.getFL().LayerInfo.Name + ", related records '" + relationInfo.name +
                                  "' for OID " + relatesLayer.getOID(inputFeature).ToString();

            try {             // Parilov style
                mapLayerName = string.Format("{0}, {1}", resultsLayer.getFL().LayerInfo.Name,
                                             inputFeature.Attributes[relatesLayer.getFL().LayerInfo.DisplayField]);
            }
            catch (Exception ex) {
                log(string.Format("doResultsLayer_Initialized, Parilov style layer name failed. SetLayerName '{0}'", mapLayerName));
            }
            MapApplication.SetLayerName(resultsLayer.lyr, mapLayerName);
            LayerProperties.SetIsVisibleInMapContents(resultsLayer.lyr, true);
            log(string.Format("doResultsLayer_Initialized, SetLayerName '{0}'", mapLayerName));
            // Add the layer to the map and set it as the selected layer so the attributes appear in the Attribute table.
            MapApplication.Current.Map.Layers.Add(resultsLayer.lyr);
        }         // private void doResultsLayer_Initialized(object sender, EventArgs e)
        /// <summary>
        /// Create the temporary layer from the results of the Query
        /// </summary>
        /// <returns>Temporary <see cref="ESRI.ArcGIS.Client.FeatureLayer"/></returns>
        /// <remarks>Uses "temporary" symbols to render the points, lines, or polygons. The temporary
        /// layer is not displayed in the Map Contents panel, but the attribute grid opens to show the feature attributes.</remarks>
        private FeatureLayer CreateTempLayer()
        {
            // Check that the results layer is not null and use the results layer to create the temporary layer
            if (resultsLayer != null)
            {
                temporaryLayer = resultsLayer;

                // ControlTemplate to create ellipse for temporary point symbol
                var template = (ControlTemplate)System.Windows.Markup.XamlReader.Load("<ControlTemplate " +
                                                                                      "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
                                                                                      "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" +
                                                                                      "<Grid RenderTransformOrigin=\"{Binding Symbol.RenderTransformPoint}\">" +
                                                                                      "<Ellipse " +
                                                                                      "Fill=\"#99FFFFFF\" " +
                                                                                      "Width=\"21\" " +
                                                                                      "Height=\"21\" " +
                                                                                      "Stroke=\"Red\" " +
                                                                                      "StrokeThickness=\"2\">" +
                                                                                      "</Ellipse>" +
                                                                                      "<Ellipse Fill=\"#99FFFFFF\" " +
                                                                                      "Width=\"3\" " +
                                                                                      "Height=\"3\" " +
                                                                                      "Stroke=\"Red\" " +
                                                                                      "StrokeThickness=\"2\">" +
                                                                                      "</Ellipse>" +
                                                                                      "</Grid> " +
                                                                                      "</ControlTemplate>");

                Symbol test = new SimpleMarkerSymbol();

                // Set the renderers to a "temporary" look for the temp Layer
                if (temporaryLayer.LayerInfo.GeometryType == GeometryType.Point || temporaryLayer.LayerInfo.GeometryType == GeometryType.MultiPoint)
                {
                    temporaryLayer.Renderer = new SimpleRenderer()
                    {
                        Symbol = new MarkerSymbol()
                        {
                            ControlTemplate = template as ControlTemplate, OffsetX = 10, OffsetY = 10
                        }
                    }
                }
                ;
                else if (temporaryLayer.LayerInfo.GeometryType == GeometryType.Polyline)
                {
                    temporaryLayer.Renderer = new SimpleRenderer()
                    {
                        Symbol = new SimpleLineSymbol()
                        {
                            Color = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)),
                            Width = 3
                        }
                    }
                }
                ;
                else if (temporaryLayer.LayerInfo.GeometryType == GeometryType.Polygon)
                {
                    temporaryLayer.Renderer = new SimpleRenderer()
                    {
                        Symbol = new SimpleFillSymbol()
                        {
                            Fill            = new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)),
                            BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)),
                            BorderThickness = 3
                        }
                    }
                }
                ;

                // Specify a name to set the ID property on the Layer. This name is associated with the layer but does not display in the map contents panel
                string tempLayerID = string.Format(Strings.RelatedTo, temporaryLayer.LayerInfo.Name, PopupInfo.PopupItem.Title);

                MapApplication.SetLayerName(temporaryLayer, tempLayerID);

                LayerProperties.SetIsVisibleInMapContents(temporaryLayer, false);
            }

            return(temporaryLayer);
        }
        } // private void resultsLayer_Initialized(object sender, EventArgs e)

        /// <summary>
        /// Get related records ID's from query result, add filtered by ID's layer to map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void doResultsLayer_Initialized(object sender, EventArgs e)
        {
            // Get the FeatureLayer's OID field off the LayerInfo
            string oidField      = resultsLayer.LayerInfo.ObjectIdField;
            var    reslyr        = new VUtils.ArcGIS.SLViewer.VLayer(resultsLayer);
            string oidFieldAlias = reslyr.getFieldAlias(oidField);

            log(string.Format(
                    "doResultsLayer_Initialized, resultsLayer.oidfield='{0}', alias='{1}'",
                    oidField, oidFieldAlias));
            if (oidFieldAlias != "")
            {
                oidField = oidFieldAlias;
            }

            // Create a List to hold the ObjectIds
            List <int>            list = new List <int>();
            IEnumerable <Graphic> RelatedRecords;

            //Go through the RelatedRecordsGroup and add the Graphic to the IEnumerable<Graphic>
            foreach (var records in queryResult.RelatedRecordsGroup)
            {
                RelatedRecords = records.Value;
                foreach (Graphic graphic in RelatedRecords)
                {
                    list.Add((int)graphic.Attributes[oidField]);
                }
            }
            log(string.Format("doResultsLayer_Initialized, relatedRecords.oidList.Count='{0}'", list.Count));
            if (list.Count <= 0)
            {
                throw new Exception("Haven't related records for that object");
            }

            int[] objectIDs = list.ToArray();
            resultsLayer.ObjectIDs = objectIDs;
            log(string.Format("doResultsLayer_Initialized, ID's set"));

            // Specify renderers for Point, Polyline, and Polygon features if the related features have geometry.
            if (resultsLayer.LayerInfo.GeometryType == GeometryType.Point)
            {
                log(string.Format("doResultsLayer_Initialized, MapPoint"));
                resultsLayer.Renderer = new SimpleRenderer()
                {
                    Symbol = new SimpleMarkerSymbol()
                    {
                        Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
                    }
                };
            }
            else if (resultsLayer.LayerInfo.GeometryType == GeometryType.Polyline)
            {
                log(string.Format("doResultsLayer_Initialized, Polyline"));
                resultsLayer.Renderer = new SimpleRenderer()
                {
                    Symbol = new SimpleLineSymbol()
                    {
                        Color = new SolidColorBrush(Colors.Red),
                        Width = 2
                    }
                };
            }
            else if (resultsLayer.LayerInfo.GeometryType == GeometryType.Polygon)
            {
                log(string.Format("doResultsLayer_Initialized, Polygon"));
                resultsLayer.Renderer = new SimpleRenderer()
                {
                    Symbol = new SimpleFillSymbol()
                    {
                        Fill        = new SolidColorBrush(Color.FromArgb(125, 255, 0, 0)),
                        BorderBrush = new SolidColorBrush(Colors.Red)
                    }
                };
            }
            log(string.Format("doResultsLayer_Initialized, resultsLayer.Geometry is '{0}'", resultsLayer.LayerInfo.GeometryType));

            // Specify a layer name so that it displays on the Attribute table,
            // but do not display the layer in the Map Contents.
            string mapLayerName = resultsLayer.LayerInfo.Name +
                                  ", related records '" +
                                  relationInfo.name +
                                  "' for OID " +
                                  inputFeature.Attributes[objectID].ToString();

            MapApplication.SetLayerName(resultsLayer, mapLayerName);
            LayerProperties.SetIsVisibleInMapContents(resultsLayer, true);
            log(string.Format("doResultsLayer_Initialized, SetLayerName '{0}'", mapLayerName));

            // Add the layer to the map and set it as the selected layer so the attributes appear in the Attribute table.
            resultsLayer.UpdateCompleted += resultsLayer_UpdateCompleted;
            MapApplication.Current.Map.Layers.Add(resultsLayer);
        } // private void doResultsLayer_Initialized(object sender, EventArgs e)