Since adding in my styling code into the generator, it keeps crashing with:
"An unhandled exception of type ‘System.IndexOutOfRangeException’ occurred in MapSuiteCore.dll
Additional information: Index was outside the bounds of the array."
It seems it is fine if I use one of the Line or Area styles, but when I’m using my custom styles it will crash the cache generator when calling layer.Draw(canvas, new Collection<SimpleCandidate()) in the DrawOnBitmap() function in the TileCacheGenerator.cs file.
The styles work perfectly when I’m using it in my program. Only the cache generator tool seem to have issues with it. Any ideas on what may cause this?
Cache Generator Crash
Hi Jonci,
You said when you using your custom style that exception thrown, so that should related with how you write your custom style.
For help you quickly, could you please upload a simple sample, we can view your code and debug to trace the reason.
Regards,
Don
Sample code below. I can’t provide the data files used, however.
publicstaticCollection<Layer> GetLayersToCache(){Collection<Layer> layersToCache =newCollection<Layer>();ShapeFileFeatureLayer layer;layer =newShapeFileFeatureLayer(@“C:\ThinkGeoFiles\62 Circles Green.shp”, ShapeFileReadWriteMode.ReadOnly);ApplyStyle(layer);layersToCache.Add(layer);…returnlayersToCache;}/// <summary>/// Returns the ZoomLevel reference based on int value passed in/// </summary>privatestaticZoomLevel GetZoomLevelByNumber(ShapeFileFeatureLayer layer,intzoomLevel){Collection<ZoomLevel> levels = layer.ZoomLevelSet.GetZoomLevels();if(zoomLevel >= 1 && zoomLevel <= 20)returnlevels[zoomLevel - 1];returnnull;}
privatestaticvoidApplyStyle(ShapeFileFeatureLayer layer){ApplyStyle(layer, 1, ApplyUntilZoomLevel.Level03, -1, ApplyUntilZoomLevel.Level04, -1, ApplyUntilZoomLevel.Level08);}/// <summary>/// Sets up for 3 scale styles (high, medium, low), due to lines not scaling for zoom./// </summary>privatestaticvoidApplyStyle(ShapeFileFeatureLayer layer,inthighApplyFrom, ApplyUntilZoomLevel highApplyTo,intmedApplyFrom, ApplyUntilZoomLevel medApplyTo,intlowApplyFrom, ApplyUntilZoomLevel lowApplyTo){CopyZoomLevelsFromMap(layer);ShapeFileFeatureLayer.BuildIndexFile(layer.ShapePathFileName, BuildIndexMode.DoNotRebuild);layer.Open();ShapeFileType type = layer.GetShapeFileType();layer.Close();if(type == ShapeFileType.Polygon)ApplyHTMLAreaStyle(layer, GetZoomLevelByNumber(layer, highApplyFrom), lowApplyTo);// Just apply from high to low, because polygons scale properly.elseif(type == ShapeFileType.Polyline)ApplyHTMLLineStyle(layer, GetZoomLevelByNumber(layer, highApplyFrom), highApplyTo, GetZoomLevelByNumber(layer, medApplyFrom), medApplyTo, GetZoomLevelByNumber(layer, lowApplyFrom), lowApplyTo);elseif(type == ShapeFileType.Point){layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;}}///////////////////// Custom style classesclassHTMLAreaStyle : AreaStyle{protectedoverridevoidDrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers){doublecustomWidth = 0;intcustomOpacity = 0;GeoColor customColor;stringhtml;foreach(Feature featureinfeatures){html = feature.ColumnValues[“HTML”];if(html.StartsWith("##"))html = html.Remove(0, 1);if(html[0] !=‘#’)html =“#”+ html;customWidth = Convert.ToDouble(feature.ColumnValues["#StrokeWei"]);customOpacity = (int)(Convert.ToInt32(feature.ColumnValues["#Opacity"]) * 2.55);customColor = GeoColor.FromHtml(html);canvas.DrawArea(feature,this.OutlinePen,newGeoSolidBrush(GeoColor.FromArgb(customOpacity, customColor)), DrawingLevel.LevelOne,this.XOffsetInPixel,this.YOffsetInPixel,this.PenBrushDrawingOrder);}}}classHTMLLineStyle : LineStyle{protectedintm_ScaleValue = 1;protectedoverridevoidDrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers){doublecustomWidth = 0;intcustomOpacity = 0;GeoColor customColor;stringhtml;foreach(Feature featureinfeatures){html = feature.ColumnValues[“HTML”];if(html.StartsWith("##"))html = html.Remove(0, 1);if(html[0] !=‘#’)html =“#”+ html;customWidth = Convert.ToDouble(feature.ColumnValues["#StrokeWei"]) * m_ScaleValue;customOpacity = (int)(Convert.ToInt32(feature.ColumnValues["#Opacity"]) * 2.55);customColor = GeoColor.FromHtml(html);canvas.DrawLine(feature,newGeoPen(GeoColor.FromArgb(customOpacity, customColor), (float)customWidth), DrawingLevel.LevelOne);}}}classHTMLLineStyleMed : HTMLLineStyle{publicHTMLLineStyleMed() :base() { m_ScaleValue = 5; }}classHTMLLineStyleLow : HTMLLineStyle{publicHTMLLineStyleLow() :base() { m_ScaleValue = 10; }}
Hi Jonci,
Thanks for your codes, but seems there still are three methods missing: CopyZoomLevelsFromMap, ApplyHTMLAreaStyle and ApplyHTMLLineStyle.
I have reviewed your codes and not sure but just guess the issue might be related the zoom level applying which might be not matched. In order to debug it, We need to the missing methods or a sample can recreate the exception.
I just guess if our shape file "Countries02.shp" or any attached shape files in the installation folder can still recreate your issue?
Thanks,
Troy
publicstaticCollection<double> GetScalesToCache(){ZoomLevelSet zls =newZoomLevelSet();
Collection<double> scalesToCache =newCollection<double>();
zls.ZoomLevel01.Scale = 576749.794921875;zls.ZoomLevel02.Scale = 288374.8974609375;zls.ZoomLevel03.Scale = 72093.7243652344;zls.ZoomLevel04.Scale = 18023.43;zls.ZoomLevel05.Scale = 4505.85;zls.ZoomLevel06.Scale = 1126.46;zls.ZoomLevel07.Scale = 281.61;zls.ZoomLevel08.Scale = 100;zls.ZoomLevel09.Scale = 10;zls.ZoomLevel10.Scale = 0;zls.ZoomLevel11.Scale = 0;zls.ZoomLevel12.Scale = 0;zls.ZoomLevel13.Scale = 0;zls.ZoomLevel14.Scale = 0;zls.ZoomLevel15.Scale = 0;zls.ZoomLevel16.Scale = 0;zls.ZoomLevel17.Scale = 0;zls.ZoomLevel18.Scale = 0;zls.ZoomLevel19.Scale = 0;zls.ZoomLevel20.Scale = 0;
scalesToCache.Add(zls.ZoomLevel01.Scale);scalesToCache.Add(zls.ZoomLevel02.Scale);scalesToCache.Add(zls.ZoomLevel03.Scale);scalesToCache.Add(zls.ZoomLevel04.Scale);scalesToCache.Add(zls.ZoomLevel05.Scale);scalesToCache.Add(zls.ZoomLevel06.Scale);scalesToCache.Add(zls.ZoomLevel07.Scale);scalesToCache.Add(zls.ZoomLevel08.Scale);scalesToCache.Add(zls.ZoomLevel09.Scale);scalesToCache.Add(zls.ZoomLevel10.Scale);scalesToCache.Add(zls.ZoomLevel11.Scale);scalesToCache.Add(zls.ZoomLevel12.Scale);scalesToCache.Add(zls.ZoomLevel13.Scale);scalesToCache.Add(zls.ZoomLevel14.Scale);scalesToCache.Add(zls.ZoomLevel15.Scale);scalesToCache.Add(zls.ZoomLevel16.Scale);scalesToCache.Add(zls.ZoomLevel17.Scale);scalesToCache.Add(zls.ZoomLevel18.Scale);scalesToCache.Add(zls.ZoomLevel19.Scale);scalesToCache.Add(zls.ZoomLevel20.Scale);
returnscalesToCache;}
/// <summary>/// Default style setting call/// </summary>privatestaticvoidApplyStyle(ShapeFileFeatureLayer layer){ApplyStyle(layer, 1, ApplyUntilZoomLevel.Level03, -1, ApplyUntilZoomLevel.Level04, -1, ApplyUntilZoomLevel.Level08);}/// <summary>/// Sets up for 3 scale styles (high, medium, low), due to lines not scaling for zoom./// </summary>privatestaticvoidApplyStyle(ShapeFileFeatureLayer layer,inthighApplyFrom, ApplyUntilZoomLevel highApplyTo,intmedApplyFrom, ApplyUntilZoomLevel medApplyTo,intlowApplyFrom, ApplyUntilZoomLevel lowApplyTo){CopyZoomLevelsFromMap(layer);ShapeFileFeatureLayer.BuildIndexFile(layer.ShapePathFileName, BuildIndexMode.DoNotRebuild);
layer.Open();ShapeFileType type = layer.GetShapeFileType();layer.Close();if(type == ShapeFileType.Polygon)ApplyHTMLAreaStyle(layer, GetZoomLevelByNumber(layer, highApplyFrom), lowApplyTo);// Just apply from high to low, because polygons scale properly.elseif(type == ShapeFileType.Polyline)ApplyHTMLLineStyle(layer, GetZoomLevelByNumber(layer, highApplyFrom), highApplyTo, GetZoomLevelByNumber(layer, medApplyFrom), medApplyTo, GetZoomLevelByNumber(layer, lowApplyFrom), lowApplyTo);elseif(type == ShapeFileType.Point){layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;}}
/// <summary>/// Grabs the Map's set zoomlevels and applies them to layer passed in/// </summary>privatestaticvoidCopyZoomLevelsFromMap(ShapeFileFeatureLayer layer){ZoomLevelSet zls =newZoomLevelSet();Collection<double> scales = GetScalesToCache();zls.ZoomLevel01.Scale = scales[0];zls.ZoomLevel02.Scale = scales[1];zls.ZoomLevel03.Scale = scales[2];zls.ZoomLevel04.Scale = scales[3];zls.ZoomLevel05.Scale = scales[4];zls.ZoomLevel06.Scale = scales[5];zls.ZoomLevel07.Scale = scales[6];zls.ZoomLevel08.Scale = scales[7];zls.ZoomLevel09.Scale = scales[8];zls.ZoomLevel10.Scale = scales[9];zls.ZoomLevel11.Scale = scales[10];zls.ZoomLevel12.Scale = scales[11];zls.ZoomLevel13.Scale = scales[12];zls.ZoomLevel14.Scale = scales[13];zls.ZoomLevel15.Scale = scales[14];zls.ZoomLevel16.Scale = scales[15];zls.ZoomLevel17.Scale = scales[16];zls.ZoomLevel18.Scale = scales[17];zls.ZoomLevel19.Scale = scales[18];zls.ZoomLevel20.Scale = scales[19];layer.ZoomLevelSet = zls;}
/// <summary>/// Returns the ZoomLevel reference based on int value passed in/// </summary>privatestaticZoomLevel GetZoomLevelByNumber(ShapeFileFeatureLayer layer,intzoomLevel){Collection<ZoomLevel> levels = layer.ZoomLevelSet.GetZoomLevels();if(zoomLevel >= 1 && zoomLevel <= 20)returnlevels[zoomLevel - 1];returnnull;}
privatestaticvoidApplyHTMLAreaStyle(ShapeFileFeatureLayer layer, ZoomLevel applyFrom, ApplyUntilZoomLevel applyTo){if(applyFrom !=null){HTMLAreaStyle areaStyle =newHTMLAreaStyle();areaStyle.RequiredColumnNames.Add("HTML");areaStyle.RequiredColumnNames.Add("#StrokeWei");areaStyle.RequiredColumnNames.Add("#Opacity");applyFrom.CustomStyles.Add(areaStyle);applyFrom.ApplyUntilZoomLevel = applyTo;}}
privatestaticvoidApplyHTMLLineStyle(ShapeFileFeatureLayer layer, ZoomLevel highApplyFrom, ApplyUntilZoomLevel highApplyTo, ZoomLevel medApplyFrom, ApplyUntilZoomLevel medApplyTo, ZoomLevel lowApplyFrom, ApplyUntilZoomLevel lowApplyTo){// High levelif(highApplyFrom !=null){HTMLLineStyle lineStyle =newHTMLLineStyle();lineStyle.RequiredColumnNames.Add("HTML");lineStyle.RequiredColumnNames.Add("#StrokeWei");lineStyle.RequiredColumnNames.Add("#Opacity");
highApplyFrom.CustomStyles.Add(lineStyle);highApplyFrom.ApplyUntilZoomLevel = highApplyTo;}// Med levelif(medApplyFrom !=null){HTMLLineStyleMed lineStyleMed =newHTMLLineStyleMed();lineStyleMed.RequiredColumnNames.Add("HTML");lineStyleMed.RequiredColumnNames.Add("#StrokeWei");lineStyleMed.RequiredColumnNames.Add("#Opacity");
medApplyFrom.CustomStyles.Add(lineStyleMed);medApplyFrom.ApplyUntilZoomLevel = medApplyTo;}// Low levelif(lowApplyFrom !=null){HTMLLineStyleLow lineStyleLow =newHTMLLineStyleLow();lineStyleLow.RequiredColumnNames.Add("HTML");lineStyleLow.RequiredColumnNames.Add("#StrokeWei");lineStyleLow.RequiredColumnNames.Add("#Opacity");
lowApplyFrom.CustomStyles.Add(lineStyleLow);lowApplyFrom.ApplyUntilZoomLevel = lowApplyTo;}}
classHTMLAreaStyle : AreaStyle{protectedoverridevoidDrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers){doublecustomWidth = 0;intcustomOpacity = 0;GeoColor customColor;stringhtml;foreach(Feature featureinfeatures){html = feature.ColumnValues["HTML"];if(html.StartsWith("##"))html = html.Remove(0, 1);if(html[0] !='#')html ="#"+ html;customWidth = Convert.ToDouble(feature.ColumnValues["#StrokeWei"]);customOpacity = (int)(Convert.ToInt32(feature.ColumnValues["#Opacity"]) * 2.55);customColor = GeoColor.FromHtml(html);canvas.DrawArea(feature,this.OutlinePen,newGeoSolidBrush(GeoColor.FromArgb(customOpacity, customColor)), DrawingLevel.LevelOne,this.XOffsetInPixel,this.YOffsetInPixel,this.PenBrushDrawingOrder);}}}
classHTMLLineStyle : LineStyle{protectedintm_ScaleValue = 1;protectedoverridevoidDrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers){doublecustomWidth = 0;intcustomOpacity = 0;GeoColor customColor;stringhtml;foreach(Feature featureinfeatures){html = feature.ColumnValues["HTML"];if(html.StartsWith("##"))html = html.Remove(0, 1);if(html[0] !='#')html ="#"+ html;customWidth = Convert.ToDouble(feature.ColumnValues["#StrokeWei"]) * m_ScaleValue;customOpacity = (int)(Convert.ToInt32(feature.ColumnValues["#Opacity"]) * 2.55);customColor = GeoColor.FromHtml(html);
canvas.DrawLine(feature,newGeoPen(GeoColor.FromArgb(customOpacity, customColor), (float)customWidth), DrawingLevel.LevelOne);}}}classHTMLLineStyleMed : HTMLLineStyle{publicHTMLLineStyleMed() :base() { m_ScaleValue = 5; }}classHTMLLineStyleLow : HTMLLineStyle{publicHTMLLineStyleLow() :base() { m_ScaleValue = 10; }}
Hi Jonci,
Sorry I still can’t recreate your issue with our existing shape files. I guess here are some ways you might try:
1. Send us the shape file to debug if possible. if the file size is too large, please send to forumsupport@thinkgeo.com
2. Comment out the DrawCore method of HTMLLineStyle and HTMLAreaStyle one by one to see if this part result to the issue.
3. Can you comparing with your program which works fine with the styles to see what’s the differences between it and the generator code? such as the scales and each zoomlevel styles you apply to.
Waiting for your further information.
Regards,
Troy