ThinkGeo.com    |     Documentation    |     Premium Support

Performance issue urgent!

Hi,


I have an application where I need to colorize the map based on zip code...   I was able to make it to work but!!!!


The time required to draw the map is terrible................................


of course the number of zip is very high.......


help required!  Thanks in advance.


jm.


 


this is the code:


 


      private void SHOW_REP_TERRITORY()

        {

            StringBuilder sb = new StringBuilder();



            layerOverlay = (LayerOverlay)Map1.CustomOverlays["layerOverlay"];



            #region Load reps geography

            _rep = (Dictionary<string, string>)Application["REPPERZIP"];

            _reps = (List<string>)Application["REPS"];

            #endregion



            try

            {

                layerOverlay.Layers.Remove("shp_zip5");

            }

            catch (System.Exception ex)

            { }

            try

            {

                Map1.CustomOverlays.Remove("inMemoryMarkerOverlay_rep_zip");

            }

            catch (System.Exception ex)

            { }



            Collection<GeoColor> colorsInHueFamily = GeoColor.GetColorsInHueFamily(GeoColor.FromArgb(70, GeoColor.SimpleColors.Red), _reps.Count);

            Collection<GeoColor> colorsInQualityFamily = GeoColor.GetColorsInQualityFamily(GeoColor.FromArgb(50, GeoColor.SimpleColors.Red), _reps.Count);



            ValueStyle valueStyleRep = new ValueStyle();

            valueStyleRep.ColumnName = "SALEREP";

            int colorIx = 0;

            foreach (string s in _reps)

            {

                valueStyleRep.ValueItems.Add(new ValueItem(s, new AreaStyle(new GeoSolidBrush(colorsInQualityFamily[colorIx++]))));

            }



            shp_zip5 = (ShapeFileFeatureLayer)Application["ZIP5"];

            shp_zip5.IsVisible = true;

            shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();

            shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyleRep);

            shp_zip5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("SALEREP");

            shp_zip5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10;

            shp_zip5.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch);

            layerOverlay.Layers.Add("shp_zip5", shp_zip5);



            sb.Clear();

            sb.Append("<tr>Name:[#SALEREP#]</tr>");

            sb.Append("<tr>Zip :[#SALEREPZIP#]</tr>");

            inMemoryMarkerOverlay_rep_zip = new InMemoryMarkerOverlay("inMemoryMarkerOverlay_rep_zip");

            inMemoryMarkerOverlay_rep_zip.Name = "inMemoryMarkerOverlay_rep_zip";

            inMemoryMarkerOverlay_rep_zip.FeatureSource.Open();

            inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREP"));

            inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREPZIP"));

            inMemoryMarkerOverlay_rep_zip.FeatureSource.Close();

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.ContentHtml = new HtmlString(sb.ToString()).ToHtmlString();

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoPan = false;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoSize = false;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Height = 32;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Width = 200;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BackgroundColor = GeoColor.StandardColors.LightBlue;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.DarkBlue;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderWidth = 2;

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.WebImage = new WebImage("../../Img/person_generic.png", 24, 24);

            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;



            inMemoryMarkerOverlay_rep_zip.FeatureSource.Open();

            foreach (Feature f in (Collection<Feature>)Application["CENTERZIP5"])

            {

                if (_rep.ContainsKey(f.ColumnValues["ZCTA5CE10"]))

                {

                    string xx = _rep[f.ColumnValues["ZCTA5CE10"]];

                    if (f.ColumnValues.ContainsKey("SALEREP"))

                        f.ColumnValues["SALEREP"] = xx;

                    else

                        f.ColumnValues.Add("SALEREP", xx);



                    if (f.ColumnValues.ContainsKey("SALEREPZIP"))

                        f.ColumnValues["SALEREPZIP"] = f.ColumnValues["ZCTA5CE10"].ToString();

                    else

                        f.ColumnValues.Add("SALEREPZIP", f.ColumnValues["ZCTA5CE10"].ToString());



                }

                inMemoryMarkerOverlay_rep_zip.Features.Add(f.Id, f);

            }

            inMemoryMarkerOverlay_rep_zip.FeatureSource.Close();

            Map1.CustomOverlays.Add(inMemoryMarkerOverlay_rep_zip);

        }


 



Jean Marie, can you edit your post and repost your code?   
  
 It seems that something happened to the post and it’s very hard to read. 
  
 Thanks!

private void SHOW_REP_TERRITORY() 
         { 
             StringBuilder sb = new StringBuilder(); 
  
             layerOverlay = (LayerOverlay)Map1.CustomOverlays["layerOverlay"]; 
  
             #region Load reps geography 
             _rep = (Dictionary<string, string>)Application["REPPERZIP"]; 
             _reps = (List<string>)Application["REPS"]; 
             #endregion 
  
             try 
             { 
                 layerOverlay.Layers.Remove("shp_zip5"); 
             } 
             catch (System.Exception ex) 
             { } 
             try 
             { 
                 Map1.CustomOverlays.Remove("inMemoryMarkerOverlay_rep_zip"); 
             } 
             catch (System.Exception ex) 
             { } 
  
             Collection<GeoColor> colorsInHueFamily = GeoColor.GetColorsInHueFamily(GeoColor.FromArgb(70, GeoColor.SimpleColors.Red), _reps.Count); 
             Collection<GeoColor> colorsInQualityFamily = GeoColor.GetColorsInQualityFamily(GeoColor.FromArgb(50, GeoColor.SimpleColors.Red), _reps.Count); 
  
             ValueStyle valueStyleRep = new ValueStyle(); 
             valueStyleRep.ColumnName = "SALEREP"; 
             int colorIx = 0; 
             foreach (string s in _reps) 
             { 
                 valueStyleRep.ValueItems.Add(new ValueItem(s, new AreaStyle(new GeoSolidBrush(colorsInQualityFamily[colorIx++])))); 
             } 
  
             shp_zip5 = (ShapeFileFeatureLayer)Application["ZIP5"]; 
             shp_zip5.IsVisible = true; 
             shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear(); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyleRep); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("SALEREP"); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10; 
             shp_zip5.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch); 
             layerOverlay.Layers.Add("shp_zip5", shp_zip5); 
  
             sb.Clear(); 
             sb.Append("Name:[#SALEREP#]"); 
             sb.Append("Zip :[#SALEREPZIP#]"); 
             inMemoryMarkerOverlay_rep_zip = new InMemoryMarkerOverlay("inMemoryMarkerOverlay_rep_zip"); 
             inMemoryMarkerOverlay_rep_zip.Name = "inMemoryMarkerOverlay_rep_zip"; 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Open(); 
             inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREP")); 
             inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREPZIP")); 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Close(); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.ContentHtml = new HtmlString(sb.ToString()).ToHtmlString(); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoPan = false; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoSize = false; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Height = 32; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Width = 200; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BackgroundColor = GeoColor.StandardColors.LightBlue; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.DarkBlue; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderWidth = 2; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.WebImage = new WebImage("…/…/Img/person_generic.png", 24, 24); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Open(); 
             foreach (Feature f in (Collection<Feature>)Application["CENTERZIP5"]) 
             { 
                 if (_rep.ContainsKey(f.ColumnValues["ZCTA5CE10"])) 
                 { 
                     string xx = _rep[f.ColumnValues["ZCTA5CE10"]]; 
                     if (f.ColumnValues.ContainsKey("SALEREP")) 
                         f.ColumnValues["SALEREP"] = xx; 
                     else 
                         f.ColumnValues.Add("SALEREP", xx); 
  
                     if (f.ColumnValues.ContainsKey("SALEREPZIP")) 
                         f.ColumnValues["SALEREPZIP"] = f.ColumnValues["ZCTA5CE10"].ToString(); 
                     else 
                         f.ColumnValues.Add("SALEREPZIP", f.ColumnValues["ZCTA5CE10"].ToString()); 
  
                 } 
                 inMemoryMarkerOverlay_rep_zip.Features.Add(f.Id, f); 
             } 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Close(); 
             Map1.CustomOverlays.Add(inMemoryMarkerOverlay_rep_zip); 
         }

private void SHOW_REP_TERRITORY() 
         { 
             StringBuilder sb = new StringBuilder(); 
  
             layerOverlay = (LayerOverlay)Map1.CustomOverlays["layerOverlay"]; 
  
             #region Load reps geography 
             _rep = (Dictionary<string, string>)Application["REPPERZIP"]; 
             _reps = (List<string>)Application["REPS"]; 
             #endregion 
  
             try 
             { 
                 layerOverlay.Layers.Remove("shp_zip5"); 
             } 
             catch (System.Exception ex) 
             { } 
             try 
             { 
                 Map1.CustomOverlays.Remove("inMemoryMarkerOverlay_rep_zip"); 
             } 
             catch (System.Exception ex) 
             { } 
  
             Collection<GeoColor> colorsInHueFamily = GeoColor.GetColorsInHueFamily(GeoColor.FromArgb(70, GeoColor.SimpleColors.Red), _reps.Count); 
             Collection<GeoColor> colorsInQualityFamily = GeoColor.GetColorsInQualityFamily(GeoColor.FromArgb(50, GeoColor.SimpleColors.Red), _reps.Count); 
  
             ValueStyle valueStyleRep = new ValueStyle(); 
             valueStyleRep.ColumnName = "SALEREP"; 
             int colorIx = 0; 
             foreach (string s in _reps) 
             { 
                 valueStyleRep.ValueItems.Add(new ValueItem(s, new AreaStyle(new GeoSolidBrush(colorsInQualityFamily[colorIx++])))); 
             } 
  
             shp_zip5 = (ShapeFileFeatureLayer)Application["ZIP5"]; 
             shp_zip5.IsVisible = true; 
             shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear(); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyleRep); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("SALEREP"); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10; 
             shp_zip5.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch); 
             layerOverlay.Layers.Add("shp_zip5", shp_zip5); 
  
             sb.Clear(); 
             sb.Append("Name:[#SALEREP#]"); 
             sb.Append("Zip :[#SALEREPZIP#]"); 
             inMemoryMarkerOverlay_rep_zip = new InMemoryMarkerOverlay("inMemoryMarkerOverlay_rep_zip"); 
             inMemoryMarkerOverlay_rep_zip.Name = "inMemoryMarkerOverlay_rep_zip"; 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Open(); 
             inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREP")); 
             inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREPZIP")); 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Close(); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.ContentHtml = new HtmlString(sb.ToString()).ToHtmlString(); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoPan = false; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoSize = false; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Height = 32; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Width = 200; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BackgroundColor = GeoColor.StandardColors.LightBlue; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.DarkBlue; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderWidth = 2; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.WebImage = new WebImage("…/…/Img/person_generic.png", 24, 24); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Open(); 
             foreach (Feature f in (Collection<Feature>)Application["CENTERZIP5"]) 
             { 
                 if (_rep.ContainsKey(f.ColumnValues["ZCTA5CE10"])) 
                 { 
                     string xx = _rep[f.ColumnValues["ZCTA5CE10"]]; 
                     if (f.ColumnValues.ContainsKey("SALEREP")) 
                         f.ColumnValues["SALEREP"] = xx; 
                     else 
                         f.ColumnValues.Add("SALEREP", xx); 
  
                     if (f.ColumnValues.ContainsKey("SALEREPZIP")) 
                         f.ColumnValues["SALEREPZIP"] = f.ColumnValues["ZCTA5CE10"].ToString(); 
                     else 
                         f.ColumnValues.Add("SALEREPZIP", f.ColumnValues["ZCTA5CE10"].ToString()); 
  
                 } 
                 inMemoryMarkerOverlay_rep_zip.Features.Add(f.Id, f); 
             } 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Close(); 
             Map1.CustomOverlays.Add(inMemoryMarkerOverlay_rep_zip); 
         }

looks like that when I past my code there is something going on…   one more try!!! 
  
 private void SHOW_REP_TERRITORY() 
         { 
             StringBuilder sb = new StringBuilder(); 
  
             layerOverlay = (LayerOverlay)Map1.CustomOverlays["layerOverlay"]; 
  
             #region Load reps geography 
             _rep = (Dictionary<string, string>)Application["REPPERZIP"]; 
             _reps = (List<string>)Application["REPS"]; 
             #endregion 
  
             try 
             { 
                 layerOverlay.Layers.Remove("shp_zip5"); 
             } 
             catch (System.Exception ex) 
             { } 
             try 
             { 
                 Map1.CustomOverlays.Remove("inMemoryMarkerOverlay_rep_zip"); 
             } 
             catch (System.Exception ex) 
             { } 
  
             Collection<GeoColor> colorsInHueFamily = GeoColor.GetColorsInHueFamily(GeoColor.FromArgb(70, GeoColor.SimpleColors.Red), _reps.Count); 
             Collection<GeoColor> colorsInQualityFamily = GeoColor.GetColorsInQualityFamily(GeoColor.FromArgb(50, GeoColor.SimpleColors.Red), _reps.Count); 
  
             ValueStyle valueStyleRep = new ValueStyle(); 
             valueStyleRep.ColumnName = "SALEREP"; 
             int colorIx = 0; 
             foreach (string s in _reps) 
             { 
                 valueStyleRep.ValueItems.Add(new ValueItem(s, new AreaStyle(new GeoSolidBrush(colorsInQualityFamily[colorIx++])))); 
             } 
  
             shp_zip5 = (ShapeFileFeatureLayer)Application["ZIP5"]; 
             shp_zip5.IsVisible = true; 
             shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear(); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyleRep); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("SALEREP"); 
             shp_zip5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10; 
             shp_zip5.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch); 
             layerOverlay.Layers.Add("shp_zip5", shp_zip5); 
  
             sb.Clear(); 
             sb.Append("Name:[#SALEREP#]"); 
             sb.Append("Zip :[#SALEREPZIP#]"); 
             inMemoryMarkerOverlay_rep_zip = new InMemoryMarkerOverlay("inMemoryMarkerOverlay_rep_zip"); 
             inMemoryMarkerOverlay_rep_zip.Name = "inMemoryMarkerOverlay_rep_zip"; 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Open(); 
             inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREP")); 
             inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn("SALEREPZIP")); 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Close(); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.ContentHtml = new HtmlString(sb.ToString()).ToHtmlString(); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoPan = false; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoSize = false; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Height = 32; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Width = 200; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BackgroundColor = GeoColor.StandardColors.LightBlue; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.DarkBlue; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderWidth = 2; 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.WebImage = new WebImage("…/…/Img/person_generic.png", 24, 24); 
             inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Open(); 
             foreach (Feature f in (Collection<Feature>)Application["CENTERZIP5"]) 
             { 
                 if (_rep.ContainsKey(f.ColumnValues["ZCTA5CE10"])) 
                 { 
                     string xx = _rep[f.ColumnValues["ZCTA5CE10"]]; 
                     if (f.ColumnValues.ContainsKey("SALEREP")) 
                         f.ColumnValues["SALEREP"] = xx; 
                     else 
                         f.ColumnValues.Add("SALEREP", xx); 
  
                     if (f.ColumnValues.ContainsKey("SALEREPZIP")) 
                         f.ColumnValues["SALEREPZIP"] = f.ColumnValues["ZCTA5CE10"].ToString(); 
                     else 
                         f.ColumnValues.Add("SALEREPZIP", f.ColumnValues["ZCTA5CE10"].ToString()); 
  
                 } 
                 inMemoryMarkerOverlay_rep_zip.Features.Add(f.Id, f); 
             } 
             inMemoryMarkerOverlay_rep_zip.FeatureSource.Close(); 
             Map1.CustomOverlays.Add(inMemoryMarkerOverlay_rep_zip); 
         }


private void SHOW_REP_TERRITORY()
        {
            StringBuilder sb = new StringBuilder();

            layerOverlay = (LayerOverlay)Map1.CustomOverlays[“layerOverlay”];

            #region Load reps geography
            _rep = (Dictionary<string, string>)Application[“REPPERZIP”];
            _reps = (List<string>)Application[“REPS”];
            #endregion

            try
            {
                layerOverlay.Layers.Remove(“shp_zip5”);
            }
            catch (System.Exception ex)
            { }
            try
            {
                Map1.CustomOverlays.Remove(“inMemoryMarkerOverlay_rep_zip”);
            }
            catch (System.Exception ex)
            { }

            Collection<GeoColor> colorsInHueFamily = GeoColor.GetColorsInHueFamily(GeoColor.FromArgb(70, GeoColor.SimpleColors.Red), _reps.Count);
            Collection<GeoColor> colorsInQualityFamily = GeoColor.GetColorsInQualityFamily(GeoColor.FromArgb(50, GeoColor.SimpleColors.Red), _reps.Count);

            ValueStyle valueStyleRep = new ValueStyle();
            valueStyleRep.ColumnName = “SALEREP”;
            int colorIx = 0;
            foreach (string s in _reps)
            {
                valueStyleRep.ValueItems.Add(new ValueItem(s, new AreaStyle(new GeoSolidBrush(colorsInQualityFamily[colorIx++]))));
            }

            shp_zip5 = (ShapeFileFeatureLayer)Application[“ZIP5”];
            shp_zip5.IsVisible = true;
            shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
            shp_zip5.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyleRep);
            shp_zip5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add(“SALEREP”);
            shp_zip5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10;
            shp_zip5.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch);
            layerOverlay.Layers.Add(“shp_zip5”, shp_zip5);

            sb.Clear();
            sb.Append("<div style=‘font-size: x-small’><tr>Name:[#SALEREP#]</tr></div>");
            sb.Append("<div style=‘font-size: x-small’><tr>Zip :[#SALEREPZIP#]</tr></div>");
            inMemoryMarkerOverlay_rep_zip = new InMemoryMarkerOverlay(“inMemoryMarkerOverlay_rep_zip”);
            inMemoryMarkerOverlay_rep_zip.Name = “inMemoryMarkerOverlay_rep_zip”;
            inMemoryMarkerOverlay_rep_zip.FeatureSource.Open();
            inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn(“SALEREP”));
            inMemoryMarkerOverlay_rep_zip.Columns.Add(new FeatureSourceColumn(“SALEREPZIP”));
            inMemoryMarkerOverlay_rep_zip.FeatureSource.Close();
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.ContentHtml = new HtmlString(sb.ToString()).ToHtmlString();
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoPan = false;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.AutoSize = false;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Height = 32;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.Width = 200;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BackgroundColor = GeoColor.StandardColors.LightBlue;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.DarkBlue;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.Popup.BorderWidth = 2;
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.DefaultMarkerStyle.WebImage = new WebImage("…/…/Img/person_generic.png", 24, 24);
            inMemoryMarkerOverlay_rep_zip.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            inMemoryMarkerOverlay_rep_zip.FeatureSource.Open();
            foreach (Feature f in (Collection<Feature>)Application[“CENTERZIP5”])
            {
                if (_rep.ContainsKey(f.ColumnValues[“ZCTA5CE10”]))
                {
                    string xx = _rep[f.ColumnValues[“ZCTA5CE10”]];
                    if (f.ColumnValues.ContainsKey(“SALEREP”))
                        f.ColumnValues[“SALEREP”] = xx;
                    else
                        f.ColumnValues.Add(“SALEREP”, xx);

                    if (f.ColumnValues.ContainsKey(“SALEREPZIP”))
                        f.ColumnValues[“SALEREPZIP”] = f.ColumnValues[“ZCTA5CE10”].ToString();
                    else
                        f.ColumnValues.Add(“SALEREPZIP”, f.ColumnValues[“ZCTA5CE10”].ToString());

                }
                inMemoryMarkerOverlay_rep_zip.Features.Add(f.Id, f);
            }
            inMemoryMarkerOverlay_rep_zip.FeatureSource.Close();
            Map1.CustomOverlays.Add(inMemoryMarkerOverlay_rep_zip);
        }

 


another function invoked. 
  
 
  void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)
        {
            if (e.ColumnName == "STATEMNGR")
            {
                ShapeFileFeatureSource fs = (ShapeFileFeatureSource)sender;
                Feature f = fs.GetFeatureById(e.Id, new string[] { "STUSPS10" });
                if (f != null)
                {
                    if (_mngr.ContainsKey(f.ColumnValues["STUSPS10"]))
                        e.ColumnValue = _mngr[f.ColumnValues["STUSPS10"]];
                }
            }
            if (e.ColumnName == "SALEREP")
            {
                ShapeFileFeatureSource fs = (ShapeFileFeatureSource)sender;
                Feature f = fs.GetFeatureById(e.Id, new string[] { "ZCTA5CE10" });
                if (f != null)
                {
                    if (_rep.ContainsKey(f.ColumnValues["ZCTA5CE10"]))
                        e.ColumnValue = _rep[f.ColumnValues["ZCTA5CE10"]];
                }
            }
        }
 


Thanks for updating the code that makes it much easier to see what is going on. 
  
 After reviewing the code I see one improvement that I think will speed things up a bunch. 
  
 I see in your CustomColumnFetch routine you are querying the FeatureSource using fs.GetFeatureById.  Since the CustomColumnFetch Routine get’s called for each feature in the shapefile that is being rendered, we want to minimize as much execution in this routine as possible. Instead of calling the fs.GetFeatureByID method each time in the Custom Column fetch routine what I would recommend is setting up a hash table  or some other object of your choice on the page load or application load that contains the feature id and the custom column value so all of that information is stored in memory.  This way when the custom column fetch is called you can access your object in memory to retrieve the value instead of querying the feature source over and over again. 
  
 This approach should speed things up dramatically.  Let me know if you have any questions about this approach and I will do by best to answer them. 
  
 Thanks! 
  
  
  
  
  
  


Hi Clint 
  
 Thanks a lot for your quick answer!   However, I need to know what is the zip code coming from the shapefile and then use it  as a key to add my custom data …   
  
 jm 


Jean Marie, 
  
 Thanks for your reply. 
  
 Maybe I’m not fully understanding what you are wanting to do so let’s take a step back with a few questions: 
  
 1. So how are you wanting to colorize your zipcodes?  What type of logic are you wanting to decide the color for example do you want the colors to be random do you want them colored based on a sales amount? 
  
 2. Where is your custom data coming from that you are setting in the custom column fetch, in looking at your code it looks like you are just copying one value from one column in your shapefile to a new custom column value.  If this is the case why don’t you just use the existing column data an not bother with the custom column data? 
  
 The custom column data is typically used to join data from an outside data source like a sales database to the shapefile at runtime.  For example if I had a database that had all the sales totals for each zip code in the USA I could use the custom column data method to bind these sales figures in real time to the map and color the zip codes accordingly so I know which zip codes have the highest amount of sales. 
  
 I think once I have a better understanding of what you are wanting to accomplish we can get a solution that performs well. 
  
 Thanks! 
  


In fact each of our sales reps is responsible for a number of ZIP5 code then the goal is to colorize the map using one color per rep.  The only way that I have found works well but take too long to build…  the custom column fetch populate the SALREP column with the name of the sales rep based on the ZIP code of the incoming feature(the one processed by the column fetch).  Of course one ValueStyle has been customized for each rep and then added as a CustomStyle to the layer.  To make a long story short I need to get the ZIP5 code from the processed feature and then to use it to retrieve the Sales rep name and when done I populate the new column with the name. 
  
 thanks. 
  
 jm    


looking at my code you should see that I am using the ZCTA5CE10 column to retrieve a value from my "_rep" table.

I have also another question and it could be nice if you could advice me on how to take  let say a number of ZIP5 shapes belonging to the same sales rep and then finding the centroid of the new shape made of ZIP5 shapes?

back to my initial problem, could you tell me why when let say we get a collection of features from a shape file each feature is having an f.Id of 2f1658f5-f601-46d8-baf6-1839d68294eb… and then when inside the column fetch the f.Id is something like 123 or 245, …  a number defined as string???  if I had the same f.Id I could use it as a key to get the ZIP code in relationship… then when I have the ZIP code I can used it to get the sales rep… 
  
 thanks.

Thanks Jean Marie, I understand what you want to accomplish now and I’m working on a quick little code sample to prove out my theory.  I will update this thread once I have it completed. 
  
 Thanks

I think that I didn’t know that when no id has been  provided for a feature a default id is created!

Jeaan Marie,


To show what I meant in my earlier post I have modified the "AddMyOwnCustomDataToFeatureLayer" sample in tthe Feature Layers Section of the How Do I Sample Apps to use my proposed approach.


You can see how it works by making the following changes to this sample application:


In the page_Load add the following cod block after you add your last overlay to the Map:



                //Build up Custom Data Ahead of Time.
                Hashtable customData = new Hashtable();
                worldLayer.Open();
                foreach (Feature f in worldLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns))
                {
                    //Put you business Logic here to set what value you want so you can use it later to color your feature.
                    //For example purposes I'm going to asssing all countries with an area of 300,000 KM to John and all others to Bob
                    string RepName;
                    if (Convert.ToDouble(f.ColumnValues["SQKM"].ToString()) > 300000)
                    {
                        RepName = "John";
                    }
                    else
                    {
                        RepName = "BOB";
                    }

                    //Add your custom data to the hash table
                    customData.Add(f.Id, RepName);
                }
                //Put the hastable into the session so it can be accesssed later in the Custom Column Fetch
                Session["CustomData"] = customData;


This code will get all your data ready upfront and cut down the performance hit you are taking on the custom column fetch dramatically.

Next modify the CustomColumnFetch routine in the sample to retrieve the already populated custom data hashtable:


        void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)
        {
            Hashtable customData = (Hashtable)Session["CustomData"];
            e.ColumnValue = customData[e.Id].ToString();
        }   


Let me know how this approach works for you.

Thanks!

 


 


 


 



Jean Marie, 
  
 To answer your second question about to take several Zip5 shapes join them together and get the new center point, here is what I would do. 
  
 1. Query your Zip Layer using the GetFeaturesByColumnValue method referencing your new custom column of RepName and by passing in the rep you want to process. 
  
 2. Once you get all the features back, loop through each one and use the Union meothod off of the AreaBaseShape to union all of the shapes together.  This will give you one giant shape made up of the combination of all the zip codes. 
  
 3. Once you have your new shape Use the GetCenterPoint Method to return your center point. 
  
 Hope this helps. 
  
 Thanks! 
  


Thanks!   I was able to find a solution looking like yours!   I have better performance now but still have to wait when zoomin or zoomout!!!!   Anything that I could do to make this thing more responsive?


my fetch column now:


 void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)

        {

            switch (e.ColumnName)

            {

                case "STATEMNGR":

                    ShapeFileFeatureSource fs = (ShapeFileFeatureSource)sender;

                    Feature f = fs.GetFeatureById(e.Id, new string[] { "STUSPS10" });

                    if (f != null)

                    {

                        if (_mngr.ContainsKey(f.ColumnValues["STUSPS10"]))

                            e.ColumnValue = _mngr[f.ColumnValues["STUSPS10"]];

                    }

                    break;



                case "SALEREP":

                    try

                    {

                        e.ColumnValue = _rep[_ZIP5Features[e.Id].ToString()];

                    }

                    catch

                    {}

                    break;



                default:

                    break;

            }

        }




Jean Marie, in looking at your screen shot it’s probably going to take quite a bit of time to render all of the zip codes for the USA at that zoom level so I’m not sure there is much we can do if you need to render that layer in realtime.    
  
 If you custom data doesn’t change very option you could cache that overlay for the top several zoom levels and then it would load quickly after the first time. 
  
 Hope this helps. 
  
 Thanks!