ThinkGeo.com    |     Documentation    |     Premium Support

Projection Error on Map

Just downloaded and installed the latest build, v3.1.0. I needed almost no changes to my source code (hooray!).


One of the main features of my app is to allow the user to select an item from a list and have it shown on the map. Each list item is a single shape file that I load via Ajax when the item is clicked.


This has worked reasonably well in the past (see some of my previous posts for problems we've worked through). In the latest build this has stopped working. The map zooms to the bounding box of the shape file in the expected location but in the upper left corner of the map this message appears: "The projection is not open. Please open it before calling this method."


I have stepped through the code an no exceptions are being generate in code. I looked through the samples and it doesn't seem that I need to explicitly call the projection's "Open" method.


Any ideas what might be causing this?


Bob Mc.



Further information: if I step through the source code slowly, i.e. one instruction at a time using F10 key in Visual Studio 2008, everything works, but only the first time through. All subsequent attempts produce the error result noted in the previous message. 
  
 If I let the code execute without stepping the problem occurs the first time through and every subsequent attempt. 
  
 Is this a timing issue? 
  
 Bob Mc.

Further further information: I’m also getting a lot of these errors on the map: 
 Exception has been thrown by the target of an invocation 
 Projection initialization failed. Parameter name internalProjectionParameters 
  
 Bob Mc.

Even more information: 
  
  
 I decided to try using FireFox 3.0.5 to see if I could use the JavaScript debugger to determine a code location. When I do that the code breaks on a call to the Feature.Open() method of a ShapeFileFeatureLayer object I’ve instantiated. The exception thrown is: 
  
 System.Reflection.TargetInvocationException was unhandled by user code 
   Message=“Exception has been thrown by the target of an invocation.” 
   Source=“mscorlib” 
   StackTrace: 
        at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
        at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)     
        at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)     
        at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)     
        at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)     
        at ThinkGeo.MapSuite.Core.Proj4Projection.xec88ebd758d8ecf7(String xc518b48efbd9149e)     
        at ThinkGeo.MapSuite.Core.Proj4Projection.OpenCore()     
        at ThinkGeo.MapSuite.Core.Projection.Open()     
        at ThinkGeo.MapSuite.Core.FeatureSource.Open()     
        <… application internal call stack here …> 
        at System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e)     
        at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)     
        at System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e)     
        at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)     
        at System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e)     
        at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)     
        at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)     
        at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)     
        at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)     
        at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)     
        at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)     
        at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
   InnerException: System.AccessViolationException 
        Message=“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” 
        Source=“Proj4ExtensionX86” 
        StackTrace: 
             at Proj4Extension.Proj4Extensionx86.pj_init(Int32 argc, String[] args)     
             at Proj4Extension.Proj4Extensionx86.Init(Int32 argc, String[] args) 
        InnerException:  
  
 Hope this helps, 
 
 
  
 Bob Mc. 


I’m implementing the new version and am receiving the exact same errors.

Bob,


We couldn’t recreate your issue, here we made a similar sample that works fine, hope it helps you with that problem.
 
Also by the way, how did you update to the latest version, uninstall the old one and reinstall the new one, or just get the latest assemblies and reference them. If you are using the latter way, please make sure you also copied some dlls, which includes our Raster and Projection engine, to System32 folder.
 
You can find a zip package under Developer Refence\System 32; please unzip it to C:\Windows\System32.


Any queries please let us know,


Ben

318-Post5134.zip (6.84 KB)

Guys, 
  
   Ben didn’t know that this is an open issue on the Web Edition dev team.  He might not have been able to re-create it but the developers can.  I has to do with Proj4 library which we use for our projection system.  The library is a C++ DLL and was not designed thread safe.  This mean in IIS when you get multiple thread there is a chance of corruption.  We had in the post put a bunch of locking on it and that prevented some of the exceptions however it still had problem eventually over time.  When you try it using the VS web server it doesn’t happen so it was hard for him to re-create. 
  
   Currently we have out C++ gurus on it to see if there are any changes to the library or some better way to do locking to prevent this.  It is a high priority issue for us.  If you have a requirement for a specific projection that you need done ASAP we can help you convert to using our other managed library projection that doesn’t have this problem.  The only issue with it is that it doesn’t take a EPSG codes so we need to lookup the parameter for it.  The interface isn’t as intuitive but it will work in IIS. 
  
   I estimate we will have a solution in before the Feb 9 2009 patch build.  Sorry for the inconvenience but we are working on it. 
  
 David

David, 
  
 Thanks for being forthright about this. I’m willing to temporarily switch to the other managed library until the problems are corrected. Please indicate how to proceed. 
  
 FYI, it does occur when using the VS 2008 web server. That’s where I’m seeing it. I’ll take a look at Ben’s code to see if I’m doing something incorrectly. 
  
 The only reason I’m using a projection is because I’m using Google Maps as a background for my map application. I was instructed to set the MapUnit to Meter and use… 
   
 Dim proj4 As New Proj4Projection(Proj4Projection.GetEpsgParametersString(4326), Proj4Projection.GetGoogleMapParametersString()) 
 
 
  
 …when adding layers to an overlay. Is this still the prescribed method? 
  
 Please advise on the workaround. 
  
 Bob Mc.

Bob, 
  
   No problem,  Ben would have told you if he knew, he is a good guy.  I must warn you though I can be optimistic about time lines, such is usually the case when one man promises and another has to deliver! 
  
   Ok, what we are going to do is use the MapSuiteCommon.dll which shipped in the 2.x version of MapSuite.  It is managed but was replaces by the better Proj4 library which isn’t working at the moment.  I will need to get a developer to setup the code to so I get the parameters right for Google’s projection.  I am pretty sure we can support this but I need to check.  Google’s projection, aka SRID 90013 is a bit non standard but I think we had someone use it before. 
  
   I will package up the DLL and the sample code and I or Ben will post it here for you.  It might take a bit to get the sample so expect it tomorrow morning. 
  
 Under normal circumstance, threading issue resolved, this would be the right way to use the projection library.  What I am going to provide will be similar but with no parameters because it will only work from decimal degrees to Google’s projection and back. 
  
 It would be good to check out Ben’s code just in case.  I know here some developers use Virtual machines and I think they only have once processor.  Then they use IIS on a real machine to do testing and I think this is when they re-create it.  It might be that it happens in the VS web if you have a dual core or hyper threading. 
  
 Please respond to this post so that it goes back into the queue and we can remember to post the code.  When a posts ends with our response it goes out of our work queue.  Things can get pretty busy around here in support.  With the new 3.x stuff it’s we seem to be attracting all kinds of new customers! 
  
 David

David, 
  
 I agree about Ben. He’s been extremely helpful to me regarding some prior issues with the betas. I have no problems with his assistance. 
  
 I checked out Ben’s code and it looks very similar to mine. I do have a multi-core development machine so this may cause the threading issue. 
   
 I’m anxiously awaiting the workaround. Thanks. 
  
 Bob Mc.

Bob,


I found out the our managed library doesn't support the Google Projection. I was able to get some word on making the Proj4 working. The developers have integrated some locking but it's hard to share the official build with you at this point.


They gave me this to hold you over and see if it solves your issue. It is a new class with implements locking on all of the main methods that call into Proj4. You have to love virtual methods! Use this instead of the Proj4Projection class. As this inherits from Proj4Projection the API is exactly the same. As you can see in the code it does a static lock. Just make sure you replace all of the Proj4Projection classes with this one or you will still get the error. Of course when the patch release comes out these kinds of changes will be rolled into the Proj4Projection and you will no longer need this.


Please let me know how this works for you.


David





    public class ThreadSafeProj4Projection : Proj4Projection
    {
        private static object lockObject = new object();

        protected override void OpenCore()
        {
            lock (lockObject)
            {
                base.OpenCore();
            }

        }

        protected override void CloseCore()
        {
            lock (lockObject)
            {
                base.CloseCore();
            }
        }

        protected override Vertex[] ConvertToExternalProjectionCore(double[] x, double[] y)
        {
            Vertex[] returnValue;
            lock (lockObject)
            {
                returnValue = base.ConvertToExternalProjectionCore(x, y);
            }
            return returnValue;
        }

        protected override Vertex[] ConvertToInternalProjectionCore(double[] x, double[] y)
        {
            Vertex[] returnValue;
            lock (lockObject)
            {
                returnValue = base.ConvertToInternalProjectionCore(x, y);
            }
            return returnValue;
        }
    }



Well, this doesn’t solve the problem. I get the same errors, but I can now trap them in code. 
  
 First off, my project is in VB.net. I’m fluent in both C# and VB so the conversion was not arduous. I’m posting it here so others may benefit and so your developers can review it for correctness. 
  
   
     Public Class ThreadSafeProj4Projection : Inherits Proj4Projection 
         Private Shared lockObject As Object = New Object() 
  
         Public Sub New() 
             MyBase.New() 
         End Sub 
  
         Public Sub New(ByVal internalProjectionParametersString As String, ByVal externalProjectionParametersString As String) 
             MyBase.New(internalProjectionParametersString, externalProjectionParametersString) 
         End Sub 
  
         Public Sub New(ByVal internalEpsgGrid As Integer, ByVal externalEpsgGrid As Integer) 
             MyBase.New(internalEpsgGrid, externalEpsgGrid) 
         End Sub 
  
         Protected Overrides Sub OpenCore() 
             SyncLock lockObject 
                 MyBase.OpenCore() 
             End SyncLock 
         End Sub 
  
         Protected Overrides Sub CloseCore() 
             SyncLock lockObject 
                 MyBase.CloseCore() 
             End SyncLock 
         End Sub 
  
         Protected Overrides Function ConvertToExternalProjectionCore(ByVal x() As Double, ByVal y() As Double) As Vertex() 
             Dim returnValue() As Vertex 
             SyncLock lockObject 
                 returnValue = MyBase.ConvertToExternalProjectionCore(x, y) 
             End SyncLock 
             Return returnValue 
         End Function 
  
         Protected Overrides Function ConvertToInternalProjectionCore(ByVal x() As Double, ByVal y() As Double) As Vertex() 
             Dim returnValue() As Vertex 
             SyncLock lockObject 
                 returnValue = MyBase.ConvertToInternalProjectionCore(x, y) 
             End SyncLock 
             Return returnValue 
         End Function 
     End Class 
 
 
  
 Second, I get an error in ConvertToInternalProjectionCore, within the SyncLock declaration, on  
   
 returnValue = MyBase.ConvertToInternalProjectionCore(x, y) 
 
 
  
 The error is: 
   
 System.Reflection.TargetInvocationException was unhandled by user code 
   Message=“Exception has been thrown by the target of an invocation.” 
   Source=“mscorlib” 
   StackTrace: 
        at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
     at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
     at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)    at ThinkGeo.MapSuite.Core.Proj4Projection.x95c4ca6342aad2f1(IntPtr xce536087faba9488, IntPtr x6d3e0b22c9356db3, Int64 x971ce686c8b74ac9, Double[] x31d531fc882737ba, Double[] x272f87fcdd19be88, Double[] xb5f5ca13f19c3e64) 
     at ThinkGeo.MapSuite.Core.Proj4Projection.ConvertToInternalProjectionCore(Double[] x, Double[] y) 
     at SMG.DMOE2.ThreadSafeProj4Projection.ConvertToInternalProjectionCore(Double[] x, Double[] y) in C:\Source\SMG\DMOE2\Web Source\DMOE\App_Code\MapHelpers.vb:line 157 
     at ThinkGeo.MapSuite.Core.Projection.ConvertToInternalProjection(RectangleShape rectangleShape) 
     at ThinkGeo.MapSuite.Core.FeatureSource.ConvertToInternalProjection(RectangleShape rectangle) 
     at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesInsideBoundingBox(RectangleShape boundingBox, IEnumerable`1 returningColumnNames) 
     at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesInsideBoundingBox(RectangleShape boundingBox, ReturningColumnsType returningColumnNamesType) 
     at ThinkGeo.MapSuite.WebEdition.InMemoryMarkerOverlay.GetMarkersCore(RectangleShape worldExtent, Int32 currentZoomLevelId)    at ThinkGeo.MapSuite.WebEdition.MarkerOverlay.GetMarkers(RectangleShape worldExtent, Int32 currentZoomLevelId) 
     at ThinkGeo.MapSuite.WebEdition.xc7cff1011d95a7ea.x3edbe401e632d8cc(MarkerOverlay x12602c8f059adbaf) 
     at ThinkGeo.MapSuite.WebEdition.xc7cff1011d95a7ea.x74301f6a6dff0247(HttpContext x367528c7f091a5d2) 
     at ThinkGeo.MapSuite.WebEdition.xc7cff1011d95a7ea.ProcessRequest(HttpContext context) 
     at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)    at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) 
     at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink) 
   InnerException: System.AccessViolationException 
        Message=“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” 
        Source=“Proj4ExtensionX86” 
        StackTrace: 
             at Proj4Extension.Proj4Extensionx86.pj_transform(IntPtr srcCs, IntPtr destCs, Int64 pointCount, Double[] x, Double[] y, Double[] z) 
     at Proj4Extension.Proj4Extensionx86.Transform(IntPtr srcCs, IntPtr destCs, Int64 pointCount, Double[] x, Double[] y, Double[] z) 
        InnerException:  
 
 
  
 I suppose I could add a Try…Catch block to trap it, but what do I do with it? Once the memory is corrupt I assume things are pretty well hosed. 
  
 I was hoping this workaround would solve the problem. Honestly, this is now causing some issues for me with my client. It’s quite embarassing for me. Is there any word on when a fix will be released? 
  
 Bob Mc. 


Bob, 
  
   We put a version that has additional locking and it has been updated on the website.  The code I gave you was to hold you over until we could get this new version our but I ended up posting over the weekend so you are getting it at the same time. 
  
 We are doing everythign we can on this. 
  
 David

Bob, 
    
   You are right at the point you get the error thngs are pretty well hosed and trapping will not help. 
  
 David

I downloaded v3.1.4 and, while it takes a bit longer, I still receive the corrupted memory error on the projection library. By "taking a bit longer" I mean that I had about five shape files loaded into the DynamicOverlay layers list. 
  
 Bob Mc.

Bob, 
  
   At this point I do not know.  The person working on that will not get back until Monday.  Can you explain a bit about how you are using it.  I mean I am not sure what you mean by I have 5 shape files loaded in the dynamic layers list.  How many total shape files do you have?  How any do you have loaded in each static and dynamic?  Are you adding or removing them on the fly?  Is it when you are refreshing?  Do you share one projetion class between the layers? 
  
 David

I'll give a brief explanation and some sample code.


I've written a web application in V2008/VB.Net. It's a fairly large app, and one of the pages is devoted to mapping. The page has a MapSuite WebEdition map control, two grids and some other textboxes, etc. Initially the map shows North America via a GoogleOverlay in the BackgroundOverlay object. At initialization I add a marker overlay for later plotting of geocoded addresses and a dynamic overlay of a shape file that we got from ThinkGeo, "countyp020.shp", to show U.S. county boundaries. The initialization code, called from the Page_Load when not in a Postback, looks like this:


Private Sub InitMap() 
    ctlMap.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#B3C6D4")) 
    ctlMap.CurrentExtent = New RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962) 
    ctlMap.MapUnit = GeographyUnit.Meter 
    ctlMap.MapTools.Logo.Enabled = False 
    ctlMap.MapTools.PanZoomBar.Enabled = True 

    'Create the google map overlay 
    Dim googleMap As New GoogleOverlay("Google Map") 
    Dim googleMapKey As String = "our Google Maps key is here"
    googleMap.JavaScriptLibraryUri = New Uri(googleMapKey) 
    googleMap.GoogleMapType = GoogleMapType.Normal 
    ctlMap.BackgroundOverlay = googleMap 

    ctlMap.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = New WebImage("../theme/default/img/marker.gif")
    ctlMap.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 
    ' Set the correct projection (Decimal Degrees to Google’s) 
    Dim proj4 As New ThreadSafeProj4Projection(ThreadSafeProj4Projection.GetEpsgParametersString(4326), ThreadSafeProj4Projection.GetGoogleMapParametersString()) 
    ctlMap.MarkerOverlay.FeatureSource.Projection = proj4 

    If Not DynamicOverlayLayerExists(COUNTY_LAYER_NAME) Then 
        Dim countyLayer As New ShapeFileFeatureLayer(DirMapPath & "countyp020.shp") 
        countyLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 
        countyLayer.ZoomLevelSet.ZoomLevel10.DefaultLineStyle = LineStyles.StateBorder1 
        countyLayer.ZoomLevelSet.ZoomLevel10.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(50, 233, 232, 214) 
        countyLayer.ZoomLevelSet.ZoomLevel10.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.DarkGray 
        Dim countyStyle As New TextStyle("COUNTY", New GeoFont("Arial", 9, DrawingFontStyles.Italic), New GeoSolidBrush(GeoColor.FromArgb(255, 0, 0, 255))) 
        countyLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle = countyStyle 
        countyLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.PointPlacement = PointPlacement.Center 
        countyLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping 
        countyLayer.Name = COUNTY_LAYER_NAME 
        countyLayer.DrawingQuality = DrawingQuality.HighQuality 
        countyLayer.FeatureSource.Projection = proj4 
        ctlMap.DynamicOverlay.Layers.Add(COUNTY_LAYER_NAME, countyLayer) 
    End If 
End Sub


The "DynamicOverlayLayerExists" method is something I wrote to check the names in the layers in the DynamicOverlay object to see if the specified layer exists. I needed this because earlier betas didn't have an "Exists" method in the object. This may have been improved in the latest releases but I haven't bothered to check.


The user then enters a search term into a text box and sees search results in a grid. No changes are made to the map. However, each of the search results is analagous to a shape file of the specific region represented by the search result. When the user clicks an item in the search results that shape file is loaded and shown on the map. They can do this for a number of regions and each shape file will get added to the map. The code that adds the shape files is shown here:


Private Sub AddRegion(ByVal regionNum As Integer, ByVal highlight As Boolean, ByVal setExtent As Boolean) 
    Dim regionLayer As ShapeFileFeatureLayer = Nothing 
    For Each shapeLayer As ShapeFileFeatureLayer In ctlMap.DynamicOverlay.Layers 
        If shapeLayer.Name = "R" & regionNum.ToString() Then 
            regionLayer = shapeLayer 
            Exit For 
        End If 
    Next 

    If regionLayer IsNot Nothing Then 
        regionLayer.IsVisible = True 
        If highlight Then 
            regionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(150, GeoColor.SimpleColors.Gold) 
        Else 
            regionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(50, GeoColor.SimpleColors.LightRed) 
        End If 
    Else 
        Dim regionNumStr As String = String.Format("{0:000000}", regionNum) 
        If File.Exists(MapPath & regionNumStr & ".shp") Then
            regionLayer = New ShapeFileFeatureLayer(MapPath & regionNumStr & ".shp") 
            regionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.FromArgb(255, GeoColor.SimpleColors.Black) 
            If highlight Then 
                regionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(150, GeoColor.SimpleColors.Gold) 
            Else 
                regionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(50, GeoColor.SimpleColors.LightRed) 
            End If 
            regionLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City1("REGIONID") 
            regionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 
            regionLayer.Name = "R" & regionNum.ToString() 
            Dim proj4 As New ThreadSafeProj4Projection(ThreadSafeProj4Projection.GetEpsgParametersString(4326), ThreadSafeProj4Projection.GetGoogleMapParametersString()) 
            regionLayer.FeatureSource.Projection = proj4 
            If setExtent Then 
                If Not regionLayer.FeatureSource.IsOpen Then
                    regionLayer.FeatureSource.Open() 
                End If 
                Dim feats As System.Collections.ObjectModel.Collection(Of Feature) = regionLayer.FeatureSource.GetAllFeatures(New String() {"REGIONID"})
                regionLayer.FeatureSource.Close() 
                ctlMap.CurrentExtent = feats(0).GetBoundingBox() 
            End If 
            regionLayer.Close() 
            ctlMap.DynamicOverlay.Layers.Add("R" & regionNum.ToString(), regionLayer) 
        End If 
    End If 

    ctlMap.DynamicOverlay.Redraw() 
End Sub 


After I get one or two shapes loaded I get the corrupted memory error on the projection. The latest build takes three or four shape file loads, but it still happens.


Would this problem go away if I use Yahoo Maps as the background? Is it specific to the projection required for Google Maps? Or do I need to do away with the background map altogether, which would be unfortunate.


Bob Mc


 


 



I need to have different shapefiles based on the zoom level (greater detail of municipality boundaries). 
 To solve the Projection issue, I just declared a projection object for each FeatureLayer with identical properties. 
 Problem solved. 
 Not elegant, but it works.

Kirk, I'm not sure what you mean by declaring a projection object for each FeatureLayer. I believe I'm already doing that (see code in my previous post) but maybe I'm missing something.


For each ShapeFileFeatureLayer I open, I declare a new projection with:



regionLayer = New ShapeFileFeatureLayer(MapPath & dirNumStr & ".shp")
'...other code
Dim proj4 As New ThreadSafeProj4Projection(ThreadSafeProj4Projection.GetEpsgParametersString(4326), ThreadSafeProj4Projection.GetGoogleMapParametersString())
dirLayer.FeatureSource.Projection = proj4

Is there something different that I can do? Some other projection in the FeatureSource that I can value?


Any assistance is greatly appreciated. Thanks.


Bob Mc



The only main difference I see is that I'm not using the thread safe version.


Here's the first of 4 similar declarations I'm using successfully:



Dim proj1 As New Proj4Projection()
      proj1.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326)
      proj1.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()