/// <summary>
 /// Gets a symbol based on a graphic.
 /// </summary>
 /// <param name="graphic">The graphic.</param>
 /// <returns>Symbol</returns>
 public Symbol GetSymbol(Graphic graphic)
 {
     if (graphic != null && Attribute != null)
     {
         if (graphic.Attributes.ContainsKey(Attribute))
         {
             object             objValue           = graphic.Attributes[Attribute];
             CurrencyFieldValue currencyFieldValue = objValue as CurrencyFieldValue;
             if (currencyFieldValue != null)
             {
                 objValue = currencyFieldValue.Value;
             }
             double value;
             if (double.TryParse(
                     string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", objValue),
                     System.Globalization.NumberStyles.Any,
                     System.Globalization.CultureInfo.InvariantCulture, out value))
             {
                 foreach (ClassBreakInfo info in Classes)
                 {
                     if (value == info.MinimumValue || value >= info.MinimumValue && value < info.MaximumValue)
                     {
                         return(info.Symbol);
                     }
                 }
             }
         }
     }
     return(DefaultSymbol);
 }
コード例 #2
0
        public override bool Equals(object obj)
        {
            CurrencyFieldValue other = obj as CurrencyFieldValue;

            if (other != null)
            {
                return(other.Value == Value && other.FormattedValue == FormattedValue);
            }
            return(base.Equals(obj));
        }
コード例 #3
0
        private void writeCurrencyFieldValue(CurrencyFieldValue currFieldValue)
        {
            if (currFieldValue == null)
            {
                return;
            }

            writer.WriteStartElement("CurrencyFieldValue", Namespaces[Constants.esriMappingPrefix]);
            if (!string.IsNullOrEmpty(currFieldValue.FormattedValue))
            {
                writer.WriteAttributeString("FormattedValue", currFieldValue.FormattedValue);
            }
            if (!double.IsNaN(currFieldValue.Value))
            {
                writer.WriteAttributeString("Value", currFieldValue.Value.ToString(CultureInfo.InvariantCulture));
            }
            writer.WriteEndElement();
        }
コード例 #4
0
        private void writeUniqueValueObj(object uniqueValueInfo)
        {
            if (uniqueValueInfo == null)
            {
                return;
            }

            NumericFieldValue numericFieldValue = uniqueValueInfo as NumericFieldValue;

            if (numericFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeNumericFieldValue(numericFieldValue);
                writer.WriteEndElement();
                return;
            }

            AttachmentFieldValue attFieldValue = uniqueValueInfo as AttachmentFieldValue;

            if (attFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeAttachmentFieldValue(attFieldValue);
                writer.WriteEndElement();
                return;
            }

            CurrencyFieldValue currFieldValue = uniqueValueInfo as CurrencyFieldValue;

            if (currFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeCurrencyFieldValue(currFieldValue);
                writer.WriteEndElement();
                return;
            }

            EntityFieldValue entityFieldValue = uniqueValueInfo as EntityFieldValue;

            if (entityFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeEntityFieldValue(entityFieldValue);
                writer.WriteEndElement();
                return;
            }

            HyperlinkFieldValue hyperlinkFieldValue = uniqueValueInfo as HyperlinkFieldValue;

            if (hyperlinkFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeHyperlinkFieldValue(hyperlinkFieldValue);
                writer.WriteEndElement();
                return;
            }

            HyperlinkImageFieldValue hyperlinkImageFieldValue = uniqueValueInfo as HyperlinkImageFieldValue;

            if (hyperlinkImageFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeHyperlinkImageFieldValue(hyperlinkImageFieldValue);
                writer.WriteEndElement();
                return;
            }

            LookupFieldValue lookupFieldValue = uniqueValueInfo as LookupFieldValue;

            if (lookupFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeLookupFieldValue(lookupFieldValue);
                writer.WriteEndElement();
                return;
            }

            DateTimeFieldValue dateTimeFieldValue = uniqueValueInfo as DateTimeFieldValue;

            if (dateTimeFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeDateTimeFieldValue(dateTimeFieldValue);
                writer.WriteEndElement();
                return;
            }

            if (uniqueValueInfo is double)
            {
                writer.WriteAttributeString("SerializedValue", ((double)uniqueValueInfo).ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                writer.WriteAttributeString("SerializedValue", uniqueValueInfo.ToString());
            }
        }
コード例 #5
0
        public static object GetFieldValue(PopupItem popupItem, string fieldName)
        {
            if (string.IsNullOrEmpty(fieldName) || popupItem == null || popupItem.Graphic == null || popupItem.Graphic.Attributes == null ||
                popupItem.FieldInfos == null)
            {
                return(null);
            }

            Layer        layer        = popupItem.Layer;
            FeatureLayer featureLayer = layer as FeatureLayer;
            Collection <LayerInformation> layerInfos = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetLayerInfos(layer);

            // Try to find feature layer from layer info
            foreach (LayerInformation item in layerInfos)
            {
                if (item.ID == popupItem.LayerId)
                {
                    featureLayer = item.FeatureLayer;
                    break;
                }
            }

            // Try to find field information from field settings collection (which are FieldInfo objects)
            FieldInfo fldInfo = null;

            foreach (FieldSettings fld in popupItem.FieldInfos)
            {
                if (fld.Name.ToLower().Equals(fieldName.ToLower()))
                {
                    fldInfo = fld as FieldInfo;
                    break;
                }
            }

            if (fldInfo == null)
            {
                return(null);
            }

            // Create local variable for attributes to improve performance since collection is referenced multiple
            // times in logic below.
            IDictionary <string, object> attributes = popupItem.Graphic.Attributes;

            // If the field is a subdomain type, then lookup the value and return
            if (FieldInfo.GetDomainSubTypeLookup(featureLayer, fldInfo) != DomainSubtypeLookup.None)
            {
                return(GetDomainValue(featureLayer, attributes, fldInfo));
            }

            // Try to extract value from field using Name and then DisplayName
            object fieldValue = null;

            if (!attributes.TryGetValue(fldInfo.Name, out fieldValue))
            {
                if (!attributes.TryGetValue(fldInfo.DisplayName, out fieldValue))
                {
                    return(null);
                }
            }

            // Special formatting if the field type is Currency or Date/Time
            if (fldInfo.FieldType == FieldType.Currency)
            {
                CurrencyFieldValue currencyFieldValue = fieldValue as CurrencyFieldValue;
                if (currencyFieldValue != null)
                {
                    fieldValue = currencyFieldValue.FormattedValue;
                }
            }
            else if (fldInfo.FieldType == FieldType.DateTime)
            {
                DateTimeFieldValue dateFieldValue = fieldValue as DateTimeFieldValue;
                if (dateFieldValue != null)
                {
                    fieldValue = dateFieldValue.FormattedValue;
                }
            }

            return(fieldValue);
        }
コード例 #6
0
        private void writeCurrencyFieldValue(CurrencyFieldValue currFieldValue)
        {
            if (currFieldValue == null)
                return;

            writer.WriteStartElement("CurrencyFieldValue", Namespaces[Constants.esriMappingPrefix]);
            if (!string.IsNullOrEmpty(currFieldValue.FormattedValue))
                writer.WriteAttributeString("FormattedValue", currFieldValue.FormattedValue);
            if (!double.IsNaN(currFieldValue.Value))
                writer.WriteAttributeString("Value", currFieldValue.Value.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();
        }