Hi Don,
I had some time to explore the issue further and was able to replicate the issue with the sample project you sent me. I will include the code below. For your information, I am primarily using Google Chrome. Whenever I run the project and the issue occurs I receive the "Failed to load resource: the server responded with a status of 500 ()" with the link being "adornment_GeoResource.axd". I select the missing reference and in a new tab the message appears "GeoImage's native image cannot be null." The times when this issue occurs for us is with the Adornment Overlay, MapShapesLayer added to a LayerOverlay, and Features being added to a FeatureOverlay then transferred to the HighlightOverlay. I am wondering if it has something to do with the custom styles or the zoom styling because we apply styling to each of the objects above. Anyway, we need to be using StateServer for the project. Any help will be greatly appreciated.
Here is the code, it's not pretty but it gets the job done. All Thinkgeo Packages are version 10.1.0
Default.aspx.cs
using System;
using ThinkGeo.MapSuite;
using ThinkGeo.MapSuite.Layers;
using ThinkGeo.MapSuite.Styles;
using ThinkGeo.MapSuite.WebForms;
using ThinkGeo.MapSuite.Shapes;
using ThinkGeo.MapSuite.Drawing;
using System.IO;
using System.Drawing;
namespace Test
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
// Set the Map Unit. The reason for setting it to DecimalDegrees is that is what the shapefile’s unit of measure is inherently in.
Map1.MapUnit = GeographyUnit.DecimalDegree;
LayerOverlay layerOverlay = new LayerOverlay();
//1. Uncomment this out to show the project working with StateServer
///////////////////// Shows the layer working with StateServer////////////////////////////////////
//ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(MapPath(@"App_Data\states.shp"));
//shapeFileLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = WorldStreetsAreaStyles.Military();
//shapeFileLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
//////////////////////////////////////////////////////////////////////////////////////////////////
//2. Uncomment this out to show the project not working with StateServer
///////////////////// Shows the layer not working with StateServer////////////////////////////////
ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(MapPath(@"App_Data\states.shp"), MapPath(@"App_Data\states.idx"), GeoFileReadWriteMode.Read, System.Text.Encoding.Default);
shapeFileLayer.Name = "Rivers";
ZoomLevel objZoom = shapeFileLayer.ZoomLevelSet.ZoomLevel01;
objZoom.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LineStyle objStyle = default(LineStyle);
objStyle = new LineStyle(new GeoPen(GeoColor.FromArgb(100, GeoColor.StandardColors.DarkBlue)));
objZoom.CustomStyles.Add(objStyle);
objZoom.CustomStyles.Add(GetHaloLabelRender(6.5F, "FULLNAME", GeoColor.StandardColors.DarkBlue));
//-- Add layer to map
shapeFileLayer.ZoomLevelSet.CustomZoomLevels.Add(objZoom);
//shapeFileLayer.FeatureSource.Projection = mobjGIS.GetProjection(strFile);
//objOverlay.Layers.Add(shapeFileLayer);
//////////////////////////////////////////////////////////////////////////////////////////////////
layerOverlay.Layers.Add(shapeFileLayer);
InMemoryFeatureLayer imf = new InMemoryFeatureLayer();
imf.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
imf.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
imf.InternalFeatures.Add(new Feature(new RectangleShape(-100, 50, -80, 30)));
layerOverlay.Layers.Add(imf);
LegendAdornmentLayer objLegend = BuildLegend(ref Map1, ref layerOverlay);
Map1.AdornmentOverlay.Layers.Add("LegendLayer", objLegend);
Map1.CustomOverlays.Add(layerOverlay);
//shapeFileLayer.Open();
//Map1.CurrentExtent = shapeFileLayer.GetBoundingBox();
Map1.CurrentExtent = new RectangleShape(-178.215027, 71.406647, -66.969849, 18.924782);
}
}
catch (Exception ex)
{
}
}
private TextStyle GetHaloLabelRender(float FontWidth, string strRenderField, GeoColor TextColor, bool blnOnTop = false)
{
if (blnOnTop == true)
{
return TextStyles.CreateSimpleTextStyle(strRenderField, "Arial", FontWidth, DrawingFontStyles.Bold, TextColor, GeoColor.StandardColors.White, 3, 10, 10);
}
else
{
return TextStyles.CreateSimpleTextStyle(strRenderField, "Arial", FontWidth, DrawingFontStyles.Bold, TextColor, GeoColor.StandardColors.White, 3, -10, -10);
}
}
public LegendAdornmentLayer BuildLegend(ref Map objMap, ref LayerOverlay objLayersOverlay, RectangleShape objExtent = null, double dblWidth = 0, GeographyUnit objUnit = GeographyUnit.Unknown, string strLegLocationIndex = "")
{
try
{
//Building the Adornament layer details.
LegendItem objTitle = new LegendItem();
objTitle.TextStyle = new TextStyle("Map Legend", new GeoFont("Arial", 11, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
LegendAdornmentLayer objLegend = new LegendAdornmentLayer();
AdornmentLocation objLocation = AdornmentLocation.LowerLeft;
if (strLegLocationIndex != "")
{
objLocation = AdornmentLocation.CenterLeft;
if (objLocation == AdornmentLocation.UseOffsets) return null; //Basically acts like there was a problem.
if (objLocation.ToString().ToUpper().Contains("RIGHT"))
objLegend.XOffsetInPixel = -5;
else if (objLocation.ToString().ToUpper().Contains("LEFT"))
objLegend.XOffsetInPixel = 5;
else
objLegend.XOffsetInPixel = 0;
if (objLocation.ToString().ToUpper().Contains("UPPER"))
objLegend.YOffsetInPixel = 5;
else if (objLocation.ToString().ToUpper().Contains("LOWER"))
if (objLocation.ToString().ToUpper().Contains("LEFT"))
objLegend.YOffsetInPixel = -17;
else
objLegend.YOffsetInPixel = -5;
else
objLegend.YOffsetInPixel = 0;
}
else //Default is Lower Left
{
objLegend.XOffsetInPixel = 5;
objLegend.YOffsetInPixel = -17;
}
objLegend.Location = objLocation;
objLegend.BackgroundMask = AreaStyles.CreateLinearGradientStyle(new GeoColor(255, 255, 255, 255), new GeoColor(255, 230, 230, 230), 90, GeoColor.SimpleColors.Black);
objLegend.Title = objTitle;
objLegend.Transparency = 220F;
double dblMapScale = 0;
if ((objExtent == null) == false)
{
dblMapScale = objMap.ZoomLevelSet.GetZoomLevel(objExtent, dblWidth, objUnit, 96).Scale;
}
foreach (Layer objLayer in objLayersOverlay.Layers)
{
if (typeof(ShapeFileFeatureLayer) == objLayer.GetType())
{
ShapeFileFeatureLayer objFLayer = (ShapeFileFeatureLayer)objLayer;
ZoomLevel objZoom = null;
int intZoom = 0;
if (objFLayer.ZoomLevelSet.CustomZoomLevels.Count != 0)
{
if (objFLayer.ZoomLevelSet.CustomZoomLevels.Count > 1)
{
for (intZoom = 0; intZoom <= objFLayer.ZoomLevelSet.CustomZoomLevels.Count - 1; intZoom++)
{
objZoom = objFLayer.ZoomLevelSet.CustomZoomLevels[intZoom];
if (objZoom.Scale >= dblMapScale)
{
break; // TODO: might not be correct. Was : Exit For
}
}
}
else
{
objZoom = objFLayer.ZoomLevelSet.CustomZoomLevels[0];
}
//Too
foreach (ThinkGeo.MapSuite.Styles.Style objCustomStyle in objZoom.CustomStyles)
{
string strVName = "";
string strfilepath = "";
GeoImage objImage = new GeoImage();
PointStyle objStyleImg = new PointStyle();
LegendItem objLegendItem = new LegendItem();
if ((objCustomStyle is ValueStyle) == true)
{
if (objLayer.IsVisible == true)
{
GeoImage objGeoNull = null;
objLegendItem = BuildLegendItem(objLayer.Name, objGeoNull, 0, false);
objLegend.LegendItems.Add(objLegendItem);
ValueStyle objValueR = (ValueStyle)objCustomStyle;
foreach (ValueItem objValue in objValueR.ValueItems)
{
if (objValue.CustomStyles[0].Name.Length == 0)
{
strVName = objValue.Value;
}
else
{
strVName = objValue.CustomStyles[0].Name;
}
//This is set in the render code to hide value render items in needed
if (strVName != "NOLEGENDITEM")
{
GeoImage objGeoImage = new GeoImage();
foreach (ThinkGeo.MapSuite.Styles.Style objStyle in objValue.CustomStyles)
{
if (objStyle is TextStyle == false)
{
objGeoImage = SaveStyleImage(objStyle);
}
}
objLegendItem = BuildLegendItem(strVName, objGeoImage, 35);
objLegend.LegendItems.Add(objLegendItem);
}
}
}
}
else if ((objCustomStyle is ClassBreakStyle) == true)
{
ClassBreakStyle objValueR = (ClassBreakStyle)objCustomStyle;
//ClassBreak objValue = default(ClassBreak);
strVName = "";
if (objLayer.IsVisible == true)
{
GeoImage objGeoNull = null;
objLegendItem = BuildLegendItem(objLayer.Name, objGeoNull, 0, false);
objLegend.LegendItems.Add(objLegendItem);
foreach (ClassBreak objValue in objValueR.ClassBreaks)
{
if (objValue.CustomStyles[0].Name.Length == 0)
{
strVName = objValue.Value.ToString();
}
else
{
strVName = objValue.CustomStyles[0].Name;
}
GeoImage objGeoImage = new GeoImage();
foreach (ThinkGeo.MapSuite.Styles.Style objStyle in objValue.CustomStyles)
{
if (objStyle is TextStyle == false)
{
objGeoImage = SaveStyleImage(objStyle);
}
}
objLegendItem = BuildLegendItem(strVName, objGeoImage, 35);
objLegend.LegendItems.Add(objLegendItem);
}
}
}
else
{
if ((objCustomStyle is TextStyle) == false)
{
foreach (ThinkGeo.MapSuite.Styles.Style objStyle in objZoom.CustomStyles)
{
if (objLayer.IsVisible == true)
{
if (objStyle is TextStyle == false & objStyle is ValueStyle == false)
{
GeoImage objGeoImage = new GeoImage();
objGeoImage = SaveStyleImage(objCustomStyle);
if (objStyle.Name.Length != 0)
objLegendItem = BuildLegendItem(objStyle.Name + "(" + objLayer.Name + ")", objGeoImage);
else
objLegendItem = BuildLegendItem(objLayer.Name, objGeoImage);
objLegend.LegendItems.Add(objLegendItem);
}
}
}
}
}
}
}
}
}
objLegend.Height = GetLegendHeight(objLegend);
objLegend.Width = GetLegendWidth(objLegend);
return objLegend;
}
catch (Exception ex)
{
return null;
}
}
private LegendItem BuildLegendItem(string strItemName, GeoImage objGeoImage, int intLeftPadding = 0, bool blnImage = true)
{
try
{
LegendItem objLegendItem = new LegendItem();
GeoImage objImage = new GeoImage();
PointStyle objStyleImg = new PointStyle();
if (blnImage == true)
{
objImage = objGeoImage;
objStyleImg = new PointStyle(objImage);
objLegendItem.ImageStyle = objStyleImg;
}
objLegendItem.LeftPadding = intLeftPadding;
objLegendItem.TextStyle = new TextStyle(strItemName, new GeoFont("Arial", 8.5F, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
return objLegendItem;
}
catch (Exception ex)
{
return null;
}
}
private GeoImage SaveStyleImage(ThinkGeo.MapSuite.Styles.Style objStyle)
{
try
{
Bitmap objBMP = new Bitmap(14, 14);
RectangleShape objRec = new RectangleShape(0, 14, 14, 0);
DrawingRectangleF objRecF = new DrawingRectangleF(7, 7, 12, 12);
GeoImage objGeoImage = new GeoImage();
PlatformGeoCanvas objCanvas = new PlatformGeoCanvas();
objCanvas.BeginDrawing(objBMP, objRec, GeographyUnit.Feet);
objStyle.DrawSample(objCanvas, objRecF);
objCanvas.EndDrawing();
MemoryStream msStream = new MemoryStream();
objBMP.Save(msStream, System.Drawing.Imaging.ImageFormat.Tiff);
objGeoImage = new GeoImage(msStream);
return objGeoImage;
}
catch (Exception ex)
{
return null;
}
}
public int GetLegendHeight(LegendAdornmentLayer objLengend)
{
try
{
PlatformGeoCanvas objGDICanvas = new PlatformGeoCanvas();
int intTextHeight = (int)objLengend.Title.Height;// +(int)objLengend.Title.Height;
foreach (LegendItem objItem in objLengend.LegendItems)
{
int intHeight = (int)objGDICanvas.MeasureText(objItem.TextStyle.TextColumnName, objItem.TextStyle.Font).Height;
intTextHeight = intTextHeight + intHeight + intHeight;
}
if (intTextHeight != 0)
return intTextHeight;
else
return 100;
}
catch (Exception ex)
{
return 100;
}
}
public int GetLegendWidth(LegendAdornmentLayer objLegend)
{
try
{
PlatformGeoCanvas objGDICanvas = new PlatformGeoCanvas();
int intTextWidth = (int)objGDICanvas.MeasureText(objLegend.Title.TextStyle.TextColumnName, objLegend.Title.TextStyle.Font).Width;
foreach (LegendItem objItem in objLegend.LegendItems)
{
int intLength = (int)objGDICanvas.MeasureText(objItem.TextStyle.TextColumnName, objItem.TextStyle.Font).Width;
if (intLength > intTextWidth)
intTextWidth = intLength;
}
if (intTextWidth < 180 && (intTextWidth + 60) < 180)
return 180;
else if (intTextWidth != 0)
return intTextWidth + 60;
else
return 180;
}
catch (Exception ex)
{
return 180;
}
}
}
}
Default.apsx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %>
<%@ Register Assembly="ThinkGeo.MapSuite.WebForms" Namespace="ThinkGeo.MapSuite.WebForms" TagPrefix="cc1" %>
<div>
<cc1:Map ID="Map1" runat="server" Height="600px" Width="800px"></cc1:Map>
</div>
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<sessionState mode="StateServer" customProvider="DefaultSessionProvider" timeout="120" stateNetworkTimeout="20" >
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<httpHandlers>
<add path="*_GeoResource.axd" verb="*" type="ThinkGeo.MapSuite.WebForms.GeoResourceFactory" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="GeoResource" preCondition="integratedMode" path="*_GeoResource.axd" verb="*" type="ThinkGeo.MapSuite.WebForms.GeoResourceFactory" />
</handlers>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Thank you,
Neil