コード例 #1
0
 private void Write(object obj)
 {
     if (obj is Layer)
     {
         LayerXamlWriter layerXamlWriter = new LayerXamlWriter(writer, Namespaces);
         layerXamlWriter.WriteLayer(obj as Layer, obj.GetType().Name, Constants.esriNamespace);
     }
     else if (obj is Brush)
     {
         new BrushXamlWriter(writer, Namespaces).WriteBrush(obj as Brush);
     }
     else if (obj is Symbol)
     {
         (new SymbolXamlWriter(writer, Namespaces)).WriteSymbol(obj as Symbol);
     }
     else if (obj is String)
     {
         writer.WriteString(obj as string);
     }
     else if (obj is double)
     {
         writer.WriteString(((double)obj).ToString("0.0", CultureInfo.InvariantCulture));
     }
     else
     {
         throw new NotSupportedException(obj.GetType().ToString());
     }
 }
コード例 #2
0
 private void Write(object obj)
 {
     if (obj is Layer)
     {
         LayerXamlWriter layerXamlWriter = new LayerXamlWriter(writer, Namespaces);
         layerXamlWriter.WriteLayer(obj as Layer, obj.GetType().Name, Constants.esriNamespace);
     }
     else if (obj is Brush) 
     {
         new BrushXamlWriter(writer, Namespaces).WriteBrush(obj as Brush);
     }
     else if (obj is Symbol)
     {
         (new SymbolXamlWriter(writer, Namespaces)).WriteSymbol(obj as Symbol);
     }
     else if (obj is String) writer.WriteString(obj as string);
     else if (obj is double) writer.WriteString(((double)obj).ToString("0.0", CultureInfo.InvariantCulture));
     else throw new NotSupportedException(obj.GetType().ToString());
 }        
コード例 #3
0
        public string MapToXaml(Map map)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            xaml   = new StringBuilder();
            writer = XmlWriter.Create(xaml, writerSettings);

            if (EncloseInUserControlTag)
            {
                writer.WriteStartElement("UserControl");
                WriteNamespaces();

                if (ResourceDictionary.Count > 0)
                {
                    writer.WriteStartElement("UserControl.Resources");
                    WriteResources(ResourceDictionary);
                    writer.WriteEndElement();
                }
            }

            writer.WriteStartElement("Map", Constants.esriNamespace);
            if (!EncloseInUserControlTag)
            {
                WriteNamespaces();
            }

            if (map.Rotation != default(double))
            {
                writer.WriteAttributeString("Rotation", map.Rotation.ToString(CultureInfo.InvariantCulture));
            }

            if (map.SnapToLevels)
            {
                writer.WriteAttributeString("SnapToLevels", map.SnapToLevels.ToString(CultureInfo.InvariantCulture));
            }

            MapUnit scaleBarUnit = ScaleBarExtensions.GetScaleBarMapUnit(map);

            if (scaleBarUnit != MapUnit.Undefined)
            {
                writer.WriteElementString(Constants.esriMappingPrefix, "ScaleBarExtensions.ScaleBarMapUnit", Constants.esriMappingNamespace, scaleBarUnit.ToString());
            }

            writer.WriteElementString(Constants.esriPrefix, "Map.IsLogoVisible", Constants.esriNamespace, map.IsLogoVisible.ToString());

            if (map.Extent != null)
            {
                writer.WriteStartElement("Map.Extent", Constants.esriNamespace);

                writer.WriteStartElement("Envelope", Constants.esriNamespace);
                writer.WriteAttributeString("XMin", map.Extent.XMin.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("XMax", map.Extent.XMax.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("YMin", map.Extent.YMin.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("YMax", map.Extent.YMax.ToString(CultureInfo.InvariantCulture));

                if (map.Extent.SpatialReference != null)
                {
                    writer.WriteStartElement("Envelope.SpatialReference", Constants.esriNamespace);

                    writer.WriteStartElement("SpatialReference", Constants.esriNamespace);
                    if (!string.IsNullOrEmpty(map.Extent.SpatialReference.WKT))
                    {
                        writer.WriteAttributeString("WKT", map.Extent.SpatialReference.WKT);
                    }
                    else
                    {
                        writer.WriteAttributeString("WKID", map.Extent.SpatialReference.WKID.ToString());
                    }
                    writer.WriteEndElement(); // SpatialReference

                    writer.WriteEndElement(); // Envelope.SpatialReference
                }

                writer.WriteEndElement(); // Envelope
                writer.WriteEndElement(); // Map.Extent
            }
            //WriteXName("MyMap");

            if (!EncloseInUserControlTag)
            {
                if (ResourceDictionary.Count > 0)
                {
                    writer.WriteStartElement("Map.Resources", Constants.esriNamespace);
                    WriteResources(ResourceDictionary);
                    writer.WriteEndElement();
                }
            }

            foreach (Layer layer in map.Layers)
            {
                if ((bool)layer.GetValue(ESRI.ArcGIS.Mapping.Core.LayerExtensions.ExcludeSerializationProperty) == true)
                {
                    continue;
                }

                ICustomLayer customlayer = layer as ICustomLayer;
                if (customlayer != null)
                {
                    customlayer.Serialize(writer, Namespaces);
                    continue;
                }

                LayerXamlWriter layerXamlWriter = XamlWriterFactory.CreateLayerXamlWriter(layer, writer, Namespaces);
                if (layerXamlWriter != null)
                {
                    if (layer is HeatMapFeatureLayer)
                    {
                        layerXamlWriter.WriteLayer(layer, layer.GetType().Name, Constants.esriMappingNamespace);
                    }
                    else
                    {
                        layerXamlWriter.WriteLayer(layer, layer.GetType().Name, Constants.esriNamespace);
                    }
                }
                else
                {
                    //writer.WriteRaw(layer.ToString()); // write the ToString equivalent
                }
            }

            writer.WriteEndElement(); //esri:Map

            if (EncloseInUserControlTag)
            {
                writer.WriteEndElement(); //UserControl
            }
            writer.Flush();
            writer = null;
            string result = xaml.ToString();

            if (!EncloseInUserControlTag)
            {
                // Replace the generated XML for the outermost element with an esri:namespace
                // and ensure that default namespaces doesn't get overwritten by esri namespace
                result = result.Replace("<Map", "<esri:Map");
                result = result.Replace("</Map>", "</esri:Map>");
                result = result.Replace("xmlns=\"" + Constants.esriNamespace + "\"", "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"");
            }
            else
            {
                // Inject default namespace
                result = result.Insert(13, "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ");
            }

            if (writerSettings.Indent)
            {
                result = result.Replace(" xmlns:", "\n\t xmlns:").Replace(" xmlns=\"", "\n\t xmlns=\"");
            }
            return(result);
        }