protected override void WriteElementContents(Layer layer)
        {
            HeatMapFeatureLayer featureLayer = layer as HeatMapFeatureLayer;

            if (featureLayer != null)
            {
                WriteHeatMapFeatureLayer(featureLayer);
            }
        }
        /*TODO: Serialize the following
         *
         * public bool DisableClientCaching { get; set; }
         * public Geometry Geometry { get; set; }
         * */
        private void WriteHeatMapFeatureLayer(HeatMapFeatureLayer layer)
        {
            WriteAttribute("Url", layer.Url);


            if (!string.IsNullOrEmpty(layer.Where))
            {
                WriteAttribute("Where", layer.Where);
            }
            if (!LayerExtensions.GetUsesProxy(layer))
            {
                if (!string.IsNullOrEmpty(layer.ProxyUrl))
                {
                    WriteAttribute("ProxyUrl", layer.ProxyUrl);
                }
                if (!string.IsNullOrEmpty(layer.Token))
                {
                    WriteAttribute("Token", layer.Token);
                }
            }
            if (!string.IsNullOrEmpty(layer.Text))
            {
                WriteAttribute("Text", layer.Text);
            }
            if (layer.MinimumResolution > double.Epsilon)
            {
                WriteAttribute("MinimumResolution", layer.MinimumResolution);
            }
            if (layer.MaximumResolution < double.MaxValue)
            {
                WriteAttribute("MaximumResolution", layer.MaximumResolution);
            }
            if (!double.IsNaN(layer.Intensity))
            {
                WriteAttribute("Intensity", layer.Intensity);
            }
            if (layer.MapSpatialReference != null)
            {
                WriteSpatialReferenceAsAttribute("MapSpatialReference", layer.MapSpatialReference);
            }

            if (layer.Gradient != null)
            {
                writer.WriteStartElement("HeatMapFeatureLayer.Gradient", Namespaces[Constants.esriMappingPrefix]);
                writer.WriteStartElement("GradientStopCollection");
                new BrushXamlWriter(writer, Namespaces).WriteGradientStops(layer.Gradient);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            WriteBaseElementContents(layer);
        }
        /*TODO: Serialize the following
         * 
        public bool DisableClientCaching { get; set; }
        public Geometry Geometry { get; set; }
         * */
        private void WriteHeatMapFeatureLayer(HeatMapFeatureLayer layer)
        {   
            WriteAttribute("Url", layer.Url);

            
            if (!string.IsNullOrEmpty(layer.Where))
            {
                WriteAttribute("Where", layer.Where);
            }
            if (!LayerExtensions.GetUsesProxy(layer))
            {
                if (!string.IsNullOrEmpty(layer.ProxyUrl))
                {
                    WriteAttribute("ProxyUrl", layer.ProxyUrl);
                }
                if (!string.IsNullOrEmpty(layer.Token))
                {
                    WriteAttribute("Token", layer.Token);
                }
            }
            if (!string.IsNullOrEmpty(layer.Text))
            {
                WriteAttribute("Text", layer.Text);
            }
            if (layer.MinimumResolution > double.Epsilon)
            {
                WriteAttribute("MinimumResolution", layer.MinimumResolution);
            }
            if (layer.MaximumResolution < double.MaxValue)
            {
                WriteAttribute("MaximumResolution", layer.MaximumResolution);
            }
            if (! double.IsNaN(layer.Intensity))
            {
                WriteAttribute("Intensity", layer.Intensity);
            }
            if (layer.MapSpatialReference != null)
                WriteSpatialReferenceAsAttribute("MapSpatialReference", layer.MapSpatialReference);

            if (layer.Gradient != null)
            {
                writer.WriteStartElement("HeatMapFeatureLayer.Gradient", Namespaces[Constants.esriMappingPrefix]);
                writer.WriteStartElement("GradientStopCollection");
                new BrushXamlWriter(writer, Namespaces).WriteGradientStops(layer.Gradient);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            WriteBaseElementContents(layer);
        }
		public static void AddHeatMapLayer(Layer layer, View view)
		{
			Map map = view.Map;
            string originalTitle = string.Empty;

            originalTitle = layer.GetValue(ESRI.ArcGIS.Client.Extensibility.MapApplication.LayerNameProperty) as string;

			FeatureLayer featureLayer = layer as FeatureLayer;
            if (featureLayer != null && !string.IsNullOrEmpty(featureLayer.Url))
            {
                HeatMapFeatureLayer heatMapFeatureLayer = new HeatMapFeatureLayer();
                heatMapFeatureLayer.DisableClientCaching = featureLayer.DisableClientCaching;
                heatMapFeatureLayer.Geometry = featureLayer.Geometry;
                heatMapFeatureLayer.ProxyUrl = featureLayer.ProxyUrl;
                heatMapFeatureLayer.Text = featureLayer.Text;
                heatMapFeatureLayer.Token = featureLayer.Token;
                heatMapFeatureLayer.Url = featureLayer.Url;
                heatMapFeatureLayer.Where = featureLayer.Where;
                heatMapFeatureLayer.MapSpatialReference = map.SpatialReference;
                heatMapFeatureLayer.ID = "EsriHeatMapLayer__" + Guid.NewGuid().ToString("N");
                foreach (Graphic item in featureLayer.Graphics)
                {
                    ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = item.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint;
                    if (mapPoint != null)
                        heatMapFeatureLayer.HeatMapPoints.Add(mapPoint);                    
                }                
                view.AddLayerToMap(heatMapFeatureLayer, true,
					string.IsNullOrEmpty(originalTitle) ? Resources.Strings.HeatMap : string.Format(Resources.Strings.HeatMapTitle, originalTitle));
            }
            else
            {
                GraphicsLayer graphicsLayer = layer as GraphicsLayer;
                if(graphicsLayer != null)
                {
                    ESRI.ArcGIS.Client.Toolkit.DataSources.HeatMapLayer heatMapLayer = new Client.Toolkit.DataSources.HeatMapLayer();
                    foreach (Graphic item in graphicsLayer.Graphics)
                    {
                        ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = item.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint;
                        if (mapPoint != null)
                            heatMapLayer.HeatMapPoints.Add(mapPoint);
                    }
                    view.AddLayerToMap(heatMapLayer, true,
										string.IsNullOrEmpty(originalTitle) ? Resources.Strings.HeatMap : string.Format(Resources.Strings.HeatMapTitle, originalTitle));
                }
            }			
		}
        public static void SetProxyUrl(Layer layer, string proxyUrl)
        {
            ArcGISDynamicMapServiceLayer dmsLayer = layer as ArcGISDynamicMapServiceLayer;
            string url = null;

            if (dmsLayer != null)
            {
                if (dmsLayer.ProxyURL != proxyUrl)
                {
                    url = dmsLayer.Url;
                    try
                    {
                        dmsLayer.Url = "";
                    }
                    catch { }
                    dmsLayer.ProxyURL = proxyUrl;
                    dmsLayer.Url      = url;
                    dmsLayer.Refresh();
                }
                return;
            }
            ArcGISImageServiceLayer isLayer = layer as ArcGISImageServiceLayer;

            if (isLayer != null)
            {
                if (isLayer.ProxyURL != proxyUrl)
                {
                    url = isLayer.Url;
                    try
                    {
                        isLayer.Url = "";
                    }
                    catch { }
                    isLayer.ProxyURL = proxyUrl;
                    isLayer.Url      = url;
                    isLayer.Refresh();
                }
                return;
            }
            ArcGISTiledMapServiceLayer tmsLayer = layer as ArcGISTiledMapServiceLayer;

            if (tmsLayer != null)
            {
                if (tmsLayer.ProxyURL != proxyUrl)
                {
                    url = tmsLayer.Url;
                    try
                    {
                        tmsLayer.Url = "";
                    }
                    catch { }
                    tmsLayer.ProxyURL = proxyUrl;
                    tmsLayer.Url      = url;
                    tmsLayer.Refresh();
                }
                return;
            }
            FeatureLayer fLayer = layer as FeatureLayer;

            if (fLayer != null)
            {
                if (fLayer.ProxyUrl != proxyUrl)
                {
                    fLayer.ProxyUrl = proxyUrl;
                    fLayer.Update();
                }
                return;
            }
            HeatMapFeatureLayer hmfLayer = layer as HeatMapFeatureLayer;

            if (hmfLayer != null)
            {
                if (hmfLayer.ProxyUrl != proxyUrl)
                {
                    hmfLayer.ProxyUrl = proxyUrl;
                    hmfLayer.Update();
                }
                return;
            }
        }